… | |
… | |
112 | { |
112 | { |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
114 | } |
114 | } |
115 | |
115 | |
116 | void |
116 | void |
|
|
117 | attachable::sever_self () |
|
|
118 | { |
|
|
119 | if (HV *self = this->self) |
|
|
120 | { |
|
|
121 | // keep a refcount because sv_unmagic might call attachable_free, |
|
|
122 | // which might clear self, causing sv_unmagic to crash on a now |
|
|
123 | // invalid object. |
|
|
124 | SvREFCNT_inc (self); |
|
|
125 | hv_clear (self); |
|
|
126 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | |
|
|
129 | // self *must* be null now because thats sv_unmagic's job. |
|
|
130 | assert (!this->self); |
|
|
131 | } |
|
|
132 | } |
|
|
133 | |
|
|
134 | void |
117 | attachable::optimise () |
135 | attachable::optimise () |
118 | { |
136 | { |
119 | if (self |
137 | if (self |
120 | && SvREFCNT (self) == 1 |
138 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
139 | && !HvTOTALKEYS (self)) |
122 | { |
140 | sever_self (); |
123 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
124 | assert (!self); |
|
|
125 | } |
|
|
126 | } |
141 | } |
127 | |
142 | |
128 | // check wether the object really is dead |
143 | // check wether the object really is dead |
129 | void |
144 | void |
130 | attachable::do_check () |
145 | attachable::do_check () |
… | |
… | |
145 | SvREFCNT_dec (cb); |
160 | SvREFCNT_dec (cb); |
146 | cb = 0; |
161 | cb = 0; |
147 | } |
162 | } |
148 | |
163 | |
149 | if (self) |
164 | if (self) |
150 | { |
165 | sever_self (); |
151 | hv_clear (self); |
|
|
152 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
153 | // self is now 0 |
|
|
154 | assert (!self);//D//TODO remove soon |
|
|
155 | } |
|
|
156 | |
166 | |
157 | mortals.push_back (this); |
167 | mortals.push_back (this); |
158 | } |
168 | } |
159 | |
169 | |
160 | void |
170 | void |
… | |
… | |
337 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
347 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
338 | |
348 | |
339 | inline SV *to_sv (UUID v) |
349 | inline SV *to_sv (UUID v) |
340 | { |
350 | { |
341 | char buf[128]; |
351 | char buf[128]; |
342 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
352 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
343 | return newSVpv (buf, 0); |
353 | return newSVpv (buf, 0); |
344 | } |
354 | } |
345 | |
355 | |
346 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
356 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
347 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
357 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
… | |
… | |
1639 | |
1649 | |
1640 | void cleanup (const char *cause, bool make_core = false) |
1650 | void cleanup (const char *cause, bool make_core = false) |
1641 | |
1651 | |
1642 | void emergency_save () |
1652 | void emergency_save () |
1643 | |
1653 | |
|
|
1654 | void _exit (int status = EXIT_SUCCESS) |
|
|
1655 | |
1644 | UV sv_2watcher (SV *w) |
1656 | UV sv_2watcher (SV *w) |
1645 | CODE: |
1657 | CODE: |
1646 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1658 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1647 | OUTPUT: |
1659 | OUTPUT: |
1648 | RETVAL |
1660 | RETVAL |
1649 | |
|
|
1650 | void _exit (int status = 0) |
|
|
1651 | |
1661 | |
1652 | #if _POSIX_MEMLOCK |
1662 | #if _POSIX_MEMLOCK |
1653 | |
1663 | |
1654 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1664 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1655 | |
1665 | |
… | |
… | |
1795 | void |
1805 | void |
1796 | set_animation (object *op, int idx) |
1806 | set_animation (object *op, int idx) |
1797 | CODE: |
1807 | CODE: |
1798 | SET_ANIMATION (op, idx); |
1808 | SET_ANIMATION (op, idx); |
1799 | |
1809 | |
|
|
1810 | int |
|
|
1811 | num_animations (object *op) |
|
|
1812 | CODE: |
|
|
1813 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1814 | OUTPUT: RETVAL |
|
|
1815 | |
1800 | object *find_best_object_match (object *op, const char *match) |
1816 | object *find_best_object_match (object *op, const char *match) |
1801 | |
1817 | |
1802 | object *find_marked_object (object *op) |
1818 | object *find_marked_object (object *op) |
1803 | |
1819 | |
1804 | int need_identify (object *obj); |
1820 | int need_identify (object *obj); |
… | |
… | |
2040 | pl->orig_stats = pl->ob->stats; |
2056 | pl->orig_stats = pl->ob->stats; |
2041 | |
2057 | |
2042 | void cf_player_move (player *pl, int dir) |
2058 | void cf_player_move (player *pl, int dir) |
2043 | |
2059 | |
2044 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2060 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2045 | |
|
|
2046 | player *first () |
|
|
2047 | CODE: |
|
|
2048 | RETVAL = first_player; |
|
|
2049 | OUTPUT: RETVAL |
|
|
2050 | |
2061 | |
2051 | bool |
2062 | bool |
2052 | cell_visible (player *pl, int dx, int dy) |
2063 | cell_visible (player *pl, int dx, int dy) |
2053 | CODE: |
2064 | CODE: |
2054 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2065 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
… | |
… | |
2131 | EXTEND (SP, THIS->players); |
2142 | EXTEND (SP, THIS->players); |
2132 | for_all_players (pl) |
2143 | for_all_players (pl) |
2133 | if (pl->ob && pl->ob->map == THIS) |
2144 | if (pl->ob && pl->ob->map == THIS) |
2134 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2145 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2135 | } |
2146 | } |
|
|
2147 | |
|
|
2148 | void |
|
|
2149 | maptile::set_regiondata (SV *data, SV *plt) |
|
|
2150 | CODE: |
|
|
2151 | { |
|
|
2152 | if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) |
|
|
2153 | croak ("maptile::set_regiondata needs arrayref as plt arg"); |
|
|
2154 | |
|
|
2155 | AV *av = (AV *)SvRV (plt); |
|
|
2156 | |
|
|
2157 | region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); |
|
|
2158 | |
|
|
2159 | for (int i = av_len (av) + 1; i--; ) |
|
|
2160 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); |
|
|
2161 | |
|
|
2162 | THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); |
|
|
2163 | THIS->regionmap = regionmap; |
|
|
2164 | } |
2136 | |
2165 | |
2137 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2166 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2138 | |
2167 | |
2139 | int out_of_map (maptile *map, int x, int y) |
2168 | int out_of_map (maptile *map, int x, int y) |
2140 | |
2169 | |
… | |
… | |
2221 | OUTPUT: RETVAL |
2250 | OUTPUT: RETVAL |
2222 | |
2251 | |
2223 | void fix_walls (maptile *map, int x, int y) |
2252 | void fix_walls (maptile *map, int x, int y) |
2224 | |
2253 | |
2225 | void fix_walls_around (maptile *map, int x, int y) |
2254 | void fix_walls_around (maptile *map, int x, int y) |
2226 | |
|
|
2227 | const char * |
|
|
2228 | region_name (maptile *m) |
|
|
2229 | CODE: |
|
|
2230 | RETVAL = get_name_of_region_for_map (m); |
|
|
2231 | OUTPUT: RETVAL |
|
|
2232 | |
2255 | |
2233 | # worst xs function of my life |
2256 | # worst xs function of my life |
2234 | bool |
2257 | bool |
2235 | _create_random_map (\ |
2258 | _create_random_map (\ |
2236 | maptile *self,\ |
2259 | maptile *self,\ |
… | |
… | |
2344 | |
2367 | |
2345 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2368 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2346 | |
2369 | |
2347 | MODULE = cf PACKAGE = cf::region |
2370 | MODULE = cf PACKAGE = cf::region |
2348 | |
2371 | |
2349 | region *first () |
2372 | void |
2350 | PROTOTYPE: |
2373 | list () |
2351 | CODE: |
2374 | PPCODE: |
2352 | RETVAL = first_region; |
2375 | for_all_regions (rgn) |
2353 | OUTPUT: RETVAL |
2376 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2354 | |
2377 | |
2355 | region *find (char *name) |
2378 | region *find (char *name) |
2356 | PROTOTYPE: $ |
2379 | PROTOTYPE: $ |
2357 | CODE: |
2380 | CODE: |
2358 | RETVAL = get_region_by_name (name); |
2381 | RETVAL = region::find (name); |
|
|
2382 | OUTPUT: RETVAL |
|
|
2383 | |
|
|
2384 | region *find_fuzzy (char *name) |
|
|
2385 | PROTOTYPE: $ |
|
|
2386 | CODE: |
|
|
2387 | RETVAL = region::find_fuzzy (name); |
2359 | OUTPUT: RETVAL |
2388 | OUTPUT: RETVAL |
2360 | |
2389 | |
2361 | INCLUDE: $PERL genacc region ../include/map.h | |
2390 | INCLUDE: $PERL genacc region ../include/map.h | |
2362 | |
2391 | |
2363 | MODULE = cf PACKAGE = cf::living |
2392 | MODULE = cf PACKAGE = cf::living |