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.388 by root, Wed Jun 30 01:57:54 2010 UTC vs.
Revision 1.399 by root, Fri Apr 22 02:03:12 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,
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)
1550 for_all_clients (ns) 1555 for_all_clients (ns)
1551 ns->reattach (); 1556 ns->reattach ();
1552 1557
1553 for_all_objects (op) 1558 for_all_objects (op)
1554 op->reattach (); 1559 op->reattach ();
1555}
1556
1557# support function for map-world.ext
1558void _quantise (SV *data_sv, SV *plt_sv)
1559 CODE:
1560{
1561 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1562 croak ("_quantise called with invalid agruments");
1563
1564 plt_sv = SvRV (plt_sv);
1565 SV **plt = AvARRAY (plt_sv);
1566 int plt_count = AvFILL (plt_sv) + 1;
1567
1568 STRLEN len;
1569 char *data = SvPVbyte (data_sv, len);
1570 char *dst = data;
1571
1572 while (len >= 3)
1573 {
1574 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1575 {
1576 char *val = SvPVX (*val_sv);
1577
1578 if (val [0] == data [0]
1579 && val [1] == data [1]
1580 && val [2] == data [2])
1581 {
1582 *dst++ = val [3];
1583 goto next;
1584 }
1585 }
1586
1587 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1588 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1589 dst - SvPVX (data_sv), len);
1590
1591 next:
1592 data += 3;
1593 len -= 3;
1594 }
1595
1596 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1597} 1560}
1598 1561
1599void init_anim () 1562void init_anim ()
1600 1563
1601void init_globals () 1564void init_globals ()
1771 1734
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1735int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1736 INIT:
1774#if __GLIBC__ 1737#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1738 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1739 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1740 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1741 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1742 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1743#endif
1780 1744
1781int munlockall () 1745int munlockall ()
1782 1746
1783#endif 1747#endif
1821int exp_to_level (val64 exp) 1785int exp_to_level (val64 exp)
1822 1786
1823val64 level_to_min_exp (int level) 1787val64 level_to_min_exp (int level)
1824 1788
1825SV * 1789SV *
1826resistance_to_string (int atnr) 1790attacktype_name (int atnr)
1827 CODE: 1791 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1792 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1793 ? newSVpv (attacktype_name [atnr], 0)
1794 : &PL_sv_undef;
1795 OUTPUT: RETVAL
1796
1797SV *
1798attacktype_desc (int atnr)
1799 CODE:
1800 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1801 ? newSVpv (attacktype_desc [atnr], 0)
1802 : &PL_sv_undef;
1803 OUTPUT: RETVAL
1804
1805SV *
1806resist_plus (int atnr)
1807 CODE:
1808 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1809 ? newSVpv (resist_plus [atnr], 0)
1830 else 1810 : &PL_sv_undef;
1831 XSRETURN_UNDEF; 1811 OUTPUT: RETVAL
1812
1813SV *
1814change_resist_msg (int atnr)
1815 CODE:
1816 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1817 ? newSVpv (change_resist_msg [atnr], 0)
1818 : &PL_sv_undef;
1832 OUTPUT: RETVAL 1819 OUTPUT: RETVAL
1833 1820
1834UUID 1821UUID
1835uuid_cur () 1822uuid_cur ()
1836 CODE: 1823 CODE:
1959int mortals_size () 1946int mortals_size ()
1960 CODE: 1947 CODE:
1961 RETVAL = attachable::mortals.size (); 1948 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1949 OUTPUT: RETVAL
1963 1950
1964const_utf8_string slot_use_name (U32 slot) 1951const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1952 ALIAS:
1953 slot_name = 0
1954 slot_use_name = 1
1966 slot_nonuse_name = 1 1955 slot_nonuse_name = 2
1967 CODE: 1956 CODE:
1968{ 1957{
1969 if (slot >= NUM_BODY_LOCATIONS) 1958 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 1959 croak ("body slot index out of range");
1971 1960
1972 switch (ix) 1961 switch (ix)
1973 { 1962 {
1963 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 1964 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1965 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 1966 }
1977} 1967}
1978 OUTPUT: 1968 OUTPUT:
1979 RETVAL 1969 RETVAL
1980 1970
2445 for (int x = 0; x < THIS->width; ++x) 2435 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2436 for (int y = 0; y < THIS->height; ++y)
2447 { 2437 {
2448 region *rgn = THIS->region (x, y); 2438 region *rgn = THIS->region (x, y);
2449 2439
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) 2440 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2441 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2442 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2443 }
2455 2444
2534} 2523}
2535 OUTPUT: RETVAL 2524 OUTPUT: RETVAL
2536 2525
2537# worst xs function of my life 2526# worst xs function of my life
2538bool 2527bool
2539_create_random_map (\ 2528_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 SV *options,\
2542 val64 total_map_hp,\
2543 region *region\
2544)
2545 CODE: 2529 CODE:
2546{ 2530{
2547 random_map_params rmp; 2531 random_map_params rmp ((HV *)SvRV (options));
2548
2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2556
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");
2560 rmp.final_map = rmp.get_str ("final_map");
2561 rmp.this_map = rmp.get_str ("this_map");
2562 rmp.xsize = rmp.get_iv ("xsize");
2563 rmp.ysize = rmp.get_iv ("ysize");
2564 rmp.expand2x = rmp.get_iv ("expand2x");
2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2568 rmp.symmetry = rmp.get_iv ("symmetry");
2569 rmp.difficulty = rmp.get_iv ("difficulty");
2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2574 rmp.orientation = rmp.get_iv ("orientation");
2575 rmp.random_seed = rmp.get_uv ("random_seed");
2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2579 rmp.region = region;
2580
2581 RETVAL = self->generate_random_map (&rmp); 2532 RETVAL = self->generate_random_map (&rmp);
2582} 2533}
2583 OUTPUT: 2534 OUTPUT:
2584 RETVAL 2535 RETVAL
2585 2536
2757 2708
2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2709void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2759 CODE: 2710 CODE:
2760{ 2711{
2761 faceinfo *f = face_info (idx); assert (f); 2712 faceinfo *f = face_info (idx); assert (f);
2762 facedata *d = &(faceset ? f->data64 : f->data32); 2713 facedata *d = f->face + faceset;
2763 sv_to (data, d->data); 2714 sv_to (data, d->data);
2764 STRLEN clen; 2715 STRLEN clen;
2765 char *cdata = SvPVbyte (chksum, clen); 2716 char *cdata = SvPVbyte (chksum, clen);
2766 clen = min (CHKSUM_MAXLEN, clen); 2717 clen = min (CHKSUM_MAXLEN, clen);
2767 2718
2919 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2870 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2920 2871
2921 self->skip (); 2872 self->skip ();
2922 } 2873 }
2923 2874
2875MODULE = cf PACKAGE = cf::layout
2876
2877INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2878

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines