… | |
… | |
84 | double runtime; |
84 | double runtime; |
85 | |
85 | |
86 | global gbl_ev; |
86 | global gbl_ev; |
87 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
87 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
88 | static SV *sv_runtime, *sv_next_tick; |
88 | static SV *sv_runtime, *sv_next_tick; |
|
|
89 | |
|
|
90 | bitset<NUM_EVENT_TYPES> ev_want_event; |
|
|
91 | bitset<NUM_TYPES> ev_want_type; |
89 | |
92 | |
90 | static HV |
93 | static 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 | |
717 | void |
720 | void |
718 | global::gather_callbacks (AV *&callbacks, event_type event) const |
721 | global::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 | |
723 | void |
726 | void |
724 | object::gather_callbacks (AV *&callbacks, event_type event) const |
727 | object::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 | |
|
|
777 | void |
|
|
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 |
|
|
797 | void |
|
|
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 | |
774 | bool |
827 | bool |
775 | attachable::invoke (event_type event, ...) |
828 | attachable::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 | |
1338 | void _connect_to_perl () |
1388 | void _connect_to_perl () |
|
|
1389 | |
|
|
1390 | void _recalc_want () |
1339 | |
1391 | |
1340 | void _global_reattach () |
1392 | void _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. |