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.375 by root, Sun Apr 18 05:08:14 2010 UTC vs.
Revision 1.397 by root, Tue Jan 25 22:39:54 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
83 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
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,
90 *stash_ext_map_world;
89 91
90static SV 92static SV
91 *cv_cf_do_invoke, 93 *cv_cf_do_invoke,
92 *cv_cf__can_merge, 94 *cv_cf__can_merge,
93 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
121 123
122 return sv; 124 return sv;
123} 125}
124#endif 126#endif
125 127
126static noinline utf8_string 128noinline utf8_string
127cfSvPVutf8_nolen (SV *sv) 129cfSvPVutf8_nolen (SV *sv)
128{ 130{
129 SvGETMAGIC (sv); 131 SvGETMAGIC (sv);
130 132
131 if (SvPOK (sv)) 133 if (SvPOK (sv))
351#endif 353#endif
352 354
353////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 355//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 356
355static SV * 357static SV *
356newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 358newSVptr (void *ptr, HV *stash, HV *hv)
357{ 359{
358 SV *sv;
359
360 if (!ptr) 360 if (!ptr)
361 return newSV (0); 361 return newSV (0);
362 362
363 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);
364 return sv_bless (newRV_noinc ((SV *)hv), stash); 364 return sv_bless (newRV_noinc ((SV *)hv), stash);
365}
366
367static SV * noinline
368newSVptr (void *ptr, HV *stash)
369{
370 return newSVptr (ptr, stash, newHV ());
365} 371}
366 372
367static int 373static int
368attachable_free (pTHX_ SV *sv, MAGIC *mg) 374attachable_free (pTHX_ SV *sv, MAGIC *mg)
369{ 375{
381 return 0; 387 return 0;
382} 388}
383 389
384MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 390MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
385 391
386static SV * 392static SV * noinline
387newSVattachable (attachable *obj, HV *stash) 393newSVattachable (attachable *obj, HV *stash)
388{ 394{
389 if (!obj) 395 if (!obj)
390 return newSV (0); 396 return newSV (0);
391 397
488{ 494{
489 if (expect_false (!SvOK (sv))) return 0; 495 if (expect_false (!SvOK (sv))) return 0;
490 496
491 if (!SvROK (sv) 497 if (!SvROK (sv)
492 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap 498 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
499 && SvSTASH (SvRV (sv)) != stash_ext_map_world
493 && !sv_derived_from (sv, "cf::map"))) 500 && !sv_derived_from (sv, "cf::map")))
494 croak ("object of type cf::map expected"); 501 croak ("object of type cf::map expected");
495 502
496 return SvPTR_nc (sv); 503 return SvPTR_nc (sv);
497} 504}
524static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 531static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
525static inline SV *to_sv (float v) { return newSVnv (v); } 532static inline SV *to_sv (float v) { return newSVnv (v); }
526static inline SV *to_sv (double v) { return newSVnv (v); } 533static inline SV *to_sv (double v) { return newSVnv (v); }
527static 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); }
528static 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
529static 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); }
530static 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); }
531static 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); }
532static 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); }
533static 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); }
534static 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); }
535static 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); }
536 546
537static inline SV *to_sv (object & v) { return to_sv (&v); } 547static inline SV *to_sv (object & v) { return to_sv (&v); }
538static inline SV *to_sv (living & v) { return to_sv (&v); } 548static inline SV *to_sv (living & v) { return to_sv (&v); }
539 549
540static 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 ()); }
586static 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"); }
587static 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"); }
588static 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"); }
589static 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"); }
590static 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"); }
591static 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"); }
592static 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" ); }
593 604
594//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)]; }
595static 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)); }
762 exit (EXIT_FAILURE); 773 exit (EXIT_FAILURE);
763 } 774 }
764 775
765 eval_pv ( 776 eval_pv (
766 "#line 1 'cfperl init'\n" 777 "#line 1 'cfperl init'\n"
767 "use EV ();\n" 778 "use EV ();\n" // required by bootstrap
768 "use Coro ();\n" 779 "use Coro ();\n" // required by bootstrap
769 "cf->bootstrap;\n" 780 "cf->bootstrap;\n" // required for cf::datadir
770 "unshift @INC, cf::datadir ();\n" 781 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
771 "require cf;\n", 782 "require cf;\n",
772 0 783 0
773 ); 784 );
774 785
775 if (SvTRUE (ERRSV)) 786 if (SvTRUE (ERRSV))
1389 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1390 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1391 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1392 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1393 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);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1394 1407
1395 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);
1396 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);
1397 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);
1398 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1411 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1446# include "attackinc.h" 1459# include "attackinc.h"
1447# undef def 1460# undef def
1448# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1449# include "skillinc.h" 1462# include "skillinc.h"
1450# undef def 1463# undef def
1451 1464# define def(name, use, nonuse) const_iv (body_ ## name)
1452 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1465# include "slotinc.h"
1453 const_iv (logBacktrace) 1466# undef def
1454
1455 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1456 1467
1457 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1468 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1458 1469
1459 const_iv (MAX_TIME) 1470 const_iv (MAX_TIME)
1460 const_iv (MAXSOCKBUF) 1471 const_iv (MAXSOCKBUF)
1485 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1496 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1486 1497
1487 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1498 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1488 }; 1499 };
1489 1500
1490 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1501 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1491 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1502 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1492 1503
1493 static const struct { 1504 static const struct {
1494 const char *name; 1505 const char *name;
1495 int skip; 1506 int skip;
1501# undef def 1512# undef def
1502 }; 1513 };
1503 1514
1504 AV *av = get_av ("cf::EVENT", 1); 1515 AV *av = get_av ("cf::EVENT", 1);
1505 1516
1506 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1517 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1507 { 1518 {
1508 AV *event = newAV (); 1519 AV *event = newAV ();
1509 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1520 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1510 av_push (event, newSViv (eiv->klass)); 1521 av_push (event, newSViv (eiv->klass));
1511 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1522 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1592 1603
1593void init_anim () 1604void init_anim ()
1594 1605
1595void init_globals () 1606void init_globals ()
1596 1607
1597void init_experience ()
1598
1599void init_attackmess () 1608void init_attackmess ()
1600 1609
1601void init_dynamic () 1610void init_dynamic ()
1602 1611
1603void load_settings () 1612void load_settings ()
1604 1613
1614void reload_exp_table ()
1615
1605void load_materials () 1616void reload_materials ()
1606 1617
1607void init_uuid () 1618void init_uuid ()
1608 CODE: 1619 CODE:
1609 UUID::init (); 1620 UUID::init ();
1610 1621
1765 1776
1766int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1777int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1767 INIT: 1778 INIT:
1768#if __GLIBC__ 1779#if __GLIBC__
1769 mallopt (M_TOP_PAD, 1024 * 1024); 1780 mallopt (M_TOP_PAD, 1024 * 1024);
1770 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1771 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))
1772 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1773#endif 1785#endif
1774 1786
1775int munlockall () 1787int munlockall ()
1776 1788
1777#endif 1789#endif
1815int exp_to_level (val64 exp) 1827int exp_to_level (val64 exp)
1816 1828
1817val64 level_to_min_exp (int level) 1829val64 level_to_min_exp (int level)
1818 1830
1819SV * 1831SV *
1820resistance_to_string (int atnr) 1832attacktype_name (int atnr)
1821 CODE: 1833 CODE:
1822 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)
1823 RETVAL = newSVpv (resist_plus[atnr], 0); 1851 ? newSVpv (resist_plus [atnr], 0)
1824 else 1852 : &PL_sv_undef;
1825 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;
1826 OUTPUT: RETVAL 1861 OUTPUT: RETVAL
1827 1862
1828UUID 1863UUID
1829uuid_cur () 1864uuid_cur ()
1830 CODE: 1865 CODE:
1880 CODE: 1915 CODE:
1881 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1916 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1882 OUTPUT: 1917 OUTPUT:
1883 RETVAL 1918 RETVAL
1884 1919
1920bool should_invoke (attachable *obj, int event)
1921 CODE:
1922 RETVAL = obj->should_invoke ((event_type)event);
1923 OUTPUT: RETVAL
1924
1885void 1925void
1886debug_trace (attachable *obj, bool on = true) 1926debug_trace (attachable *obj, bool on = true)
1887 CODE: 1927 CODE:
1888 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1928 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1889 if (on) 1929 if (on)
1948int mortals_size () 1988int mortals_size ()
1949 CODE: 1989 CODE:
1950 RETVAL = attachable::mortals.size (); 1990 RETVAL = attachable::mortals.size ();
1951 OUTPUT: RETVAL 1991 OUTPUT: RETVAL
1952 1992
1953const_utf8_string slot_use_name (U32 slot) 1993const_utf8_string slot_name (U32 slot)
1954 ALIAS: 1994 ALIAS:
1995 slot_name = 0
1996 slot_use_name = 1
1955 slot_nonuse_name = 1 1997 slot_nonuse_name = 2
1956 CODE: 1998 CODE:
1957{ 1999{
1958 if (slot >= NUM_BODY_LOCATIONS) 2000 if (slot >= NUM_BODY_LOCATIONS)
1959 croak ("body slot index out of range"); 2001 croak ("body slot index out of range");
1960 2002
1961 switch (ix) 2003 switch (ix)
1962 { 2004 {
2005 case 0: RETVAL = body_locations[slot].name ; break;
1963 case 0: RETVAL = body_locations[slot].use_name; break; 2006 case 1: RETVAL = body_locations[slot].use_name ; break;
1964 case 1: RETVAL = body_locations[slot].nonuse_name; break; 2007 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1965 } 2008 }
1966} 2009}
1967 OUTPUT: 2010 OUTPUT:
1968 RETVAL 2011 RETVAL
1969 2012
2075 2118
2076void pick_up (object *who, object *op) 2119void pick_up (object *who, object *op)
2077 2120
2078void update_object (object *op, int action) 2121void update_object (object *op, int action)
2079 2122
2080void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2123void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2081 2124
2082void player_lvl_adj (object *who, object *skill = 0) 2125void player_lvl_adj (object *who, object *skill = 0)
2083 2126
2084int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2127int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2085 2128
2450 if (oblinkpt *obp = map->find_link (connection)) 2493 if (oblinkpt *obp = map->find_link (connection))
2451 for (objectlink *ol = obp->link; ol; ol = ol->next) 2494 for (objectlink *ol = obp->link; ol; ol = ol->next)
2452 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2495 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2453 2496
2454void 2497void
2455get_map_flags (maptile *map, int x, int y) 2498xy_normalise (maptile *map, int x, int y, int dir = 0)
2456 PPCODE: 2499 PPCODE:
2457{ 2500{
2458 maptile *nmap = 0; 2501 mapxy pos (map, x, y);
2459 I16 nx = 0, ny = 0; 2502 if (!pos.move (dir).normalise ())
2503 XSRETURN_EMPTY;
2460 2504
2461 PUTBACK;
2462 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2463 SPAGAIN;
2464
2465 EXTEND (SP, 4); 2505 EXTEND (SP, 3);
2466 PUSHs (sv_2mortal (newSViv (flags)));
2467
2468 if (GIMME_V == G_ARRAY)
2469 {
2470 PUSHs (sv_2mortal (to_sv (nmap))); 2506 PUSHs (sv_2mortal (to_sv (pos.m)));
2471 PUSHs (sv_2mortal (newSViv (nx))); 2507 PUSHs (sv_2mortal (to_sv (pos.x)));
2472 PUSHs (sv_2mortal (newSViv (ny))); 2508 PUSHs (sv_2mortal (to_sv (pos.y)));
2473 }
2474} 2509}
2475 2510
2476mapspace * 2511mapspace *
2477ms (maptile *map, unsigned int x, unsigned int y) 2512ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2478 PROTOTYPE: $$$ 2513 PROTOTYPE: $$$;$
2479 CODE: 2514 CODE:
2480{ 2515{
2481 maptile *nmap = 0; 2516 mapxy pos (map, x, y);
2482 I16 nx, ny; 2517 if (!pos.move (dir).normalise ())
2483
2484 PUTBACK;
2485 get_map_flags (map, &nmap, x, y, &nx, &ny);
2486 SPAGAIN;
2487
2488 if (!nmap)
2489 XSRETURN_UNDEF; 2518 XSRETURN_UNDEF;
2490 2519
2491 RETVAL = &nmap->at (nx, ny); 2520 RETVAL = &*pos;
2492} 2521}
2493 OUTPUT: 2522 OUTPUT:
2494 RETVAL 2523 RETVAL
2495 2524
2496void 2525void
2497at (maptile *map, unsigned int x, unsigned int y) 2526at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2498 PROTOTYPE: $$$ 2527 PROTOTYPE: $$$;$
2499 PPCODE: 2528 PPCODE:
2500{ 2529 mapxy pos (map, x, y);
2501 maptile *nmap = 0; 2530 if (pos.move (dir).normalise ())
2502 I16 nx, ny;
2503
2504 PUTBACK;
2505 get_map_flags (map, &nmap, x, y, &nx, &ny);
2506 SPAGAIN;
2507
2508 if (nmap)
2509 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2531 for (object *o = pos->bot; o; o = o->above)
2510 XPUSHs (sv_2mortal (to_sv (o))); 2532 XPUSHs (sv_2mortal (to_sv (o)));
2511}
2512 2533
2513SV * 2534SV *
2514bot_at (maptile *map, unsigned int x, unsigned int y) 2535bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2515 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2516 ALIAS: 2537 ALIAS:
2517 top_at = 1 2538 top_at = 1
2518 flags_at = 2 2539 flags_at = 2
2519 light_at = 3 2540 light_at = 3
2520 move_block_at = 4 2541 move_block_at = 4
2521 move_slow_at = 5 2542 move_slow_at = 5
2522 move_on_at = 6 2543 move_on_at = 6
2523 move_off_at = 7 2544 move_off_at = 7
2524 CODE: 2545 CODE:
2525{ 2546{
2526 sint16 nx = x; 2547 mapxy pos (map, x, y);
2527 sint16 ny = y; 2548 if (!pos.move (dir).normalise ())
2528
2529 if (!xy_normalise (map, nx, ny))
2530 XSRETURN_UNDEF; 2549 XSRETURN_UNDEF;
2531 2550
2532 mapspace &ms = map->at (nx, ny); 2551 mapspace &ms = *pos;
2533 2552
2534 ms.update (); 2553 ms.update ();
2535 2554
2536 switch (ix) 2555 switch (ix)
2537 { 2556 {
2547} 2566}
2548 OUTPUT: RETVAL 2567 OUTPUT: RETVAL
2549 2568
2550# worst xs function of my life 2569# worst xs function of my life
2551bool 2570bool
2552_create_random_map (\ 2571_create_random_map (maptile *self, SV *options)
2553 maptile *self,\
2554 utf8_string wallstyle,\
2555 utf8_string wall_name,\
2556 utf8_string floorstyle,\
2557 utf8_string monsterstyle,\
2558 utf8_string treasurestyle,\
2559 utf8_string layoutstyle,\
2560 utf8_string doorstyle,\
2561 utf8_string decorstyle,\
2562 utf8_string miningstyle,\
2563 utf8_string origin_map,\
2564 utf8_string final_map,\
2565 utf8_string exitstyle,\
2566 utf8_string this_map,\
2567 utf8_string exit_on_final_map,\
2568 int xsize,\
2569 int ysize,\
2570 int expand2x,\
2571 int layoutoptions1,\
2572 int layoutoptions2,\
2573 int layoutoptions3,\
2574 int symmetry,\
2575 int difficulty,\
2576 int difficulty_given,\
2577 float difficulty_increase,\
2578 int dungeon_level,\
2579 int dungeon_depth,\
2580 int decoroptions,\
2581 int orientation,\
2582 int origin_y,\
2583 int origin_x,\
2584 U32 random_seed,\
2585 val64 total_map_hp,\
2586 int map_layout_style,\
2587 int treasureoptions,\
2588 int symmetry_used,\
2589 region *region,\
2590 utf8_string custom\
2591)
2592 CODE: 2572 CODE:
2593{ 2573{
2594 random_map_params rmp; 2574 random_map_params rmp ((HV *)SvRV (options));
2595
2596 assign (rmp.wallstyle , wallstyle);
2597 assign (rmp.wall_name , wall_name);
2598 assign (rmp.floorstyle , floorstyle);
2599 assign (rmp.monsterstyle , monsterstyle);
2600 assign (rmp.treasurestyle , treasurestyle);
2601 assign (rmp.layoutstyle , layoutstyle);
2602 assign (rmp.doorstyle , doorstyle);
2603 assign (rmp.decorstyle , decorstyle);
2604 assign (rmp.miningstyle , miningstyle);
2605 assign (rmp.exitstyle , exitstyle);
2606 assign (rmp.exit_on_final_map, exit_on_final_map);
2607
2608 rmp.origin_map = origin_map;
2609 rmp.final_map = final_map;
2610 rmp.this_map = this_map;
2611 rmp.xsize = xsize;
2612 rmp.ysize = ysize;
2613 rmp.expand2x = expand2x;
2614 rmp.layoutoptions1 = layoutoptions1;
2615 rmp.layoutoptions2 = layoutoptions2;
2616 rmp.layoutoptions3 = layoutoptions3;
2617 rmp.symmetry = symmetry;
2618 rmp.difficulty = difficulty;
2619 rmp.difficulty_given = difficulty_given;
2620 rmp.difficulty_increase = difficulty_increase;
2621 rmp.dungeon_level = dungeon_level;
2622 rmp.dungeon_depth = dungeon_depth;
2623 rmp.decoroptions = decoroptions;
2624 rmp.orientation = orientation;
2625 rmp.origin_y = origin_y;
2626 rmp.origin_x = origin_x;
2627 rmp.random_seed = random_seed;
2628 rmp.total_map_hp = (uint64_t) total_map_hp;
2629 rmp.map_layout_style = map_layout_style;
2630 rmp.treasureoptions = treasureoptions;
2631 rmp.symmetry_used = symmetry_used;
2632 rmp.region = region;
2633 rmp.custom = custom;
2634
2635 RETVAL = self->generate_random_map (&rmp); 2575 RETVAL = self->generate_random_map (&rmp);
2636} 2576}
2637 OUTPUT: 2577 OUTPUT:
2638 RETVAL 2578 RETVAL
2639 2579
2670void 2610void
2671list () 2611list ()
2672 PPCODE: 2612 PPCODE:
2673 for_all_regions (rgn) 2613 for_all_regions (rgn)
2674 XPUSHs (sv_2mortal (to_sv (rgn))); 2614 XPUSHs (sv_2mortal (to_sv (rgn)));
2675
2676region *find (utf8_string name)
2677 PROTOTYPE: $
2678 CODE:
2679 RETVAL = region::find (name);
2680 OUTPUT: RETVAL
2681 2615
2682int specificity (region *rgn) 2616int specificity (region *rgn)
2683 CODE: 2617 CODE:
2684 RETVAL = 0; 2618 RETVAL = 0;
2685 while (rgn = rgn->parent) 2619 while (rgn = rgn->parent)
2817 2751
2818void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2752void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2819 CODE: 2753 CODE:
2820{ 2754{
2821 faceinfo *f = face_info (idx); assert (f); 2755 faceinfo *f = face_info (idx); assert (f);
2822 facedata *d = &(faceset ? f->data64 : f->data32); 2756 facedata *d = f->face + faceset;
2823 sv_to (data, d->data); 2757 sv_to (data, d->data);
2824 STRLEN clen; 2758 STRLEN clen;
2825 char *cdata = SvPVbyte (chksum, clen); 2759 char *cdata = SvPVbyte (chksum, clen);
2826 clen = min (CHKSUM_MAXLEN, clen); 2760 clen = min (CHKSUM_MAXLEN, clen);
2827 2761
2979 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2913 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2980 2914
2981 self->skip (); 2915 self->skip ();
2982 } 2916 }
2983 2917
2918MODULE = cf PACKAGE = cf::layout
2919
2920INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines