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.134 by root, Tue Jan 9 21:32:42 2007 UTC vs.
Revision 1.162 by root, Thu Feb 1 19:40:42 2007 UTC

29#include <plugin_common.h> 29#include <plugin_common.h>
30#include <sounds.h> 30#include <sounds.h>
31#include <cstdarg> 31#include <cstdarg>
32#include <sproto.h> 32#include <sproto.h>
33 33
34#include "loader.h"
34#include "cfperl.h" 35#include "cfperl.h"
35#include "shstr.h" 36#include "shstr.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
102unordered_vector<attachable *> attachable::mortals; 103unordered_vector<attachable *> attachable::mortals;
103 104
104attachable::~attachable () 105attachable::~attachable ()
105{ 106{
106 assert (!self); 107 assert (!self);
108 assert (!cb);
107} 109}
108 110
109int 111int
110attachable::refcnt_cnt () const 112attachable::refcnt_cnt () const
111{ 113{
112 return refcnt + (self ? SvREFCNT (self) : 0); 114 return refcnt + (self ? SvREFCNT (self) - 1 : 0);
115}
116
117void
118attachable::sever_self ()
119{
120 if (HV *self = this->self)
121 {
122 // keep a refcount because sv_unmagic might call attachable_free,
123 // which might clear self, causing sv_unmagic to crash on a now
124 // invalid object.
125 SvREFCNT_inc (self);
126 hv_clear (self);
127 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
128 SvREFCNT_dec (self);
129
130 // self *must* be null now because thats sv_unmagic's job.
131 assert (!this->self);
132 }
113} 133}
114 134
115void 135void
116attachable::optimise () 136attachable::optimise ()
117{ 137{
118 if (self 138 if (self
119 && SvREFCNT (self) == 1 139 && SvREFCNT (self) == 1
120 && !HvTOTALKEYS (self)) 140 && !HvTOTALKEYS (self))
141 sever_self ();
142}
143
144// check wether the object really is dead
145void
146attachable::do_check ()
147{
148 if (refcnt_cnt () > 0)
149 return;
150
151 destroy ();
152}
153
154void
155attachable::do_destroy ()
156{
157 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
158
159 if (cb)
121 { 160 {
122 refcnt_inc ();
123 SvREFCNT_dec ((SV *)self); 161 SvREFCNT_dec (cb);
162 cb = 0;
124 } 163 }
125}
126
127// check wether the object really is dead
128void
129attachable::do_check ()
130{
131 if (refcnt > 0 || refcnt_cnt () > 0)
132 return;
133
134 destroy ();
135 164
136 if (self) 165 if (self)
137 { 166 sever_self ();
138 hv_clear (self);
139 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
140 SvREFCNT_dec (self);
141 self = 0;
142 }
143}
144
145void
146attachable::do_destroy ()
147{
148 invoke (EVENT_ATTACHABLE_DESTROY, DT_END);
149
150 if (self)
151 hv_clear (self);
152 167
153 mortals.push_back (this); 168 mortals.push_back (this);
154} 169}
155 170
156void 171void
164} 179}
165 180
166void 181void
167attachable::check_mortals () 182attachable::check_mortals ()
168{ 183{
169 for (int i = 0; i < mortals.size (); ) 184 static int i = 0;
185
186 for (;;)
170 { 187 {
188 if (i >= mortals.size ())
189 {
190 i = 0;
191
192 if (mortals.size () > 1000)
193 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
194
195 break;
196 }
197
171 attachable *obj = mortals [i]; 198 attachable *obj = mortals [i];
172 199
173 obj->refcnt_chk (); // unborrow from perl, if necessary 200 obj->refcnt_chk (); // unborrow from perl, if necessary
174 201
202 //if (obj->refcnt > 0 || obj->self)
175 if (obj->refcnt || obj->self) 203 if (obj->refcnt || obj->self)
176 { 204 {
177#if 0 205//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D
178 if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (),
179 obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D
180#endif
181
182 ++i; // further delay freeing 206 ++i; // further delay freeing
207
208 if (!(i & 0x3ff))
209 break;
183 }//D 210 }
184 else 211 else
185 { 212 {
186 //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D
187 mortals.erase (i); 213 mortals.erase (i);
188 delete obj; 214 delete obj;
189 } 215 }
190 } 216 }
191} 217}
216 242
217static int 243static int
218attachable_free (pTHX_ SV *sv, MAGIC *mg) 244attachable_free (pTHX_ SV *sv, MAGIC *mg)
219{ 245{
220 attachable *at = (attachable *)mg->mg_ptr; 246 attachable *at = (attachable *)mg->mg_ptr;
247
248 //TODO: check if transaction behaviour is really required here
249 if (SV *self = (SV *)at->self)
250 {
221 at->self = 0; 251 at->self = 0;
252 SvREFCNT_dec (self);
253 }
254
222 // next line makes sense, but most objects still have refcnt 0 by default 255 // next line makes sense, but most objects still have refcnt 0 by default
223 //at->refcnt_chk (); 256 //at->refcnt_chk ();
224 return 0; 257 return 0;
225} 258}
226 259
235 if (!obj->self) 268 if (!obj->self)
236 { 269 {
237 obj->self = newHV (); 270 obj->self = newHV ();
238 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 271 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
239 272
240 // borrow the refcnt from the object
241 // it is important thta no refcnt_chk is being executed here
242 obj->refcnt_dec ();
243
244 // now bless the object _once_ 273 // now bless the object _once_
245 return sv_bless (newRV_inc ((SV *)obj->self), stash); 274 return sv_bless (newRV_inc ((SV *)obj->self), stash);
246 } 275 }
247 else 276 else
277 {
248 return newRV_inc ((SV *)obj->self); 278 SV *sv = newRV_inc ((SV *)obj->self);
279
280 if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not
281 SvAMAGIC_on (sv);
282
283 return sv;
284 }
249} 285}
250 286
251static void 287static void
252clearSVptr (SV *sv) 288clearSVptr (SV *sv)
253{ 289{
306inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 342inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
307 343
308inline SV *to_sv (object & v) { return to_sv (&v); } 344inline SV *to_sv (object & v) { return to_sv (&v); }
309inline SV *to_sv (living & v) { return to_sv (&v); } 345inline SV *to_sv (living & v) { return to_sv (&v); }
310 346
311//TODO:
312inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 347inline SV *to_sv (facetile * v) { return to_sv (v->name); }
313inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 348inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
314 349
315inline SV *to_sv (UUID v) 350inline SV *to_sv (UUID v)
316{ 351{
317 char buf[128]; 352 char buf[128];
318 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 353 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
319 return newSVpv (buf, 0); 354 return newSVpv (buf, 0);
320} 355}
321 356
322inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 357inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
323inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 358inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
342inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 377inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
343inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 378inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
344inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } 379inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
345inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 380inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
346 381
347inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO 382inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; }
348inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO 383inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); }
349 384
350template<class T> 385template<class T>
351inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 386inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
352 387
353template<int N> 388template<int N>
489 if (!ext->cb) 524 if (!ext->cb)
490 ext->cb = newAV (); 525 ext->cb = newAV ();
491 526
492 return newRV_inc ((SV *)ext->cb); 527 return newRV_inc ((SV *)ext->cb);
493} 528}
494
495#if 0
496void attachable::clear ()
497{
498 if (self)
499 {
500 // disconnect Perl from C, to avoid crashes
501 sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext);
502
503 // clear the perl hash, might or might not be a good idea
504 hv_clear ((HV *)SvRV ((SV *)self));
505
506 SvREFCNT_dec (self);
507 self = 0;
508 }
509
510 if (cb)
511 {
512 SvREFCNT_dec (cb);
513 cb = 0;
514 }
515
516 attach = 0;
517}
518#endif
519 529
520///////////////////////////////////////////////////////////////////////////// 530/////////////////////////////////////////////////////////////////////////////
521 531
522extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 532extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
523{ 533{
595 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 605 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
596 { 606 {
597 printf ("unable to initialize perl-interpreter, aborting.\n"); 607 printf ("unable to initialize perl-interpreter, aborting.\n");
598 exit (EXIT_FAILURE); 608 exit (EXIT_FAILURE);
599 } 609 }
610
611 {
612 dSP;
613
614 PUSHMARK (SP);
615 PUTBACK;
616 call_pv ("cf::init", G_DISCARD | G_VOID);
617 }
600} 618}
601 619
602void cfperl_main () 620void cfperl_main ()
603{ 621{
604 dSP; 622 dSP;
845 CALL_END; 863 CALL_END;
846 864
847 return retval; 865 return retval;
848} 866}
849 867
868maptile *
869maptile::find_async (const char *path, maptile *origin)
870{
871 CALL_BEGIN (2);
872 CALL_ARG (path);
873 CALL_ARG (origin);
874 CALL_CALL ("cf::map::find_async", G_SCALAR);
875
876 maptile *retval;
877
878 if (count)
879 sv_to (POPs, retval);
880 else
881 retval = 0;
882
883 CALL_END;
884
885 return retval;
886}
887
850void 888void
851maptile::do_load_sync () 889maptile::do_load_sync ()
852{ 890{
853 CALL_BEGIN (1); 891 CALL_BEGIN (1);
854 CALL_ARG (this); 892 CALL_ARG (this);
894void 932void
895iw::alloc () 933iw::alloc ()
896{ 934{
897 pe = GEventAPI->new_idle (0, 0); 935 pe = GEventAPI->new_idle (0, 0);
898 936
937 WaREENTRANT_off (pe);
899 pe->base.callback = (void *)iw_dispatch; 938 pe->base.callback = (void *)iw_dispatch;
900 pe->base.ext_data = (void *)this; 939 pe->base.ext_data = (void *)this;
901} 940}
902 941
903static void iow_dispatch (pe_event *ev) 942static void iow_dispatch (pe_event *ev)
909void 948void
910iow::alloc () 949iow::alloc ()
911{ 950{
912 pe = GEventAPI->new_io (0, 0); 951 pe = GEventAPI->new_io (0, 0);
913 952
953 WaREENTRANT_off (pe);
914 pe->base.callback = (void *)iow_dispatch; 954 pe->base.callback = (void *)iow_dispatch;
915 pe->base.ext_data = (void *)this; 955 pe->base.ext_data = (void *)this;
916 956
917 pe->fd = -1; 957 pe->fd = -1;
918 pe->poll = 0; 958 pe->poll = 0;
1246 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1286 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1247 const_iv (FLAG_IS_WATER) 1287 const_iv (FLAG_IS_WATER)
1248 const_iv (FLAG_CONTENT_ON_GEN) 1288 const_iv (FLAG_CONTENT_ON_GEN)
1249 const_iv (FLAG_IS_A_TEMPLATE) 1289 const_iv (FLAG_IS_A_TEMPLATE)
1250 const_iv (FLAG_IS_BUILDABLE) 1290 const_iv (FLAG_IS_BUILDABLE)
1291 const_iv (FLAG_DESTROY_ON_DEATH)
1292 const_iv (FLAG_NO_MAP_SAVE)
1251 1293
1252 const_iv (NDI_BLACK) 1294 const_iv (NDI_BLACK)
1253 const_iv (NDI_WHITE) 1295 const_iv (NDI_WHITE)
1254 const_iv (NDI_NAVY) 1296 const_iv (NDI_NAVY)
1255 const_iv (NDI_RED) 1297 const_iv (NDI_RED)
1440 const_iv (ATNR_BLIND) 1482 const_iv (ATNR_BLIND)
1441 const_iv (ATNR_INTERNAL) 1483 const_iv (ATNR_INTERNAL)
1442 const_iv (ATNR_LIFE_STEALING) 1484 const_iv (ATNR_LIFE_STEALING)
1443 const_iv (ATNR_DISEASE) 1485 const_iv (ATNR_DISEASE)
1444 1486
1445 const_iv (MAP_FLUSH)
1446 const_iv (MAP_PLAYER_UNIQUE)
1447 const_iv (MAP_BLOCK)
1448 const_iv (MAP_STYLE)
1449 const_iv (MAP_OVERLAY)
1450
1451 const_iv (MAP_IN_MEMORY) 1487 const_iv (MAP_IN_MEMORY)
1452 const_iv (MAP_SWAPPED) 1488 const_iv (MAP_SWAPPED)
1453 const_iv (MAP_LOADING) 1489 const_iv (MAP_LOADING)
1454 const_iv (MAP_SAVING) 1490 const_iv (MAP_SAVING)
1455 1491
1548} 1584}
1549 1585
1550NV floor (NV x) 1586NV floor (NV x)
1551 1587
1552NV ceil (NV x) 1588NV ceil (NV x)
1589
1590NV rndm (...)
1591 CODE:
1592 switch (items)
1593 {
1594 case 0: RETVAL = rndm (); break;
1595 case 1: RETVAL = rndm (SvUV (ST (0))); break;
1596 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break;
1597 default: croak ("cf::rndm requires none, one or two parameters."); break;
1598 }
1599 OUTPUT:
1600 RETVAL
1553 1601
1554void server_tick () 1602void server_tick ()
1555 CODE: 1603 CODE:
1556 runtime = SvNVx (sv_runtime); 1604 runtime = SvNVx (sv_runtime);
1557 server_tick (); 1605 server_tick ();
1604 } 1652 }
1605 OUTPUT: RETVAL 1653 OUTPUT: RETVAL
1606 1654
1607void abort () 1655void abort ()
1608 1656
1657void fork_abort (char *cause = "cf::fork_abort")
1658
1609void cleanup (const char *cause, bool make_core = false) 1659void cleanup (const char *cause, bool make_core = false)
1610 1660
1611void emergency_save () 1661void emergency_save ()
1612 1662
1613void _exit (int status = 0) 1663void _exit (int status = EXIT_SUCCESS)
1664
1665UV sv_2watcher (SV *w)
1666 CODE:
1667 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1668 OUTPUT:
1669 RETVAL
1614 1670
1615#if _POSIX_MEMLOCK 1671#if _POSIX_MEMLOCK
1616 1672
1617int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1673int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1618 1674
1664 RETVAL = newSVpv (resist_plus[atnr], 0); 1720 RETVAL = newSVpv (resist_plus[atnr], 0);
1665 else 1721 else
1666 XSRETURN_UNDEF; 1722 XSRETURN_UNDEF;
1667 OUTPUT: RETVAL 1723 OUTPUT: RETVAL
1668 1724
1725bool
1726load_regions (const char *filename)
1727 CODE:
1728 RETVAL = loader_region ().load (filename);
1729 OUTPUT: RETVAL
1730
1669MODULE = cf PACKAGE = cf::attachable 1731MODULE = cf PACKAGE = cf::attachable
1670 1732
1671int 1733int
1672valid (SV *obj) 1734valid (SV *obj)
1673 CODE: 1735 CODE:
1674 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1736 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1675 OUTPUT: 1737 OUTPUT:
1676 RETVAL 1738 RETVAL
1739
1740int mortals_size ()
1741 CODE:
1742 RETVAL = attachable::mortals.size ();
1743 OUTPUT: RETVAL
1744
1745#object *mortals (U32 index)
1746# CODE:
1747# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1748# OUTPUT: RETVAL
1677 1749
1678INCLUDE: $PERL genacc attachable ../include/cfperl.h | 1750INCLUDE: $PERL genacc attachable ../include/cfperl.h |
1679 1751
1680MODULE = cf PACKAGE = cf::global 1752MODULE = cf PACKAGE = cf::global
1681 1753
1699 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); 1771 RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END);
1700 OUTPUT: RETVAL 1772 OUTPUT: RETVAL
1701 1773
1702SV *registry (object *op) 1774SV *registry (object *op)
1703 1775
1704void mortals ()
1705 PPCODE:
1706 EXTEND (SP, object::mortals.size ());
1707 for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i)
1708 PUSHs (to_sv (*i));
1709
1710int objects_size () 1776int objects_size ()
1711 CODE: 1777 CODE:
1712 RETVAL = objects.size (); 1778 RETVAL = objects.size ();
1713 OUTPUT: RETVAL 1779 OUTPUT: RETVAL
1714 1780
1753 1819
1754void 1820void
1755set_animation (object *op, int idx) 1821set_animation (object *op, int idx)
1756 CODE: 1822 CODE:
1757 SET_ANIMATION (op, idx); 1823 SET_ANIMATION (op, idx);
1824
1825int
1826num_animations (object *op)
1827 CODE:
1828 RETVAL = NUM_ANIMATIONS (op);
1829 OUTPUT: RETVAL
1758 1830
1759object *find_best_object_match (object *op, const char *match) 1831object *find_best_object_match (object *op, const char *match)
1760 1832
1761object *find_marked_object (object *op) 1833object *find_marked_object (object *op)
1762 1834
1837 1909
1838void drop (object *who, object *op) 1910void drop (object *who, object *op)
1839 1911
1840void pick_up (object *who, object *op) 1912void pick_up (object *who, object *op)
1841 1913
1842object *cf_object_insert_object (object *op, object *container)
1843
1844object *cf_object_insert_in_ob (object *ob, object *where)
1845
1846int cf_object_teleport (object *op, maptile *map, int x, int y) 1914int cf_object_teleport (object *op, maptile *map, int x, int y)
1847 1915
1848void update_object (object *op, int action) 1916void update_object (object *op, int action)
1849 1917
1850object *cf_create_object_by_name (const char *name) 1918object *cf_create_object_by_name (const char *name)
1969void esrv_update_item (object *op, int what, object *item) 2037void esrv_update_item (object *op, int what, object *item)
1970 C_ARGS: what, op, item 2038 C_ARGS: what, op, item
1971 2039
1972void clear_los (object *op) 2040void clear_los (object *op)
1973 2041
1974int command_teleport (object *op, char *params)
1975
1976int command_summon (object *op, char *params) 2042int command_summon (object *op, char *params)
1977 2043
1978int command_arrest (object *op, char *params) 2044int command_arrest (object *op, char *params)
1979 2045
1980int command_kick (object *op, char *params) 2046int command_kick (object *op, char *params)
2005 pl->orig_stats = pl->ob->stats; 2071 pl->orig_stats = pl->ob->stats;
2006 2072
2007void cf_player_move (player *pl, int dir) 2073void cf_player_move (player *pl, int dir)
2008 2074
2009void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2075void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2010
2011player *first ()
2012 CODE:
2013 RETVAL = first_player;
2014 OUTPUT: RETVAL
2015 2076
2016bool 2077bool
2017cell_visible (player *pl, int dx, int dy) 2078cell_visible (player *pl, int dx, int dy)
2018 CODE: 2079 CODE:
2019 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2080 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2097 for_all_players (pl) 2158 for_all_players (pl)
2098 if (pl->ob && pl->ob->map == THIS) 2159 if (pl->ob && pl->ob->map == THIS)
2099 PUSHs (sv_2mortal (to_sv (pl->ob))); 2160 PUSHs (sv_2mortal (to_sv (pl->ob)));
2100 } 2161 }
2101 2162
2163void
2164maptile::set_regiondata (SV *data, SV *plt)
2165 CODE:
2166{
2167 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV)
2168 croak ("maptile::set_regiondata needs arrayref as plt arg");
2169
2170 AV *av = (AV *)SvRV (plt);
2171
2172 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *));
2173
2174 for (int i = av_len (av) + 1; i--; )
2175 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1)));
2176
2177 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data));
2178 THIS->regionmap = regionmap;
2179}
2180
2102void play_sound_map (maptile *map, int x, int y, int sound_num) 2181void play_sound_map (maptile *map, int x, int y, int sound_num)
2103 2182
2104int out_of_map (maptile *map, int x, int y) 2183int out_of_map (maptile *map, int x, int y)
2105 2184
2106void 2185void
2122 2201
2123object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) 2202object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2124 C_ARGS: str, map, nx, ny 2203 C_ARGS: str, map, nx, ny
2125 2204
2126void 2205void
2127cf_map_normalise (maptile *map, int x, int y) 2206get_map_flags (maptile *map, int x, int y)
2128 PPCODE: 2207 PPCODE:
2129{ 2208{
2130 maptile *nmap = 0; 2209 maptile *nmap = 0;
2131 I16 nx = 0, ny = 0; 2210 I16 nx = 0, ny = 0;
2132 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2211 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2187 2266
2188void fix_walls (maptile *map, int x, int y) 2267void fix_walls (maptile *map, int x, int y)
2189 2268
2190void fix_walls_around (maptile *map, int x, int y) 2269void fix_walls_around (maptile *map, int x, int y)
2191 2270
2192const char *
2193region_name (maptile *m)
2194 CODE:
2195 RETVAL = get_name_of_region_for_map (m);
2196 OUTPUT: RETVAL
2197
2198# worst xs function of my life 2271# worst xs function of my life
2199maptile * 2272bool
2200_create_random_map (\ 2273_create_random_map (\
2201 char *path,\ 2274 maptile *self,\
2202 char *wallstyle,\ 2275 char *wallstyle,\
2203 char *wall_name,\ 2276 char *wall_name,\
2204 char *floorstyle,\ 2277 char *floorstyle,\
2205 char *monsterstyle,\ 2278 char *monsterstyle,\
2206 char *treasurestyle,\ 2279 char *treasurestyle,\
2210 char *origin_map,\ 2283 char *origin_map,\
2211 char *final_map,\ 2284 char *final_map,\
2212 char *exitstyle,\ 2285 char *exitstyle,\
2213 char *this_map,\ 2286 char *this_map,\
2214 char *exit_on_final_map,\ 2287 char *exit_on_final_map,\
2215 int Xsize,\ 2288 int xsize,\
2216 int Ysize,\ 2289 int ysize,\
2217 int expand2x,\ 2290 int expand2x,\
2218 int layoutoptions1,\ 2291 int layoutoptions1,\
2219 int layoutoptions2,\ 2292 int layoutoptions2,\
2220 int layoutoptions3,\ 2293 int layoutoptions3,\
2221 int symmetry,\ 2294 int symmetry,\
2226 int dungeon_depth,\ 2299 int dungeon_depth,\
2227 int decoroptions,\ 2300 int decoroptions,\
2228 int orientation,\ 2301 int orientation,\
2229 int origin_y,\ 2302 int origin_y,\
2230 int origin_x,\ 2303 int origin_x,\
2231 int random_seed,\ 2304 U32 random_seed,\
2232 val64 total_map_hp,\ 2305 val64 total_map_hp,\
2233 int map_layout_style,\ 2306 int map_layout_style,\
2234 int treasureoptions,\ 2307 int treasureoptions,\
2235 int symmetry_used,\ 2308 int symmetry_used,\
2236 region *region\ 2309 region *region,\
2310 char *custom\
2237) 2311)
2238 CODE: 2312 CODE:
2239{ 2313{
2240 random_map_params rmp; 2314 random_map_params rmp;
2241 2315
2251 assign (rmp.exit_on_final_map, exit_on_final_map); 2325 assign (rmp.exit_on_final_map, exit_on_final_map);
2252 2326
2253 rmp.origin_map = origin_map; 2327 rmp.origin_map = origin_map;
2254 rmp.final_map = final_map; 2328 rmp.final_map = final_map;
2255 rmp.this_map = this_map; 2329 rmp.this_map = this_map;
2256 rmp.Xsize = Xsize; 2330 rmp.xsize = xsize;
2257 rmp.Ysize = Ysize; 2331 rmp.ysize = ysize;
2258 rmp.expand2x = expand2x; 2332 rmp.expand2x = expand2x;
2259 rmp.layoutoptions1 = layoutoptions1; 2333 rmp.layoutoptions1 = layoutoptions1;
2260 rmp.layoutoptions2 = layoutoptions2; 2334 rmp.layoutoptions2 = layoutoptions2;
2261 rmp.layoutoptions3 = layoutoptions3; 2335 rmp.layoutoptions3 = layoutoptions3;
2262 rmp.symmetry = symmetry; 2336 rmp.symmetry = symmetry;
2273 rmp.total_map_hp = total_map_hp; 2347 rmp.total_map_hp = total_map_hp;
2274 rmp.map_layout_style = map_layout_style; 2348 rmp.map_layout_style = map_layout_style;
2275 rmp.treasureoptions = treasureoptions; 2349 rmp.treasureoptions = treasureoptions;
2276 rmp.symmetry_used = symmetry_used; 2350 rmp.symmetry_used = symmetry_used;
2277 rmp.region = region; 2351 rmp.region = region;
2352 rmp.custom = custom;
2278 2353
2279 RETVAL = generate_random_map (path, &rmp); 2354 RETVAL = self->generate_random_map (&rmp);
2280} 2355}
2281 OUTPUT: 2356 OUTPUT:
2282 RETVAL 2357 RETVAL
2283 2358
2284MODULE = cf PACKAGE = cf::arch 2359MODULE = cf PACKAGE = cf::arch
2307 2382
2308INCLUDE: $PERL genacc partylist ../include/player.h | 2383INCLUDE: $PERL genacc partylist ../include/player.h |
2309 2384
2310MODULE = cf PACKAGE = cf::region 2385MODULE = cf PACKAGE = cf::region
2311 2386
2312region *first () 2387void
2313 PROTOTYPE: 2388list ()
2314 CODE: 2389 PPCODE:
2315 RETVAL = first_region; 2390 for_all_regions (rgn)
2316 OUTPUT: RETVAL 2391 XPUSHs (sv_2mortal (to_sv (rgn)));
2317 2392
2318region *find (char *name) 2393region *find (char *name)
2319 PROTOTYPE: $ 2394 PROTOTYPE: $
2320 CODE: 2395 CODE:
2321 RETVAL = get_region_by_name (name); 2396 RETVAL = region::find (name);
2397 OUTPUT: RETVAL
2398
2399region *find_fuzzy (char *name)
2400 PROTOTYPE: $
2401 CODE:
2402 RETVAL = region::find_fuzzy (name);
2322 OUTPUT: RETVAL 2403 OUTPUT: RETVAL
2323 2404
2324INCLUDE: $PERL genacc region ../include/map.h | 2405INCLUDE: $PERL genacc region ../include/map.h |
2325 2406
2326MODULE = cf PACKAGE = cf::living 2407MODULE = cf PACKAGE = cf::living

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines