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.384 by root, Fri Apr 30 21:00:40 2010 UTC vs.
Revision 1.398 by root, Fri Feb 25 08:34:19 2011 UTC

28 28
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "../random_maps/random_map.h" 33#include "rmg.h"
34#include "evthread.h" 34#include "evthread.h"
35#include "sproto.h" 35#include "sproto.h"
36 36
37#include <unistd.h> 37#include <unistd.h>
38#if _POSIX_MEMLOCK 38#if _POSIX_MEMLOCK
84 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
88 *stash_cf_living_wrap, 88 *stash_cf_living_wrap,
89 *stash_cf_layout_wrap,
89 *stash_ext_map_world; 90 *stash_ext_map_world;
90 91
91static SV 92static SV
92 *cv_cf_do_invoke, 93 *cv_cf_do_invoke,
93 *cv_cf__can_merge, 94 *cv_cf__can_merge,
122 123
123 return sv; 124 return sv;
124} 125}
125#endif 126#endif
126 127
127static noinline utf8_string 128noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 129cfSvPVutf8_nolen (SV *sv)
129{ 130{
130 SvGETMAGIC (sv); 131 SvGETMAGIC (sv);
131 132
132 if (SvPOK (sv)) 133 if (SvPOK (sv))
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 355//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 356
356static SV * 357static SV *
357newSVptr (void *ptr, HV *stash, HV *hv) 358newSVptr (void *ptr, HV *stash, HV *hv)
358{ 359{
359 SV *sv;
360
361 if (!ptr) 360 if (!ptr)
362 return newSV (0); 361 return newSV (0);
363 362
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 364 return sv_bless (newRV_noinc ((SV *)hv), stash);
366} 365}
367 366
368static SV * 367static SV * noinline
369newSVptr (void *ptr, HV *stash) 368newSVptr (void *ptr, HV *stash)
370{ 369{
371 return newSVptr (ptr, stash, newHV ()); 370 return newSVptr (ptr, stash, newHV ());
372} 371}
373 372
388 return 0; 387 return 0;
389} 388}
390 389
391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 390MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
392 391
393static SV * 392static SV * noinline
394newSVattachable (attachable *obj, HV *stash) 393newSVattachable (attachable *obj, HV *stash)
395{ 394{
396 if (!obj) 395 if (!obj)
397 return newSV (0); 396 return newSV (0);
398 397
532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 531static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
533static inline SV *to_sv (float v) { return newSVnv (v); } 532static inline SV *to_sv (float v) { return newSVnv (v); }
534static inline SV *to_sv (double v) { return newSVnv (v); } 533static inline SV *to_sv (double v) { return newSVnv (v); }
535static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 534static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 535static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
536// gcc dislikes noilnine on to_sv
537static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 537static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
538static inline SV *to_sv (object * v) { return to_sv_ni (v); }
538static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 539static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 540static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 541static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 542static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 543static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
543static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 544static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
545static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
544 546
545static inline SV *to_sv (object & v) { return to_sv (&v); } 547static inline SV *to_sv (object & v) { return to_sv (&v); }
546static inline SV *to_sv (living & v) { return to_sv (&v); } 548static inline SV *to_sv (living & v) { return to_sv (&v); }
547 549
548static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 550static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 596static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 597static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 598static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 599static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 600static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
601static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
599static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 602static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
600static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 603static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
601 604
602//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 605//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
603static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 606static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1403 1407
1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1408 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1409 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1410 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1455# include "attackinc.h" 1459# include "attackinc.h"
1456# undef def 1460# undef def
1457# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1458# include "skillinc.h" 1462# include "skillinc.h"
1459# undef def 1463# undef def
1460 1464# define def(name, use, nonuse) const_iv (body_ ## name)
1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1465# include "slotinc.h"
1466# undef def
1462 1467
1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1468 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1464 1469
1465 const_iv (MAX_TIME) 1470 const_iv (MAX_TIME)
1466 const_iv (MAXSOCKBUF) 1471 const_iv (MAXSOCKBUF)
1598 1603
1599void init_anim () 1604void init_anim ()
1600 1605
1601void init_globals () 1606void init_globals ()
1602 1607
1603void init_experience ()
1604
1605void init_attackmess () 1608void init_attackmess ()
1606 1609
1607void init_dynamic () 1610void init_dynamic ()
1608 1611
1609void load_settings () 1612void load_settings ()
1610 1613
1614void reload_exp_table ()
1615
1611void load_materials () 1616void reload_materials ()
1612 1617
1613void init_uuid () 1618void init_uuid ()
1614 CODE: 1619 CODE:
1615 UUID::init (); 1620 UUID::init ();
1616 1621
1771 1776
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1777int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1778 INIT:
1774#if __GLIBC__ 1779#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1780 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1782 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1783 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1785#endif
1780 1786
1781int munlockall () 1787int munlockall ()
1782 1788
1783#endif 1789#endif
1821int exp_to_level (val64 exp) 1827int exp_to_level (val64 exp)
1822 1828
1823val64 level_to_min_exp (int level) 1829val64 level_to_min_exp (int level)
1824 1830
1825SV * 1831SV *
1826resistance_to_string (int atnr) 1832attacktype_name (int atnr)
1827 CODE: 1833 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1835 ? newSVpv (attacktype_name [atnr], 0)
1836 : &PL_sv_undef;
1837 OUTPUT: RETVAL
1838
1839SV *
1840attacktype_desc (int atnr)
1841 CODE:
1842 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1843 ? newSVpv (attacktype_desc [atnr], 0)
1844 : &PL_sv_undef;
1845 OUTPUT: RETVAL
1846
1847SV *
1848resist_plus (int atnr)
1849 CODE:
1850 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1851 ? newSVpv (resist_plus [atnr], 0)
1830 else 1852 : &PL_sv_undef;
1831 XSRETURN_UNDEF; 1853 OUTPUT: RETVAL
1854
1855SV *
1856change_resist_msg (int atnr)
1857 CODE:
1858 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1859 ? newSVpv (change_resist_msg [atnr], 0)
1860 : &PL_sv_undef;
1832 OUTPUT: RETVAL 1861 OUTPUT: RETVAL
1833 1862
1834UUID 1863UUID
1835uuid_cur () 1864uuid_cur ()
1836 CODE: 1865 CODE:
1959int mortals_size () 1988int mortals_size ()
1960 CODE: 1989 CODE:
1961 RETVAL = attachable::mortals.size (); 1990 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1991 OUTPUT: RETVAL
1963 1992
1964const_utf8_string slot_use_name (U32 slot) 1993const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1994 ALIAS:
1995 slot_name = 0
1996 slot_use_name = 1
1966 slot_nonuse_name = 1 1997 slot_nonuse_name = 2
1967 CODE: 1998 CODE:
1968{ 1999{
1969 if (slot >= NUM_BODY_LOCATIONS) 2000 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 2001 croak ("body slot index out of range");
1971 2002
1972 switch (ix) 2003 switch (ix)
1973 { 2004 {
2005 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 2006 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 2007 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 2008 }
1977} 2009}
1978 OUTPUT: 2010 OUTPUT:
1979 RETVAL 2011 RETVAL
1980 2012
2445 for (int x = 0; x < THIS->width; ++x) 2477 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2478 for (int y = 0; y < THIS->height; ++y)
2447 { 2479 {
2448 region *rgn = THIS->region (x, y); 2480 region *rgn = THIS->region (x, y);
2449 2481
2450 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2451 if (object *op = THIS->at (x, y).top) 2482 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2483 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2484 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2485 }
2455 2486
2534} 2565}
2535 OUTPUT: RETVAL 2566 OUTPUT: RETVAL
2536 2567
2537# worst xs function of my life 2568# worst xs function of my life
2538bool 2569bool
2539_create_random_map (\ 2570_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 utf8_string wallstyle,\
2542 utf8_string wall_name,\
2543 utf8_string floorstyle,\
2544 utf8_string monsterstyle,\
2545 utf8_string treasurestyle,\
2546 utf8_string layoutstyle,\
2547 utf8_string doorstyle,\
2548 utf8_string decorstyle,\
2549 utf8_string miningstyle,\
2550 utf8_string origin_map,\
2551 utf8_string final_map,\
2552 utf8_string exitstyle,\
2553 utf8_string this_map,\
2554 utf8_string exit_on_final_map,\
2555 int xsize,\
2556 int ysize,\
2557 int expand2x,\
2558 int layoutoptions1,\
2559 int layoutoptions2,\
2560 int layoutoptions3,\
2561 int symmetry,\
2562 int difficulty,\
2563 int difficulty_given,\
2564 float difficulty_increase,\
2565 int dungeon_level,\
2566 int dungeon_depth,\
2567 int decoroptions,\
2568 int orientation,\
2569 int origin_y,\
2570 int origin_x,\
2571 U32 random_seed,\
2572 val64 total_map_hp,\
2573 int map_layout_style,\
2574 int treasureoptions,\
2575 int symmetry_used,\
2576 region *region,\
2577 utf8_string custom\
2578)
2579 CODE: 2571 CODE:
2580{ 2572{
2581 random_map_params rmp; 2573 random_map_params rmp ((HV *)SvRV (options));
2582
2583 assign (rmp.wallstyle , wallstyle);
2584 assign (rmp.wall_name , wall_name);
2585 assign (rmp.floorstyle , floorstyle);
2586 assign (rmp.monsterstyle , monsterstyle);
2587 assign (rmp.treasurestyle , treasurestyle);
2588 assign (rmp.layoutstyle , layoutstyle);
2589 assign (rmp.doorstyle , doorstyle);
2590 assign (rmp.decorstyle , decorstyle);
2591 assign (rmp.miningstyle , miningstyle);
2592 assign (rmp.exitstyle , exitstyle);
2593 assign (rmp.exit_on_final_map, exit_on_final_map);
2594
2595 rmp.origin_map = origin_map;
2596 rmp.final_map = final_map;
2597 rmp.this_map = this_map;
2598 rmp.xsize = xsize;
2599 rmp.ysize = ysize;
2600 rmp.expand2x = expand2x;
2601 rmp.layoutoptions1 = layoutoptions1;
2602 rmp.layoutoptions2 = layoutoptions2;
2603 rmp.layoutoptions3 = layoutoptions3;
2604 rmp.symmetry = symmetry;
2605 rmp.difficulty = difficulty;
2606 rmp.difficulty_given = difficulty_given;
2607 rmp.difficulty_increase = difficulty_increase;
2608 rmp.dungeon_level = dungeon_level;
2609 rmp.dungeon_depth = dungeon_depth;
2610 rmp.decoroptions = decoroptions;
2611 rmp.orientation = orientation;
2612 rmp.origin_y = origin_y;
2613 rmp.origin_x = origin_x;
2614 rmp.random_seed = random_seed;
2615 rmp.total_map_hp = (uint64_t) total_map_hp;
2616 rmp.map_layout_style = map_layout_style;
2617 rmp.treasureoptions = treasureoptions;
2618 rmp.symmetry_used = symmetry_used;
2619 rmp.region = region;
2620 rmp.custom = custom;
2621
2622 RETVAL = self->generate_random_map (&rmp); 2574 RETVAL = self->generate_random_map (&rmp);
2623} 2575}
2624 OUTPUT: 2576 OUTPUT:
2625 RETVAL 2577 RETVAL
2626 2578
2798 2750
2799void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2751void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2800 CODE: 2752 CODE:
2801{ 2753{
2802 faceinfo *f = face_info (idx); assert (f); 2754 faceinfo *f = face_info (idx); assert (f);
2803 facedata *d = &(faceset ? f->data64 : f->data32); 2755 facedata *d = f->face + faceset;
2804 sv_to (data, d->data); 2756 sv_to (data, d->data);
2805 STRLEN clen; 2757 STRLEN clen;
2806 char *cdata = SvPVbyte (chksum, clen); 2758 char *cdata = SvPVbyte (chksum, clen);
2807 clen = min (CHKSUM_MAXLEN, clen); 2759 clen = min (CHKSUM_MAXLEN, clen);
2808 2760
2960 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2912 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2961 2913
2962 self->skip (); 2914 self->skip ();
2963 } 2915 }
2964 2916
2917MODULE = cf PACKAGE = cf::layout
2918
2919INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2920

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines