… | |
… | |
102 | unordered_vector<attachable *> attachable::mortals; |
102 | unordered_vector<attachable *> attachable::mortals; |
103 | |
103 | |
104 | attachable::~attachable () |
104 | attachable::~attachable () |
105 | { |
105 | { |
106 | assert (!self); |
106 | assert (!self); |
|
|
107 | assert (!cb); |
107 | } |
108 | } |
108 | |
109 | |
109 | int |
110 | int |
110 | attachable::refcnt_cnt () const |
111 | attachable::refcnt_cnt () const |
111 | { |
112 | { |
112 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
113 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
|
|
114 | } |
|
|
115 | |
|
|
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 | } |
113 | } |
132 | } |
114 | |
133 | |
115 | void |
134 | void |
116 | attachable::optimise () |
135 | attachable::optimise () |
117 | { |
136 | { |
118 | if (self |
137 | if (self |
119 | && SvREFCNT (self) == 1 |
138 | && SvREFCNT (self) == 1 |
120 | && !HvTOTALKEYS (self)) |
139 | && !HvTOTALKEYS (self)) |
121 | { |
140 | sever_self (); |
122 | SvREFCNT_dec ((SV *)self); |
|
|
123 | assert (!self); |
|
|
124 | } |
|
|
125 | } |
141 | } |
126 | |
142 | |
127 | // check wether the object really is dead |
143 | // check wether the object really is dead |
128 | void |
144 | void |
129 | attachable::do_check () |
145 | attachable::do_check () |
130 | { |
146 | { |
131 | if (refcnt_cnt () > 0) |
147 | if (refcnt_cnt () > 0) |
132 | return; |
148 | return; |
133 | |
149 | |
134 | destroy (); |
150 | destroy (); |
|
|
151 | } |
|
|
152 | |
|
|
153 | void |
|
|
154 | attachable::do_destroy () |
|
|
155 | { |
|
|
156 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
157 | |
|
|
158 | if (cb) |
|
|
159 | { |
|
|
160 | SvREFCNT_dec (cb); |
|
|
161 | cb = 0; |
|
|
162 | } |
135 | |
163 | |
136 | if (self) |
164 | if (self) |
137 | { |
165 | sever_self (); |
138 | hv_clear (self); |
|
|
139 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
|
|
140 | SvREFCNT_dec (self); |
|
|
141 | self = 0; |
|
|
142 | } |
|
|
143 | } |
|
|
144 | |
|
|
145 | void |
|
|
146 | attachable::do_destroy () |
|
|
147 | { |
|
|
148 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
149 | |
|
|
150 | if (self) |
|
|
151 | hv_clear (self); |
|
|
152 | |
166 | |
153 | mortals.push_back (this); |
167 | mortals.push_back (this); |
154 | } |
168 | } |
155 | |
169 | |
156 | void |
170 | void |
… | |
… | |
227 | |
241 | |
228 | static int |
242 | static int |
229 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
243 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
230 | { |
244 | { |
231 | attachable *at = (attachable *)mg->mg_ptr; |
245 | attachable *at = (attachable *)mg->mg_ptr; |
|
|
246 | |
|
|
247 | //TODO: check if transaction behaviour is really required here |
|
|
248 | if (SV *self = (SV *)at->self) |
|
|
249 | { |
232 | at->self = 0; |
250 | at->self = 0; |
|
|
251 | SvREFCNT_dec (self); |
|
|
252 | } |
|
|
253 | |
233 | // next line makes sense, but most objects still have refcnt 0 by default |
254 | // next line makes sense, but most objects still have refcnt 0 by default |
234 | //at->refcnt_chk (); |
255 | //at->refcnt_chk (); |
235 | return 0; |
256 | return 0; |
236 | } |
257 | } |
237 | |
258 | |
… | |
… | |
326 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
347 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
327 | |
348 | |
328 | inline SV *to_sv (UUID v) |
349 | inline SV *to_sv (UUID v) |
329 | { |
350 | { |
330 | char buf[128]; |
351 | char buf[128]; |
331 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
352 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
332 | return newSVpv (buf, 0); |
353 | return newSVpv (buf, 0); |
333 | } |
354 | } |
334 | |
355 | |
335 | 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; } |
336 | 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; } |
… | |
… | |
1628 | |
1649 | |
1629 | void cleanup (const char *cause, bool make_core = false) |
1650 | void cleanup (const char *cause, bool make_core = false) |
1630 | |
1651 | |
1631 | void emergency_save () |
1652 | void emergency_save () |
1632 | |
1653 | |
|
|
1654 | void _exit (int status = EXIT_SUCCESS) |
|
|
1655 | |
1633 | UV sv_2watcher (SV *w) |
1656 | UV sv_2watcher (SV *w) |
1634 | CODE: |
1657 | CODE: |
1635 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1658 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
1636 | OUTPUT: |
1659 | OUTPUT: |
1637 | RETVAL |
1660 | RETVAL |
1638 | |
|
|
1639 | void _exit (int status = 0) |
|
|
1640 | |
1661 | |
1641 | #if _POSIX_MEMLOCK |
1662 | #if _POSIX_MEMLOCK |
1642 | |
1663 | |
1643 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1664 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1644 | |
1665 | |
… | |
… | |
1699 | CODE: |
1720 | CODE: |
1700 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1721 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1701 | OUTPUT: |
1722 | OUTPUT: |
1702 | RETVAL |
1723 | RETVAL |
1703 | |
1724 | |
|
|
1725 | int mortals_size () |
|
|
1726 | CODE: |
|
|
1727 | RETVAL = attachable::mortals.size (); |
|
|
1728 | OUTPUT: RETVAL |
|
|
1729 | |
|
|
1730 | #object *mortals (U32 index) |
|
|
1731 | # CODE: |
|
|
1732 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
|
|
1733 | # OUTPUT: RETVAL |
|
|
1734 | |
1704 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1735 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1705 | |
1736 | |
1706 | MODULE = cf PACKAGE = cf::global |
1737 | MODULE = cf PACKAGE = cf::global |
1707 | |
1738 | |
1708 | int invoke (SV *klass, int event, ...) |
1739 | int invoke (SV *klass, int event, ...) |
… | |
… | |
1725 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1756 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1726 | OUTPUT: RETVAL |
1757 | OUTPUT: RETVAL |
1727 | |
1758 | |
1728 | SV *registry (object *op) |
1759 | SV *registry (object *op) |
1729 | |
1760 | |
1730 | void mortals () |
|
|
1731 | PPCODE: |
|
|
1732 | EXTEND (SP, object::mortals.size ()); |
|
|
1733 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1734 | PUSHs (to_sv (*i)); |
|
|
1735 | |
|
|
1736 | int objects_size () |
1761 | int objects_size () |
1737 | CODE: |
1762 | CODE: |
1738 | RETVAL = objects.size (); |
1763 | RETVAL = objects.size (); |
1739 | OUTPUT: RETVAL |
1764 | OUTPUT: RETVAL |
1740 | |
1765 | |
… | |
… | |
1779 | |
1804 | |
1780 | void |
1805 | void |
1781 | set_animation (object *op, int idx) |
1806 | set_animation (object *op, int idx) |
1782 | CODE: |
1807 | CODE: |
1783 | SET_ANIMATION (op, idx); |
1808 | SET_ANIMATION (op, idx); |
|
|
1809 | |
|
|
1810 | int |
|
|
1811 | num_animations (object *op) |
|
|
1812 | CODE: |
|
|
1813 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1814 | OUTPUT: RETVAL |
1784 | |
1815 | |
1785 | object *find_best_object_match (object *op, const char *match) |
1816 | object *find_best_object_match (object *op, const char *match) |
1786 | |
1817 | |
1787 | object *find_marked_object (object *op) |
1818 | object *find_marked_object (object *op) |
1788 | |
1819 | |
… | |
… | |
2116 | EXTEND (SP, THIS->players); |
2147 | EXTEND (SP, THIS->players); |
2117 | for_all_players (pl) |
2148 | for_all_players (pl) |
2118 | if (pl->ob && pl->ob->map == THIS) |
2149 | if (pl->ob && pl->ob->map == THIS) |
2119 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2150 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2120 | } |
2151 | } |
|
|
2152 | |
|
|
2153 | void |
|
|
2154 | maptile::set_regiondata (SV *data, SV *plt) |
|
|
2155 | CODE: |
|
|
2156 | { |
|
|
2157 | if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) |
|
|
2158 | croak ("maptile::set_regiondata needs arrayref as plt arg"); |
|
|
2159 | |
|
|
2160 | AV *av = (AV *)SvRV (plt); |
|
|
2161 | |
|
|
2162 | region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); |
|
|
2163 | |
|
|
2164 | for (int i = av_len (av) + 1; i--; ) |
|
|
2165 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); |
|
|
2166 | |
|
|
2167 | THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); |
|
|
2168 | THIS->regionmap = regionmap; |
|
|
2169 | } |
2121 | |
2170 | |
2122 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2171 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2123 | |
2172 | |
2124 | int out_of_map (maptile *map, int x, int y) |
2173 | int out_of_map (maptile *map, int x, int y) |
2125 | |
2174 | |
… | |
… | |
2206 | OUTPUT: RETVAL |
2255 | OUTPUT: RETVAL |
2207 | |
2256 | |
2208 | void fix_walls (maptile *map, int x, int y) |
2257 | void fix_walls (maptile *map, int x, int y) |
2209 | |
2258 | |
2210 | void fix_walls_around (maptile *map, int x, int y) |
2259 | void fix_walls_around (maptile *map, int x, int y) |
2211 | |
|
|
2212 | const char * |
|
|
2213 | region_name (maptile *m) |
|
|
2214 | CODE: |
|
|
2215 | RETVAL = get_name_of_region_for_map (m); |
|
|
2216 | OUTPUT: RETVAL |
|
|
2217 | |
2260 | |
2218 | # worst xs function of my life |
2261 | # worst xs function of my life |
2219 | bool |
2262 | bool |
2220 | _create_random_map (\ |
2263 | _create_random_map (\ |
2221 | maptile *self,\ |
2264 | maptile *self,\ |
… | |
… | |
2338 | OUTPUT: RETVAL |
2381 | OUTPUT: RETVAL |
2339 | |
2382 | |
2340 | region *find (char *name) |
2383 | region *find (char *name) |
2341 | PROTOTYPE: $ |
2384 | PROTOTYPE: $ |
2342 | CODE: |
2385 | CODE: |
2343 | RETVAL = get_region_by_name (name); |
2386 | RETVAL = region::find (name); |
2344 | OUTPUT: RETVAL |
2387 | OUTPUT: RETVAL |
2345 | |
2388 | |
2346 | INCLUDE: $PERL genacc region ../include/map.h | |
2389 | INCLUDE: $PERL genacc region ../include/map.h | |
2347 | |
2390 | |
2348 | MODULE = cf PACKAGE = cf::living |
2391 | MODULE = cf PACKAGE = cf::living |