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.209 by root, Thu May 17 14:14:55 2007 UTC vs.
Revision 1.210 by root, Sat May 19 00:08:12 2007 UTC

84double runtime; 84double 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
90bitset<NUM_EVENT_TYPES> ev_want_event;
91bitset<NUM_TYPES> ev_want_type;
89 92
90static HV 93static HV
91 *stash_cf, 94 *stash_cf,
92 *stash_cf_object_wrap, 95 *stash_cf_object_wrap,
93 *stash_cf_object_player_wrap, 96 *stash_cf_object_player_wrap,
715} 718}
716 719
717void 720void
718global::gather_callbacks (AV *&callbacks, event_type event) const 721global::gather_callbacks (AV *&callbacks, event_type event) const
719{ 722{
720 ::gather_callbacks (callbacks, cb_object, event); 723 ::gather_callbacks (callbacks, cb_global, event);
721} 724}
722 725
723void 726void
724object::gather_callbacks (AV *&callbacks, event_type event) const 727object::gather_callbacks (AV *&callbacks, event_type event) const
725{ 728{
726 if (subtype && type + subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) 729 if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type))
727 { 730 {
728 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_SUBTYPES]; 731 SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES];
729 732
730 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) 733 if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV)
731 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event); 734 ::gather_callbacks (callbacks, (AV *)SvRV (registry), event);
732 } 735 }
733 736
769{ 772{
770 attachable::gather_callbacks (callbacks, event); 773 attachable::gather_callbacks (callbacks, event);
771 ::gather_callbacks (callbacks, cb_map, event); 774 ::gather_callbacks (callbacks, cb_map, event);
772} 775}
773 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
774bool 827bool
775attachable::invoke (event_type event, ...) 828attachable::vinvoke (event_type event, va_list &ap)
776{ 829{
777 data_type dt; 830 data_type dt;
778 va_list ap;
779
780 va_start (ap, event);
781 831
782 // callback call ordering should be: 832 // callback call ordering should be:
783 // 1. per-object callback 833 // 1. per-object callback
784 // 2. per-class object 834 // 2. per-class object
785 // 3. per-type callback 835 // 3. per-type callback
1169 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL) 1219 const_iv (CONTAINER) const_iv (ARMOUR_IMPROVER) const_iv (WEAPON_IMPROVER) const_iv (SKILLSCROLL)
1170 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE) 1220 const_iv (DEEP_SWAMP) const_iv (IDENTIFY_ALTAR) const_iv (MENU) const_iv (RUNE)
1171 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE) 1221 const_iv (TRAP) const_iv (POWER_CRYSTAL) const_iv (CORPSE) const_iv (DISEASE)
1172 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER) 1222 const_iv (SYMPTOM) const_iv (BUILDER) const_iv (MATERIAL) const_iv (ITEM_TRANSFORMER)
1173 1223
1174 const_iv (NUM_SUBTYPES) 1224 const_iv (NUM_TYPES) const_iv (NUM_SUBTYPES)
1175 1225
1176 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE) 1226 const_iv (ST_BD_BUILD) const_iv (ST_BD_REMOVE)
1177 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) 1227 const_iv (ST_MAT_FLOOR) const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM)
1178 1228
1179 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY) 1229 const_iv (AT_PHYSICAL) const_iv (AT_MAGIC) const_iv (AT_FIRE) const_iv (AT_ELECTRICITY)
1334 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); 1384 newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv));
1335 } 1385 }
1336} 1386}
1337 1387
1338void _connect_to_perl () 1388void _connect_to_perl ()
1389
1390void _recalc_want ()
1339 1391
1340void _global_reattach () 1392void _global_reattach ()
1341 CODE: 1393 CODE:
1342{ 1394{
1343 // reattach to all attachable objects in the game. 1395 // reattach to all attachable objects in the game.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines