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.208 by root, Sat May 12 13:27:38 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
1119 const_iv (MAX_TIME) 1138 const_iv (MAX_TIME)
1139
1140 const_iv (NUM_BODY_LOCATIONS)
1141 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1142 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1143 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1144 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1145 const_iv (body_wrist) const_iv (body_waist)
1120 1146
1121 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1147 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1122 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1148 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1123 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1149 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1124 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1150 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1265 1291
1266 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1292 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1267 1293
1268 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) 1294 const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM)
1269 1295
1270 const_iv (ST_CHANGE_CLASS)
1271
1272 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1296 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1273 1297
1274 // random map generator 1298 // random map generator
1275 const_iv (LAYOUT_NONE) const_iv (LAYOUT_ONION) const_iv (LAYOUT_MAZE) const_iv (LAYOUT_SPIRAL) 1299 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) 1300 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) 1303 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) 1304 const_iv (RMOPT_WALL_OFF) const_iv (RMOPT_WALLS_ONLY) const_iv (RMOPT_NO_DOORS)
1281 1305
1282 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1306 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1283 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1307 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1308
1309 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1310 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1311 const_iv (GT_MINIMAL)
1284 }; 1312 };
1285 1313
1286 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1314 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1287 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1315 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1288 1316
1382 default: croak ("cf::rndm requires none, one or two parameters."); break; 1410 default: croak ("cf::rndm requires none, one or two parameters."); break;
1383 } 1411 }
1384 OUTPUT: 1412 OUTPUT:
1385 RETVAL 1413 RETVAL
1386 1414
1415NV clamp (NV value, NV min_value, NV max_value)
1416 CODE:
1417 RETVAL = clamp (value, min_value, max_value);
1418 OUTPUT:
1419 RETVAL
1420
1421NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1422 CODE:
1423 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1424 OUTPUT:
1425 RETVAL
1426
1427void cede_to_tick ()
1428 CODE:
1429 coroapi::cede_to_tick ();
1430
1387void server_tick () 1431void server_tick ()
1388 CODE: 1432 CODE:
1389 runtime = SvNVx (sv_runtime); 1433 runtime = SvNVx (sv_runtime);
1390 server_tick (); 1434 server_tick ();
1391 1435
1392void 1436void
1437log_backtrace (utf8_string msg)
1438
1439void
1393LOG (int level, utf8_string msg) 1440LOG (int flags, utf8_string msg)
1394 PROTOTYPE: $$ 1441 PROTOTYPE: $$
1395 C_ARGS: (LogLevel)level, "%s", msg 1442 C_ARGS: flags, "%s", msg
1396 1443
1397octet_string path_combine (octet_string base, octet_string path) 1444octet_string path_combine (octet_string base, octet_string path)
1398 PROTOTYPE: $$ 1445 PROTOTYPE: $$
1399 1446
1400octet_string path_combine_and_normalize (octet_string base, octet_string path) 1447octet_string path_combine_and_normalize (octet_string base, octet_string path)
1437 } 1484 }
1438 OUTPUT: RETVAL 1485 OUTPUT: RETVAL
1439 1486
1440void abort () 1487void abort ()
1441 1488
1489void reset_signals ()
1490
1442void fork_abort (octet_string cause = "cf::fork_abort") 1491void fork_abort (octet_string cause = "cf::fork_abort")
1443 1492
1444void cleanup (octet_string cause, bool make_core = false) 1493void cleanup (octet_string cause, bool make_core = false)
1445 1494
1446void emergency_save () 1495void emergency_save ()
1580object *actives (U32 index) 1629object *actives (U32 index)
1581 CODE: 1630 CODE:
1582 RETVAL = index < actives.size () ? actives [index] : 0; 1631 RETVAL = index < actives.size () ? actives [index] : 0;
1583 OUTPUT: RETVAL 1632 OUTPUT: RETVAL
1584 1633
1634const char *slot_save_name (U32 slot)
1635 ALIAS:
1636 slot_use_name = 1
1637 slot_nonuse_name = 2
1638 CODE:
1639{
1640 if (slot >= NUM_BODY_LOCATIONS)
1641 croak ("body slot index out of range");
1642
1643 switch (ix)
1644 {
1645 case 0: RETVAL = body_locations[slot].save_name; break;
1646 case 1: RETVAL = body_locations[slot].use_name; break;
1647 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1648 }
1649}
1650 OUTPUT:
1651 RETVAL
1652
1585# missing properties 1653# missing properties
1586 1654
1587object *head (object *op) 1655object *head (object *op)
1588 PROTOTYPE: $ 1656 PROTOTYPE: $
1589 CODE: 1657 CODE:
1614int 1682int
1615num_animations (object *op) 1683num_animations (object *op)
1616 CODE: 1684 CODE:
1617 RETVAL = NUM_ANIMATIONS (op); 1685 RETVAL = NUM_ANIMATIONS (op);
1618 OUTPUT: RETVAL 1686 OUTPUT: RETVAL
1687
1688int slot_info (object *op, UV slot, int value = 0)
1689 ALIAS:
1690 slot_used = 1
1691 CODE:
1692{
1693 if (slot >= NUM_BODY_LOCATIONS)
1694 croak ("body slot index out of range");
1695
1696 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1697
1698 if (items > 2)
1699 if (ix)
1700 op->slot[slot].used = value;
1701 else
1702 op->slot[slot].info = value;
1703}
1704 OUTPUT:
1705 RETVAL
1619 1706
1620object *find_best_object_match (object *op, utf8_string match) 1707object *find_best_object_match (object *op, utf8_string match)
1621 1708
1622object *find_marked_object (object *op) 1709object *find_marked_object (object *op)
1623 1710
1972 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2059 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1973 { 2060 {
1974 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2061 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1975 ob->flag [FLAG_NO_MAP_SAVE] = true; 2062 ob->flag [FLAG_NO_MAP_SAVE] = true;
1976 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2063 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2064
2065 if (ob->randomitems)
2066 {
2067 if (!ob->above)
2068 {
2069 ob->create_treasure (ob->randomitems);
2070
2071 for (object *op = ob->above; op; op = op->above)
2072 op->flag [FLAG_NO_MAP_SAVE] = true;
2073 }
2074
2075 ob->randomitems = 0;
2076 }
1977 } 2077 }
1978 } 2078 }
1979 } 2079 }
1980 2080
1981 skip_space: ; 2081 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines