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.197 by root, Fri Apr 27 03:38:33 2007 UTC vs.
Revision 1.209 by root, Thu May 17 14:14:55 2007 UTC

1/*****************************************************************************/
2/* CrossFire, A Multiplayer game for the X Window System */
3/*****************************************************************************/
4
5/* 1/*
2 * CrossFire, A Multiplayer game
3 *
6 * This code is placed under the GNU General Public Licence (GPL) 4 * This code is placed under the GNU General Public Licence (GPL)
7 * 5 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann 6 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> 7 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 8 *
21 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */ 22 */
25 23
24#include "autoconf.h"
25
26#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 27#define PLUGIN_VERSION "cfperl 0.5"
28 28
29#define CEDES_PER_TICK 5 29#define CEDES_PER_TICK 5
30
31#if HAVE_EXECINFO_H
32# include <execinfo.h>
33#endif
30 34
31#include <plugin_common.h> 35#include <plugin_common.h>
32#include <sounds.h> 36#include <sounds.h>
33#include <cstdarg> 37#include <cstdarg>
34#include <sproto.h> 38#include <sproto.h>
180 if (destroyed ()) 184 if (destroyed ())
181 return; 185 return;
182 186
183 flags |= F_DESTROYED; 187 flags |= F_DESTROYED;
184 do_destroy (); 188 do_destroy ();
189 sever_self ();
185} 190}
186 191
187void 192void
188attachable::check_mortals () 193attachable::check_mortals ()
189{ 194{
209 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); 214 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
210 obj->sever_self (); 215 obj->sever_self ();
211 } 216 }
212#endif 217#endif
213 218
214 if (obj->refcnt_cnt ()) 219 if (obj->refcnt)
215 { 220 {
216 ++i; // further delay freeing 221 ++i; // further delay freeing
217 222
218 if (!(i & 0x3ff)) 223 if (!(i & 0x3ff))
219 break; 224 break;
397inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 402inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
398 403
399template<int N> 404template<int N>
400inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 405inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
401 406
402inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
403inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } 407inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
404inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } 408inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
405inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } 409inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
406inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 410inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
407 411
610 perl_construct (perl); 614 perl_construct (perl);
611 615
612 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
613 617
614 const char *argv[] = { 618 const char *argv[] = {
615 "", 619 settings.argv [0],
616 "-e" 620 "-e"
617 "use Event; use Coro;" // required for bootstrap 621 "use Event; use Coro;" // required for bootstrap
618 "cf->bootstrap;" // required for datadir :*> 622 "cf->bootstrap;" // required for datadir :*>
619 "unshift @INC, cf::datadir ();" 623 "unshift @INC, cf::datadir ();"
620 "require cf;" 624 "require cf;"
942 CALL_ARG (exit); 946 CALL_ARG (exit);
943 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 947 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
944 CALL_END; 948 CALL_END;
945} 949}
946 950
951void
952log_backtrace (const char *msg)
953{
954#if HAVE_BACKTRACE
955 void *addr [20];
956 int size = backtrace (addr, 20);
957
958 CALL_BEGIN (size);
959 CALL_ARG (msg);
960 for (int i = 0; i < size; ++i)
961 CALL_ARG ((IV)addr [i]);
962 CALL_CALL ("cf::_log_backtrace", G_VOID);
963 CALL_END;
964#endif
965}
966
947///////////////////////////////////////////////////////////////////////////// 967/////////////////////////////////////////////////////////////////////////////
948 968
949struct EventAPI *watcher_base::GEventAPI; 969struct EventAPI *watcher_base::GEventAPI;
950struct CoroAPI *coroapi::GCoroAPI; 970struct CoroAPI *coroapi::GCoroAPI;
951 971
1105 const char *name; 1125 const char *name;
1106 IV iv; 1126 IV iv;
1107 } *civ, const_iv[] = { 1127 } *civ, const_iv[] = {
1108# define const_iv(name) { # name, (IV)name }, 1128# define const_iv(name) { # name, (IV)name },
1109 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1129 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster)
1130 const_iv (logBacktrace)
1110 1131
1111 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1132 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1112 1133
1113 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1134 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1114 1135
1115 const_iv (MAX_TIME) 1136 const_iv (MAX_TIME)
1137
1138 const_iv (NUM_BODY_LOCATIONS)
1139 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1140 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1141 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1142 const_iv (body_shoulder) const_iv (body_foot) const_iv (body_hand)
1143 const_iv (body_wrist) const_iv (body_waist)
1116 1144
1117 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE) 1145 const_iv (PLAYER) const_iv (TRANSPORT) const_iv (ROD) const_iv (TREASURE)
1118 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK) 1146 const_iv (POTION) const_iv (FOOD) const_iv (POISON) const_iv (BOOK)
1119 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON) 1147 const_iv (CLOCK) const_iv (ARROW) const_iv (BOW) const_iv (WEAPON)
1120 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR) 1148 const_iv (ARMOUR) const_iv (PEDESTAL) const_iv (ALTAR) const_iv (LOCKED_DOOR)
1159 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) 1187 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE)
1160 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) 1188 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH)
1161 const_iv (WEAP_BLUD) 1189 const_iv (WEAP_BLUD)
1162 1190
1163 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) 1191 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED)
1164 const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) 1192 const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD)
1165 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) 1193 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY)
1166 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) 1194 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD)
1167 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) 1195 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE)
1168 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) 1196 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING)
1169 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) 1197 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW)
1380 default: croak ("cf::rndm requires none, one or two parameters."); break; 1408 default: croak ("cf::rndm requires none, one or two parameters."); break;
1381 } 1409 }
1382 OUTPUT: 1410 OUTPUT:
1383 RETVAL 1411 RETVAL
1384 1412
1413NV clamp (NV value, NV min_value, NV max_value)
1414 CODE:
1415 RETVAL = clamp (value, min_value, max_value);
1416 OUTPUT:
1417 RETVAL
1418
1419NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1420 CODE:
1421 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1422 OUTPUT:
1423 RETVAL
1424
1425void cede_to_tick ()
1426 CODE:
1427 coroapi::cede_to_tick ();
1428
1385void server_tick () 1429void server_tick ()
1386 CODE: 1430 CODE:
1387 runtime = SvNVx (sv_runtime); 1431 runtime = SvNVx (sv_runtime);
1388 server_tick (); 1432 server_tick ();
1389 1433
1390void 1434void
1435log_backtrace (utf8_string msg)
1436
1437void
1391LOG (int level, utf8_string msg) 1438LOG (int flags, utf8_string msg)
1392 PROTOTYPE: $$ 1439 PROTOTYPE: $$
1393 C_ARGS: (LogLevel)level, "%s", msg 1440 C_ARGS: flags, "%s", msg
1394 1441
1395octet_string path_combine (octet_string base, octet_string path) 1442octet_string path_combine (octet_string base, octet_string path)
1396 PROTOTYPE: $$ 1443 PROTOTYPE: $$
1397 1444
1398octet_string path_combine_and_normalize (octet_string base, octet_string path) 1445octet_string path_combine_and_normalize (octet_string base, octet_string path)
1435 } 1482 }
1436 OUTPUT: RETVAL 1483 OUTPUT: RETVAL
1437 1484
1438void abort () 1485void abort ()
1439 1486
1487void reset_signals ()
1488
1440void fork_abort (octet_string cause = "cf::fork_abort") 1489void fork_abort (octet_string cause = "cf::fork_abort")
1441 1490
1442void cleanup (octet_string cause, bool make_core = false) 1491void cleanup (octet_string cause, bool make_core = false)
1443 1492
1444void emergency_save () 1493void emergency_save ()
1578object *actives (U32 index) 1627object *actives (U32 index)
1579 CODE: 1628 CODE:
1580 RETVAL = index < actives.size () ? actives [index] : 0; 1629 RETVAL = index < actives.size () ? actives [index] : 0;
1581 OUTPUT: RETVAL 1630 OUTPUT: RETVAL
1582 1631
1632const char *slot_save_name (U32 slot)
1633 ALIAS:
1634 slot_use_name = 1
1635 slot_nonuse_name = 2
1636 CODE:
1637{
1638 if (slot >= NUM_BODY_LOCATIONS)
1639 croak ("body slot index out of range");
1640
1641 switch (ix)
1642 {
1643 case 0: RETVAL = body_locations[slot].save_name; break;
1644 case 1: RETVAL = body_locations[slot].use_name; break;
1645 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1646 }
1647}
1648 OUTPUT:
1649 RETVAL
1650
1583# missing properties 1651# missing properties
1584 1652
1585object *head (object *op) 1653object *head (object *op)
1586 PROTOTYPE: $ 1654 PROTOTYPE: $
1587 CODE: 1655 CODE:
1612int 1680int
1613num_animations (object *op) 1681num_animations (object *op)
1614 CODE: 1682 CODE:
1615 RETVAL = NUM_ANIMATIONS (op); 1683 RETVAL = NUM_ANIMATIONS (op);
1616 OUTPUT: RETVAL 1684 OUTPUT: RETVAL
1685
1686int slot_info (object *op, UV slot, int value = 0)
1687 ALIAS:
1688 slot_used = 1
1689 CODE:
1690{
1691 if (slot >= NUM_BODY_LOCATIONS)
1692 croak ("body slot index out of range");
1693
1694 RETVAL = ix ? op->slot[slot].used : op->slot[slot].info;
1695
1696 if (items > 2)
1697 if (ix)
1698 op->slot[slot].used = value;
1699 else
1700 op->slot[slot].info = value;
1701}
1702 OUTPUT:
1703 RETVAL
1617 1704
1618object *find_best_object_match (object *op, utf8_string match) 1705object *find_best_object_match (object *op, utf8_string match)
1619 1706
1620object *find_marked_object (object *op) 1707object *find_marked_object (object *op)
1621 1708
1970 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2057 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1971 { 2058 {
1972 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2059 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1973 ob->flag [FLAG_NO_MAP_SAVE] = true; 2060 ob->flag [FLAG_NO_MAP_SAVE] = true;
1974 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2061 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2062
2063 if (ob->randomitems)
2064 {
2065 if (!ob->above)
2066 {
2067 ob->create_treasure (ob->randomitems);
2068
2069 for (object *op = ob->above; op; op = op->above)
2070 op->flag [FLAG_NO_MAP_SAVE] = true;
2071 }
2072
2073 ob->randomitems = 0;
2074 }
1975 } 2075 }
1976 } 2076 }
1977 } 2077 }
1978 2078
1979 skip_space: ; 2079 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines