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.193 by root, Thu Apr 19 16:23:48 2007 UTC vs.
Revision 1.204 by root, Mon Apr 30 04:25:30 2007 UTC

21 * You should have received a copy of the GNU General Public License 21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */ 24 */
25 25
26#include "autoconf.h"
27
26#define PLUGIN_NAME "perl" 28#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 29#define PLUGIN_VERSION "cfperl 0.5"
28 30
29#define CEDES_PER_TICK 5 31#define CEDES_PER_TICK 5
32
33#if HAVE_EXECINFO_H
34# include <execinfo.h>
35#endif
30 36
31#include <plugin_common.h> 37#include <plugin_common.h>
32#include <sounds.h> 38#include <sounds.h>
33#include <cstdarg> 39#include <cstdarg>
34#include <sproto.h> 40#include <sproto.h>
56 62
57typedef char *octet_string; 63typedef char *octet_string;
58typedef char *utf8_string; 64typedef char *utf8_string;
59typedef const char *const_octet_string; 65typedef const char *const_octet_string;
60typedef const char *const_utf8_string; 66typedef const char *const_utf8_string;
67
68typedef std::string std__string;
61 69
62#if IVSIZE >= 8 70#if IVSIZE >= 8
63 typedef IV val64; 71 typedef IV val64;
64# define newSVval64 newSViv 72# define newSVval64 newSViv
65# define SvVAL64 SvIV 73# define SvVAL64 SvIV
109 117
110unordered_vector<attachable *> attachable::mortals; 118unordered_vector<attachable *> attachable::mortals;
111 119
112attachable::~attachable () 120attachable::~attachable ()
113{ 121{
114 flags |=0x3300;//D
115 assert (!self); 122 assert (!self);
116 assert (!cb); 123 assert (!cb);
117} 124}
118 125
119int 126int
135 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 142 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
136 SvREFCNT_dec (self); 143 SvREFCNT_dec (self);
137 144
138 // self *must* be null now because thats sv_unmagic's job. 145 // self *must* be null now because thats sv_unmagic's job.
139 assert (!this->self); 146 assert (!this->self);
140 flags |= 0x80; // severed //D
141 } 147 }
142} 148}
143 149
144void 150void
145attachable::optimise () 151attachable::optimise ()
146{ 152{
147 if (self 153 if (self
148 && SvREFCNT (self) == 1 154 && SvREFCNT (self) == 1
149 && !HvTOTALKEYS (self)) 155 && !HvTOTALKEYS (self))
150 flags |= 0x40,//D
151 sever_self (); 156 sever_self ();
152} 157}
153 158
154// check wether the object really is dead 159// check wether the object really is dead
155void 160void
170 { 175 {
171 SvREFCNT_dec (cb); 176 SvREFCNT_dec (cb);
172 cb = 0; 177 cb = 0;
173 } 178 }
174 179
175 if (self)
176 sever_self ();
177
178 flags |= 0x20; //D
179 mortals.push_back (this); 180 mortals.push_back (this);
180} 181}
181 182
182void 183void
183attachable::destroy () 184attachable::destroy ()
185 if (destroyed ()) 186 if (destroyed ())
186 return; 187 return;
187 188
188 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
189 do_destroy (); 190 do_destroy ();
191 sever_self ();
190} 192}
191 193
192void 194void
193attachable::check_mortals () 195attachable::check_mortals ()
194{ 196{
199 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
200 { 202 {
201 i = 0; 203 i = 0;
202 204
203 if (mortals.size () > 1000) 205 if (mortals.size () > 1000)
204 fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 206 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ());
205 207
206 break; 208 break;
207 } 209 }
208 210
209 attachable *obj = mortals [i]; 211 attachable *obj = mortals [i];
210 212
211 obj->refcnt_chk (); // unborrow from perl, if necessary 213#if 0
212 214 if (obj->self)//D make this an assert later
213 //if (obj->refcnt > 0 || obj->self)
214 if (obj->refcnt || obj->self)
215 { 215 {
216//printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D 216 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
217 obj->sever_self ();
218 }
219#endif
220
221 if (obj->refcnt)
222 {
217 ++i; // further delay freeing 223 ++i; // further delay freeing
218 224
219 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
220 break; 226 break;
221 } 227 }
222 else 228 else
223 { 229 {
224 mortals.erase (i); 230 mortals.erase (i);
231 obj->sever_self ();
225 delete obj; 232 delete obj;
226 } 233 }
227 } 234 }
228} 235}
229 236
278 285
279 if (!obj->self) 286 if (!obj->self)
280 { 287 {
281 obj->self = newHV (); 288 obj->self = newHV ();
282 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 289 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 290
287 // now bless the object _once_ 291 // now bless the object _once_
288 return sv_bless (newRV_inc ((SV *)obj->self), stash); 292 return sv_bless (newRV_inc ((SV *)obj->self), stash);
289 } 293 }
290 else 294 else
356inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 360inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
357 361
358inline SV *to_sv (object & v) { return to_sv (&v); } 362inline SV *to_sv (object & v) { return to_sv (&v); }
359inline SV *to_sv (living & v) { return to_sv (&v); } 363inline SV *to_sv (living & v) { return to_sv (&v); }
360 364
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 ()); } 365inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
366inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); }
364 367
365inline SV *to_sv (UUID v) 368inline SV *to_sv (UUID v)
366{ 369{
367 char buf[128]; 370 char buf[128];
368 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 371 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
401inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 404inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
402 405
403template<int N> 406template<int N>
404inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 407inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
405 408
406inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
407inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 409inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
408inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 410inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
409inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 411inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
410inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 412inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
411 413
614 perl_construct (perl); 616 perl_construct (perl);
615 617
616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 618 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
617 619
618 const char *argv[] = { 620 const char *argv[] = {
619 "", 621 settings.argv [0],
620 "-e" 622 "-e"
621 "use Event; use Coro;" // required for bootstrap 623 "use Event; use Coro;" // required for bootstrap
622 "cf->bootstrap;" // required for datadir :*> 624 "cf->bootstrap;" // required for datadir :*>
623 "unshift @INC, cf::datadir ();" 625 "unshift @INC, cf::datadir ();"
624 "require cf;" 626 "require cf;"
946 CALL_ARG (exit); 948 CALL_ARG (exit);
947 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 949 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
948 CALL_END; 950 CALL_END;
949} 951}
950 952
953void
954log_backtrace (const char *msg)
955{
956#if HAVE_BACKTRACE
957 void *addr [20];
958 int size = backtrace (addr, 20);
959
960 CALL_BEGIN (size);
961 CALL_ARG (msg);
962 for (int i = 0; i < size; ++i)
963 CALL_ARG ((IV)addr [i]);
964 CALL_CALL ("cf::_log_backtrace", G_VOID);
965 CALL_END;
966#endif
967}
968
951///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
952 970
953struct EventAPI *watcher_base::GEventAPI; 971struct EventAPI *watcher_base::GEventAPI;
954struct CoroAPI *coroapi::GCoroAPI; 972struct CoroAPI *coroapi::GCoroAPI;
955 973
1109 const char *name; 1127 const char *name;
1110 IV iv; 1128 IV iv;
1111 } *civ, const_iv[] = { 1129 } *civ, const_iv[] = {
1112# define const_iv(name) { # name, (IV)name }, 1130# define const_iv(name) { # name, (IV)name },
1113 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1131 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1132 const_iv (logBacktrace)
1114 1133
1115 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1134 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1116 1135
1117 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1136 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1118 1137
1265 1284
1266 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1285 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1267 1286
1268 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1287 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1269 1288
1270 const_iv (ST_CHANGE_CLASS)
1271
1272 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1289 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1273 1290
1274 // random map generator 1291 // random map generator
1275 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1292 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) 1293 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) 1296 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) 1297 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1281 1298
1282 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1299 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1283 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1300 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1301
1302 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1303 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1304 const_iv (GT_MINIMAL)
1284 }; 1305 };
1285 1306
1286 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1307 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1287 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1308 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1288 1309
1388 CODE: 1409 CODE:
1389 runtime = SvNVx (sv_runtime); 1410 runtime = SvNVx (sv_runtime);
1390 server_tick (); 1411 server_tick ();
1391 1412
1392void 1413void
1414log_backtrace (utf8_string msg)
1415
1416void
1393LOG (int level, utf8_string msg) 1417LOG (int flags, utf8_string msg)
1394 PROTOTYPE: $$ 1418 PROTOTYPE: $$
1395 C_ARGS: (LogLevel)level, "%s", msg 1419 C_ARGS: flags, "%s", msg
1396 1420
1397octet_string path_combine (octet_string base, octet_string path) 1421octet_string path_combine (octet_string base, octet_string path)
1398 PROTOTYPE: $$ 1422 PROTOTYPE: $$
1399 1423
1400octet_string path_combine_and_normalize (octet_string base, octet_string path) 1424octet_string path_combine_and_normalize (octet_string base, octet_string path)
1437 } 1461 }
1438 OUTPUT: RETVAL 1462 OUTPUT: RETVAL
1439 1463
1440void abort () 1464void abort ()
1441 1465
1466void reset_signals ()
1467
1442void fork_abort (octet_string cause = "cf::fork_abort") 1468void fork_abort (octet_string cause = "cf::fork_abort")
1443 1469
1444void cleanup (octet_string cause, bool make_core = false) 1470void cleanup (octet_string cause, bool make_core = false)
1445 1471
1446void emergency_save () 1472void emergency_save ()
1972 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 1998 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1973 { 1999 {
1974 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2000 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1975 ob->flag [FLAG_NO_MAP_SAVE] = true; 2001 ob->flag [FLAG_NO_MAP_SAVE] = true;
1976 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2002 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2003
2004 if (ob->randomitems)
2005 {
2006 if (!ob->above)
2007 {
2008 ob->create_treasure (ob->randomitems);
2009
2010 for (object *op = ob->above; op; op = op->above)
2011 op->flag [FLAG_NO_MAP_SAVE] = true;
2012 }
2013
2014 ob->randomitems = 0;
2015 }
1977 } 2016 }
1978 } 2017 }
1979 } 2018 }
1980 2019
1981 skip_space: ; 2020 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines