… | |
… | |
164 | } |
164 | } |
165 | |
165 | |
166 | void |
166 | void |
167 | attachable::check_mortals () |
167 | attachable::check_mortals () |
168 | { |
168 | { |
169 | for (int i = 0; i < mortals.size (); ) |
169 | static int i = 0; |
|
|
170 | |
|
|
171 | for (;;) |
170 | { |
172 | { |
|
|
173 | if (i >= mortals.size ()) |
|
|
174 | { |
|
|
175 | i = 0; |
|
|
176 | |
|
|
177 | if (mortals.size () > 1000) |
|
|
178 | fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", mortals.size ()); |
|
|
179 | |
|
|
180 | break; |
|
|
181 | } |
|
|
182 | |
171 | attachable *obj = mortals [i]; |
183 | attachable *obj = mortals [i]; |
172 | |
184 | |
173 | obj->refcnt_chk (); // unborrow from perl, if necessary |
185 | obj->refcnt_chk (); // unborrow from perl, if necessary |
174 | |
186 | |
|
|
187 | //if (obj->refcnt > 0 || obj->self) |
175 | if (obj->refcnt || obj->self) |
188 | if (obj->refcnt || obj->self) |
176 | { |
189 | { |
177 | #if 0 |
190 | //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 |
191 | ++i; // further delay freeing |
|
|
192 | |
|
|
193 | if (!(i & 0x3ff)) |
|
|
194 | break; |
183 | }//D |
195 | } |
184 | else |
196 | else |
185 | { |
197 | { |
186 | //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D |
|
|
187 | mortals.erase (i); |
198 | mortals.erase (i); |
188 | delete obj; |
199 | delete obj; |
189 | } |
200 | } |
190 | } |
201 | } |
191 | } |
202 | } |
… | |
… | |
243 | |
254 | |
244 | // now bless the object _once_ |
255 | // now bless the object _once_ |
245 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
256 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
246 | } |
257 | } |
247 | else |
258 | else |
|
|
259 | { |
248 | return newRV_inc ((SV *)obj->self); |
260 | SV *sv = newRV_inc ((SV *)obj->self); |
|
|
261 | |
|
|
262 | if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not |
|
|
263 | SvAMAGIC_on (sv); |
|
|
264 | |
|
|
265 | return sv; |
|
|
266 | } |
249 | } |
267 | } |
250 | |
268 | |
251 | static void |
269 | static void |
252 | clearSVptr (SV *sv) |
270 | clearSVptr (SV *sv) |
253 | { |
271 | { |
… | |
… | |
306 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
324 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
307 | |
325 | |
308 | inline SV *to_sv (object & v) { return to_sv (&v); } |
326 | inline SV *to_sv (object & v) { return to_sv (&v); } |
309 | inline SV *to_sv (living & v) { return to_sv (&v); } |
327 | inline SV *to_sv (living & v) { return to_sv (&v); } |
310 | |
328 | |
311 | //TODO: |
|
|
312 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
329 | inline SV *to_sv (facetile * v) { return to_sv (v->name); } |
313 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
330 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
314 | |
331 | |
315 | inline SV *to_sv (UUID v) |
332 | inline SV *to_sv (UUID v) |
316 | { |
333 | { |
317 | char buf[128]; |
334 | char buf[128]; |
… | |
… | |
342 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
359 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
343 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
360 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
344 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
361 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
345 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
362 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
346 | |
363 | |
347 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
364 | inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } |
348 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
365 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
349 | |
366 | |
350 | template<class T> |
367 | template<class T> |
351 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
368 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
352 | |
369 | |
353 | template<int N> |
370 | template<int N> |
… | |
… | |
489 | if (!ext->cb) |
506 | if (!ext->cb) |
490 | ext->cb = newAV (); |
507 | ext->cb = newAV (); |
491 | |
508 | |
492 | return newRV_inc ((SV *)ext->cb); |
509 | return newRV_inc ((SV *)ext->cb); |
493 | } |
510 | } |
494 | |
|
|
495 | #if 0 |
|
|
496 | void 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 | |
511 | |
520 | ///////////////////////////////////////////////////////////////////////////// |
512 | ///////////////////////////////////////////////////////////////////////////// |
521 | |
513 | |
522 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
514 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
523 | { |
515 | { |
… | |
… | |
845 | CALL_END; |
837 | CALL_END; |
846 | |
838 | |
847 | return retval; |
839 | return retval; |
848 | } |
840 | } |
849 | |
841 | |
|
|
842 | maptile * |
|
|
843 | maptile::find_async (const char *path, maptile *origin) |
|
|
844 | { |
|
|
845 | CALL_BEGIN (2); |
|
|
846 | CALL_ARG (path); |
|
|
847 | CALL_ARG (origin); |
|
|
848 | CALL_CALL ("cf::map::find_async", G_SCALAR); |
|
|
849 | |
|
|
850 | maptile *retval; |
|
|
851 | |
|
|
852 | if (count) |
|
|
853 | sv_to (POPs, retval); |
|
|
854 | else |
|
|
855 | retval = 0; |
|
|
856 | |
|
|
857 | CALL_END; |
|
|
858 | |
|
|
859 | return retval; |
|
|
860 | } |
|
|
861 | |
850 | void |
862 | void |
851 | maptile::do_load_sync () |
863 | maptile::do_load_sync () |
852 | { |
864 | { |
853 | CALL_BEGIN (1); |
865 | CALL_BEGIN (1); |
854 | CALL_ARG (this); |
866 | CALL_ARG (this); |
… | |
… | |
894 | void |
906 | void |
895 | iw::alloc () |
907 | iw::alloc () |
896 | { |
908 | { |
897 | pe = GEventAPI->new_idle (0, 0); |
909 | pe = GEventAPI->new_idle (0, 0); |
898 | |
910 | |
|
|
911 | WaREENTRANT_off (pe); |
899 | pe->base.callback = (void *)iw_dispatch; |
912 | pe->base.callback = (void *)iw_dispatch; |
900 | pe->base.ext_data = (void *)this; |
913 | pe->base.ext_data = (void *)this; |
901 | } |
914 | } |
902 | |
915 | |
903 | static void iow_dispatch (pe_event *ev) |
916 | static void iow_dispatch (pe_event *ev) |
… | |
… | |
909 | void |
922 | void |
910 | iow::alloc () |
923 | iow::alloc () |
911 | { |
924 | { |
912 | pe = GEventAPI->new_io (0, 0); |
925 | pe = GEventAPI->new_io (0, 0); |
913 | |
926 | |
|
|
927 | WaREENTRANT_off (pe); |
914 | pe->base.callback = (void *)iow_dispatch; |
928 | pe->base.callback = (void *)iow_dispatch; |
915 | pe->base.ext_data = (void *)this; |
929 | pe->base.ext_data = (void *)this; |
916 | |
930 | |
917 | pe->fd = -1; |
931 | pe->fd = -1; |
918 | pe->poll = 0; |
932 | pe->poll = 0; |
… | |
… | |
1246 | const_iv (FLAG_ACTIVATE_ON_RELEASE) |
1260 | const_iv (FLAG_ACTIVATE_ON_RELEASE) |
1247 | const_iv (FLAG_IS_WATER) |
1261 | const_iv (FLAG_IS_WATER) |
1248 | const_iv (FLAG_CONTENT_ON_GEN) |
1262 | const_iv (FLAG_CONTENT_ON_GEN) |
1249 | const_iv (FLAG_IS_A_TEMPLATE) |
1263 | const_iv (FLAG_IS_A_TEMPLATE) |
1250 | const_iv (FLAG_IS_BUILDABLE) |
1264 | const_iv (FLAG_IS_BUILDABLE) |
|
|
1265 | const_iv (FLAG_DESTROY_ON_DEATH) |
|
|
1266 | const_iv (FLAG_NO_MAP_SAVE) |
1251 | |
1267 | |
1252 | const_iv (NDI_BLACK) |
1268 | const_iv (NDI_BLACK) |
1253 | const_iv (NDI_WHITE) |
1269 | const_iv (NDI_WHITE) |
1254 | const_iv (NDI_NAVY) |
1270 | const_iv (NDI_NAVY) |
1255 | const_iv (NDI_RED) |
1271 | const_iv (NDI_RED) |
… | |
… | |
1440 | const_iv (ATNR_BLIND) |
1456 | const_iv (ATNR_BLIND) |
1441 | const_iv (ATNR_INTERNAL) |
1457 | const_iv (ATNR_INTERNAL) |
1442 | const_iv (ATNR_LIFE_STEALING) |
1458 | const_iv (ATNR_LIFE_STEALING) |
1443 | const_iv (ATNR_DISEASE) |
1459 | const_iv (ATNR_DISEASE) |
1444 | |
1460 | |
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) |
1461 | const_iv (MAP_IN_MEMORY) |
1452 | const_iv (MAP_SWAPPED) |
1462 | const_iv (MAP_SWAPPED) |
1453 | const_iv (MAP_LOADING) |
1463 | const_iv (MAP_LOADING) |
1454 | const_iv (MAP_SAVING) |
1464 | const_iv (MAP_SAVING) |
1455 | |
1465 | |
… | |
… | |
1548 | } |
1558 | } |
1549 | |
1559 | |
1550 | NV floor (NV x) |
1560 | NV floor (NV x) |
1551 | |
1561 | |
1552 | NV ceil (NV x) |
1562 | NV ceil (NV x) |
|
|
1563 | |
|
|
1564 | NV rndm (...) |
|
|
1565 | CODE: |
|
|
1566 | switch (items) |
|
|
1567 | { |
|
|
1568 | case 0: RETVAL = rndm (); break; |
|
|
1569 | case 1: RETVAL = rndm (SvUV (ST (0))); break; |
|
|
1570 | case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; |
|
|
1571 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
|
|
1572 | } |
|
|
1573 | OUTPUT: |
|
|
1574 | RETVAL |
1553 | |
1575 | |
1554 | void server_tick () |
1576 | void server_tick () |
1555 | CODE: |
1577 | CODE: |
1556 | runtime = SvNVx (sv_runtime); |
1578 | runtime = SvNVx (sv_runtime); |
1557 | server_tick (); |
1579 | server_tick (); |
… | |
… | |
1604 | } |
1626 | } |
1605 | OUTPUT: RETVAL |
1627 | OUTPUT: RETVAL |
1606 | |
1628 | |
1607 | void abort () |
1629 | void abort () |
1608 | |
1630 | |
|
|
1631 | void fork_abort (char *cause = "cf::fork_abort") |
|
|
1632 | |
1609 | void cleanup (const char *cause, bool make_core = false) |
1633 | void cleanup (const char *cause, bool make_core = false) |
1610 | |
1634 | |
1611 | void emergency_save () |
1635 | void emergency_save () |
|
|
1636 | |
|
|
1637 | UV sv_2watcher (SV *w) |
|
|
1638 | CODE: |
|
|
1639 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
|
|
1640 | OUTPUT: |
|
|
1641 | RETVAL |
1612 | |
1642 | |
1613 | void _exit (int status = 0) |
1643 | void _exit (int status = 0) |
1614 | |
1644 | |
1615 | #if _POSIX_MEMLOCK |
1645 | #if _POSIX_MEMLOCK |
1616 | |
1646 | |
… | |
… | |
1837 | |
1867 | |
1838 | void drop (object *who, object *op) |
1868 | void drop (object *who, object *op) |
1839 | |
1869 | |
1840 | void pick_up (object *who, object *op) |
1870 | void pick_up (object *who, object *op) |
1841 | |
1871 | |
1842 | object *cf_object_insert_object (object *op, object *container) |
|
|
1843 | |
|
|
1844 | object *cf_object_insert_in_ob (object *ob, object *where) |
|
|
1845 | |
|
|
1846 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1872 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1847 | |
1873 | |
1848 | void update_object (object *op, int action) |
1874 | void update_object (object *op, int action) |
1849 | |
1875 | |
1850 | object *cf_create_object_by_name (const char *name) |
1876 | object *cf_create_object_by_name (const char *name) |
… | |
… | |
1968 | |
1994 | |
1969 | void esrv_update_item (object *op, int what, object *item) |
1995 | void esrv_update_item (object *op, int what, object *item) |
1970 | C_ARGS: what, op, item |
1996 | C_ARGS: what, op, item |
1971 | |
1997 | |
1972 | void clear_los (object *op) |
1998 | void clear_los (object *op) |
1973 | |
|
|
1974 | int command_teleport (object *op, char *params) |
|
|
1975 | |
1999 | |
1976 | int command_summon (object *op, char *params) |
2000 | int command_summon (object *op, char *params) |
1977 | |
2001 | |
1978 | int command_arrest (object *op, char *params) |
2002 | int command_arrest (object *op, char *params) |
1979 | |
2003 | |
… | |
… | |
2122 | |
2146 | |
2123 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2147 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2124 | C_ARGS: str, map, nx, ny |
2148 | C_ARGS: str, map, nx, ny |
2125 | |
2149 | |
2126 | void |
2150 | void |
2127 | cf_map_normalise (maptile *map, int x, int y) |
2151 | get_map_flags (maptile *map, int x, int y) |
2128 | PPCODE: |
2152 | PPCODE: |
2129 | { |
2153 | { |
2130 | maptile *nmap = 0; |
2154 | maptile *nmap = 0; |
2131 | I16 nx = 0, ny = 0; |
2155 | I16 nx = 0, ny = 0; |
2132 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2156 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
… | |
… | |
2194 | CODE: |
2218 | CODE: |
2195 | RETVAL = get_name_of_region_for_map (m); |
2219 | RETVAL = get_name_of_region_for_map (m); |
2196 | OUTPUT: RETVAL |
2220 | OUTPUT: RETVAL |
2197 | |
2221 | |
2198 | # worst xs function of my life |
2222 | # worst xs function of my life |
2199 | maptile * |
2223 | bool |
2200 | _create_random_map (\ |
2224 | _create_random_map (\ |
2201 | char *path,\ |
2225 | maptile *self,\ |
2202 | char *wallstyle,\ |
2226 | char *wallstyle,\ |
2203 | char *wall_name,\ |
2227 | char *wall_name,\ |
2204 | char *floorstyle,\ |
2228 | char *floorstyle,\ |
2205 | char *monsterstyle,\ |
2229 | char *monsterstyle,\ |
2206 | char *treasurestyle,\ |
2230 | char *treasurestyle,\ |
… | |
… | |
2210 | char *origin_map,\ |
2234 | char *origin_map,\ |
2211 | char *final_map,\ |
2235 | char *final_map,\ |
2212 | char *exitstyle,\ |
2236 | char *exitstyle,\ |
2213 | char *this_map,\ |
2237 | char *this_map,\ |
2214 | char *exit_on_final_map,\ |
2238 | char *exit_on_final_map,\ |
2215 | int Xsize,\ |
2239 | int xsize,\ |
2216 | int Ysize,\ |
2240 | int ysize,\ |
2217 | int expand2x,\ |
2241 | int expand2x,\ |
2218 | int layoutoptions1,\ |
2242 | int layoutoptions1,\ |
2219 | int layoutoptions2,\ |
2243 | int layoutoptions2,\ |
2220 | int layoutoptions3,\ |
2244 | int layoutoptions3,\ |
2221 | int symmetry,\ |
2245 | int symmetry,\ |
… | |
… | |
2226 | int dungeon_depth,\ |
2250 | int dungeon_depth,\ |
2227 | int decoroptions,\ |
2251 | int decoroptions,\ |
2228 | int orientation,\ |
2252 | int orientation,\ |
2229 | int origin_y,\ |
2253 | int origin_y,\ |
2230 | int origin_x,\ |
2254 | int origin_x,\ |
2231 | int random_seed,\ |
2255 | U32 random_seed,\ |
2232 | val64 total_map_hp,\ |
2256 | val64 total_map_hp,\ |
2233 | int map_layout_style,\ |
2257 | int map_layout_style,\ |
2234 | int treasureoptions,\ |
2258 | int treasureoptions,\ |
2235 | int symmetry_used,\ |
2259 | int symmetry_used,\ |
2236 | region *region\ |
2260 | region *region,\ |
|
|
2261 | char *custom\ |
2237 | ) |
2262 | ) |
2238 | CODE: |
2263 | CODE: |
2239 | { |
2264 | { |
2240 | random_map_params rmp; |
2265 | random_map_params rmp; |
2241 | |
2266 | |
… | |
… | |
2251 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2276 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2252 | |
2277 | |
2253 | rmp.origin_map = origin_map; |
2278 | rmp.origin_map = origin_map; |
2254 | rmp.final_map = final_map; |
2279 | rmp.final_map = final_map; |
2255 | rmp.this_map = this_map; |
2280 | rmp.this_map = this_map; |
2256 | rmp.Xsize = Xsize; |
2281 | rmp.xsize = xsize; |
2257 | rmp.Ysize = Ysize; |
2282 | rmp.ysize = ysize; |
2258 | rmp.expand2x = expand2x; |
2283 | rmp.expand2x = expand2x; |
2259 | rmp.layoutoptions1 = layoutoptions1; |
2284 | rmp.layoutoptions1 = layoutoptions1; |
2260 | rmp.layoutoptions2 = layoutoptions2; |
2285 | rmp.layoutoptions2 = layoutoptions2; |
2261 | rmp.layoutoptions3 = layoutoptions3; |
2286 | rmp.layoutoptions3 = layoutoptions3; |
2262 | rmp.symmetry = symmetry; |
2287 | rmp.symmetry = symmetry; |
… | |
… | |
2273 | rmp.total_map_hp = total_map_hp; |
2298 | rmp.total_map_hp = total_map_hp; |
2274 | rmp.map_layout_style = map_layout_style; |
2299 | rmp.map_layout_style = map_layout_style; |
2275 | rmp.treasureoptions = treasureoptions; |
2300 | rmp.treasureoptions = treasureoptions; |
2276 | rmp.symmetry_used = symmetry_used; |
2301 | rmp.symmetry_used = symmetry_used; |
2277 | rmp.region = region; |
2302 | rmp.region = region; |
|
|
2303 | rmp.custom = custom; |
2278 | |
2304 | |
2279 | RETVAL = generate_random_map (path, &rmp); |
2305 | RETVAL = self->generate_random_map (&rmp); |
2280 | } |
2306 | } |
2281 | OUTPUT: |
2307 | OUTPUT: |
2282 | RETVAL |
2308 | RETVAL |
2283 | |
2309 | |
2284 | MODULE = cf PACKAGE = cf::arch |
2310 | MODULE = cf PACKAGE = cf::arch |