… | |
… | |
57 | typedef char *octet_string; |
57 | typedef char *octet_string; |
58 | typedef char *utf8_string; |
58 | typedef char *utf8_string; |
59 | typedef const char *const_octet_string; |
59 | typedef const char *const_octet_string; |
60 | typedef const char *const_utf8_string; |
60 | typedef const char *const_utf8_string; |
61 | |
61 | |
|
|
62 | typedef std::string std__string; |
|
|
63 | |
62 | #if IVSIZE >= 8 |
64 | #if IVSIZE >= 8 |
63 | typedef IV val64; |
65 | typedef IV val64; |
64 | # define newSVval64 newSViv |
66 | # define newSVval64 newSViv |
65 | # define SvVAL64 SvIV |
67 | # define SvVAL64 SvIV |
66 | #else |
68 | #else |
… | |
… | |
109 | |
111 | |
110 | unordered_vector<attachable *> attachable::mortals; |
112 | unordered_vector<attachable *> attachable::mortals; |
111 | |
113 | |
112 | attachable::~attachable () |
114 | attachable::~attachable () |
113 | { |
115 | { |
114 | flags |=0x3300;//D |
|
|
115 | assert (!self); |
116 | assert (!self); |
116 | assert (!cb); |
117 | assert (!cb); |
117 | } |
118 | } |
118 | |
119 | |
119 | int |
120 | int |
… | |
… | |
135 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
136 | SvREFCNT_dec (self); |
137 | SvREFCNT_dec (self); |
137 | |
138 | |
138 | // self *must* be null now because thats sv_unmagic's job. |
139 | // self *must* be null now because thats sv_unmagic's job. |
139 | assert (!this->self); |
140 | assert (!this->self); |
140 | flags |= 0x80; // severed //D |
|
|
141 | } |
141 | } |
142 | } |
142 | } |
143 | |
143 | |
144 | void |
144 | void |
145 | attachable::optimise () |
145 | attachable::optimise () |
146 | { |
146 | { |
147 | if (self |
147 | if (self |
148 | && SvREFCNT (self) == 1 |
148 | && SvREFCNT (self) == 1 |
149 | && !HvTOTALKEYS (self)) |
149 | && !HvTOTALKEYS (self)) |
150 | flags |= 0x40,//D |
|
|
151 | sever_self (); |
150 | sever_self (); |
152 | } |
151 | } |
153 | |
152 | |
154 | // check wether the object really is dead |
153 | // check wether the object really is dead |
155 | void |
154 | void |
… | |
… | |
170 | { |
169 | { |
171 | SvREFCNT_dec (cb); |
170 | SvREFCNT_dec (cb); |
172 | cb = 0; |
171 | cb = 0; |
173 | } |
172 | } |
174 | |
173 | |
175 | if (self) |
|
|
176 | sever_self (); |
|
|
177 | |
|
|
178 | flags |= 0x20; //D |
|
|
179 | mortals.push_back (this); |
174 | mortals.push_back (this); |
180 | } |
175 | } |
181 | |
176 | |
182 | void |
177 | void |
183 | attachable::destroy () |
178 | attachable::destroy () |
… | |
… | |
199 | if (i >= mortals.size ()) |
194 | if (i >= mortals.size ()) |
200 | { |
195 | { |
201 | i = 0; |
196 | i = 0; |
202 | |
197 | |
203 | if (mortals.size () > 1000) |
198 | if (mortals.size () > 1000) |
204 | 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 ()); |
205 | |
200 | |
206 | break; |
201 | break; |
207 | } |
202 | } |
208 | |
203 | |
209 | attachable *obj = mortals [i]; |
204 | attachable *obj = mortals [i]; |
210 | |
205 | |
211 | obj->refcnt_chk (); // unborrow from perl, if necessary |
206 | #if 0 |
212 | |
207 | if (obj->self)//D make this an assert later |
213 | //if (obj->refcnt > 0 || obj->self) |
|
|
214 | if (obj->refcnt || obj->self) |
|
|
215 | { |
208 | { |
216 | //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 | { |
217 | ++i; // further delay freeing |
216 | ++i; // further delay freeing |
218 | |
217 | |
219 | if (!(i & 0x3ff)) |
218 | if (!(i & 0x3ff)) |
220 | break; |
219 | break; |
221 | } |
220 | } |
222 | else |
221 | else |
223 | { |
222 | { |
224 | mortals.erase (i); |
223 | mortals.erase (i); |
|
|
224 | obj->sever_self (); |
225 | delete obj; |
225 | delete obj; |
226 | } |
226 | } |
227 | } |
227 | } |
228 | } |
228 | } |
229 | |
229 | |
… | |
… | |
278 | |
278 | |
279 | if (!obj->self) |
279 | if (!obj->self) |
280 | { |
280 | { |
281 | obj->self = newHV (); |
281 | obj->self = newHV (); |
282 | 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); |
283 | obj->flags |= (obj->flags & 0xc0) << 8; |
|
|
284 | obj->flags &= ~0xc0;//D |
|
|
285 | obj->flags |= 0x10;//D |
|
|
286 | |
283 | |
287 | // now bless the object _once_ |
284 | // now bless the object _once_ |
288 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
285 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
289 | } |
286 | } |
290 | else |
287 | else |
… | |
… | |
356 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
353 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
357 | |
354 | |
358 | inline SV *to_sv (object & v) { return to_sv (&v); } |
355 | inline SV *to_sv (object & v) { return to_sv (&v); } |
359 | inline SV *to_sv (living & v) { return to_sv (&v); } |
356 | inline SV *to_sv (living & v) { return to_sv (&v); } |
360 | |
357 | |
361 | //inline SV *to_sv (faceinfo * v) { return to_sv (v->name); } |
|
|
362 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
|
|
363 | inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } |
358 | inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
|
|
359 | inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
364 | |
360 | |
365 | inline SV *to_sv (UUID v) |
361 | inline SV *to_sv (UUID v) |
366 | { |
362 | { |
367 | char buf[128]; |
363 | char buf[128]; |
368 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
364 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
… | |
… | |
1265 | |
1261 | |
1266 | 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) |
1267 | |
1263 | |
1268 | 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) |
1269 | |
1265 | |
1270 | const_iv (ST_CHANGE_CLASS) |
|
|
1271 | |
|
|
1272 | 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) |
1273 | |
1267 | |
1274 | // random map generator |
1268 | // random map generator |
1275 | 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) |
1276 | 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) |
… | |
… | |
1279 | 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) |
1280 | 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) |
1281 | |
1275 | |
1282 | 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) |
1283 | 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) |
1284 | }; |
1282 | }; |
1285 | |
1283 | |
1286 | 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; ) |
1287 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1285 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1288 | |
1286 | |
… | |
… | |
2008 | sfree (THIS->regions, THIS->size ()); |
2006 | sfree (THIS->regions, THIS->size ()); |
2009 | free (THIS->regionmap); |
2007 | free (THIS->regionmap); |
2010 | |
2008 | |
2011 | THIS->regions = regions; |
2009 | THIS->regions = regions; |
2012 | THIS->regionmap = regionmap; |
2010 | THIS->regionmap = regionmap; |
|
|
2011 | } |
|
|
2012 | |
|
|
2013 | void |
|
|
2014 | maptile::create_region_treasure () |
|
|
2015 | CODE: |
|
|
2016 | { |
|
|
2017 | object *op = object::create (); |
|
|
2018 | op->type = FLOOR; |
|
|
2019 | op->map = THIS; |
|
|
2020 | |
|
|
2021 | for (int x = 0; x < THIS->width; ++x) |
|
|
2022 | for (int y = 0; y < THIS->height; ++y) |
|
|
2023 | { |
|
|
2024 | region *rgn = THIS->region (x, y); |
|
|
2025 | |
|
|
2026 | //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D |
|
|
2027 | if (rgn->treasure && rndm () < rgn->treasure_density) |
|
|
2028 | { |
|
|
2029 | op->x = x; |
|
|
2030 | op->y = y; |
|
|
2031 | create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
|
|
2032 | } |
|
|
2033 | } |
|
|
2034 | |
|
|
2035 | op->destroy (); |
2013 | } |
2036 | } |
2014 | |
2037 | |
2015 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2038 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2016 | |
2039 | |
2017 | int out_of_map (maptile *map, int x, int y) |
2040 | int out_of_map (maptile *map, int x, int y) |
… | |
… | |
2241 | RETVAL = 0; |
2264 | RETVAL = 0; |
2242 | while (rgn = rgn->parent) |
2265 | while (rgn = rgn->parent) |
2243 | RETVAL++; |
2266 | RETVAL++; |
2244 | OUTPUT: RETVAL |
2267 | OUTPUT: RETVAL |
2245 | |
2268 | |
2246 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2269 | INCLUDE: $PERL $srcdir/genacc region ../include/region.h | |
2247 | |
2270 | |
2248 | MODULE = cf PACKAGE = cf::living |
2271 | MODULE = cf PACKAGE = cf::living |
2249 | |
2272 | |
2250 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2273 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2251 | |
2274 | |