ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.189 by root, Tue Apr 17 10:06:34 2007 UTC vs.
Revision 1.197 by root, Fri Apr 27 03:38:33 2007 UTC

57typedef char *octet_string; 57typedef char *octet_string;
58typedef char *utf8_string; 58typedef char *utf8_string;
59typedef const char *const_octet_string; 59typedef const char *const_octet_string;
60typedef const char *const_utf8_string; 60typedef const char *const_utf8_string;
61 61
62typedef 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
110unordered_vector<attachable *> attachable::mortals; 112unordered_vector<attachable *> attachable::mortals;
111 113
112attachable::~attachable () 114attachable::~attachable ()
113{ 115{
114 flags |=0x3300;//D
115 assert (!self); 116 assert (!self);
116 assert (!cb); 117 assert (!cb);
117} 118}
118 119
119int 120int
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
144void 144void
145attachable::optimise () 145attachable::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
155void 154void
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
182void 177void
183attachable::destroy () 178attachable::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
356inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 353inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
357 354
358inline SV *to_sv (object & v) { return to_sv (&v); } 355inline SV *to_sv (object & v) { return to_sv (&v); }
359inline SV *to_sv (living & v) { return to_sv (&v); } 356inline SV *to_sv (living & v) { return to_sv (&v); }
360 357
361//inline SV *to_sv (faceinfo * v) { return to_sv (v->name); }
362inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
363inline SV *to_sv (std::string & v) { return newSVpvn (v.data (), v.size ()); } 358inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
359inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
364 360
365inline SV *to_sv (UUID v) 361inline 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
1325void _post_tick () 1323void _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
1328void _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
1329NV floor (NV x) 1369NV floor (NV x)
1330 1370
1331NV ceil (NV x) 1371NV ceil (NV x)
1332 1372
1466 OUTPUT: RETVAL 1506 OUTPUT: RETVAL
1467 1507
1468bool 1508bool
1469load_resource_file (octet_string filename) 1509load_resource_file (octet_string filename)
1470 1510
1471bool
1472load_archetype_file (octet_string filename)
1473
1474bool
1475load_treasure_file (octet_string filename)
1476
1477MODULE = cf PACKAGE = cf::attachable 1511MODULE = cf PACKAGE = cf::attachable
1478 1512
1479int 1513int
1480valid (SV *obj) 1514valid (SV *obj)
1481 CODE: 1515 CODE:
1972 sfree (THIS->regions, THIS->size ()); 2006 sfree (THIS->regions, THIS->size ());
1973 free (THIS->regionmap); 2007 free (THIS->regionmap);
1974 2008
1975 THIS->regions = regions; 2009 THIS->regions = regions;
1976 THIS->regionmap = regionmap; 2010 THIS->regionmap = regionmap;
2011}
2012
2013void
2014maptile::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 ();
1977} 2036}
1978 2037
1979void play_sound_map (maptile *map, int x, int y, int sound_num) 2038void play_sound_map (maptile *map, int x, int y, int sound_num)
1980 2039
1981int out_of_map (maptile *map, int x, int y) 2040int out_of_map (maptile *map, int x, int y)
2205 RETVAL = 0; 2264 RETVAL = 0;
2206 while (rgn = rgn->parent) 2265 while (rgn = rgn->parent)
2207 RETVAL++; 2266 RETVAL++;
2208 OUTPUT: RETVAL 2267 OUTPUT: RETVAL
2209 2268
2210INCLUDE: $PERL $srcdir/genacc region ../include/map.h | 2269INCLUDE: $PERL $srcdir/genacc region ../include/region.h |
2211 2270
2212MODULE = cf PACKAGE = cf::living 2271MODULE = cf PACKAGE = cf::living
2213 2272
2214INCLUDE: $PERL $srcdir/genacc living ../include/living.h | 2273INCLUDE: $PERL $srcdir/genacc living ../include/living.h |
2215 2274

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines