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.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>
180 if (destroyed ()) 186 if (destroyed ())
181 return; 187 return;
182 188
183 flags |= F_DESTROYED; 189 flags |= F_DESTROYED;
184 do_destroy (); 190 do_destroy ();
191 sever_self ();
185} 192}
186 193
187void 194void
188attachable::check_mortals () 195attachable::check_mortals ()
189{ 196{
209 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); 216 LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ());
210 obj->sever_self (); 217 obj->sever_self ();
211 } 218 }
212#endif 219#endif
213 220
214 if (obj->refcnt_cnt ()) 221 if (obj->refcnt)
215 { 222 {
216 ++i; // further delay freeing 223 ++i; // further delay freeing
217 224
218 if (!(i & 0x3ff)) 225 if (!(i & 0x3ff))
219 break; 226 break;
397inline 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; }
398 405
399template<int N> 406template<int N>
400inline 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)); }
401 408
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); } 409inline 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); } 410inline 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); } 411inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
406inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } 412inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
407 413
610 perl_construct (perl); 616 perl_construct (perl);
611 617
612 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 618 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
613 619
614 const char *argv[] = { 620 const char *argv[] = {
615 "", 621 settings.argv [0],
616 "-e" 622 "-e"
617 "use Event; use Coro;" // required for bootstrap 623 "use Event; use Coro;" // required for bootstrap
618 "cf->bootstrap;" // required for datadir :*> 624 "cf->bootstrap;" // required for datadir :*>
619 "unshift @INC, cf::datadir ();" 625 "unshift @INC, cf::datadir ();"
620 "require cf;" 626 "require cf;"
942 CALL_ARG (exit); 948 CALL_ARG (exit);
943 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 949 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
944 CALL_END; 950 CALL_END;
945} 951}
946 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
947///////////////////////////////////////////////////////////////////////////// 969/////////////////////////////////////////////////////////////////////////////
948 970
949struct EventAPI *watcher_base::GEventAPI; 971struct EventAPI *watcher_base::GEventAPI;
950struct CoroAPI *coroapi::GCoroAPI; 972struct CoroAPI *coroapi::GCoroAPI;
951 973
1105 const char *name; 1127 const char *name;
1106 IV iv; 1128 IV iv;
1107 } *civ, const_iv[] = { 1129 } *civ, const_iv[] = {
1108# define const_iv(name) { # name, (IV)name }, 1130# define const_iv(name) { # name, (IV)name },
1109 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)
1110 1133
1111 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1134 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1112 1135
1113 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1136 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1114 1137
1115 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)
1116 1146
1117 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)
1118 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)
1119 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)
1120 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)
1380 default: croak ("cf::rndm requires none, one or two parameters."); break; 1410 default: croak ("cf::rndm requires none, one or two parameters."); break;
1381 } 1411 }
1382 OUTPUT: 1412 OUTPUT:
1383 RETVAL 1413 RETVAL
1384 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
1385void server_tick () 1431void server_tick ()
1386 CODE: 1432 CODE:
1387 runtime = SvNVx (sv_runtime); 1433 runtime = SvNVx (sv_runtime);
1388 server_tick (); 1434 server_tick ();
1389 1435
1390void 1436void
1437log_backtrace (utf8_string msg)
1438
1439void
1391LOG (int level, utf8_string msg) 1440LOG (int flags, utf8_string msg)
1392 PROTOTYPE: $$ 1441 PROTOTYPE: $$
1393 C_ARGS: (LogLevel)level, "%s", msg 1442 C_ARGS: flags, "%s", msg
1394 1443
1395octet_string path_combine (octet_string base, octet_string path) 1444octet_string path_combine (octet_string base, octet_string path)
1396 PROTOTYPE: $$ 1445 PROTOTYPE: $$
1397 1446
1398octet_string path_combine_and_normalize (octet_string base, octet_string path) 1447octet_string path_combine_and_normalize (octet_string base, octet_string path)
1435 } 1484 }
1436 OUTPUT: RETVAL 1485 OUTPUT: RETVAL
1437 1486
1438void abort () 1487void abort ()
1439 1488
1489void reset_signals ()
1490
1440void fork_abort (octet_string cause = "cf::fork_abort") 1491void fork_abort (octet_string cause = "cf::fork_abort")
1441 1492
1442void cleanup (octet_string cause, bool make_core = false) 1493void cleanup (octet_string cause, bool make_core = false)
1443 1494
1444void emergency_save () 1495void emergency_save ()
1578object *actives (U32 index) 1629object *actives (U32 index)
1579 CODE: 1630 CODE:
1580 RETVAL = index < actives.size () ? actives [index] : 0; 1631 RETVAL = index < actives.size () ? actives [index] : 0;
1581 OUTPUT: RETVAL 1632 OUTPUT: RETVAL
1582 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
1583# missing properties 1653# missing properties
1584 1654
1585object *head (object *op) 1655object *head (object *op)
1586 PROTOTYPE: $ 1656 PROTOTYPE: $
1587 CODE: 1657 CODE:
1612int 1682int
1613num_animations (object *op) 1683num_animations (object *op)
1614 CODE: 1684 CODE:
1615 RETVAL = NUM_ANIMATIONS (op); 1685 RETVAL = NUM_ANIMATIONS (op);
1616 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
1617 1706
1618object *find_best_object_match (object *op, utf8_string match) 1707object *find_best_object_match (object *op, utf8_string match)
1619 1708
1620object *find_marked_object (object *op) 1709object *find_marked_object (object *op)
1621 1710
1970 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2059 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
1971 { 2060 {
1972 object *ob = get_archetype (SvPVutf8_nolen (*elem)); 2061 object *ob = get_archetype (SvPVutf8_nolen (*elem));
1973 ob->flag [FLAG_NO_MAP_SAVE] = true; 2062 ob->flag [FLAG_NO_MAP_SAVE] = true;
1974 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 }
1975 } 2077 }
1976 } 2078 }
1977 } 2079 }
1978 2080
1979 skip_space: ; 2081 skip_space: ;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines