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.253 by root, Mon Sep 10 17:24:36 2007 UTC vs.
Revision 1.270 by root, Sat Mar 15 13:52:38 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include "autoconf.h" 24#include "autoconf.h"
25 25
26#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
30 30
31#if HAVE_EXECINFO_H 31#if HAVE_EXECINFO_H
32# include <execinfo.h> 32# include <execinfo.h>
33#endif 33#endif
34 34
35#include <plugin_common.h>
36#include <sounds.h>
37#include <cstdarg> 35#include <cstdarg>
36
37#include "global.h"
38#include "loader.h"
39#include "../random_maps/random_map.h"
38#include <sproto.h> 40#include <sproto.h>
39
40#include "loader.h"
41#include "cfperl.h"
42#include "shstr.h"
43 41
44#include <unistd.h> 42#include <unistd.h>
45#if _POSIX_MEMLOCK 43#if _POSIX_MEMLOCK
46# include <sys/mman.h> 44# include <sys/mman.h>
45#endif
46
47#if HAVE_MALLOC_H
48# include <malloc.h>
47#endif 49#endif
48 50
49#include <EXTERN.h> 51#include <EXTERN.h>
50#include <perl.h> 52#include <perl.h>
51#include <XSUB.h> 53#include <XSUB.h>
68 typedef double val64; 70 typedef double val64;
69# define newSVval64 newSVnv 71# define newSVval64 newSVnv
70# define SvVAL64 SvNV 72# define SvVAL64 SvNV
71#endif 73#endif
72 74
73static f_plug_api gethook = cfapi_get_hooks;
74static f_plug_api object_insert = cfapi_object_insert;
75
76static PerlInterpreter *perl; 75static PerlInterpreter *perl;
77 76
78tstamp NOW, runtime; 77tstamp NOW, runtime;
79 78
80global gbl_ev; 79global gbl_ev;
81static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 80static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
82static SV *sv_runtime, *sv_next_tick; 81static SV *sv_runtime, *sv_next_tick, *sv_now;
83 82
84bitset<NUM_EVENT_TYPES> ev_want_event; 83bitset<NUM_EVENT_TYPES> ev_want_event;
85bitset<NUM_TYPES> ev_want_type; 84bitset<NUM_TYPES> ev_want_type;
86 85
87static HV 86static HV
590 va_end (ap); 589 va_end (ap);
591 590
592 return sv; 591 return sv;
593} 592}
594 593
595static SV *
596newSVcfapi (int type, ...)
597{
598 SV *sv;
599
600 va_list ap;
601 va_start (ap, type);
602
603 switch (type)
604 {
605 case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break;
606 case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break;
607 case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break;
608 case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break;
609 case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break;
610 case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break;
611 case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break;
612 case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break;
613 case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break;
614 case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break;
615
616 default:
617 assert (("unhandled type in newSVcfapi", 0));
618 }
619
620 va_end (ap);
621
622 return sv;
623}
624
625////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 594//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
626 595
627SV * 596SV *
628registry (attachable *ext) 597registry (attachable *ext)
629{ 598{
633 return newRV_inc ((SV *)ext->cb); 602 return newRV_inc ((SV *)ext->cb);
634} 603}
635 604
636///////////////////////////////////////////////////////////////////////////// 605/////////////////////////////////////////////////////////////////////////////
637 606
638extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
639{
640 return 0;
641}
642
643static CommArray_s rtn_cmd;
644
645static int
646runPluginCommand (object *obj, char *params)
647{
648 return -1;
649}
650
651extern "C" void *cfperl_getPluginProperty (int *type, ...)
652{
653 va_list args;
654 char *propname;
655 int i;
656 va_start (args, type);
657 propname = va_arg (args, char *);
658 //printf ("Property name: %s\n", propname);
659
660 if (!strcmp (propname, "command?"))
661 return NULL;
662 else if (!strcmp (propname, "Identification"))
663 {
664 va_end (args);
665 return (void *)PLUGIN_NAME;
666 }
667 else if (!strcmp (propname, "FullName"))
668 {
669 va_end (args);
670 return (void *)PLUGIN_VERSION;
671 }
672 else
673 va_end (args);
674
675 return NULL;
676}
677
678extern "C" int cfperl_postInitPlugin ()
679{
680 int hooktype = 1;
681 int rtype = 0;
682
683 cf_init_plugin (gethook);
684
685 return 0;
686}
687
688extern "C" int cfperl_closePlugin ()
689{
690 return 0;
691}
692
693void 607void
694cfperl_init () 608cfperl_init ()
695{ 609{
610 extern char **environ;
611
696 PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); 612 PERL_SYS_INIT3 (&settings.argc, &settings.argv, &environ);
697 perl = perl_alloc (); 613 perl = perl_alloc ();
698 perl_construct (perl); 614 perl_construct (perl);
699 615
700 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 616 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
701 617
702 const char *argv[] = { 618 const char *argv[] = {
703 settings.argv [0], 619 settings.argv [0],
704 "-e" 620 "-e"
705 "use Event; use Coro;" // required for bootstrap 621 "use EV; use Coro;" // required for bootstrap
706 "cf->bootstrap;" // required for datadir :*> 622 "cf->bootstrap;" // required for datadir :*>
707 "unshift @INC, cf::datadir ();" 623 "unshift @INC, cf::datadir ();"
708 "require cf;" 624 "require cf;"
709 }; 625 };
710 626
711 if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) 627 if (perl_parse (perl, xs_init, 2, (char **)argv, environ)
712 || perl_run (perl)) 628 || perl_run (perl))
713 { 629 {
714 printf ("unable to initialize perl-interpreter, aborting.\n"); 630 printf ("unable to initialize perl-interpreter, aborting.\n");
715 exit (EXIT_FAILURE); 631 exit (EXIT_FAILURE);
716 } 632 }
1185#endif 1101#endif
1186} 1102}
1187 1103
1188///////////////////////////////////////////////////////////////////////////// 1104/////////////////////////////////////////////////////////////////////////////
1189 1105
1190struct EventAPI *watcher_base::GEventAPI; 1106struct EVAPI *evapi::GEVAPI;
1191struct CoroAPI *coroapi::GCoroAPI; 1107struct CoroAPI *coroapi::GCoroAPI;
1192 1108
1193int coroapi::cede_counter; 1109int coroapi::cede_counter;
1194tstamp coroapi::next_cede; 1110tstamp coroapi::next_cede;
1195 1111
1196void coroapi::do_cede_to_tick () 1112void coroapi::do_cede_to_tick ()
1198 cede_counter = 0; 1114 cede_counter = 0;
1199 1115
1200 cede (); 1116 cede ();
1201 1117
1202 next_cede += (TICK / CEDES_PER_TICK) * 0.99; 1118 next_cede += (TICK / CEDES_PER_TICK) * 0.99;
1203 if (next_cede > SvNV (sv_next_tick) - 0.02) 1119 if (next_cede > SvNVx (sv_next_tick) - 0.02)
1204 next_cede = SvNV (sv_next_tick); 1120 next_cede = SvNVx (sv_next_tick);
1205} 1121}
1206 1122
1207void coroapi::do_cede_every () 1123void coroapi::do_cede_every ()
1208{ 1124{
1209 cede_counter = 0; 1125 cede_counter = 0;
1233 CALL_BEGIN (0); 1149 CALL_BEGIN (0);
1234 CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); 1150 CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD);
1235 CALL_END; 1151 CALL_END;
1236} 1152}
1237 1153
1238static void
1239iw_dispatch (pe_event *ev)
1240{
1241 iw *w = (iw *)ev->ext_data;
1242 w->call (*w);
1243}
1244
1245void
1246iw::alloc ()
1247{
1248 pe = GEventAPI->new_idle (0, 0);
1249
1250 WaREENTRANT_off (pe);
1251 pe->base.callback = (void *)iw_dispatch;
1252 pe->base.ext_data = (void *)this;
1253}
1254
1255static void iow_dispatch (pe_event *ev)
1256{
1257 iow *w = (iow *)ev->ext_data;
1258 w->call (*w, ((pe_ioevent *)ev)->got);
1259}
1260
1261void
1262iow::alloc ()
1263{
1264 pe = GEventAPI->new_io (0, 0);
1265
1266 WaREENTRANT_off (pe);
1267 pe->base.callback = (void *)iow_dispatch;
1268 pe->base.ext_data = (void *)this;
1269
1270 pe->fd = -1;
1271 pe->poll = 0;
1272}
1273
1274void
1275iow::fd (int fd)
1276{
1277 pe->fd = fd;
1278}
1279
1280int
1281iow::poll ()
1282{
1283 return pe->poll;
1284}
1285
1286void 1154void
1287iow::poll (int events) 1155iow::poll (int events)
1288{ 1156{
1289 if (pe->poll != events) 1157 if (events != this->events)
1290 { 1158 {
1159 int active = ev_is_active ((ev_io *)this);
1291 if (pe->poll) stop (); 1160 if (active) stop ();
1292 pe->poll = events; 1161 ev_io_set ((ev_io *)this, fd, events);
1293 if (pe->poll) start (); 1162 if (active) start ();
1294 } 1163 }
1295} 1164}
1296 1165
1297void 1166void
1298_connect_to_perl () 1167_connect_to_perl ()
1307 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1176 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1308 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1177 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1309 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1178 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1310 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1179 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1311 1180
1181 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1312 sv_runtime = get_sv ("cf::RUNTIME" , 1); sv_upgrade (sv_runtime , SVt_NV); 1182 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1313 sv_next_tick = get_sv ("cf::NEXT_TICK", 1); sv_upgrade (sv_next_tick, SVt_NV); 1183 sv_next_tick = get_sv ("cf::NEXT_TICK", 1); SvUPGRADE (sv_next_tick, SVt_NV);
1314 1184
1315 cb_global = get_av ("cf::CB_GLOBAL", 1); 1185 cb_global = get_av ("cf::CB_GLOBAL", 1);
1316 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1186 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1317 cb_object = get_av ("cf::CB_OBJECT", 1); 1187 cb_object = get_av ("cf::CB_OBJECT", 1);
1318 cb_player = get_av ("cf::CB_PLAYER", 1); 1188 cb_player = get_av ("cf::CB_PLAYER", 1);
1323 1193
1324MODULE = cf PACKAGE = cf PREFIX = cf_ 1194MODULE = cf PACKAGE = cf PREFIX = cf_
1325 1195
1326BOOT: 1196BOOT:
1327{ 1197{
1328 I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; 1198 I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI;
1329 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1199 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1330 1200
1331 _connect_to_perl (); 1201 _connect_to_perl ();
1332 1202
1333 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1203 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1334 1204
1352 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1222 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1353 1223
1354 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1224 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1355 1225
1356 const_iv (MAX_TIME) 1226 const_iv (MAX_TIME)
1227 const_iv (MAXSOCKBUF)
1357 1228
1358 const_iv (NUM_BODY_LOCATIONS) 1229 const_iv (NUM_BODY_LOCATIONS)
1359 const_iv (body_range) const_iv (body_shield) const_iv (body_combat) 1230 const_iv (body_range) const_iv (body_shield) const_iv (body_combat)
1360 const_iv (body_arm) const_iv (body_torso) const_iv (body_head) 1231 const_iv (body_arm) const_iv (body_torso) const_iv (body_head)
1361 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) 1232 const_iv (body_neck) const_iv (body_skill) const_iv (body_finger)
1506 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) 1377 const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE)
1507 1378
1508 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) 1379 const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE)
1509 1380
1510 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) 1381 const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON)
1511 const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) const_iv (INS_MAP_LOAD) 1382 const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR)
1512 1383
1513 const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) 1384 const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL)
1514 const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) 1385 const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD)
1515 1386
1516 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1387 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1667 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1538 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1668} 1539}
1669 1540
1670void _post_tick () 1541void _post_tick ()
1671 CODE: 1542 CODE:
1672 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); 1543 coroapi::next_cede = SvNVx (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1673 1544
1674NV till_cede () 1545NV till_cede ()
1675 CODE: 1546 CODE:
1676 RETVAL = coroapi::next_cede - now (); 1547 RETVAL = coroapi::next_cede - now ();
1677 OUTPUT: 1548 OUTPUT:
1678 RETVAL 1549 RETVAL
1679 1550
1680NV till_tick () 1551NV till_tick ()
1681 CODE: 1552 CODE:
1682 RETVAL = SvNV (sv_next_tick) - now (); 1553 RETVAL = SvNVx (sv_next_tick) - now ();
1683 OUTPUT: 1554 OUTPUT:
1684 RETVAL 1555 RETVAL
1685 1556
1686NV floor (NV x) 1557NV floor (NV x)
1687 1558
1709 CODE: 1580 CODE:
1710 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1581 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1711 OUTPUT: 1582 OUTPUT:
1712 RETVAL 1583 RETVAL
1713 1584
1585void weaken (...)
1586 PROTOTYPE: @
1587 CODE:
1588 while (items > 0)
1589 sv_rvweaken (ST (--items));
1590
1714void cede_to_tick () 1591void cede_to_tick ()
1715 CODE: 1592 CODE:
1716 coroapi::cede_to_tick (); 1593 coroapi::cede_to_tick ();
1717 1594
1718void server_tick () 1595void server_tick ()
1719 CODE: 1596 CODE:
1720 NOW = now (); 1597 NOW = SvNVx (sv_now);
1721 runtime = SvNVx (sv_runtime); 1598 runtime = SvNVx (sv_runtime);
1722 server_tick (); 1599 server_tick ();
1723 1600
1724void 1601void
1725log_backtrace (utf8_string msg) 1602log_backtrace (utf8_string msg)
1732octet_string path_combine (octet_string base, octet_string path) 1609octet_string path_combine (octet_string base, octet_string path)
1733 PROTOTYPE: $$ 1610 PROTOTYPE: $$
1734 1611
1735octet_string path_combine_and_normalize (octet_string base, octet_string path) 1612octet_string path_combine_and_normalize (octet_string base, octet_string path)
1736 PROTOTYPE: $$ 1613 PROTOTYPE: $$
1614
1615void
1616mallinfo ()
1617 PPCODE:
1618{
1619#if __GLIBC__
1620 struct mallinfo mai = mallinfo ();
1621 EXTEND (SP, 10*2);
1622 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1623 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1624 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1625 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1626 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1627 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1628 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1629 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1630 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1631 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1632#endif
1633 EXTEND (SP, 2*2);
1634 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1635 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1636}
1737 1637
1738void 1638void
1739sub_generation_inc () 1639sub_generation_inc ()
1740 CODE: 1640 CODE:
1741 PL_sub_generation++; 1641 PL_sub_generation++;
1766 1666
1767void abort () 1667void abort ()
1768 1668
1769void reset_signals () 1669void reset_signals ()
1770 1670
1771void fork_abort (octet_string cause = "cf::fork_abort") 1671void fork_abort (const_octet_string cause = "cf::fork_abort")
1772 1672
1773void cleanup (octet_string cause, bool make_core = false) 1673void cleanup (const_octet_string cause, bool make_core = false)
1774 1674
1775void emergency_save () 1675void emergency_save ()
1776 1676
1777void _exit (int status = EXIT_SUCCESS) 1677void _exit (int status = EXIT_SUCCESS)
1778
1779UV sv_2watcher (SV *w)
1780 CODE:
1781 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1782 OUTPUT:
1783 RETVAL
1784 1678
1785#if _POSIX_MEMLOCK 1679#if _POSIX_MEMLOCK
1786 1680
1787int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1681int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1788 1682
1939void 1833void
1940inv (object *obj) 1834inv (object *obj)
1941 PROTOTYPE: $ 1835 PROTOTYPE: $
1942 PPCODE: 1836 PPCODE:
1943{ 1837{
1944 object *o;
1945 for (o = obj->inv; o; o = o->below) 1838 for (object *o = obj->inv; o; o = o->below)
1946 XPUSHs (sv_2mortal (to_sv (o))); 1839 XPUSHs (sv_2mortal (to_sv (o)));
1947} 1840}
1948 1841
1949void 1842void
1950set_animation (object *op, int idx) 1843set_animation (object *op, int idx)
1982 1875
1983int need_identify (object *obj); 1876int need_identify (object *obj);
1984 1877
1985int apply_shop_mat (object *shop_mat, object *op); 1878int apply_shop_mat (object *shop_mat, object *op);
1986 1879
1987int move_player (object *op, int dir)
1988 CODE:
1989 RETVAL = move_player (op, dir);
1990 OUTPUT:
1991 RETVAL
1992
1993int move (object *op, int dir, object *originator = op) 1880int move (object *op, int dir, object *originator = op)
1994 CODE: 1881 CODE:
1995 RETVAL = move_ob (op, dir, originator); 1882 RETVAL = move_ob (op, dir, originator);
1996 OUTPUT: 1883 OUTPUT:
1997 RETVAL 1884 RETVAL
2003void apply_below (object *op) 1890void apply_below (object *op)
2004 CODE: 1891 CODE:
2005 player_apply_below (op); 1892 player_apply_below (op);
2006 1893
2007int cast_heal (object *op, object *caster, object *spell, int dir = 0) 1894int cast_heal (object *op, object *caster, object *spell, int dir = 0)
2008
2009object *cf_object_present_archname_inside (object *op, utf8_string whatstr)
2010
2011int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
2012
2013int cf_object_change_map (object *op, int x, int y, maptile *map)
2014 1895
2015#//TODO 1896#//TODO
2016object *clone_ (object *op, int recursive = 0) 1897object *clone_ (object *op, int recursive = 0)
2017 CODE: 1898 CODE:
2018 if (recursive) 1899 if (recursive)
2065 1946
2066void drop (object *who, object *op) 1947void drop (object *who, object *op)
2067 1948
2068void pick_up (object *who, object *op) 1949void pick_up (object *who, object *op)
2069 1950
2070int cf_object_teleport (object *op, maptile *map, int x, int y)
2071
2072void update_object (object *op, int action) 1951void update_object (object *op, int action)
2073 1952
2074object *cf_create_object_by_name (utf8_string name)
2075
2076void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 1953void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0)
2077 1954
2078void player_lvl_adj (object *who, object *skill = 0) 1955void player_lvl_adj (object *who, object *skill = 0)
2079 1956
2080int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 1957int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2091 1968
2092void handle_apply_yield (object *op); 1969void handle_apply_yield (object *op);
2093 1970
2094 1971
2095MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1972MODULE = cf PACKAGE = cf::object PREFIX = cf_
2096
2097object *cf_insert_ob_in_ob (object *ob, object *where)
2098 1973
2099# no clean way to get an object from an archetype - stupid idiotic 1974# no clean way to get an object from an archetype - stupid idiotic
2100# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1975# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2101 1976
2102object *new (utf8_string archetype = 0) 1977object *new (utf8_string archetype = 0)
2111# TODO: nuke 1986# TODO: nuke
2112object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 1987object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2113 PROTOTYPE: $$$$$$ 1988 PROTOTYPE: $$$$$$
2114 CODE: 1989 CODE:
2115{ 1990{
2116 int unused_type; 1991 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2117 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2118} 1992}
2119 1993
2120const_utf8_string get_ob_key_value (object *op, utf8_string key) 1994const_utf8_string get_ob_key_value (object *op, utf8_string key)
2121 1995
2122bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 1996bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
2135 EXTEND (SP, 5); 2009 EXTEND (SP, 5);
2136 PUSHs (newSVuv (rv.distance)); 2010 PUSHs (newSVuv (rv.distance));
2137 PUSHs (newSViv (rv.distance_x)); 2011 PUSHs (newSViv (rv.distance_x));
2138 PUSHs (newSViv (rv.distance_y)); 2012 PUSHs (newSViv (rv.distance_y));
2139 PUSHs (newSViv (rv.direction)); 2013 PUSHs (newSViv (rv.direction));
2140 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); 2014 PUSHs (to_sv (rv.part));
2141} 2015}
2142 2016
2143bool on_same_map_as (object *ob, object *other) 2017bool on_same_map_as (object *ob, object *other)
2144 CODE: 2018 CODE:
2145 RETVAL = on_same_map (ob, other); 2019 RETVAL = on_same_map (ob, other);
2151 RETVAL = query_base_name (op, plural); 2025 RETVAL = query_base_name (op, plural);
2152 OUTPUT: RETVAL 2026 OUTPUT: RETVAL
2153 2027
2154object *decrease_ob_nr (object *op, unsigned long i) 2028object *decrease_ob_nr (object *op, unsigned long i)
2155 2029
2030# return the tail of an object, excluding itself
2031void
2032tail (object *op)
2033 PPCODE:
2034 while ((op = op->more))
2035 XPUSHs (sv_2mortal (to_sv (op)));
2036
2156MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2037MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
2157 2038
2158player *player (object *op) 2039player *player (object *op)
2159 CODE: 2040 CODE:
2160 RETVAL = op->contr; 2041 RETVAL = op->contr;
2161 OUTPUT: RETVAL 2042 OUTPUT: RETVAL
2162 2043
2044bool move_player (object *op, int dir)
2045
2163void check_score (object *op) 2046void check_score (object *op)
2164 2047
2165void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2048void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2166 CODE: 2049 CODE:
2167 new_draw_info (flags, 0, op, txt); 2050 new_draw_info (flags, 0, op, txt);
2168 2051
2169void kill_player (object *op) 2052void kill_player (object *op)
2170 2053
2054void esrv_send_item (object *pl, object *item)
2055
2171void esrv_update_item (object *op, int what, object *item) 2056void esrv_update_item (object *pl, int what, object *item)
2172 C_ARGS: what, op, item 2057 C_ARGS: what, pl, item
2058
2059void esrv_del_item (object *pl, int tag)
2060 C_ARGS: pl->contr, tag
2173 2061
2174int command_summon (object *op, utf8_string params) 2062int command_summon (object *op, utf8_string params)
2175 2063
2176int command_arrest (object *op, utf8_string params) 2064int command_arrest (object *op, utf8_string params)
2177 2065
2198 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2086 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2199 pl->orig_stats = pl->ob->stats; 2087 pl->orig_stats = pl->ob->stats;
2200 2088
2201void clear_los (player *pl) 2089void clear_los (player *pl)
2202 2090
2203void cf_player_move (player *pl, int dir)
2204
2205bool 2091bool
2206cell_visible (player *pl, int dx, int dy) 2092cell_visible (player *pl, int dx, int dy)
2207 CODE: 2093 CODE:
2208 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2094 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2209 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; 2095 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2215 CODE: 2101 CODE:
2216{ 2102{
2217 STRLEN len; 2103 STRLEN len;
2218 char *buf = SvPVbyte (packet, len); 2104 char *buf = SvPVbyte (packet, len);
2219 2105
2106 if (len > MAXSOCKBUF)
2107 pl->failmsg ("[packet too long for client]");
2220 if (pl->ns) 2108 else if (pl->ns)
2221 pl->ns->send_packet (buf, len); 2109 pl->ns->send_packet (buf, len);
2222} 2110}
2223 2111
2224int 2112int
2225listening (player *pl, int new_value = -1) 2113listening (player *pl, int new_value = -1)
2261 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); 2149 RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END);
2262 OUTPUT: RETVAL 2150 OUTPUT: RETVAL
2263 2151
2264SV *registry (maptile *map) 2152SV *registry (maptile *map)
2265 2153
2154void
2155find_tagged_objects (maptile *map, utf8_string tag = 0)
2156 PPCODE:
2157{
2158 if (!map->spaces)
2159 XSRETURN_EMPTY;
2160
2161 if (tag)
2162 {
2163 shstr_cmp tag_ (tag);
2164
2165 for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; )
2166 for (object *op = ms->bot; op; op = op->above)
2167 if (op->tag == tag_)
2168 XPUSHs (sv_2mortal (to_sv (op)));
2169 }
2170 else
2171 {
2172 for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; )
2173 for (object *op = ms->bot; op; op = op->above)
2174 if (op->tag)
2175 XPUSHs (sv_2mortal (to_sv (op)));
2176 }
2177}
2178
2266INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | 2179INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h |
2267 2180
2268void 2181void
2269maptile::instantiate () 2182maptile::instantiate ()
2270 2183
2401get_connection (maptile *map, long connection) 2314get_connection (maptile *map, long connection)
2402 PPCODE: 2315 PPCODE:
2403 oblinkpt *obp = get_connection_links (map, connection); 2316 oblinkpt *obp = get_connection_links (map, connection);
2404 if (obp) 2317 if (obp)
2405 for (objectlink *ol = obp->link; ol; ol = ol->next) 2318 for (objectlink *ol = obp->link; ol; ol = ol->next)
2406 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); 2319 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2407
2408object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags)
2409
2410object *cf_map_insert_object (maptile *where, object* op, int x, int y)
2411
2412object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny)
2413 C_ARGS: str, map, nx, ny
2414 2320
2415void 2321void
2416get_map_flags (maptile *map, int x, int y) 2322get_map_flags (maptile *map, int x, int y)
2417 PPCODE: 2323 PPCODE:
2418{ 2324{
2423 EXTEND (SP, 4); 2329 EXTEND (SP, 4);
2424 PUSHs (sv_2mortal (newSViv (flags))); 2330 PUSHs (sv_2mortal (newSViv (flags)));
2425 2331
2426 if (GIMME_V == G_ARRAY) 2332 if (GIMME_V == G_ARRAY)
2427 { 2333 {
2428 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); 2334 PUSHs (sv_2mortal (to_sv (nmap)));
2429 PUSHs (sv_2mortal (newSViv (nx))); 2335 PUSHs (sv_2mortal (newSViv (nx)));
2430 PUSHs (sv_2mortal (newSViv (ny))); 2336 PUSHs (sv_2mortal (newSViv (ny)));
2431 } 2337 }
2432} 2338}
2433 2339
2442 2348
2443 get_map_flags (map, &nmap, x, y, &nx, &ny); 2349 get_map_flags (map, &nmap, x, y, &nx, &ny);
2444 2350
2445 if (nmap) 2351 if (nmap)
2446 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2352 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
2447 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 2353 XPUSHs (sv_2mortal (to_sv (o)));
2448} 2354}
2449 2355
2450SV * 2356SV *
2451bot_at (maptile *obj, unsigned int x, unsigned int y) 2357bot_at (maptile *obj, unsigned int x, unsigned int y)
2452 PROTOTYPE: $$$ 2358 PROTOTYPE: $$$
2461 INIT: 2367 INIT:
2462 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; 2368 if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF;
2463 CODE: 2369 CODE:
2464 switch (ix) 2370 switch (ix)
2465 { 2371 {
2466 case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; 2372 case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break;
2467 case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; 2373 case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break;
2468 case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; 2374 case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break;
2469 case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; 2375 case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break;
2470 case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; 2376 case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break;
2471 case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; 2377 case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break;
2472 case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; 2378 case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break;
2473 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2379 case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break;
2474 } 2380 }
2475 OUTPUT: RETVAL 2381 OUTPUT: RETVAL
2476 2382
2477void fix_walls (maptile *map, int x, int y) 2383void fix_walls (maptile *map, int x, int y)
2478 2384
2659 CODE: 2565 CODE:
2660{ 2566{
2661 STRLEN len; 2567 STRLEN len;
2662 char *buf = SvPVbyte (packet, len); 2568 char *buf = SvPVbyte (packet, len);
2663 2569
2570 if (len > MAXSOCKBUF)
2571 {
2572 // ugly
2573 if (THIS->pl)
2574 THIS->pl->failmsg ("[packet too long for client]");
2575 }
2576 else
2664 THIS->send_packet (buf, len); 2577 THIS->send_packet (buf, len);
2665} 2578}
2666 2579
2667faceidx 2580faceidx
2668client::need_face (utf8_string name, int pri = 0) 2581client::need_face (utf8_string name, int pri = 0)
2669 CODE: 2582 CODE:
2768 } 2681 }
2769} 2682}
2770 2683
2771int get_data_size (faceidx idx, int faceset = 0) 2684int get_data_size (faceidx idx, int faceset = 0)
2772 CODE: 2685 CODE:
2773 facedata *d = face_data (idx, faceset); assert (d); 2686 facedata *d = face_data (idx, faceset);
2687 if (!d) XSRETURN_UNDEF;
2774 RETVAL = d->data.size (); 2688 RETVAL = d->data.size ();
2775 OUTPUT: 2689 OUTPUT:
2776 RETVAL 2690 RETVAL
2777 2691
2778SV *get_chksum (faceidx idx, int faceset = 0) 2692SV *get_chksum (faceidx idx, int faceset = 0)
2779 CODE: 2693 CODE:
2780 facedata *d = face_data (idx, faceset); assert (d); 2694 facedata *d = face_data (idx, faceset);
2695 if (!d) XSRETURN_UNDEF;
2781 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); 2696 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2697 OUTPUT:
2698 RETVAL
2699
2700SV *get_data (faceidx idx, int faceset = 0)
2701 CODE:
2702 facedata *d = face_data (idx, faceset);
2703 if (!d) XSRETURN_UNDEF;
2704 RETVAL = newSVpvn (d->data.data (), d->data.length ());
2782 OUTPUT: 2705 OUTPUT:
2783 RETVAL 2706 RETVAL
2784 2707
2785void invalidate (faceidx idx) 2708void invalidate (faceidx idx)
2786 CODE: 2709 CODE:
2874 sv_to (sv, self); 2797 sv_to (sv, self);
2875 delete self; 2798 delete self;
2876 2799
2877void 2800void
2878extract_tags (object_thawer *self) 2801extract_tags (object_thawer *self)
2879 CODE: 2802 PPCODE:
2880 while (self->kw != KW_EOF) 2803 while (self->kw != KW_EOF)
2881 { 2804 {
2805 PUTBACK;
2882 coroapi::cede_to_tick_every (5000); 2806 coroapi::cede_to_tick_every (5000);
2807 SPAGAIN;
2883 2808
2884 if (self->kw == KW_tag) 2809 if (self->kw == KW_tag)
2885 XPUSHs (sv_2mortal (to_sv (self->get_str ()))); 2810 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2886 2811
2887 self->skip (); 2812 self->skip ();
2888 } 2813 }
2889 2814

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines