… | |
… | |
111 | |
111 | |
112 | unordered_vector<attachable *> attachable::mortals; |
112 | unordered_vector<attachable *> attachable::mortals; |
113 | |
113 | |
114 | attachable::~attachable () |
114 | attachable::~attachable () |
115 | { |
115 | { |
116 | flags |=0x3300;//D |
|
|
117 | assert (!self); |
116 | assert (!self); |
118 | assert (!cb); |
117 | assert (!cb); |
119 | } |
118 | } |
120 | |
119 | |
121 | int |
120 | int |
… | |
… | |
137 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
138 | SvREFCNT_dec (self); |
137 | SvREFCNT_dec (self); |
139 | |
138 | |
140 | // self *must* be null now because thats sv_unmagic's job. |
139 | // self *must* be null now because thats sv_unmagic's job. |
141 | assert (!this->self); |
140 | assert (!this->self); |
142 | flags |= 0x80; // severed //D |
|
|
143 | } |
141 | } |
144 | } |
142 | } |
145 | |
143 | |
146 | void |
144 | void |
147 | attachable::optimise () |
145 | attachable::optimise () |
148 | { |
146 | { |
149 | if (self |
147 | if (self |
150 | && SvREFCNT (self) == 1 |
148 | && SvREFCNT (self) == 1 |
151 | && !HvTOTALKEYS (self)) |
149 | && !HvTOTALKEYS (self)) |
152 | flags |= 0x40,//D |
|
|
153 | sever_self (); |
150 | sever_self (); |
154 | } |
151 | } |
155 | |
152 | |
156 | // check wether the object really is dead |
153 | // check wether the object really is dead |
157 | void |
154 | void |
… | |
… | |
172 | { |
169 | { |
173 | SvREFCNT_dec (cb); |
170 | SvREFCNT_dec (cb); |
174 | cb = 0; |
171 | cb = 0; |
175 | } |
172 | } |
176 | |
173 | |
177 | if (self) |
|
|
178 | sever_self (); |
|
|
179 | |
|
|
180 | flags |= 0x20; //D |
|
|
181 | mortals.push_back (this); |
174 | mortals.push_back (this); |
182 | } |
175 | } |
183 | |
176 | |
184 | void |
177 | void |
185 | attachable::destroy () |
178 | attachable::destroy () |
… | |
… | |
201 | if (i >= mortals.size ()) |
194 | if (i >= mortals.size ()) |
202 | { |
195 | { |
203 | i = 0; |
196 | i = 0; |
204 | |
197 | |
205 | if (mortals.size () > 1000) |
198 | if (mortals.size () > 1000) |
206 | fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
199 | LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
207 | |
200 | |
208 | break; |
201 | break; |
209 | } |
202 | } |
210 | |
203 | |
211 | attachable *obj = mortals [i]; |
204 | attachable *obj = mortals [i]; |
212 | |
205 | |
213 | obj->refcnt_chk (); // unborrow from perl, if necessary |
206 | #if 0 |
214 | |
207 | if (obj->self)//D make this an assert later |
215 | //if (obj->refcnt > 0 || obj->self) |
|
|
216 | if (obj->refcnt || obj->self) |
|
|
217 | { |
208 | { |
218 | //printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D |
209 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
|
|
210 | obj->sever_self (); |
|
|
211 | } |
|
|
212 | #endif |
|
|
213 | |
|
|
214 | if (obj->refcnt_cnt ()) |
|
|
215 | { |
219 | ++i; // further delay freeing |
216 | ++i; // further delay freeing |
220 | |
217 | |
221 | if (!(i & 0x3ff)) |
218 | if (!(i & 0x3ff)) |
222 | break; |
219 | break; |
223 | } |
220 | } |
224 | else |
221 | else |
225 | { |
222 | { |
226 | mortals.erase (i); |
223 | mortals.erase (i); |
|
|
224 | obj->sever_self (); |
227 | delete obj; |
225 | delete obj; |
228 | } |
226 | } |
229 | } |
227 | } |
230 | } |
228 | } |
231 | |
229 | |
… | |
… | |
280 | |
278 | |
281 | if (!obj->self) |
279 | if (!obj->self) |
282 | { |
280 | { |
283 | obj->self = newHV (); |
281 | obj->self = newHV (); |
284 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
282 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
285 | obj->flags |= (obj->flags & 0xc0) << 8; |
|
|
286 | obj->flags &= ~0xc0;//D |
|
|
287 | obj->flags |= 0x10;//D |
|
|
288 | |
283 | |
289 | // now bless the object _once_ |
284 | // now bless the object _once_ |
290 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
285 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
291 | } |
286 | } |
292 | else |
287 | else |
… | |
… | |
1266 | |
1261 | |
1267 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1262 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1268 | |
1263 | |
1269 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1264 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1270 | |
1265 | |
1271 | const_iv (ST_CHANGE_CLASS) |
|
|
1272 | |
|
|
1273 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1266 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1274 | |
1267 | |
1275 | // random map generator |
1268 | // random map generator |
1276 | const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) |
1269 | const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) |
1277 | const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) |
1270 | const_iv (LAYOUT_ROGUELIKE) const_iv (LAYOUT_SNAKE) const_iv (LAYOUT_SQUARE_SPIRAL) |
… | |
… | |
1280 | const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) |
1273 | const_iv (RMOPT_BOTTOM_C) const_iv (RMOPT_BOTTOM_R) const_iv (RMOPT_IRR_SPACE) |
1281 | const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) |
1274 | const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS) |
1282 | |
1275 | |
1283 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1276 | const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) |
1284 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
1277 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
|
|
1278 | |
|
|
1279 | const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) |
|
|
1280 | const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) |
|
|
1281 | const_iv (GT_MINIMAL) |
1285 | }; |
1282 | }; |
1286 | |
1283 | |
1287 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1284 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1288 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1285 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1289 | |
1286 | |