ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.376 by root, Sun Apr 18 07:08:08 2010 UTC vs.
Revision 1.388 by root, Wed Jun 30 01:57:54 2010 UTC

122 122
123 return sv; 123 return sv;
124} 124}
125#endif 125#endif
126 126
127static noinline utf8_string 127noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 128cfSvPVutf8_nolen (SV *sv)
129{ 129{
130 SvGETMAGIC (sv); 130 SvGETMAGIC (sv);
131 131
132 if (SvPOK (sv)) 132 if (SvPOK (sv))
352#endif 352#endif
353 353
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 354//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 355
356static SV * 356static SV *
357newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 357newSVptr (void *ptr, HV *stash, HV *hv)
358{ 358{
359 SV *sv;
360
361 if (!ptr) 359 if (!ptr)
362 return newSV (0); 360 return newSV (0);
363 361
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 362 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 363 return sv_bless (newRV_noinc ((SV *)hv), stash);
364}
365
366static SV * noinline
367newSVptr (void *ptr, HV *stash)
368{
369 return newSVptr (ptr, stash, newHV ());
366} 370}
367 371
368static int 372static int
369attachable_free (pTHX_ SV *sv, MAGIC *mg) 373attachable_free (pTHX_ SV *sv, MAGIC *mg)
370{ 374{
382 return 0; 386 return 0;
383} 387}
384 388
385MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 389MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
386 390
387static SV * 391static SV * noinline
388newSVattachable (attachable *obj, HV *stash) 392newSVattachable (attachable *obj, HV *stash)
389{ 393{
390 if (!obj) 394 if (!obj)
391 return newSV (0); 395 return newSV (0);
392 396
526static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 530static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
527static inline SV *to_sv (float v) { return newSVnv (v); } 531static inline SV *to_sv (float v) { return newSVnv (v); }
528static inline SV *to_sv (double v) { return newSVnv (v); } 532static inline SV *to_sv (double v) { return newSVnv (v); }
529static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 533static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
530static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 534static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
535// gcc dislikes noilnine on to_sv
531static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 536static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
537static inline SV *to_sv (object * v) { return to_sv_ni (v); }
532static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 538static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
533static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
534static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
535static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
536static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
764 exit (EXIT_FAILURE); 770 exit (EXIT_FAILURE);
765 } 771 }
766 772
767 eval_pv ( 773 eval_pv (
768 "#line 1 'cfperl init'\n" 774 "#line 1 'cfperl init'\n"
769 "use EV ();\n" 775 "use EV ();\n" // required by bootstrap
770 "use Coro ();\n" 776 "use Coro ();\n" // required by bootstrap
771 "cf->bootstrap;\n" 777 "cf->bootstrap;\n" // required for cf::datadir
772 "unshift @INC, cf::datadir ();\n" 778 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
773 "require cf;\n", 779 "require cf;\n",
774 0 780 0
775 ); 781 );
776 782
777 if (SvTRUE (ERRSV)) 783 if (SvTRUE (ERRSV))
1450# undef def 1456# undef def
1451# define def(uc, flags) const_iv (SK_ ## uc) 1457# define def(uc, flags) const_iv (SK_ ## uc)
1452# include "skillinc.h" 1458# include "skillinc.h"
1453# undef def 1459# undef def
1454 1460
1455 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1456 const_iv (logBacktrace)
1457
1458 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1459 1462
1460 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1461 1464
1462 const_iv (MAX_TIME) 1465 const_iv (MAX_TIME)
1488 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1489 1492
1490 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1493 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1491 }; 1494 };
1492 1495
1493 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1496 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1494 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1495 1498
1496 static const struct { 1499 static const struct {
1497 const char *name; 1500 const char *name;
1498 int skip; 1501 int skip;
1504# undef def 1507# undef def
1505 }; 1508 };
1506 1509
1507 AV *av = get_av ("cf::EVENT", 1); 1510 AV *av = get_av ("cf::EVENT", 1);
1508 1511
1509 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1512 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1510 { 1513 {
1511 AV *event = newAV (); 1514 AV *event = newAV ();
1512 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1513 av_push (event, newSViv (eiv->klass)); 1516 av_push (event, newSViv (eiv->klass));
1514 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1595 1598
1596void init_anim () 1599void init_anim ()
1597 1600
1598void init_globals () 1601void init_globals ()
1599 1602
1600void init_experience ()
1601
1602void init_attackmess () 1603void init_attackmess ()
1603 1604
1604void init_dynamic () 1605void init_dynamic ()
1605 1606
1606void load_settings () 1607void load_settings ()
1607 1608
1609void reload_exp_table ()
1610
1608void load_materials () 1611void reload_materials ()
1609 1612
1610void init_uuid () 1613void init_uuid ()
1611 CODE: 1614 CODE:
1612 UUID::init (); 1615 UUID::init ();
1613 1616
1883 CODE: 1886 CODE:
1884 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1885 OUTPUT: 1888 OUTPUT:
1886 RETVAL 1889 RETVAL
1887 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1888void 1896void
1889debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1890 CODE: 1898 CODE:
1891 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1892 if (on) 1900 if (on)
2078 2086
2079void pick_up (object *who, object *op) 2087void pick_up (object *who, object *op)
2080 2088
2081void update_object (object *op, int action) 2089void update_object (object *op, int action)
2082 2090
2083void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2091void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2084 2092
2085void player_lvl_adj (object *who, object *skill = 0) 2093void player_lvl_adj (object *who, object *skill = 0)
2086 2094
2087int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2095int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2088 2096
2453 if (oblinkpt *obp = map->find_link (connection)) 2461 if (oblinkpt *obp = map->find_link (connection))
2454 for (objectlink *ol = obp->link; ol; ol = ol->next) 2462 for (objectlink *ol = obp->link; ol; ol = ol->next)
2455 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2456 2464
2457void 2465void
2458get_map_flags (maptile *map, int x, int y) 2466xy_normalise (maptile *map, int x, int y, int dir = 0)
2459 PPCODE: 2467 PPCODE:
2460{ 2468{
2461 maptile *nmap = 0; 2469 mapxy pos (map, x, y);
2462 I16 nx = 0, ny = 0; 2470 if (!pos.move (dir).normalise ())
2471 XSRETURN_EMPTY;
2463 2472
2464 PUTBACK;
2465 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2466 SPAGAIN;
2467
2468 EXTEND (SP, 4); 2473 EXTEND (SP, 3);
2469 PUSHs (sv_2mortal (newSViv (flags)));
2470
2471 if (GIMME_V == G_ARRAY)
2472 {
2473 PUSHs (sv_2mortal (to_sv (nmap))); 2474 PUSHs (sv_2mortal (to_sv (pos.m)));
2474 PUSHs (sv_2mortal (newSViv (nx))); 2475 PUSHs (sv_2mortal (to_sv (pos.x)));
2475 PUSHs (sv_2mortal (newSViv (ny))); 2476 PUSHs (sv_2mortal (to_sv (pos.y)));
2476 }
2477} 2477}
2478 2478
2479mapspace * 2479mapspace *
2480ms (maptile *map, unsigned int x, unsigned int y) 2480ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2481 PROTOTYPE: $$$ 2481 PROTOTYPE: $$$;$
2482 CODE: 2482 CODE:
2483{ 2483{
2484 maptile *nmap = 0; 2484 mapxy pos (map, x, y);
2485 I16 nx, ny; 2485 if (!pos.move (dir).normalise ())
2486
2487 PUTBACK;
2488 get_map_flags (map, &nmap, x, y, &nx, &ny);
2489 SPAGAIN;
2490
2491 if (!nmap)
2492 XSRETURN_UNDEF; 2486 XSRETURN_UNDEF;
2493 2487
2494 RETVAL = &nmap->at (nx, ny); 2488 RETVAL = &*pos;
2495} 2489}
2496 OUTPUT: 2490 OUTPUT:
2497 RETVAL 2491 RETVAL
2498 2492
2499void 2493void
2500at (maptile *map, unsigned int x, unsigned int y) 2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2501 PROTOTYPE: $$$ 2495 PROTOTYPE: $$$;$
2502 PPCODE: 2496 PPCODE:
2503{ 2497 mapxy pos (map, x, y);
2504 maptile *nmap = 0; 2498 if (pos.move (dir).normalise ())
2505 I16 nx, ny;
2506
2507 PUTBACK;
2508 get_map_flags (map, &nmap, x, y, &nx, &ny);
2509 SPAGAIN;
2510
2511 if (nmap)
2512 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2499 for (object *o = pos->bot; o; o = o->above)
2513 XPUSHs (sv_2mortal (to_sv (o))); 2500 XPUSHs (sv_2mortal (to_sv (o)));
2514}
2515 2501
2516SV * 2502SV *
2517bot_at (maptile *map, unsigned int x, unsigned int y) 2503bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2518 PROTOTYPE: $$$ 2504 PROTOTYPE: $$$;$
2519 ALIAS: 2505 ALIAS:
2520 top_at = 1 2506 top_at = 1
2521 flags_at = 2 2507 flags_at = 2
2522 light_at = 3 2508 light_at = 3
2523 move_block_at = 4 2509 move_block_at = 4
2524 move_slow_at = 5 2510 move_slow_at = 5
2525 move_on_at = 6 2511 move_on_at = 6
2526 move_off_at = 7 2512 move_off_at = 7
2527 CODE: 2513 CODE:
2528{ 2514{
2529 sint16 nx = x; 2515 mapxy pos (map, x, y);
2530 sint16 ny = y; 2516 if (!pos.move (dir).normalise ())
2531
2532 if (!xy_normalise (map, nx, ny))
2533 XSRETURN_UNDEF; 2517 XSRETURN_UNDEF;
2534 2518
2535 mapspace &ms = map->at (nx, ny); 2519 mapspace &ms = *pos;
2536 2520
2537 ms.update (); 2521 ms.update ();
2538 2522
2539 switch (ix) 2523 switch (ix)
2540 { 2524 {
2552 2536
2553# worst xs function of my life 2537# worst xs function of my life
2554bool 2538bool
2555_create_random_map (\ 2539_create_random_map (\
2556 maptile *self,\ 2540 maptile *self,\
2557 utf8_string wallstyle,\ 2541 SV *options,\
2558 utf8_string wall_name,\
2559 utf8_string floorstyle,\
2560 utf8_string monsterstyle,\
2561 utf8_string treasurestyle,\
2562 utf8_string layoutstyle,\
2563 utf8_string doorstyle,\
2564 utf8_string decorstyle,\
2565 utf8_string miningstyle,\
2566 utf8_string origin_map,\
2567 utf8_string final_map,\
2568 utf8_string exitstyle,\
2569 utf8_string this_map,\
2570 utf8_string exit_on_final_map,\
2571 int xsize,\
2572 int ysize,\
2573 int expand2x,\
2574 int layoutoptions1,\
2575 int layoutoptions2,\
2576 int layoutoptions3,\
2577 int symmetry,\
2578 int difficulty,\
2579 int difficulty_given,\
2580 float difficulty_increase,\
2581 int dungeon_level,\
2582 int dungeon_depth,\
2583 int decoroptions,\
2584 int orientation,\
2585 int origin_y,\
2586 int origin_x,\
2587 U32 random_seed,\
2588 val64 total_map_hp,\ 2542 val64 total_map_hp,\
2589 int map_layout_style,\
2590 int treasureoptions,\
2591 int symmetry_used,\
2592 region *region,\ 2543 region *region\
2593 utf8_string custom\
2594) 2544)
2595 CODE: 2545 CODE:
2596{ 2546{
2597 random_map_params rmp; 2547 random_map_params rmp;
2598 2548
2599 assign (rmp.wallstyle , wallstyle); 2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2600 assign (rmp.wall_name , wall_name); 2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2601 assign (rmp.floorstyle , floorstyle);
2602 assign (rmp.monsterstyle , monsterstyle); 2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2603 assign (rmp.treasurestyle , treasurestyle);
2604 assign (rmp.layoutstyle , layoutstyle); 2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2605 assign (rmp.doorstyle , doorstyle); 2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2606 assign (rmp.decorstyle , decorstyle);
2607 assign (rmp.miningstyle , miningstyle);
2608 assign (rmp.exitstyle , exitstyle);
2609 assign (rmp.exit_on_final_map, exit_on_final_map); 2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2610 2556
2611 rmp.origin_map = origin_map; 2557 rmp.origin_map = rmp.get_str ("origin_map");
2558 rmp.origin_x = rmp.get_iv ("origin_x");
2559 rmp.origin_y = rmp.get_iv ("origin_y");
2612 rmp.final_map = final_map; 2560 rmp.final_map = rmp.get_str ("final_map");
2613 rmp.this_map = this_map; 2561 rmp.this_map = rmp.get_str ("this_map");
2614 rmp.xsize = xsize; 2562 rmp.xsize = rmp.get_iv ("xsize");
2615 rmp.ysize = ysize; 2563 rmp.ysize = rmp.get_iv ("ysize");
2616 rmp.expand2x = expand2x; 2564 rmp.expand2x = rmp.get_iv ("expand2x");
2617 rmp.layoutoptions1 = layoutoptions1; 2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2618 rmp.layoutoptions2 = layoutoptions2; 2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2619 rmp.layoutoptions3 = layoutoptions3; 2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2620 rmp.symmetry = symmetry; 2568 rmp.symmetry = rmp.get_iv ("symmetry");
2621 rmp.difficulty = difficulty; 2569 rmp.difficulty = rmp.get_iv ("difficulty");
2622 rmp.difficulty_given = difficulty_given; 2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2623 rmp.difficulty_increase = difficulty_increase; 2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2624 rmp.dungeon_level = dungeon_level; 2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2625 rmp.dungeon_depth = dungeon_depth; 2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2626 rmp.decoroptions = decoroptions;
2627 rmp.orientation = orientation; 2574 rmp.orientation = rmp.get_iv ("orientation");
2628 rmp.origin_y = origin_y;
2629 rmp.origin_x = origin_x;
2630 rmp.random_seed = random_seed; 2575 rmp.random_seed = rmp.get_uv ("random_seed");
2631 rmp.total_map_hp = (uint64_t) total_map_hp; 2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2632 rmp.map_layout_style = map_layout_style; 2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2633 rmp.treasureoptions = treasureoptions;
2634 rmp.symmetry_used = symmetry_used; 2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2635 rmp.region = region; 2579 rmp.region = region;
2636 rmp.custom = custom;
2637 2580
2638 RETVAL = self->generate_random_map (&rmp); 2581 RETVAL = self->generate_random_map (&rmp);
2639} 2582}
2640 OUTPUT: 2583 OUTPUT:
2641 RETVAL 2584 RETVAL
2673void 2616void
2674list () 2617list ()
2675 PPCODE: 2618 PPCODE:
2676 for_all_regions (rgn) 2619 for_all_regions (rgn)
2677 XPUSHs (sv_2mortal (to_sv (rgn))); 2620 XPUSHs (sv_2mortal (to_sv (rgn)));
2678
2679region *find (utf8_string name)
2680 PROTOTYPE: $
2681 CODE:
2682 RETVAL = region::find (name);
2683 OUTPUT: RETVAL
2684 2621
2685int specificity (region *rgn) 2622int specificity (region *rgn)
2686 CODE: 2623 CODE:
2687 RETVAL = 0; 2624 RETVAL = 0;
2688 while (rgn = rgn->parent) 2625 while (rgn = rgn->parent)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines