… | |
… | |
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 (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 | } |
|
|
133 | } |
|
|
134 | |
|
|
135 | void |
117 | attachable::optimise () |
136 | attachable::optimise () |
118 | { |
137 | { |
119 | if (self |
138 | if (self |
120 | && SvREFCNT (self) == 1 |
139 | && SvREFCNT (self) == 1 |
121 | && !HvTOTALKEYS (self)) |
140 | && !HvTOTALKEYS (self)) |
122 | { |
141 | sever_self (); |
123 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
124 | assert (!self); |
|
|
125 | } |
|
|
126 | } |
142 | } |
127 | |
143 | |
128 | // check wether the object really is dead |
144 | // check wether the object really is dead |
129 | void |
145 | void |
130 | attachable::do_check () |
146 | attachable::do_check () |
… | |
… | |
145 | SvREFCNT_dec (cb); |
161 | SvREFCNT_dec (cb); |
146 | cb = 0; |
162 | cb = 0; |
147 | } |
163 | } |
148 | |
164 | |
149 | if (self) |
165 | if (self) |
150 | { |
166 | 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 | |
167 | |
157 | mortals.push_back (this); |
168 | mortals.push_back (this); |
158 | } |
169 | } |
159 | |
170 | |
160 | void |
171 | void |
… | |
… | |
337 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
348 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
338 | |
349 | |
339 | inline SV *to_sv (UUID v) |
350 | inline SV *to_sv (UUID v) |
340 | { |
351 | { |
341 | char buf[128]; |
352 | char buf[128]; |
342 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
353 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
343 | return newSVpv (buf, 0); |
354 | return newSVpv (buf, 0); |
344 | } |
355 | } |
345 | |
356 | |
346 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
357 | 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; } |
358 | 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)) |
605 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) |
595 | { |
606 | { |
596 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
607 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
597 | exit (EXIT_FAILURE); |
608 | exit (EXIT_FAILURE); |
598 | } |
609 | } |
|
|
610 | |
|
|
611 | { |
|
|
612 | dSP; |
|
|
613 | |
|
|
614 | PUSHMARK (SP); |
|
|
615 | PUTBACK; |
|
|
616 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
617 | } |
599 | } |
618 | } |
600 | |
619 | |
601 | void cfperl_main () |
620 | void cfperl_main () |
602 | { |
621 | { |
603 | dSP; |
622 | dSP; |
… | |
… | |
1639 | |
1658 | |
1640 | void cleanup (const char *cause, bool make_core = false) |
1659 | void cleanup (const char *cause, bool make_core = false) |
1641 | |
1660 | |
1642 | void emergency_save () |
1661 | void emergency_save () |
1643 | |
1662 | |
|
|
1663 | void _exit (int status = EXIT_SUCCESS) |
|
|
1664 | |
1644 | UV sv_2watcher (SV *w) |
1665 | UV sv_2watcher (SV *w) |
1645 | CODE: |
1666 | CODE: |
1646 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1667 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1647 | OUTPUT: |
1668 | OUTPUT: |
1648 | RETVAL |
1669 | RETVAL |
1649 | |
|
|
1650 | void _exit (int status = 0) |
|
|
1651 | |
1670 | |
1652 | #if _POSIX_MEMLOCK |
1671 | #if _POSIX_MEMLOCK |
1653 | |
1672 | |
1654 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1673 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1655 | |
1674 | |
… | |
… | |
1701 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1720 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1702 | else |
1721 | else |
1703 | XSRETURN_UNDEF; |
1722 | XSRETURN_UNDEF; |
1704 | OUTPUT: RETVAL |
1723 | OUTPUT: RETVAL |
1705 | |
1724 | |
|
|
1725 | bool |
|
|
1726 | load_regions (const char *filename) |
|
|
1727 | CODE: |
|
|
1728 | RETVAL = loader_region ().load (filename); |
|
|
1729 | OUTPUT: RETVAL |
|
|
1730 | |
1706 | MODULE = cf PACKAGE = cf::attachable |
1731 | MODULE = cf PACKAGE = cf::attachable |
1707 | |
1732 | |
1708 | int |
1733 | int |
1709 | valid (SV *obj) |
1734 | valid (SV *obj) |
1710 | CODE: |
1735 | CODE: |
… | |
… | |
1794 | |
1819 | |
1795 | void |
1820 | void |
1796 | set_animation (object *op, int idx) |
1821 | set_animation (object *op, int idx) |
1797 | CODE: |
1822 | CODE: |
1798 | SET_ANIMATION (op, idx); |
1823 | SET_ANIMATION (op, idx); |
|
|
1824 | |
|
|
1825 | int |
|
|
1826 | num_animations (object *op) |
|
|
1827 | CODE: |
|
|
1828 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1829 | OUTPUT: RETVAL |
1799 | |
1830 | |
1800 | object *find_best_object_match (object *op, const char *match) |
1831 | object *find_best_object_match (object *op, const char *match) |
1801 | |
1832 | |
1802 | object *find_marked_object (object *op) |
1833 | object *find_marked_object (object *op) |
1803 | |
1834 | |
… | |
… | |
2040 | pl->orig_stats = pl->ob->stats; |
2071 | pl->orig_stats = pl->ob->stats; |
2041 | |
2072 | |
2042 | void cf_player_move (player *pl, int dir) |
2073 | void cf_player_move (player *pl, int dir) |
2043 | |
2074 | |
2044 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2075 | 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 | |
2076 | |
2051 | bool |
2077 | bool |
2052 | cell_visible (player *pl, int dx, int dy) |
2078 | cell_visible (player *pl, int dx, int dy) |
2053 | CODE: |
2079 | CODE: |
2054 | 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 |
… | |
… | |
2131 | EXTEND (SP, THIS->players); |
2157 | EXTEND (SP, THIS->players); |
2132 | for_all_players (pl) |
2158 | for_all_players (pl) |
2133 | if (pl->ob && pl->ob->map == THIS) |
2159 | if (pl->ob && pl->ob->map == THIS) |
2134 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2160 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2135 | } |
2161 | } |
|
|
2162 | |
|
|
2163 | void |
|
|
2164 | maptile::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 | } |
2136 | |
2180 | |
2137 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2181 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2138 | |
2182 | |
2139 | int out_of_map (maptile *map, int x, int y) |
2183 | int out_of_map (maptile *map, int x, int y) |
2140 | |
2184 | |
… | |
… | |
2221 | OUTPUT: RETVAL |
2265 | OUTPUT: RETVAL |
2222 | |
2266 | |
2223 | void fix_walls (maptile *map, int x, int y) |
2267 | void fix_walls (maptile *map, int x, int y) |
2224 | |
2268 | |
2225 | void fix_walls_around (maptile *map, int x, int y) |
2269 | 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 | |
2270 | |
2233 | # worst xs function of my life |
2271 | # worst xs function of my life |
2234 | bool |
2272 | bool |
2235 | _create_random_map (\ |
2273 | _create_random_map (\ |
2236 | maptile *self,\ |
2274 | maptile *self,\ |
… | |
… | |
2344 | |
2382 | |
2345 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2383 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2346 | |
2384 | |
2347 | MODULE = cf PACKAGE = cf::region |
2385 | MODULE = cf PACKAGE = cf::region |
2348 | |
2386 | |
2349 | region *first () |
2387 | void |
2350 | PROTOTYPE: |
2388 | list () |
2351 | CODE: |
2389 | PPCODE: |
2352 | RETVAL = first_region; |
2390 | for_all_regions (rgn) |
2353 | OUTPUT: RETVAL |
2391 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2354 | |
2392 | |
2355 | region *find (char *name) |
2393 | region *find (char *name) |
2356 | PROTOTYPE: $ |
2394 | PROTOTYPE: $ |
2357 | CODE: |
2395 | CODE: |
2358 | RETVAL = get_region_by_name (name); |
2396 | RETVAL = region::find (name); |
|
|
2397 | OUTPUT: RETVAL |
|
|
2398 | |
|
|
2399 | region *find_fuzzy (char *name) |
|
|
2400 | PROTOTYPE: $ |
|
|
2401 | CODE: |
|
|
2402 | RETVAL = region::find_fuzzy (name); |
2359 | OUTPUT: RETVAL |
2403 | OUTPUT: RETVAL |
2360 | |
2404 | |
2361 | INCLUDE: $PERL genacc region ../include/map.h | |
2405 | INCLUDE: $PERL genacc region ../include/map.h | |
2362 | |
2406 | |
2363 | MODULE = cf PACKAGE = cf::living |
2407 | MODULE = cf PACKAGE = cf::living |