From 4f03d1a0d8d97fe7f6bb792a53bae3dc5c6aded9 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 21 Mar 2024 15:42:34 +0100 Subject: [PATCH] Fix "Performance warning: SimpleSerialization" (#83) * Fix showScore invoking global showMessage event * Drop location type variable * Prevent serialization warning on initial timeout message --- addons/civilian/functions/fnc_getCityName.sqf | 10 ++++---- .../functions/fnc_getCityRandomPos.sqf | 7 +++--- addons/civilian/functions/fnc_initCity.sqf | 7 +++--- addons/score/XEH_postInit.sqf | 24 +++++++++++-------- addons/score/functions/fnc_showScore.sqf | 2 +- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/addons/civilian/functions/fnc_getCityName.sqf b/addons/civilian/functions/fnc_getCityName.sqf index 1607ee6d..cf207833 100644 --- a/addons/civilian/functions/fnc_getCityName.sqf +++ b/addons/civilian/functions/fnc_getCityName.sqf @@ -26,12 +26,14 @@ if (_city isEqualType locationNull) exitWith { private _name = _city getVariable [QGVAR(Name), ""]; if !(_name isEqualTo "") exitWith {_name}; -// Get logic assigned location -private _location = _city getVariable [QGVAR(Location), [_city] call EFUNC(common,getNearestCityLocation)]; -if (_location isEqualTo locationNull) exitWith {""}; +// Get logic assigned location class name +private _locationClassName = _city getVariable [QGVAR(locationClassName), + className ([_city] call EFUNC(common,getNearestCityLocation))]; + +if (_locationClassName isEqualTo "") exitWith {""}; // Get location name from config and save as logic variable for future calls -_name = getText (configFile >> "CfgWorlds" >> worldName >> "Names" >> className _location >> "name"); +_name = getText (configFile >> "CfgWorlds" >> worldName >> "Names" >> _locationClassName >> "name"); _city setVariable [QGVAR(Name), _name]; _name diff --git a/addons/civilian/functions/fnc_getCityRandomPos.sqf b/addons/civilian/functions/fnc_getCityRandomPos.sqf index 31967bab..25fbb7fc 100644 --- a/addons/civilian/functions/fnc_getCityRandomPos.sqf +++ b/addons/civilian/functions/fnc_getCityRandomPos.sqf @@ -54,12 +54,11 @@ if (!(_objectType isEqualType "")) then { // If no object is given, just random position is enough if (_objectType isEqualTo "") exitWith {[_cityArea, _nearRoad, _allowOnRoad, _nearHouse, _emptyPosSearchRadius] call _fnc_randomPos}; - -private _location = _cityNamespace getVariable QGVAR(Location); +private _cityArea = _cityNamespace getVariable QGVAR(cityArea); private _randomPos = []; private _loopLimit = 250; // Loop until acquired random empty pos is within location area (or loop limit reached) -while {(_loopLimit >= 0) && {(_randomPos isEqualTo []) || {!(_randomPos inArea _location)}}} do { +while {(_loopLimit >= 0) && {(_randomPos isEqualTo []) || {!(_randomPos inArea _cityArea)}}} do { _randomPos = [_cityArea, _nearRoad, _allowOnRoad, _nearHouse, _emptyPosSearchRadius] call _fnc_randomPos; _randomPos = _randomPos findEmptyPosition [0, _emptyPosSearchRadius, _objectType]; _loopLimit = _loopLimit - 1; @@ -67,4 +66,4 @@ while {(_loopLimit >= 0) && {(_randomPos isEqualTo []) || {!(_randomPos inArea _ if (_loopLimit isEqualTo 0) exitWith {[]}; -_randomPos; +_randomPos diff --git a/addons/civilian/functions/fnc_initCity.sqf b/addons/civilian/functions/fnc_initCity.sqf index 926267bf..3a8046d0 100644 --- a/addons/civilian/functions/fnc_initCity.sqf +++ b/addons/civilian/functions/fnc_initCity.sqf @@ -21,12 +21,13 @@ if (_cityLocation isEqualType configNull) then { _cityLocation = [getArray (_cityLocation >> 'position'), 10] call EFUNC(common,getNearestCityLocation); }; -private _cityLocationConfig = (configFile >> "CfgWorlds" >> worldName >> "Names" >> className _cityLocation); +private _cityLocationClassName = className _cityLocation; +private _cityLocationConfig = (configFile >> "CfgWorlds" >> worldName >> "Names" >> _cityLocationClassName); // Create city namespace private _cityNamespace = true call CBA_fnc_createNamespace; -GVAR(citiesLocations) setVariable [className _cityLocation, _cityNamespace, true]; -_cityNamespace setVariable [QGVAR(Location), _cityLocation, true]; +GVAR(citiesLocations) setVariable [_cityLocationClassName, _cityNamespace, true]; +_cityNamespace setVariable [QGVAR(locationClassName), _cityLocationClassName, true]; _cityNamespace setVariable [QGVAR(Name), [_cityLocation] call FUNC(getCityName), true]; private _cityType = [_cityLocation] call EFUNC(common,getLocationType); _cityNamespace setVariable [QGVAR(cityType), _cityType, true]; diff --git a/addons/score/XEH_postInit.sqf b/addons/score/XEH_postInit.sqf index dacbcc61..73185a6c 100644 --- a/addons/score/XEH_postInit.sqf +++ b/addons/score/XEH_postInit.sqf @@ -34,16 +34,7 @@ if (isServer) then { // Idle timeout init if (GVAR(idleTimeMax) isEqualTo -1) exitWith {}; [{ - private _msg = composeText [ - text format [LLSTRING(IdleTime_Inital_Message), (GVAR(IdleTimeMax) / 60)], - lineBreak, - lineBreak, - text format ["%1: %2", LELSTRING(killers,Killers), GVAR(idleTimeKillersScoreChange)], - lineBreak, - text format ["%1: %2", LELSTRING(police,Police), GVAR(idleTimePoliceScoreChange)] - ]; - _msg setAttributes ["valign", "middle"]; - [QEGVAR(common,showMessage), [_msg, [3]]] call CBA_fnc_globalEvent; + [QGVAR(showTimeoutInitialMessage)] call CBA_fnc_globalEvent; call FUNC(monitorTimeouts); }, [], GVAR(idleTimeMax)] call CBA_fnc_waitAndExecute; @@ -68,6 +59,19 @@ if (hasInterface) then { _this call FUNC(showScore); }] call CBA_fnc_addEventHandler; + [QGVAR(showTimeoutInitialMessage), { + private _msg = composeText [ + text format [LLSTRING(IdleTime_Inital_Message), (GVAR(IdleTimeMax) / 60)], + lineBreak, + lineBreak, + text format ["%1: %2", LELSTRING(killers,Killers), GVAR(idleTimeKillersScoreChange)], + lineBreak, + text format ["%1: %2", LELSTRING(police,Police), GVAR(idleTimePoliceScoreChange)] + ]; + _msg setAttributes ["valign", "middle"]; + [QEGVAR(common,showMessage), [_msg, [3]]] call CBA_fnc_localEvent; + }] call CBA_fnc_addEventHandler; + // Disable vanilla ratings player addEventHandler ["HandleRating", { 0 }]; }; diff --git a/addons/score/functions/fnc_showScore.sqf b/addons/score/functions/fnc_showScore.sqf index 98f5e273..e211b1a1 100644 --- a/addons/score/functions/fnc_showScore.sqf +++ b/addons/score/functions/fnc_showScore.sqf @@ -61,4 +61,4 @@ private _msg = composeText [ ]; _msg setAttributes ["valign", "middle"]; -[QEGVAR(common,showMessage), [_msg, [5]]] call CBA_fnc_globalEvent; +[QEGVAR(common,showMessage), [_msg, [5]]] call CBA_fnc_localEvent;