Skip to content

Commit

Permalink
Fix "Performance warning: SimpleSerialization" (#83)
Browse files Browse the repository at this point in the history
* Fix showScore invoking global showMessage event

* Drop location type variable

* Prevent serialization warning on initial timeout message
  • Loading branch information
3Mydlo3 authored Mar 21, 2024
1 parent 3135a81 commit 4f03d1a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
10 changes: 6 additions & 4 deletions addons/civilian/functions/fnc_getCityName.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions addons/civilian/functions/fnc_getCityRandomPos.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ 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;
};

if (_loopLimit isEqualTo 0) exitWith {[]};

_randomPos;
_randomPos
7 changes: 4 additions & 3 deletions addons/civilian/functions/fnc_initCity.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
24 changes: 14 additions & 10 deletions addons/score/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 }];
};
2 changes: 1 addition & 1 deletion addons/score/functions/fnc_showScore.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 4f03d1a

Please sign in to comment.