… | |
… | |
101 | |
101 | |
102 | unordered_vector<attachable *> attachable::mortals; |
102 | unordered_vector<attachable *> attachable::mortals; |
103 | |
103 | |
104 | attachable::~attachable () |
104 | attachable::~attachable () |
105 | { |
105 | { |
106 | assert (!(flags & F_BORROWED)); |
106 | assert (!self); |
107 | } |
107 | } |
108 | |
108 | |
109 | int |
109 | int |
110 | attachable::refcnt_cnt () const |
110 | attachable::refcnt_cnt () const |
111 | { |
111 | { |
… | |
… | |
117 | { |
117 | { |
118 | if (self |
118 | if (self |
119 | && SvREFCNT (self) == 1 |
119 | && SvREFCNT (self) == 1 |
120 | && !HvTOTALKEYS (self)) |
120 | && !HvTOTALKEYS (self)) |
121 | { |
121 | { |
122 | flags &= ~F_BORROWED; |
|
|
123 | refcnt_inc (); |
122 | refcnt_inc (); |
124 | SvREFCNT_dec ((SV *)self); |
123 | SvREFCNT_dec ((SV *)self); |
125 | } |
124 | } |
126 | } |
125 | } |
127 | |
126 | |
128 | // check wether the object really is dead |
127 | // check wether the object really is dead |
129 | void |
128 | void |
130 | attachable::do_check () |
129 | attachable::do_check () |
131 | { |
130 | { |
132 | if (refcnt > 0) |
131 | if (refcnt > 0 || refcnt_cnt () > 0) |
133 | return; |
132 | return; |
134 | |
133 | |
135 | optimise (); |
134 | destroy (); |
136 | |
135 | |
137 | if (self) |
136 | if (self) |
138 | { |
137 | { |
139 | if (refcnt + SvREFCNT (self) > 0) |
138 | hv_clear (self); |
140 | return; |
139 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
141 | |
|
|
142 | assert (flags & F_BORROWED); |
|
|
143 | |
|
|
144 | flags &= ~F_BORROWED; |
|
|
145 | refcnt_inc (); |
|
|
146 | SvREFCNT_dec (self); |
140 | SvREFCNT_dec (self); |
147 | self = 0; |
141 | self = 0; |
148 | } |
142 | } |
149 | |
|
|
150 | if (refcnt > 0) |
|
|
151 | return; |
|
|
152 | |
|
|
153 | destroy (); |
|
|
154 | } |
143 | } |
155 | |
144 | |
156 | void |
145 | void |
157 | attachable::do_destroy () |
146 | attachable::do_destroy () |
158 | { |
147 | { |
… | |
… | |
227 | |
216 | |
228 | static int |
217 | static int |
229 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
218 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
230 | { |
219 | { |
231 | attachable *at = (attachable *)mg->mg_ptr; |
220 | attachable *at = (attachable *)mg->mg_ptr; |
232 | assert (!(at->flags & attachable::F_BORROWED)); |
|
|
233 | at->self = 0; |
221 | at->self = 0; |
234 | // next line makes sense, but most objects still have refcnt 0 by default |
222 | // next line makes sense, but most objects still have refcnt 0 by default |
235 | //at->refcnt_chk (); |
223 | //at->refcnt_chk (); |
236 | return 0; |
224 | return 0; |
237 | } |
225 | } |
… | |
… | |
248 | { |
236 | { |
249 | obj->self = newHV (); |
237 | obj->self = newHV (); |
250 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
238 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
251 | |
239 | |
252 | // borrow the refcnt from the object |
240 | // borrow the refcnt from the object |
253 | obj->flags |= attachable::F_BORROWED; |
241 | // it is important thta no refcnt_chk is being executed here |
254 | obj->refcnt_dec (); |
242 | obj->refcnt_dec (); |
255 | |
243 | |
256 | // now bless the object _once_ |
244 | // now bless the object _once_ |
257 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
245 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
258 | } |
246 | } |
… | |
… | |
318 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
306 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
319 | |
307 | |
320 | inline SV *to_sv (object & v) { return to_sv (&v); } |
308 | inline SV *to_sv (object & v) { return to_sv (&v); } |
321 | inline SV *to_sv (living & v) { return to_sv (&v); } |
309 | inline SV *to_sv (living & v) { return to_sv (&v); } |
322 | |
310 | |
323 | //TODO: |
|
|
324 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
311 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
325 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
312 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
326 | |
313 | |
327 | inline SV *to_sv (UUID v) |
314 | inline SV *to_sv (UUID v) |
328 | { |
315 | { |
… | |
… | |
354 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
341 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
355 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
342 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
356 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
343 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
357 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
344 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
358 | |
345 | |
359 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
346 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } |
360 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
347 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
361 | |
348 | |
362 | template<class T> |
349 | template<class T> |
363 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
350 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
364 | |
351 | |
365 | template<int N> |
352 | template<int N> |
… | |
… | |
830 | } |
817 | } |
831 | |
818 | |
832 | ///////////////////////////////////////////////////////////////////////////// |
819 | ///////////////////////////////////////////////////////////////////////////// |
833 | |
820 | |
834 | void |
821 | void |
835 | maptile::emergency_save () |
822 | cfperl_emergency_save () |
836 | { |
823 | { |
837 | CALL_BEGIN (0); |
824 | CALL_BEGIN (0); |
838 | CALL_CALL ("cf::map::emergency_save", G_VOID); |
825 | CALL_CALL ("cf::emergency_save", G_VOID); |
839 | CALL_END; |
826 | CALL_END; |
840 | } |
827 | } |
841 | |
828 | |
842 | maptile * |
829 | maptile * |
843 | maptile::find_sync (const char *path, maptile *origin) |
830 | maptile::find_sync (const char *path, maptile *origin) |
844 | { |
831 | { |
845 | CALL_BEGIN (2); |
832 | CALL_BEGIN (2); |
846 | CALL_ARG (path); |
833 | CALL_ARG (path); |
847 | CALL_ARG (origin); |
834 | CALL_ARG (origin); |
848 | CALL_CALL ("cf::map::find_sync", G_SCALAR); |
835 | CALL_CALL ("cf::map::find_sync", G_SCALAR); |
|
|
836 | |
|
|
837 | maptile *retval; |
|
|
838 | |
|
|
839 | if (count) |
|
|
840 | sv_to (POPs, retval); |
|
|
841 | else |
|
|
842 | retval = 0; |
|
|
843 | |
|
|
844 | CALL_END; |
|
|
845 | |
|
|
846 | return retval; |
|
|
847 | } |
|
|
848 | |
|
|
849 | maptile * |
|
|
850 | maptile::find_async (const char *path, maptile *origin) |
|
|
851 | { |
|
|
852 | CALL_BEGIN (2); |
|
|
853 | CALL_ARG (path); |
|
|
854 | CALL_ARG (origin); |
|
|
855 | CALL_CALL ("cf::map::find_async", G_SCALAR); |
849 | |
856 | |
850 | maptile *retval; |
857 | maptile *retval; |
851 | |
858 | |
852 | if (count) |
859 | if (count) |
853 | sv_to (POPs, retval); |
860 | sv_to (POPs, retval); |
… | |
… | |
1616 | } |
1623 | } |
1617 | OUTPUT: RETVAL |
1624 | OUTPUT: RETVAL |
1618 | |
1625 | |
1619 | void abort () |
1626 | void abort () |
1620 | |
1627 | |
|
|
1628 | void cleanup (const char *cause, bool make_core = false) |
|
|
1629 | |
1621 | void emergency_save () |
1630 | void emergency_save () |
1622 | |
1631 | |
1623 | void _exit (int status = 0) |
1632 | void _exit (int status = 0) |
1624 | |
1633 | |
1625 | #if _POSIX_MEMLOCK |
1634 | #if _POSIX_MEMLOCK |
… | |
… | |
1715 | PPCODE: |
1724 | PPCODE: |
1716 | EXTEND (SP, object::mortals.size ()); |
1725 | EXTEND (SP, object::mortals.size ()); |
1717 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1726 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1718 | PUSHs (to_sv (*i)); |
1727 | PUSHs (to_sv (*i)); |
1719 | |
1728 | |
1720 | object *first () |
1729 | int objects_size () |
1721 | CODE: |
1730 | CODE: |
1722 | RETVAL = object::first; |
1731 | RETVAL = objects.size (); |
|
|
1732 | OUTPUT: RETVAL |
|
|
1733 | |
|
|
1734 | object *objects (U32 index) |
|
|
1735 | CODE: |
|
|
1736 | RETVAL = index < objects.size () ? objects [index] : 0; |
|
|
1737 | OUTPUT: RETVAL |
|
|
1738 | |
|
|
1739 | int actives_size () |
|
|
1740 | CODE: |
|
|
1741 | RETVAL = actives.size (); |
|
|
1742 | OUTPUT: RETVAL |
|
|
1743 | |
|
|
1744 | object *actives (U32 index) |
|
|
1745 | CODE: |
|
|
1746 | RETVAL = index < actives.size () ? actives [index] : 0; |
1723 | OUTPUT: RETVAL |
1747 | OUTPUT: RETVAL |
1724 | |
1748 | |
1725 | # missing properties |
1749 | # missing properties |
1726 | |
1750 | |
1727 | object *head (object *op) |
1751 | object *head (object *op) |
1728 | PROTOTYPE: $ |
1752 | PROTOTYPE: $ |
1729 | CODE: |
1753 | CODE: |
1730 | RETVAL = op->head ? op->head : op; |
1754 | RETVAL = op->head_ (); |
1731 | OUTPUT: RETVAL |
1755 | OUTPUT: RETVAL |
1732 | |
1756 | |
1733 | int is_head (object *op) |
1757 | int is_head (object *op) |
1734 | PROTOTYPE: $ |
1758 | PROTOTYPE: $ |
1735 | CODE: |
1759 | CODE: |
1736 | RETVAL = !op->head; |
1760 | RETVAL = op->head_ () == op; |
1737 | OUTPUT: RETVAL |
1761 | OUTPUT: RETVAL |
1738 | |
1762 | |
1739 | void |
1763 | void |
1740 | inv (object *obj) |
1764 | inv (object *obj) |
1741 | PROTOTYPE: $ |
1765 | PROTOTYPE: $ |
… | |
… | |
2226 | int random_seed,\ |
2250 | int random_seed,\ |
2227 | val64 total_map_hp,\ |
2251 | val64 total_map_hp,\ |
2228 | int map_layout_style,\ |
2252 | int map_layout_style,\ |
2229 | int treasureoptions,\ |
2253 | int treasureoptions,\ |
2230 | int symmetry_used,\ |
2254 | int symmetry_used,\ |
2231 | region *region\ |
2255 | region *region,\ |
|
|
2256 | char *custom\ |
2232 | ) |
2257 | ) |
2233 | CODE: |
2258 | CODE: |
2234 | { |
2259 | { |
2235 | random_map_params rmp; |
2260 | random_map_params rmp; |
2236 | |
2261 | |
… | |
… | |
2268 | rmp.total_map_hp = total_map_hp; |
2293 | rmp.total_map_hp = total_map_hp; |
2269 | rmp.map_layout_style = map_layout_style; |
2294 | rmp.map_layout_style = map_layout_style; |
2270 | rmp.treasureoptions = treasureoptions; |
2295 | rmp.treasureoptions = treasureoptions; |
2271 | rmp.symmetry_used = symmetry_used; |
2296 | rmp.symmetry_used = symmetry_used; |
2272 | rmp.region = region; |
2297 | rmp.region = region; |
|
|
2298 | rmp.custom = custom; |
2273 | |
2299 | |
2274 | RETVAL = generate_random_map (path, &rmp); |
2300 | RETVAL = generate_random_map (path, &rmp); |
2275 | } |
2301 | } |
2276 | OUTPUT: |
2302 | OUTPUT: |
2277 | RETVAL |
2303 | RETVAL |