From c9a0fbeacc65d82d1f68c0e6b0cd31e5cde7d894 Mon Sep 17 00:00:00 2001 From: Moritz Schmidt Date: Sun, 3 Jan 2021 13:52:05 +0100 Subject: [PATCH] Fix state machine multiplicator (#116) * fix state machine overclocking on headless clients * react to smMultiplicator settings change --- addons/activities/XEH_PREP.hpp | 1 - addons/lifecycle/XEH_PREP.hpp | 1 + addons/lifecycle/functions/fnc_initConfig.sqf | 13 ++++++++++++- .../functions/fnc_overclockStateMachines.sqf | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) rename addons/{activities => lifecycle}/functions/fnc_overclockStateMachines.sqf (82%) diff --git a/addons/activities/XEH_PREP.hpp b/addons/activities/XEH_PREP.hpp index 5ec5d9c9..24d02c21 100644 --- a/addons/activities/XEH_PREP.hpp +++ b/addons/activities/XEH_PREP.hpp @@ -16,7 +16,6 @@ PREP(initCommonEventhandlers); PREP(initConfig); PREP(isInHouse); PREP(onCivAdded); -PREP(overclockStateMachines); PREP(reverse_abort); PREP(reverse_internal_end); PREP(reverse_internal_pfh); diff --git a/addons/lifecycle/XEH_PREP.hpp b/addons/lifecycle/XEH_PREP.hpp index f9b9b6ba..f30df858 100644 --- a/addons/lifecycle/XEH_PREP.hpp +++ b/addons/lifecycle/XEH_PREP.hpp @@ -13,6 +13,7 @@ PREP(getGlobalCivs); PREP(globalSpawnPass); PREP(initHCs); PREP(isInDistanceFromOtherPlayers); +PREP(overclockStateMachines); PREP(sm_lifecycle); PREP(sm_lifecycle_state_death_enter); PREP(sm_lifecycle_state_despawn_enter); diff --git a/addons/lifecycle/functions/fnc_initConfig.sqf b/addons/lifecycle/functions/fnc_initConfig.sqf index d733c52e..7df6ab50 100644 --- a/addons/lifecycle/functions/fnc_initConfig.sqf +++ b/addons/lifecycle/functions/fnc_initConfig.sqf @@ -77,6 +77,17 @@ private _settingsGroup = ["GRAD Civs", "2) lifecycle - performance & spawning"]; _settingsGroup, [1, 10, 1, 0], true, - {}, + { + if (!CBA_isHeadlessClient) exitWith {}; + + ISNILS(GVAR(efIDs), []); + INFO_1("removing %1 previous addditional state machine ticks per frame", count GVAR(efIDs)); + { + removeMissionEventHandler ["EachFrame", _x]; + } forEach GVAR(efIDs); + GVAR(efIDs) = []; + + [] call FUNC(overclockStateMachines); + }, false ] call CBA_fnc_addSetting; diff --git a/addons/activities/functions/fnc_overclockStateMachines.sqf b/addons/lifecycle/functions/fnc_overclockStateMachines.sqf similarity index 82% rename from addons/activities/functions/fnc_overclockStateMachines.sqf rename to addons/lifecycle/functions/fnc_overclockStateMachines.sqf index ddbaf0aa..e7cfae98 100644 --- a/addons/activities/functions/fnc_overclockStateMachines.sqf +++ b/addons/lifecycle/functions/fnc_overclockStateMachines.sqf @@ -1,7 +1,8 @@ #include "..\script_component.hpp" ISNILS(GVAR(efIDs), []); -for "_i" from 2 to GVAR(smMultiplicator) do { + +for "_i" from 2 to (round GVAR(smMultiplicator)) do { GVAR(efIDs) pushBack (addMissionEventHandler ["EachFrame", {call cba_statemachine_fnc_clockwork}]); }; INFO_1("CBA statemachines are running %1 more ticks per frame now", count GVAR(efIDs));