… | |
… | |
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 | } |
… | |
… | |
830 | } |
818 | } |
831 | |
819 | |
832 | ///////////////////////////////////////////////////////////////////////////// |
820 | ///////////////////////////////////////////////////////////////////////////// |
833 | |
821 | |
834 | void |
822 | void |
835 | maptile::emergency_save () |
823 | cfperl_emergency_save () |
836 | { |
824 | { |
837 | CALL_BEGIN (0); |
825 | CALL_BEGIN (0); |
838 | CALL_CALL ("cf::map::emergency_save", G_VOID); |
826 | CALL_CALL ("cf::emergency_save", G_VOID); |
839 | CALL_END; |
827 | CALL_END; |
840 | } |
828 | } |
841 | |
829 | |
842 | maptile * |
830 | maptile * |
843 | maptile::find_sync (const char *path, maptile *origin) |
831 | maptile::find_sync (const char *path, maptile *origin) |
… | |
… | |
1616 | } |
1604 | } |
1617 | OUTPUT: RETVAL |
1605 | OUTPUT: RETVAL |
1618 | |
1606 | |
1619 | void abort () |
1607 | void abort () |
1620 | |
1608 | |
|
|
1609 | void cleanup (const char *cause, bool make_core = false) |
|
|
1610 | |
1621 | void emergency_save () |
1611 | void emergency_save () |
1622 | |
1612 | |
1623 | void _exit (int status = 0) |
1613 | void _exit (int status = 0) |
1624 | |
1614 | |
1625 | #if _POSIX_MEMLOCK |
1615 | #if _POSIX_MEMLOCK |
… | |
… | |
1715 | PPCODE: |
1705 | PPCODE: |
1716 | EXTEND (SP, object::mortals.size ()); |
1706 | EXTEND (SP, object::mortals.size ()); |
1717 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1707 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
1718 | PUSHs (to_sv (*i)); |
1708 | PUSHs (to_sv (*i)); |
1719 | |
1709 | |
1720 | object *first () |
1710 | int objects_size () |
1721 | CODE: |
1711 | CODE: |
1722 | RETVAL = object::first; |
1712 | RETVAL = objects.size (); |
|
|
1713 | OUTPUT: RETVAL |
|
|
1714 | |
|
|
1715 | object *objects (U32 index) |
|
|
1716 | CODE: |
|
|
1717 | RETVAL = index < objects.size () ? objects [index] : 0; |
|
|
1718 | OUTPUT: RETVAL |
|
|
1719 | |
|
|
1720 | int actives_size () |
|
|
1721 | CODE: |
|
|
1722 | RETVAL = actives.size (); |
|
|
1723 | OUTPUT: RETVAL |
|
|
1724 | |
|
|
1725 | object *actives (U32 index) |
|
|
1726 | CODE: |
|
|
1727 | RETVAL = index < actives.size () ? actives [index] : 0; |
1723 | OUTPUT: RETVAL |
1728 | OUTPUT: RETVAL |
1724 | |
1729 | |
1725 | # missing properties |
1730 | # missing properties |
1726 | |
1731 | |
1727 | object *head (object *op) |
1732 | object *head (object *op) |
1728 | PROTOTYPE: $ |
1733 | PROTOTYPE: $ |
1729 | CODE: |
1734 | CODE: |
1730 | RETVAL = op->head ? op->head : op; |
1735 | RETVAL = op->head_ (); |
1731 | OUTPUT: RETVAL |
1736 | OUTPUT: RETVAL |
1732 | |
1737 | |
1733 | int is_head (object *op) |
1738 | int is_head (object *op) |
1734 | PROTOTYPE: $ |
1739 | PROTOTYPE: $ |
1735 | CODE: |
1740 | CODE: |
1736 | RETVAL = !op->head; |
1741 | RETVAL = op->head_ () == op; |
1737 | OUTPUT: RETVAL |
1742 | OUTPUT: RETVAL |
1738 | |
1743 | |
1739 | void |
1744 | void |
1740 | inv (object *obj) |
1745 | inv (object *obj) |
1741 | PROTOTYPE: $ |
1746 | PROTOTYPE: $ |
… | |
… | |
2053 | void |
2058 | void |
2054 | list () |
2059 | list () |
2055 | PPCODE: |
2060 | PPCODE: |
2056 | for_all_players (pl) |
2061 | for_all_players (pl) |
2057 | XPUSHs (sv_2mortal (to_sv (pl))); |
2062 | XPUSHs (sv_2mortal (to_sv (pl))); |
2058 | |
|
|
2059 | bool |
|
|
2060 | peaceful (player *pl, bool new_setting = 0) |
|
|
2061 | PROTOTYPE: $;$ |
|
|
2062 | CODE: |
|
|
2063 | RETVAL = pl->peaceful; |
|
|
2064 | if (items > 1) |
|
|
2065 | pl->peaceful = new_setting; |
|
|
2066 | OUTPUT: |
|
|
2067 | RETVAL |
|
|
2068 | |
|
|
2069 | living * |
|
|
2070 | orig_stats (player *pl) |
|
|
2071 | CODE: |
|
|
2072 | RETVAL = &pl->orig_stats; |
|
|
2073 | OUTPUT: RETVAL |
|
|
2074 | |
|
|
2075 | living * |
|
|
2076 | last_stats (player *pl) |
|
|
2077 | CODE: |
|
|
2078 | RETVAL = &pl->last_stats; |
|
|
2079 | OUTPUT: RETVAL |
|
|
2080 | |
2063 | |
2081 | |
2064 | |
2082 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2065 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2083 | |
2066 | |
2084 | int invoke (maptile *map, int event, ...) |
2067 | int invoke (maptile *map, int event, ...) |