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.208 by root, Sat May 12 13:27:38 2007 UTC vs.
Revision 1.215 by root, Sun May 27 23:56:21 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 *
87 85
88global gbl_ev; 86global gbl_ev;
89static 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;
90static SV *sv_runtime, *sv_next_tick; 88static SV *sv_runtime, *sv_next_tick;
91 89
90bitset<NUM_EVENT_TYPES> ev_want_event;
91bitset<NUM_TYPES> ev_want_type;
92
92static HV 93static HV
93 *stash_cf, 94 *stash_cf,
94 *stash_cf_object_wrap, 95 *stash_cf_object_wrap,
95 *stash_cf_object_player_wrap, 96 *stash_cf_object_player_wrap,
96 *stash_cf_player_wrap, 97 *stash_cf_player_wrap,
167} 168}
168 169
169void 170void
170attachable::do_destroy () 171attachable::do_destroy ()
171{ 172{
172 invoke (EVENT_ATTACHABLE_DESTROY, DT_END); 173 INVOKE_ATTACHABLE (DESTROY, this);
173 174
174 if (cb) 175 if (cb)
175 { 176 {
176 SvREFCNT_dec (cb); 177 SvREFCNT_dec (cb);
177 cb = 0; 178 cb = 0;
654void 655void
655attachable::instantiate () 656attachable::instantiate ()
656{ 657{
657 if (attach) 658 if (attach)
658 { 659 {
659 invoke (EVENT_ATTACHABLE_INSTANTIATE, ARG_STRING (attach), DT_END); 660 INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach));
660 attach = 0; 661 attach = 0;
661 } 662 }
662} 663}
663 664
664void 665void
665attachable::reattach () 666attachable::reattach ()
666{ 667{
667 optimise (); 668 optimise ();
668 //TODO: check for _attachment's, very important for restarts 669 //TODO: check for _attachment's, very important for restarts
669 invoke (EVENT_ATTACHABLE_REATTACH, DT_END); 670 INVOKE_ATTACHABLE (REATTACH, this);
670} 671}
671 672
672static event_klass klass_of[NUM_EVENT_TYPES] = { 673static event_klass klass_of[NUM_EVENT_TYPES] = {
673# define def(type,name) KLASS_ ## type, 674# define def(type,name) KLASS_ ## type,
674# include "eventinc.h" 675# include "eventinc.h"
717} 718}
718 719
719void 720void
720global::gather_callbacks (AV *&callbacks, event_type event) const 721global::gather_callbacks (AV *&callbacks, event_type event) const
721{ 722{
722 ::gather_callbacks (callbacks, cb_object, event); 723 ::gather_callbacks (callbacks, cb_global, event);
723} 724}
724 725
725void 726void
726object::gather_callbacks (AV *&callbacks, event_type event) const 727object::gather_callbacks (AV *&callbacks, event_type event) const
727{ 728{
728 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 729 if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type))
729 { 730 {
730 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; 731 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES];
731 732
732 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) 733 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
733 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); 734 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
734 } 735 }
735 736
771{ 772{
772 attachable::gather_callbacks (callbacks, event); 773 attachable::gather_callbacks (callbacks, event);
773 ::gather_callbacks (callbacks, cb_map, event); 774 ::gather_callbacks (callbacks, cb_map, event);
774} 775}
775 776
777void
778_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
779{
780 for (int event = 0; event <= AvFILLp (registry); ++event)
781 {
782 SV *cbs_ = AvARRAY (registry)[event];
783
784 // element must be list of callback entries
785 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
786 {
787 AV *cbs = (AV *)SvRV (cbs_);
788
789 // no callback entries, no callbacks to call
790 if (AvFILLp (cbs) >= 0)
791 set.set (event);
792 }
793 }
794}
795
796// very slow and inefficient way to recalculate the global want bitsets
797void
798_recalc_want ()
799{
800 ev_want_event.reset ();
801
802 _recalc_want (ev_want_event, cb_global);
803 _recalc_want (ev_want_event, cb_attachable);
804 _recalc_want (ev_want_event, cb_object);
805 _recalc_want (ev_want_event, cb_client);
806 _recalc_want (ev_want_event, cb_player);
807 _recalc_want (ev_want_event, cb_map);
808
809 ev_want_type.reset ();
810
811 for (int type = 0; type <= AvFILLp (cb_type); ++type)
812 {
813 SV *cbs_ = AvARRAY (cb_type)[type];
814
815 // element must be list of callback entries
816 if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV)
817 {
818 AV *cbs = (AV *)SvRV (cbs_);
819
820 // no callback entries, no callbacks to call
821 if (AvFILLp (cbs) >= 0)
822 ev_want_type.set (type % NUM_TYPES);
823 }
824 }
825}
826
776bool 827bool
777attachable::invoke (event_type event, ...) 828attachable::invoke (event_type event, ...)
778{ 829{
779 data_type dt; 830 data_type dt;
780 va_list ap;
781
782 va_start (ap, event);
783 831
784 // callback call ordering should be: 832 // callback call ordering should be:
785 // 1. per-object callback 833 // 1. per-object callback
786 // 2. per-class object 834 // 2. per-class object
787 // 3. per-type callback 835 // 3. per-type callback
791 gather_callbacks (callbacks, event); 839 gather_callbacks (callbacks, event);
792 840
793 // short-circuit processing if no callbacks found/defined 841 // short-circuit processing if no callbacks found/defined
794 if (!callbacks) 842 if (!callbacks)
795 return 0; 843 return 0;
844
845 va_list ap;
846 va_start (ap, event);
796 847
797 CALL_BEGIN (3); 848 CALL_BEGIN (3);
798 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays 849 CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays
799 CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); 850 CALL_ARG_SV (newRV_noinc ((SV *)callbacks));
800 851
874cfperl_cleanup (int make_core) 925cfperl_cleanup (int make_core)
875{ 926{
876 CALL_BEGIN (1); 927 CALL_BEGIN (1);
877 CALL_ARG (make_core); 928 CALL_ARG (make_core);
878 CALL_CALL ("cf::post_cleanup", G_VOID); 929 CALL_CALL ("cf::post_cleanup", G_VOID);
930 CALL_END;
931}
932
933void
934cfperl_make_book (object *book, int level)
935{
936 CALL_BEGIN (2);
937 CALL_ARG (book);
938 CALL_ARG (level);
939 CALL_CALL ("ext::books::make_book", G_VOID);
879 CALL_END; 940 CALL_END;
880} 941}
881 942
882maptile * 943maptile *
883maptile::find_sync (const char *path, maptile *origin) 944maptile::find_sync (const char *path, maptile *origin)
1171 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1232 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1172 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1233 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1173 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1234 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1174 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1235 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1175 1236
1176 const_iv (NUM_SUBTYPES) 1237 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1177 1238
1178 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1239 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1179 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1240 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1180 1241
1181 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) 1242 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY)
1189 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE) 1250 const_iv (WEAP_HIT) const_iv (WEAP_SLASH) const_iv (WEAP_PIERCE) const_iv (WEAP_CLEAVE)
1190 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH) 1251 const_iv (WEAP_SLICE) const_iv (WEAP_STAB) const_iv (WEAP_WHIP) const_iv (WEAP_CRUSH)
1191 const_iv (WEAP_BLUD) 1252 const_iv (WEAP_BLUD)
1192 1253
1193 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED) 1254 const_iv (FLAG_ALIVE) const_iv (FLAG_WIZ) const_iv (FLAG_REMOVED) const_iv (FLAG_FREED)
1194 const_iv (FLAG_WAS_WIZ) const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD) 1255 const_iv (FLAG_APPLIED) const_iv (FLAG_UNPAID) const_iv (FLAG_USE_SHIELD)
1195 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY) 1256 const_iv (FLAG_NO_PICK) const_iv (FLAG_ANIMATE) const_iv (FLAG_MONSTER) const_iv (FLAG_FRIENDLY)
1196 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD) 1257 const_iv (FLAG_GENERATOR) const_iv (FLAG_IS_THROWN) const_iv (FLAG_AUTO_APPLY) const_iv (FLAG_PLAYER_SOLD)
1197 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE) 1258 const_iv (FLAG_SEE_INVISIBLE) const_iv (FLAG_CAN_ROLL) const_iv (FLAG_OVERLAY_FLOOR) const_iv (FLAG_IS_TURNABLE)
1198 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING) 1259 const_iv (FLAG_IS_USED_UP) const_iv (FLAG_IDENTIFIED) const_iv (FLAG_REFLECTING) const_iv (FLAG_CHANGING)
1199 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW) 1260 const_iv (FLAG_SPLITTING) const_iv (FLAG_HITBACK) const_iv (FLAG_STARTEQUIP) const_iv (FLAG_BLOCKSVIEW)
1226 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1287 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1227 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1288 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1228 1289
1229 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1290 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1230 1291
1292 const_iv (SP_RAISE_DEAD)
1293 const_iv (SP_RUNE)
1294 const_iv (SP_MAKE_MARK)
1295 const_iv (SP_BOLT)
1296 const_iv (SP_BULLET)
1297 const_iv (SP_EXPLOSION)
1298 const_iv (SP_CONE)
1299 const_iv (SP_BOMB)
1300 const_iv (SP_WONDER)
1301 const_iv (SP_SMITE)
1302 const_iv (SP_MAGIC_MISSILE)
1303 const_iv (SP_SUMMON_GOLEM)
1304 const_iv (SP_DIMENSION_DOOR)
1305 const_iv (SP_MAGIC_MAPPING)
1306 const_iv (SP_MAGIC_WALL)
1307 const_iv (SP_DESTRUCTION)
1308 const_iv (SP_PERCEIVE_SELF)
1309 const_iv (SP_WORD_OF_RECALL)
1310 const_iv (SP_INVISIBLE)
1311 const_iv (SP_PROBE)
1312 const_iv (SP_HEALING)
1313 const_iv (SP_CREATE_FOOD)
1314 const_iv (SP_EARTH_TO_DUST)
1315 const_iv (SP_CHANGE_ABILITY)
1316 const_iv (SP_BLESS)
1317 const_iv (SP_CURSE)
1318 const_iv (SP_SUMMON_MONSTER)
1319 const_iv (SP_CHARGING)
1320 const_iv (SP_POLYMORPH)
1321 const_iv (SP_ALCHEMY)
1322 const_iv (SP_REMOVE_CURSE)
1323 const_iv (SP_IDENTIFY)
1324 const_iv (SP_DETECTION)
1325 const_iv (SP_MOOD_CHANGE)
1326 const_iv (SP_MOVING_BALL)
1327 const_iv (SP_SWARM)
1328 const_iv (SP_CHANGE_MANA)
1329 const_iv (SP_DISPEL_RUNE)
1330 const_iv (SP_CREATE_MISSILE)
1331 const_iv (SP_CONSECRATE)
1332 const_iv (SP_ANIMATE_WEAPON)
1333 const_iv (SP_LIGHT)
1334 const_iv (SP_CHANGE_MAP_LIGHT)
1335 const_iv (SP_FAERY_FIRE)
1336 const_iv (SP_CAUSE_DISEASE)
1337 const_iv (SP_AURA)
1338 const_iv (SP_TOWN_PORTAL)
1339 const_iv (SP_PARTY_SPELL)
1340
1231 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) 1341 const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC)
1232 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) 1342 const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK)
1233 const_iv (F_LOCKED) 1343 const_iv (F_LOCKED)
1234 1344
1235 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL) 1345 const_iv (F_BUY) const_iv (F_SHOP) const_iv (F_SELL)
1336 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); 1446 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv));
1337 } 1447 }
1338} 1448}
1339 1449
1340void _connect_to_perl () 1450void _connect_to_perl ()
1451
1452void _recalc_want ()
1341 1453
1342void _global_reattach () 1454void _global_reattach ()
1343 CODE: 1455 CODE:
1344{ 1456{
1345 // reattach to all attachable objects in the game. 1457 // reattach to all attachable objects in the game.
1629object *actives (U32 index) 1741object *actives (U32 index)
1630 CODE: 1742 CODE:
1631 RETVAL = index < actives.size () ? actives [index] : 0; 1743 RETVAL = index < actives.size () ? actives [index] : 0;
1632 OUTPUT: RETVAL 1744 OUTPUT: RETVAL
1633 1745
1634const char *slot_save_name (U32 slot) 1746const char *slot_use_name (U32 slot)
1635 ALIAS: 1747 ALIAS:
1636 slot_use_name = 1
1637 slot_nonuse_name = 2 1748 slot_nonuse_name = 1
1638 CODE: 1749 CODE:
1639{ 1750{
1640 if (slot >= NUM_BODY_LOCATIONS) 1751 if (slot >= NUM_BODY_LOCATIONS)
1641 croak ("body slot index out of range"); 1752 croak ("body slot index out of range");
1642 1753
1643 switch (ix) 1754 switch (ix)
1644 { 1755 {
1645 case 0: RETVAL = body_locations[slot].save_name; break;
1646 case 1: RETVAL = body_locations[slot].use_name; break; 1756 case 0: RETVAL = body_locations[slot].use_name; break;
1647 case 2: RETVAL = body_locations[slot].nonuse_name; break; 1757 case 1: RETVAL = body_locations[slot].nonuse_name; break;
1648 } 1758 }
1649} 1759}
1650 OUTPUT: 1760 OUTPUT:
1651 RETVAL 1761 RETVAL
1652 1762
1891void check_score (object *op) 2001void check_score (object *op)
1892 2002
1893void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2003void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1894 CODE: 2004 CODE:
1895 new_draw_info (flags, 0, op, txt); 2005 new_draw_info (flags, 0, op, txt);
1896
1897object *cf_player_send_inventory (object *op)
1898
1899octet_string cf_player_get_ip (object *op)
1900 ALIAS: ip = 0
1901
1902object *cf_player_get_marked_item (object *op)
1903 ALIAS: marked_item = 0
1904
1905void cf_player_set_marked_item (object *op, object *ob)
1906
1907partylist *cf_player_get_party (object *op)
1908 ALIAS: party = 0
1909
1910void cf_player_set_party (object *op, partylist *party)
1911 2006
1912void kill_player (object *op) 2007void kill_player (object *op)
1913 2008
1914void esrv_update_item (object *op, int what, object *item) 2009void esrv_update_item (object *op, int what, object *item)
1915 C_ARGS: what, op, item 2010 C_ARGS: what, op, item
2301 rmp.decoroptions = decoroptions; 2396 rmp.decoroptions = decoroptions;
2302 rmp.orientation = orientation; 2397 rmp.orientation = orientation;
2303 rmp.origin_y = origin_y; 2398 rmp.origin_y = origin_y;
2304 rmp.origin_x = origin_x; 2399 rmp.origin_x = origin_x;
2305 rmp.random_seed = random_seed; 2400 rmp.random_seed = random_seed;
2306 rmp.total_map_hp = total_map_hp; 2401 rmp.total_map_hp = (uint64_t) total_map_hp;
2307 rmp.map_layout_style = map_layout_style; 2402 rmp.map_layout_style = map_layout_style;
2308 rmp.treasureoptions = treasureoptions; 2403 rmp.treasureoptions = treasureoptions;
2309 rmp.symmetry_used = symmetry_used; 2404 rmp.symmetry_used = symmetry_used;
2310 rmp.region = region; 2405 rmp.region = region;
2311 rmp.custom = custom; 2406 rmp.custom = custom;
2326archetype *first() 2421archetype *first()
2327 PROTOTYPE: 2422 PROTOTYPE:
2328 CODE: 2423 CODE:
2329 RETVAL = first_archetype; 2424 RETVAL = first_archetype;
2330 OUTPUT: RETVAL 2425 OUTPUT: RETVAL
2426
2427object *instantiate (archetype *arch)
2428 CODE:
2429 RETVAL = arch_to_object (arch);
2430 OUTPUT:
2431 RETVAL
2331 2432
2332INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h | 2433INCLUDE: $PERL $srcdir/genacc archetype ../include/object.h |
2333 2434
2334MODULE = cf PACKAGE = cf::party 2435MODULE = cf PACKAGE = cf::party
2335 2436

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines