… | |
… | |
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 *self = (SV *)this->self; |
|
|
124 | |
|
|
125 | SvREFCNT_inc (self); |
|
|
126 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
127 | SvREFCNT_dec (self); |
|
|
128 | assert (!this->self); |
|
|
129 | } |
|
|
130 | } |
142 | } |
131 | |
143 | |
132 | // check wether the object really is dead |
144 | // check wether the object really is dead |
133 | void |
145 | void |
134 | attachable::do_check () |
146 | attachable::do_check () |
… | |
… | |
149 | SvREFCNT_dec (cb); |
161 | SvREFCNT_dec (cb); |
150 | cb = 0; |
162 | cb = 0; |
151 | } |
163 | } |
152 | |
164 | |
153 | if (self) |
165 | if (self) |
154 | { |
166 | sever_self (); |
155 | hv_clear (self); |
|
|
156 | |
|
|
157 | SV *self = (SV *)this->self; |
|
|
158 | SvREFCNT_inc (self); |
|
|
159 | sv_unmagic (self, PERL_MAGIC_ext); |
|
|
160 | SvREFCNT_dec (self); |
|
|
161 | // self is now 0 |
|
|
162 | assert (!this->self);//D//TODO remove soon |
|
|
163 | } |
|
|
164 | |
167 | |
165 | mortals.push_back (this); |
168 | mortals.push_back (this); |
166 | } |
169 | } |
167 | |
170 | |
168 | void |
171 | void |
… | |
… | |
345 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
348 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
346 | |
349 | |
347 | inline SV *to_sv (UUID v) |
350 | inline SV *to_sv (UUID v) |
348 | { |
351 | { |
349 | char buf[128]; |
352 | char buf[128]; |
350 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
353 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
351 | return newSVpv (buf, 0); |
354 | return newSVpv (buf, 0); |
352 | } |
355 | } |
353 | |
356 | |
354 | 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; } |
355 | 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; } |
… | |
… | |
602 | 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)) |
603 | { |
606 | { |
604 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
607 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
605 | exit (EXIT_FAILURE); |
608 | exit (EXIT_FAILURE); |
606 | } |
609 | } |
|
|
610 | |
|
|
611 | { |
|
|
612 | dSP; |
|
|
613 | |
|
|
614 | PUSHMARK (SP); |
|
|
615 | PUTBACK; |
|
|
616 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
617 | } |
607 | } |
618 | } |
608 | |
619 | |
609 | void cfperl_main () |
620 | void cfperl_main () |
610 | { |
621 | { |
611 | dSP; |
622 | dSP; |
… | |
… | |
1647 | |
1658 | |
1648 | void cleanup (const char *cause, bool make_core = false) |
1659 | void cleanup (const char *cause, bool make_core = false) |
1649 | |
1660 | |
1650 | void emergency_save () |
1661 | void emergency_save () |
1651 | |
1662 | |
|
|
1663 | void _exit (int status = EXIT_SUCCESS) |
|
|
1664 | |
1652 | UV sv_2watcher (SV *w) |
1665 | UV sv_2watcher (SV *w) |
1653 | CODE: |
1666 | CODE: |
1654 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1667 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1655 | OUTPUT: |
1668 | OUTPUT: |
1656 | RETVAL |
1669 | RETVAL |
1657 | |
|
|
1658 | void _exit (int status = 0) |
|
|
1659 | |
1670 | |
1660 | #if _POSIX_MEMLOCK |
1671 | #if _POSIX_MEMLOCK |
1661 | |
1672 | |
1662 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1673 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1663 | |
1674 | |
… | |
… | |
1709 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1720 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1710 | else |
1721 | else |
1711 | XSRETURN_UNDEF; |
1722 | XSRETURN_UNDEF; |
1712 | OUTPUT: RETVAL |
1723 | OUTPUT: RETVAL |
1713 | |
1724 | |
|
|
1725 | bool |
|
|
1726 | load_regions (const char *filename) |
|
|
1727 | CODE: |
|
|
1728 | RETVAL = loader_region ().load (filename); |
|
|
1729 | OUTPUT: RETVAL |
|
|
1730 | |
1714 | MODULE = cf PACKAGE = cf::attachable |
1731 | MODULE = cf PACKAGE = cf::attachable |
1715 | |
1732 | |
1716 | int |
1733 | int |
1717 | valid (SV *obj) |
1734 | valid (SV *obj) |
1718 | CODE: |
1735 | CODE: |
… | |
… | |
1802 | |
1819 | |
1803 | void |
1820 | void |
1804 | set_animation (object *op, int idx) |
1821 | set_animation (object *op, int idx) |
1805 | CODE: |
1822 | CODE: |
1806 | 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 |
1807 | |
1830 | |
1808 | object *find_best_object_match (object *op, const char *match) |
1831 | object *find_best_object_match (object *op, const char *match) |
1809 | |
1832 | |
1810 | object *find_marked_object (object *op) |
1833 | object *find_marked_object (object *op) |
1811 | |
1834 | |
… | |
… | |
2048 | pl->orig_stats = pl->ob->stats; |
2071 | pl->orig_stats = pl->ob->stats; |
2049 | |
2072 | |
2050 | void cf_player_move (player *pl, int dir) |
2073 | void cf_player_move (player *pl, int dir) |
2051 | |
2074 | |
2052 | 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); |
2053 | |
|
|
2054 | player *first () |
|
|
2055 | CODE: |
|
|
2056 | RETVAL = first_player; |
|
|
2057 | OUTPUT: RETVAL |
|
|
2058 | |
2076 | |
2059 | bool |
2077 | bool |
2060 | cell_visible (player *pl, int dx, int dy) |
2078 | cell_visible (player *pl, int dx, int dy) |
2061 | CODE: |
2079 | CODE: |
2062 | 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 |
… | |
… | |
2139 | EXTEND (SP, THIS->players); |
2157 | EXTEND (SP, THIS->players); |
2140 | for_all_players (pl) |
2158 | for_all_players (pl) |
2141 | if (pl->ob && pl->ob->map == THIS) |
2159 | if (pl->ob && pl->ob->map == THIS) |
2142 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2160 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2143 | } |
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 | } |
2144 | |
2180 | |
2145 | 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) |
2146 | |
2182 | |
2147 | int out_of_map (maptile *map, int x, int y) |
2183 | int out_of_map (maptile *map, int x, int y) |
2148 | |
2184 | |
… | |
… | |
2229 | OUTPUT: RETVAL |
2265 | OUTPUT: RETVAL |
2230 | |
2266 | |
2231 | void fix_walls (maptile *map, int x, int y) |
2267 | void fix_walls (maptile *map, int x, int y) |
2232 | |
2268 | |
2233 | void fix_walls_around (maptile *map, int x, int y) |
2269 | void fix_walls_around (maptile *map, int x, int y) |
2234 | |
|
|
2235 | const char * |
|
|
2236 | region_name (maptile *m) |
|
|
2237 | CODE: |
|
|
2238 | RETVAL = get_name_of_region_for_map (m); |
|
|
2239 | OUTPUT: RETVAL |
|
|
2240 | |
2270 | |
2241 | # worst xs function of my life |
2271 | # worst xs function of my life |
2242 | bool |
2272 | bool |
2243 | _create_random_map (\ |
2273 | _create_random_map (\ |
2244 | maptile *self,\ |
2274 | maptile *self,\ |
… | |
… | |
2352 | |
2382 | |
2353 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2383 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2354 | |
2384 | |
2355 | MODULE = cf PACKAGE = cf::region |
2385 | MODULE = cf PACKAGE = cf::region |
2356 | |
2386 | |
2357 | region *first () |
2387 | void |
2358 | PROTOTYPE: |
2388 | list () |
2359 | CODE: |
2389 | PPCODE: |
2360 | RETVAL = first_region; |
2390 | for_all_regions (rgn) |
2361 | OUTPUT: RETVAL |
2391 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2362 | |
2392 | |
2363 | region *find (char *name) |
2393 | region *find (char *name) |
2364 | PROTOTYPE: $ |
2394 | PROTOTYPE: $ |
2365 | CODE: |
2395 | CODE: |
2366 | 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); |
2367 | OUTPUT: RETVAL |
2403 | OUTPUT: RETVAL |
2368 | |
2404 | |
2369 | INCLUDE: $PERL genacc region ../include/map.h | |
2405 | INCLUDE: $PERL genacc region ../include/map.h | |
2370 | |
2406 | |
2371 | MODULE = cf PACKAGE = cf::living |
2407 | MODULE = cf PACKAGE = cf::living |