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.210 by root, Sat May 19 00:08:12 2007 UTC vs.
Revision 1.221 by root, Sat Jun 16 00:12:20 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * This code is placed under the GNU General Public Licence (GPL) 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 *
6 * Copyright (C) 2001-2005 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
7 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
8 * 7 *
9 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
10 * it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
11 * the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
12 * (at your option) any later version. 11 * any later version.
13 * 12 *
14 * 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, but
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * GNU General Public License for more details. 16 * for more details.
18 * 17 *
19 * 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 along
20 * along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
21 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22 */ 23 */
23 24
24#include "autoconf.h" 25#include "autoconf.h"
25 26
26#define PLUGIN_NAME "perl" 27#define PLUGIN_NAME "perl"
74# define newSVval64 newSVnv 75# define newSVval64 newSVnv
75# define SvVAL64 SvNV 76# define SvVAL64 SvNV
76#endif 77#endif
77 78
78static f_plug_api gethook = cfapi_get_hooks; 79static f_plug_api gethook = cfapi_get_hooks;
79static f_plug_api object_set_property = cfapi_object_set_property;
80static f_plug_api object_insert = cfapi_object_insert; 80static f_plug_api object_insert = cfapi_object_insert;
81 81
82static PerlInterpreter *perl; 82static PerlInterpreter *perl;
83 83
84double runtime; 84tstamp NOW, runtime;
85 85
86global gbl_ev; 86global gbl_ev;
87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 87static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
88static SV *sv_runtime, *sv_next_tick; 88static SV *sv_runtime, *sv_next_tick;
89 89
168} 168}
169 169
170void 170void
171attachable::do_destroy () 171attachable::do_destroy ()
172{ 172{
173 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
174 174
175 if (cb) 175 if (cb)
176 { 176 {
177 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
178 cb = 0; 178 cb = 0;
201 { 201 {
202 if (i >= mortals.size ()) 202 if (i >= mortals.size ())
203 { 203 {
204 i = 0; 204 i = 0;
205 205
206 if (mortals.size () > 1000) 206 if (mortals.size () >= 512)
207 {
208 static int last_mortalcount;
209 if (mortals.size () != last_mortalcount)
210 {
211 last_mortalcount = mortals.size ();
207 LOG (llevInfo, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); 212 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ());
213
214 if (0)
215 {
216 for (int j = 0; j < mortals.size (); ++j)//D
217 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
218 fprintf (stderr, "\n");//D
219 }
220 }
221 }
208 222
209 break; 223 break;
210 } 224 }
211 225
212 attachable *obj = mortals [i]; 226 attachable *obj = mortals [i];
241 //if (self || cb) 255 //if (self || cb)
242 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 256 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
243 257
244 attach = src.attach; 258 attach = src.attach;
245 return *this; 259 return *this;
260}
261
262template<typename T>
263static bool
264find_backref (void *ptr, T *obj)
265{
266 char *s = (char *)obj;
267 while (s < (char *)obj + sizeof (T))
268 {
269 if (ptr == *(void **)s)
270 return true;
271
272 s += sizeof (void *); // assume natural alignment
273 }
274
275 return false;
276}
277
278// for debugging, find "live" objects containing this ptr
279void
280find_backref (void *ptr)
281{
282 for_all_objects (op)
283 if (find_backref (ptr, op))
284 fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name);
285
286 for_all_players (pl)
287 if (find_backref (ptr, pl))
288 fprintf (stderr, "P %p\n", pl);
289
290 for_all_clients (ns)
291 if (find_backref (ptr, ns))
292 fprintf (stderr, "C %p\n", ns);
293
246} 294}
247 295
248////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 296//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
249 297
250static SV * 298static SV *
655void 703void
656attachable::instantiate () 704attachable::instantiate ()
657{ 705{
658 if (attach) 706 if (attach)
659 { 707 {
660 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 708 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
661 attach = 0; 709 attach = 0;
662 } 710 }
663} 711}
664 712
665void 713void
666attachable::reattach () 714attachable::reattach ()
667{ 715{
668 optimise (); 716 optimise ();
669 //TODO: check for _attachment's, very important for restarts 717 //TODO: check for _attachment's, very important for restarts
670 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 718 INVOKE_ATTACHABLE (REATTACH, this);
671} 719}
672 720
673static event_klass klass_of[NUM_EVENT_TYPES] = { 721static event_klass klass_of[NUM_EVENT_TYPES] = {
674# define def(type,name) KLASS_ ## type, 722# define def(type,name) KLASS_ ## type,
675# include "eventinc.h" 723# include "eventinc.h"
823 } 871 }
824 } 872 }
825} 873}
826 874
827bool 875bool
828attachable::vinvoke (event_type event, va_list &ap) 876attachable::invoke (event_type event, ...)
829{ 877{
830 data_type dt; 878 data_type dt;
831 879
832 // callback call ordering should be: 880 // callback call ordering should be:
833 // 1. per-object callback 881 // 1. per-object callback
839 gather_callbacks (callbacks, event); 887 gather_callbacks (callbacks, event);
840 888
841 // short-circuit processing if no callbacks found/defined 889 // short-circuit processing if no callbacks found/defined
842 if (!callbacks) 890 if (!callbacks)
843 return 0; 891 return 0;
892
893 va_list ap;
894 va_start (ap, event);
844 895
845 CALL_BEGIN (3); 896 CALL_BEGIN (3);
846 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 897 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
847 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 898 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
848 899
925 CALL_ARG (make_core); 976 CALL_ARG (make_core);
926 CALL_CALL ("cf::post_cleanup", G_VOID); 977 CALL_CALL ("cf::post_cleanup", G_VOID);
927 CALL_END; 978 CALL_END;
928} 979}
929 980
981void
982cfperl_make_book (object *book, int level)
983{
984 CALL_BEGIN (2);
985 CALL_ARG (book);
986 CALL_ARG (level);
987 CALL_CALL ("ext::books::make_book", G_VOID);
988 CALL_END;
989}
990
930maptile * 991maptile *
931maptile::find_sync (const char *path, maptile *origin) 992maptile::find_sync (const char *path, maptile *origin)
932{ 993{
933 CALL_BEGIN (2); 994 CALL_BEGIN (2);
934 CALL_ARG (path); 995 CALL_ARG (path);
1018 1079
1019struct EventAPI *watcher_base::GEventAPI; 1080struct EventAPI *watcher_base::GEventAPI;
1020struct CoroAPI *coroapi::GCoroAPI; 1081struct CoroAPI *coroapi::GCoroAPI;
1021 1082
1022int coroapi::cede_counter; 1083int coroapi::cede_counter;
1023double (*coroapi::time)();
1024double coroapi::next_cede; 1084tstamp coroapi::next_cede;
1025 1085
1026void coroapi::do_cede_to_tick () 1086void coroapi::do_cede_to_tick ()
1027{ 1087{
1028 cede_counter = 0; 1088 cede_counter = 0;
1029 1089
1160 1220
1161 _connect_to_perl (); 1221 _connect_to_perl ();
1162 1222
1163 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1223 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1164 1224
1165 { 1225 //{
1166 require_pv ("Time::HiRes"); 1226 // require_pv ("Time::HiRes");
1167 1227 //
1168 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 1228 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1169 if (!svp) croak ("Time::HiRes is required"); 1229 // if (!svp) croak ("Time::HiRes is required");
1170 if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); 1230 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1171 coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); 1231 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1172 } 1232 //}
1173 1233
1174 static const struct { 1234 static const struct {
1175 const char *name; 1235 const char *name;
1176 IV iv; 1236 IV iv;
1177 } *civ, const_iv[] = { 1237 } *civ, const_iv[] = {
1274 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1334 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1275 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1335 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1276 1336
1277 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1337 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1278 1338
1339 const_iv (SP_RAISE_DEAD)
1340 const_iv (SP_RUNE)
1341 const_iv (SP_MAKE_MARK)
1342 const_iv (SP_BOLT)
1343 const_iv (SP_BULLET)
1344 const_iv (SP_EXPLOSION)
1345 const_iv (SP_CONE)
1346 const_iv (SP_BOMB)
1347 const_iv (SP_WONDER)
1348 const_iv (SP_SMITE)
1349 const_iv (SP_MAGIC_MISSILE)
1350 const_iv (SP_SUMMON_GOLEM)
1351 const_iv (SP_DIMENSION_DOOR)
1352 const_iv (SP_MAGIC_MAPPING)
1353 const_iv (SP_MAGIC_WALL)
1354 const_iv (SP_DESTRUCTION)
1355 const_iv (SP_PERCEIVE_SELF)
1356 const_iv (SP_WORD_OF_RECALL)
1357 const_iv (SP_INVISIBLE)
1358 const_iv (SP_PROBE)
1359 const_iv (SP_HEALING)
1360 const_iv (SP_CREATE_FOOD)
1361 const_iv (SP_EARTH_TO_DUST)
1362 const_iv (SP_CHANGE_ABILITY)
1363 const_iv (SP_BLESS)
1364 const_iv (SP_CURSE)
1365 const_iv (SP_SUMMON_MONSTER)
1366 const_iv (SP_CHARGING)
1367 const_iv (SP_POLYMORPH)
1368 const_iv (SP_ALCHEMY)
1369 const_iv (SP_REMOVE_CURSE)
1370 const_iv (SP_IDENTIFY)
1371 const_iv (SP_DETECTION)
1372 const_iv (SP_MOOD_CHANGE)
1373 const_iv (SP_MOVING_BALL)
1374 const_iv (SP_SWARM)
1375 const_iv (SP_CHANGE_MANA)
1376 const_iv (SP_DISPEL_RUNE)
1377 const_iv (SP_CREATE_MISSILE)
1378 const_iv (SP_CONSECRATE)
1379 const_iv (SP_ANIMATE_WEAPON)
1380 const_iv (SP_LIGHT)
1381 const_iv (SP_CHANGE_MAP_LIGHT)
1382 const_iv (SP_FAERY_FIRE)
1383 const_iv (SP_CAUSE_DISEASE)
1384 const_iv (SP_AURA)
1385 const_iv (SP_TOWN_PORTAL)
1386 const_iv (SP_PARTY_SPELL)
1387
1279 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1388 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1280 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1389 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1281 const_iv (F_LOCKED) 1390 const_iv (F_LOCKED)
1282 1391
1283 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1392 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1478 CODE: 1587 CODE:
1479 coroapi::cede_to_tick (); 1588 coroapi::cede_to_tick ();
1480 1589
1481void server_tick () 1590void server_tick ()
1482 CODE: 1591 CODE:
1592 NOW = now ();
1483 runtime = SvNVx (sv_runtime); 1593 runtime = SvNVx (sv_runtime);
1484 server_tick (); 1594 server_tick ();
1485 1595
1486void 1596void
1487log_backtrace (utf8_string msg) 1597log_backtrace (utf8_string msg)
1679object *actives (U32 index) 1789object *actives (U32 index)
1680 CODE: 1790 CODE:
1681 RETVAL = index < actives.size () ? actives [index] : 0; 1791 RETVAL = index < actives.size () ? actives [index] : 0;
1682 OUTPUT: RETVAL 1792 OUTPUT: RETVAL
1683 1793
1684const char *slot_save_name (U32 slot) 1794const char *slot_use_name (U32 slot)
1685 ALIAS: 1795 ALIAS:
1686 slot_use_name = 1
1687 slot_nonuse_name = 2 1796 slot_nonuse_name = 1
1688 CODE: 1797 CODE:
1689{ 1798{
1690 if (slot >= NUM_BODY_LOCATIONS) 1799 if (slot >= NUM_BODY_LOCATIONS)
1691 croak ("body slot index out of range"); 1800 croak ("body slot index out of range");
1692 1801
1693 switch (ix) 1802 switch (ix)
1694 { 1803 {
1695 case 0: RETVAL = body_locations[slot].save_name; break;
1696 case 1: RETVAL = body_locations[slot].use_name; break; 1804 case 0: RETVAL = body_locations[slot].use_name; break;
1697 case 2: RETVAL = body_locations[slot].nonuse_name; break; 1805 case 1: RETVAL = body_locations[slot].nonuse_name; break;
1698 } 1806 }
1699} 1807}
1700 OUTPUT: 1808 OUTPUT:
1701 RETVAL 1809 RETVAL
1702 1810
1704 1812
1705object *head (object *op) 1813object *head (object *op)
1706 PROTOTYPE: $ 1814 PROTOTYPE: $
1707 CODE: 1815 CODE:
1708 RETVAL = op->head_ (); 1816 RETVAL = op->head_ ();
1709 OUTPUT: RETVAL
1710
1711int is_head (object *op)
1712 PROTOTYPE: $
1713 CODE:
1714 RETVAL = op->head_ () == op;
1715 OUTPUT: RETVAL 1817 OUTPUT: RETVAL
1716 1818
1717void 1819void
1718inv (object *obj) 1820inv (object *obj)
1719 PROTOTYPE: $ 1821 PROTOTYPE: $
1876# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 1978# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1877 1979
1878object *new (utf8_string archetype = 0) 1980object *new (utf8_string archetype = 0)
1879 PROTOTYPE: ;$ 1981 PROTOTYPE: ;$
1880 CODE: 1982 CODE:
1881 RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); 1983 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1882 OUTPUT: 1984 OUTPUT:
1883 RETVAL 1985 RETVAL
1884 1986
1987# TODO: nuke
1885object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 1988object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1886 PROTOTYPE: $$$$$$ 1989 PROTOTYPE: $$$$$$
1887 CODE: 1990 CODE:
1888{ 1991{
1889 int unused_type; 1992 int unused_type;
1942 2045
1943void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2046void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1944 CODE: 2047 CODE:
1945 new_draw_info (flags, 0, op, txt); 2048 new_draw_info (flags, 0, op, txt);
1946 2049
1947object *cf_player_send_inventory (object *op)
1948
1949octet_string cf_player_get_ip (object *op)
1950 ALIAS: ip = 0
1951
1952object *cf_player_get_marked_item (object *op)
1953 ALIAS: marked_item = 0
1954
1955void cf_player_set_marked_item (object *op, object *ob)
1956
1957partylist *cf_player_get_party (object *op)
1958 ALIAS: party = 0
1959
1960void cf_player_set_party (object *op, partylist *party)
1961
1962void kill_player (object *op) 2050void kill_player (object *op)
1963 2051
1964void esrv_update_item (object *op, int what, object *item) 2052void esrv_update_item (object *op, int what, object *item)
1965 C_ARGS: what, op, item 2053 C_ARGS: what, op, item
1966
1967void clear_los (object *op)
1968 2054
1969int command_summon (object *op, utf8_string params) 2055int command_summon (object *op, utf8_string params)
1970 2056
1971int command_arrest (object *op, utf8_string params) 2057int command_arrest (object *op, utf8_string params)
1972 2058
1990 CODE: 2076 CODE:
1991 pl->ob->stats.hp = pl->ob->stats.maxhp; 2077 pl->ob->stats.hp = pl->ob->stats.maxhp;
1992 pl->ob->stats.sp = pl->ob->stats.maxsp; 2078 pl->ob->stats.sp = pl->ob->stats.maxsp;
1993 pl->ob->stats.grace = pl->ob->stats.maxgrace; 2079 pl->ob->stats.grace = pl->ob->stats.maxgrace;
1994 pl->orig_stats = pl->ob->stats; 2080 pl->orig_stats = pl->ob->stats;
2081
2082void clear_los (player *pl)
1995 2083
1996void cf_player_move (player *pl, int dir) 2084void cf_player_move (player *pl, int dir)
1997 2085
1998void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2086void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
1999 2087
2351 rmp.decoroptions = decoroptions; 2439 rmp.decoroptions = decoroptions;
2352 rmp.orientation = orientation; 2440 rmp.orientation = orientation;
2353 rmp.origin_y = origin_y; 2441 rmp.origin_y = origin_y;
2354 rmp.origin_x = origin_x; 2442 rmp.origin_x = origin_x;
2355 rmp.random_seed = random_seed; 2443 rmp.random_seed = random_seed;
2356 rmp.total_map_hp = total_map_hp; 2444 rmp.total_map_hp = (uint64_t) total_map_hp;
2357 rmp.map_layout_style = map_layout_style; 2445 rmp.map_layout_style = map_layout_style;
2358 rmp.treasureoptions = treasureoptions; 2446 rmp.treasureoptions = treasureoptions;
2359 rmp.symmetry_used = symmetry_used; 2447 rmp.symmetry_used = symmetry_used;
2360 rmp.region = region; 2448 rmp.region = region;
2361 rmp.custom = custom; 2449 rmp.custom = custom;
2371 CODE: 2459 CODE:
2372 RETVAL = archetype::find (name); 2460 RETVAL = archetype::find (name);
2373 OUTPUT: 2461 OUTPUT:
2374 RETVAL 2462 RETVAL
2375 2463
2376archetype *first() 2464int archetypes_size ()
2377 PROTOTYPE: 2465 CODE:
2378 CODE:
2379 RETVAL = first_archetype; 2466 RETVAL = archetypes.size ();
2467 OUTPUT: RETVAL
2468
2469archetype *archetypes (U32 index)
2470 CODE:
2471 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2472 OUTPUT: RETVAL
2473
2474object *instantiate (archetype *arch)
2475 CODE:
2476 RETVAL = arch_to_object (arch);
2477 OUTPUT:
2380 OUTPUT: RETVAL 2478 RETVAL
2381 2479
2382INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2480INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2383 2481
2384MODULE = cf PACKAGE = cf::party 2482MODULE = cf PACKAGE = cf::party
2385 2483

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines