… | |
… | |
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 |
… | |
… | |
112 | { |
113 | { |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
114 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
114 | } |
115 | } |
115 | |
116 | |
116 | void |
117 | void |
|
|
118 | attachable::sever_self () |
|
|
119 | { |
|
|
120 | if (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 (!self); |
|
|
132 | flags |= 0x80; // severed //D |
|
|
133 | } |
|
|
134 | } |
|
|
135 | |
|
|
136 | void |
117 | attachable::optimise () |
137 | attachable::optimise () |
118 | { |
138 | { |
119 | if (self |
139 | if (self |
120 | && SvREFCNT (self) == 1 |
140 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
141 | && !HvTOTALKEYS (self)) |
122 | { |
142 | flags |= 0x40,//D |
123 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
143 | sever_self (); |
124 | assert (!self); |
|
|
125 | } |
|
|
126 | } |
144 | } |
127 | |
145 | |
128 | // check wether the object really is dead |
146 | // check wether the object really is dead |
129 | void |
147 | void |
130 | attachable::do_check () |
148 | attachable::do_check () |
… | |
… | |
145 | SvREFCNT_dec (cb); |
163 | SvREFCNT_dec (cb); |
146 | cb = 0; |
164 | cb = 0; |
147 | } |
165 | } |
148 | |
166 | |
149 | if (self) |
167 | if (self) |
150 | { |
168 | 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 | |
169 | |
|
|
170 | flags |= 0x20; //D |
157 | mortals.push_back (this); |
171 | mortals.push_back (this); |
158 | } |
172 | } |
159 | |
173 | |
160 | void |
174 | void |
161 | attachable::destroy () |
175 | attachable::destroy () |
… | |
… | |
256 | |
270 | |
257 | if (!obj->self) |
271 | if (!obj->self) |
258 | { |
272 | { |
259 | obj->self = newHV (); |
273 | obj->self = newHV (); |
260 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
274 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
|
|
275 | obj->flags &= ~0xc0;//D |
|
|
276 | obj->flags |= 0x10;//D |
261 | |
277 | |
262 | // now bless the object _once_ |
278 | // now bless the object _once_ |
263 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
279 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
264 | } |
280 | } |
265 | else |
281 | else |
… | |
… | |
337 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
353 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
338 | |
354 | |
339 | inline SV *to_sv (UUID v) |
355 | inline SV *to_sv (UUID v) |
340 | { |
356 | { |
341 | char buf[128]; |
357 | char buf[128]; |
342 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
358 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
343 | return newSVpv (buf, 0); |
359 | return newSVpv (buf, 0); |
344 | } |
360 | } |
345 | |
361 | |
346 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
362 | 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; } |
363 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
… | |
… | |
594 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
610 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
595 | { |
611 | { |
596 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
612 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
597 | exit (EXIT_FAILURE); |
613 | exit (EXIT_FAILURE); |
598 | } |
614 | } |
|
|
615 | |
|
|
616 | { |
|
|
617 | dSP; |
|
|
618 | |
|
|
619 | PUSHMARK (SP); |
|
|
620 | PUTBACK; |
|
|
621 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
622 | } |
599 | } |
623 | } |
600 | |
624 | |
601 | void cfperl_main () |
625 | void cfperl_main () |
602 | { |
626 | { |
603 | dSP; |
627 | dSP; |
… | |
… | |
1639 | |
1663 | |
1640 | void cleanup (const char *cause, bool make_core = false) |
1664 | void cleanup (const char *cause, bool make_core = false) |
1641 | |
1665 | |
1642 | void emergency_save () |
1666 | void emergency_save () |
1643 | |
1667 | |
|
|
1668 | void _exit (int status = EXIT_SUCCESS) |
|
|
1669 | |
1644 | UV sv_2watcher (SV *w) |
1670 | UV sv_2watcher (SV *w) |
1645 | CODE: |
1671 | CODE: |
1646 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1672 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1647 | OUTPUT: |
1673 | OUTPUT: |
1648 | RETVAL |
1674 | RETVAL |
1649 | |
|
|
1650 | void _exit (int status = 0) |
|
|
1651 | |
1675 | |
1652 | #if _POSIX_MEMLOCK |
1676 | #if _POSIX_MEMLOCK |
1653 | |
1677 | |
1654 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1678 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1655 | |
1679 | |
… | |
… | |
1701 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1725 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1702 | else |
1726 | else |
1703 | XSRETURN_UNDEF; |
1727 | XSRETURN_UNDEF; |
1704 | OUTPUT: RETVAL |
1728 | OUTPUT: RETVAL |
1705 | |
1729 | |
|
|
1730 | bool |
|
|
1731 | load_regions (const char *filename) |
|
|
1732 | CODE: |
|
|
1733 | RETVAL = loader_region ().load (filename); |
|
|
1734 | OUTPUT: RETVAL |
|
|
1735 | |
1706 | MODULE = cf PACKAGE = cf::attachable |
1736 | MODULE = cf PACKAGE = cf::attachable |
1707 | |
1737 | |
1708 | int |
1738 | int |
1709 | valid (SV *obj) |
1739 | valid (SV *obj) |
1710 | CODE: |
1740 | CODE: |
… | |
… | |
1794 | |
1824 | |
1795 | void |
1825 | void |
1796 | set_animation (object *op, int idx) |
1826 | set_animation (object *op, int idx) |
1797 | CODE: |
1827 | CODE: |
1798 | SET_ANIMATION (op, idx); |
1828 | SET_ANIMATION (op, idx); |
|
|
1829 | |
|
|
1830 | int |
|
|
1831 | num_animations (object *op) |
|
|
1832 | CODE: |
|
|
1833 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1834 | OUTPUT: RETVAL |
1799 | |
1835 | |
1800 | object *find_best_object_match (object *op, const char *match) |
1836 | object *find_best_object_match (object *op, const char *match) |
1801 | |
1837 | |
1802 | object *find_marked_object (object *op) |
1838 | object *find_marked_object (object *op) |
1803 | |
1839 | |
… | |
… | |
2040 | pl->orig_stats = pl->ob->stats; |
2076 | pl->orig_stats = pl->ob->stats; |
2041 | |
2077 | |
2042 | void cf_player_move (player *pl, int dir) |
2078 | void cf_player_move (player *pl, int dir) |
2043 | |
2079 | |
2044 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2080 | 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 | |
2081 | |
2051 | bool |
2082 | bool |
2052 | cell_visible (player *pl, int dx, int dy) |
2083 | cell_visible (player *pl, int dx, int dy) |
2053 | CODE: |
2084 | CODE: |
2054 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2085 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
… | |
… | |
2131 | EXTEND (SP, THIS->players); |
2162 | EXTEND (SP, THIS->players); |
2132 | for_all_players (pl) |
2163 | for_all_players (pl) |
2133 | if (pl->ob && pl->ob->map == THIS) |
2164 | if (pl->ob && pl->ob->map == THIS) |
2134 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2165 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2135 | } |
2166 | } |
|
|
2167 | |
|
|
2168 | void |
|
|
2169 | maptile::set_regiondata (SV *data, SV *plt) |
|
|
2170 | CODE: |
|
|
2171 | { |
|
|
2172 | if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) |
|
|
2173 | croak ("maptile::set_regiondata needs arrayref as plt arg"); |
|
|
2174 | |
|
|
2175 | AV *av = (AV *)SvRV (plt); |
|
|
2176 | |
|
|
2177 | region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); |
|
|
2178 | |
|
|
2179 | for (int i = av_len (av) + 1; i--; ) |
|
|
2180 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); |
|
|
2181 | |
|
|
2182 | THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); |
|
|
2183 | THIS->regionmap = regionmap; |
|
|
2184 | } |
2136 | |
2185 | |
2137 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2186 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2138 | |
2187 | |
2139 | int out_of_map (maptile *map, int x, int y) |
2188 | int out_of_map (maptile *map, int x, int y) |
2140 | |
2189 | |
… | |
… | |
2221 | OUTPUT: RETVAL |
2270 | OUTPUT: RETVAL |
2222 | |
2271 | |
2223 | void fix_walls (maptile *map, int x, int y) |
2272 | void fix_walls (maptile *map, int x, int y) |
2224 | |
2273 | |
2225 | void fix_walls_around (maptile *map, int x, int y) |
2274 | 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 | |
2275 | |
2233 | # worst xs function of my life |
2276 | # worst xs function of my life |
2234 | bool |
2277 | bool |
2235 | _create_random_map (\ |
2278 | _create_random_map (\ |
2236 | maptile *self,\ |
2279 | maptile *self,\ |
… | |
… | |
2344 | |
2387 | |
2345 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2388 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2346 | |
2389 | |
2347 | MODULE = cf PACKAGE = cf::region |
2390 | MODULE = cf PACKAGE = cf::region |
2348 | |
2391 | |
2349 | region *first () |
2392 | void |
2350 | PROTOTYPE: |
2393 | list () |
2351 | CODE: |
2394 | PPCODE: |
2352 | RETVAL = first_region; |
2395 | for_all_regions (rgn) |
2353 | OUTPUT: RETVAL |
2396 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2354 | |
2397 | |
2355 | region *find (char *name) |
2398 | region *find (char *name) |
2356 | PROTOTYPE: $ |
2399 | PROTOTYPE: $ |
2357 | CODE: |
2400 | CODE: |
2358 | RETVAL = get_region_by_name (name); |
2401 | RETVAL = region::find (name); |
|
|
2402 | OUTPUT: RETVAL |
|
|
2403 | |
|
|
2404 | region *find_fuzzy (char *name) |
|
|
2405 | PROTOTYPE: $ |
|
|
2406 | CODE: |
|
|
2407 | RETVAL = region::find_fuzzy (name); |
2359 | OUTPUT: RETVAL |
2408 | OUTPUT: RETVAL |
2360 | |
2409 | |
2361 | INCLUDE: $PERL genacc region ../include/map.h | |
2410 | INCLUDE: $PERL genacc region ../include/map.h | |
2362 | |
2411 | |
2363 | MODULE = cf PACKAGE = cf::living |
2412 | MODULE = cf PACKAGE = cf::living |