… | |
… | |
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 | |
… | |
… | |
1323 | } |
1321 | } |
1324 | |
1322 | |
1325 | void _post_tick () |
1323 | void _post_tick () |
1326 | CODE: |
1324 | CODE: |
1327 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
1325 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1326 | |
|
|
1327 | # support function for map-world.ext |
|
|
1328 | void _quantise (SV *data_sv, SV *plt_sv) |
|
|
1329 | CODE: |
|
|
1330 | { |
|
|
1331 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
|
|
1332 | croak ("_quantise called with invalid agruments"); |
|
|
1333 | |
|
|
1334 | plt_sv = SvRV (plt_sv); |
|
|
1335 | SV **plt = AvARRAY (plt_sv); |
|
|
1336 | int plt_count = AvFILL (plt_sv) + 1; |
|
|
1337 | |
|
|
1338 | STRLEN len; |
|
|
1339 | char *data = SvPVbyte (data_sv, len); |
|
|
1340 | char *dst = data; |
|
|
1341 | |
|
|
1342 | while (len >= 3) |
|
|
1343 | { |
|
|
1344 | for (SV **val_sv = plt + plt_count; val_sv-- > plt; ) |
|
|
1345 | { |
|
|
1346 | char *val = SvPVX (*val_sv); |
|
|
1347 | |
|
|
1348 | if (val [0] == data [0] |
|
|
1349 | && val [1] == data [1] |
|
|
1350 | && val [2] == data [2]) |
|
|
1351 | { |
|
|
1352 | *dst++ = val [3]; |
|
|
1353 | goto next; |
|
|
1354 | } |
|
|
1355 | } |
|
|
1356 | |
|
|
1357 | croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d", |
|
|
1358 | (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2], |
|
|
1359 | dst - SvPVX (data_sv), len); |
|
|
1360 | |
|
|
1361 | next: |
|
|
1362 | data += 3; |
|
|
1363 | len -= 3; |
|
|
1364 | } |
|
|
1365 | |
|
|
1366 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
|
|
1367 | } |
1328 | |
1368 | |
1329 | NV floor (NV x) |
1369 | NV floor (NV x) |
1330 | |
1370 | |
1331 | NV ceil (NV x) |
1371 | NV ceil (NV x) |
1332 | |
1372 | |
… | |
… | |
1966 | sfree (THIS->regions, THIS->size ()); |
2006 | sfree (THIS->regions, THIS->size ()); |
1967 | free (THIS->regionmap); |
2007 | free (THIS->regionmap); |
1968 | |
2008 | |
1969 | THIS->regions = regions; |
2009 | THIS->regions = regions; |
1970 | 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 (); |
1971 | } |
2036 | } |
1972 | |
2037 | |
1973 | 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) |
1974 | |
2039 | |
1975 | int out_of_map (maptile *map, int x, int y) |
2040 | int out_of_map (maptile *map, int x, int y) |
… | |
… | |
2199 | RETVAL = 0; |
2264 | RETVAL = 0; |
2200 | while (rgn = rgn->parent) |
2265 | while (rgn = rgn->parent) |
2201 | RETVAL++; |
2266 | RETVAL++; |
2202 | OUTPUT: RETVAL |
2267 | OUTPUT: RETVAL |
2203 | |
2268 | |
2204 | INCLUDE: $PERL $srcdir/genacc region ../include/map.h | |
2269 | INCLUDE: $PERL $srcdir/genacc region ../include/region.h | |
2205 | |
2270 | |
2206 | MODULE = cf PACKAGE = cf::living |
2271 | MODULE = cf PACKAGE = cf::living |
2207 | |
2272 | |
2208 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2273 | INCLUDE: $PERL $srcdir/genacc living ../include/living.h | |
2209 | |
2274 | |