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.195 by root, Tue Apr 24 00:42:02 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>
111 117
112unordered_vector<attachable *> attachable::mortals; 118unordered_vector<attachable *> attachable::mortals;
113 119
114attachable::~attachable () 120attachable::~attachable ()
115{ 121{
116 flags |=0x3300;//D
117 assert (!self); 122 assert (!self);
118 assert (!cb); 123 assert (!cb);
119} 124}
120 125
121int 126int
137 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 142 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
138 SvREFCNT_dec (self); 143 SvREFCNT_dec (self);
139 144
140 // self *must* be null now because thats sv_unmagic's job. 145 // self *must* be null now because thats sv_unmagic's job.
141 assert (!this->self); 146 assert (!this->self);
142 flags |= 0x80; // severed //D
143 } 147 }
144} 148}
145 149
146void 150void
147attachable::optimise () 151attachable::optimise ()
148{ 152{
149 if (self 153 if (self
150 && SvREFCNT (self) == 1 154 && SvREFCNT (self) == 1
151 && !HvTOTALKEYS (self)) 155 && !HvTOTALKEYS (self))
152 flags |= 0x40,//D
153 sever_self (); 156 sever_self ();
154} 157}
155 158
156// check wether the object really is dead 159// check wether the object really is dead
157void 160void
172 { 175 {
173 SvREFCNT_dec (cb); 176 SvREFCNT_dec (cb);
174 cb = 0; 177 cb = 0;
175 } 178 }
176 179
177 if (self)
178 sever_self ();
179
180 flags |= 0x20; //D
181 mortals.push_back (this); 180 mortals.push_back (this);
182} 181}
183 182
184void 183void
185attachable::destroy () 184attachable::destroy ()
187 if (destroyed ()) 186 if (destroyed ())
188 return; 187 return;
189 188
190 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
191 do_destroy (); 190 do_destroy ();
191 sever_self ();
192} 192}
193 193
194void 194void
195attachable::check_mortals () 195attachable::check_mortals ()
196{ 196{
201 if (i >= mortals.size ()) 201 if (i >= mortals.size ())
202 { 202 {
203 i = 0; 203 i = 0;
204 204
205 if (mortals.size () > 1000) 205 if (mortals.size () > 1000)
206 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 ());
207 207
208 break; 208 break;
209 } 209 }
210 210
211 attachable *obj = mortals [i]; 211 attachable *obj = mortals [i];
212 212
213 obj->refcnt_chk (); // unborrow from perl, if necessary 213#if 0
214 214 if (obj->self)//D make this an assert later
215 //if (obj->refcnt > 0 || obj->self)
216 if (obj->refcnt || obj->self)
217 { 215 {
218//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 {
219 ++i; // further delay freeing 223 ++i; // further delay freeing
220 224
221 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
222 break; 226 break;
223 } 227 }
224 else 228 else
225 { 229 {
226 mortals.erase (i); 230 mortals.erase (i);
231 obj->sever_self ();
227 delete obj; 232 delete obj;
228 } 233 }
229 } 234 }
230} 235}
231 236
280 285
281 if (!obj->self) 286 if (!obj->self)
282 { 287 {
283 obj->self = newHV (); 288 obj->self = newHV ();
284 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);
285 obj->flags |= (obj->flags & 0xc0) << 8;
286 obj->flags &= ~0xc0;//D
287 obj->flags |= 0x10;//D
288 290
289 // now bless the object _once_ 291 // now bless the object _once_
290 return sv_bless (newRV_inc ((SV *)obj->self), stash); 292 return sv_bless (newRV_inc ((SV *)obj->self), stash);
291 } 293 }
292 else 294 else
402inline 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; }
403 405
404template<int N> 406template<int N>
405inline 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)); }
406 408
407inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
408inline 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); }
409inline 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); }
410inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 411inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
411inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 412inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
412 413
615 perl_construct (perl); 616 perl_construct (perl);
616 617
617 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 618 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
618 619
619 const char *argv[] = { 620 const char *argv[] = {
620 "", 621 settings.argv [0],
621 "-e" 622 "-e"
622 "use Event; use Coro;" // required for bootstrap 623 "use Event; use Coro;" // required for bootstrap
623 "cf->bootstrap;" // required for datadir :*> 624 "cf->bootstrap;" // required for datadir :*>
624 "unshift @INC, cf::datadir ();" 625 "unshift @INC, cf::datadir ();"
625 "require cf;" 626 "require cf;"
947 CALL_ARG (exit); 948 CALL_ARG (exit);
948 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 949 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
949 CALL_END; 950 CALL_END;
950} 951}
951 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
952///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
953 970
954struct EventAPI *watcher_base::GEventAPI; 971struct EventAPI *watcher_base::GEventAPI;
955struct CoroAPI *coroapi::GCoroAPI; 972struct CoroAPI *coroapi::GCoroAPI;
956 973
1110 const char *name; 1127 const char *name;
1111 IV iv; 1128 IV iv;
1112 } *civ, const_iv[] = { 1129 } *civ, const_iv[] = {
1113# define const_iv(name) { # name, (IV)name }, 1130# define const_iv(name) { # name, (IV)name },
1114 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)
1115 1133
1116 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1134 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1117 1135
1118 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1136 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1119 1137
1120 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)
1121 1146
1122 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)
1123 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)
1124 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)
1125 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)
1385 default: croak ("cf::rndm requires none, one or two parameters."); break; 1410 default: croak ("cf::rndm requires none, one or two parameters."); break;
1386 } 1411 }
1387 OUTPUT: 1412 OUTPUT:
1388 RETVAL 1413 RETVAL
1389 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
1390void server_tick () 1431void server_tick ()
1391 CODE: 1432 CODE:
1392 runtime = SvNVx (sv_runtime); 1433 runtime = SvNVx (sv_runtime);
1393 server_tick (); 1434 server_tick ();
1394 1435
1395void 1436void
1437log_backtrace (utf8_string msg)
1438
1439void
1396LOG (int level, utf8_string msg) 1440LOG (int flags, utf8_string msg)
1397 PROTOTYPE: $$ 1441 PROTOTYPE: $$
1398 C_ARGS: (LogLevel)level, "%s", msg 1442 C_ARGS: flags, "%s", msg
1399 1443
1400octet_string path_combine (octet_string base, octet_string path) 1444octet_string path_combine (octet_string base, octet_string path)
1401 PROTOTYPE: $$ 1445 PROTOTYPE: $$
1402 1446
1403octet_string path_combine_and_normalize (octet_string base, octet_string path) 1447octet_string path_combine_and_normalize (octet_string base, octet_string path)
1440 } 1484 }
1441 OUTPUT: RETVAL 1485 OUTPUT: RETVAL
1442 1486
1443void abort () 1487void abort ()
1444 1488
1489void reset_signals ()
1490
1445void fork_abort (octet_string cause = "cf::fork_abort") 1491void fork_abort (octet_string cause = "cf::fork_abort")
1446 1492
1447void cleanup (octet_string cause, bool make_core = false) 1493void cleanup (octet_string cause, bool make_core = false)
1448 1494
1449void emergency_save () 1495void emergency_save ()
1583object *actives (U32 index) 1629object *actives (U32 index)
1584 CODE: 1630 CODE:
1585 RETVAL = index < actives.size () ? actives [index] : 0; 1631 RETVAL = index < actives.size () ? actives [index] : 0;
1586 OUTPUT: RETVAL 1632 OUTPUT: RETVAL
1587 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
1588# missing properties 1653# missing properties
1589 1654
1590object *head (object *op) 1655object *head (object *op)
1591 PROTOTYPE: $ 1656 PROTOTYPE: $
1592 CODE: 1657 CODE:
1617int 1682int
1618num_animations (object *op) 1683num_animations (object *op)
1619 CODE: 1684 CODE:
1620 RETVAL = NUM_ANIMATIONS (op); 1685 RETVAL = NUM_ANIMATIONS (op);
1621 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
1622 1706
1623object *find_best_object_match (object *op, utf8_string match) 1707object *find_best_object_match (object *op, utf8_string match)
1624 1708
1625object *find_marked_object (object *op) 1709object *find_marked_object (object *op)
1626 1710
1975 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2059 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1976 { 2060 {
1977 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2061 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1978 ob->flag [FLAG_NO_MAP_SAVE] = true; 2062 ob->flag [FLAG_NO_MAP_SAVE] = true;
1979 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 }
1980 } 2077 }
1981 } 2078 }
1982 } 2079 }
1983 2080
1984 skip_space: ; 2081 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines