From 2265a96571798e28a0366970d1c6a61cd299e587 Mon Sep 17 00:00:00 2001 From: mharis001 Date: Tue, 12 Nov 2024 02:11:23 -0500 Subject: [PATCH 1/2] Editor - Prevent forced empty objects from being decluttered --- addons/editor/XEH_preStart.sqf | 30 ++++++++++++++ .../functions/fnc_declutterEmptyTree.sqf | 39 +++++++++++++------ 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/addons/editor/XEH_preStart.sqf b/addons/editor/XEH_preStart.sqf index 022888575..c4373a963 100644 --- a/addons/editor/XEH_preStart.sqf +++ b/addons/editor/XEH_preStart.sqf @@ -1,3 +1,33 @@ #include "script_component.hpp" #include "XEH_PREP.hpp" + +// Get faction names for west, east, independent, and civilian sides +private _factionNames = configProperties [configFile >> "CfgFactionClasses", "isClass _x"] select { + getNumber (_x >> "side") in [0, 1, 2, 3] +} apply { + getText (_x >> "displayName") +}; + +// Find objects that are forced empty. This relatively small number of objects are included only in +// the empty tree and, if we delete the entire faction node, then there is no way to place them. +private _forcedEmptyFactions = []; +private _forcedEmptyObjects = createHashMap; +private _cfgFactionClasses = configFile >> "CfgFactionClasses"; + +{ + if ( + getNumber (_x >> "scope") != 2 + || {getNumber (_x >> "editorForceEmpty") != 1} + ) then {continue}; + + private _faction = getText (_cfgFactionClasses >> getText (_x >> "faction") >> "displayName"); + _forcedEmptyFactions pushBack _faction; + _forcedEmptyObjects set [configName _x, nil]; +} forEach configProperties [configFile >> "CfgVehicles", "isClass _x"]; + +private _fastDeclutterFactions = (_factionNames - _forcedEmptyFactions) createHashMapFromArray []; +private _slowDeclutterFactions = _forcedEmptyFactions createHashMapFromArray []; +uiNamespace setVariable [QGVAR(fastDeclutterFactions), compileFinal _fastDeclutterFactions]; +uiNamespace setVariable [QGVAR(slowDeclutterFactions), compileFinal _slowDeclutterFactions]; +uiNamespace setVariable [QGVAR(forcedEmptyObjects), compileFinal _forcedEmptyObjects] diff --git a/addons/editor/functions/fnc_declutterEmptyTree.sqf b/addons/editor/functions/fnc_declutterEmptyTree.sqf index 1fdd6f1c4..87035f40f 100644 --- a/addons/editor/functions/fnc_declutterEmptyTree.sqf +++ b/addons/editor/functions/fnc_declutterEmptyTree.sqf @@ -19,23 +19,38 @@ if (!GVAR(declutterEmptyTree)) exitWith {}; params ["_display"]; -// Get faction names for west, east, independent, and civilian sides -if (isNil QGVAR(factionNames)) then { - GVAR(factionNames) = configProperties [configFile >> "CfgFactionClasses", "isClass _x"] select { - getNumber (_x >> "side") in [0, 1, 2, 3] - } apply { - getText (_x >> "displayName") - }; -}; - -private _factionNames = GVAR(factionNames); - // Remove factions from empty tree // Backwards since tree item paths will change as items are deleted private _ctrlTree = _display displayCtrl IDC_RSCDISPLAYCURATOR_CREATE_UNITS_EMPTY; +private _fastDeclutterFactions = uiNamespace getVariable [QGVAR(fastDeclutterFactions), createHashMap]; +private _slowDeclutterFactions = uiNamespace getVariable [QGVAR(slowDeclutterFactions), createHashMap]; +private _forcedEmptyObjects = uiNamespace getVariable [QGVAR(forcedEmptyObjects), createHashMap]; for "_i" from (_ctrlTree tvCount []) - 1 to 0 step -1 do { - if (_ctrlTree tvText [_i] in _factionNames) then { + private _faction = _ctrlTree tvText [_i]; + + // Delete entire node for factions that do not contain any forced empty objects (fast case) + if (_faction in _fastDeclutterFactions) then { _ctrlTree tvDelete [_i]; + continue; + }; + + // For factions that contain forced empty objects, need to check every leaf node individually (slow case) + if (_faction in _slowDeclutterFactions) then { + for "_j" from (_ctrlTree tvCount [_i]) - 1 to 0 step -1 do { + for "_k" from (_ctrlTree tvCount [_i, _j]) - 1 to 0 step -1 do { + private _data = _ctrlTree tvData [_i, _j, _k]; + if (_data in _forcedEmptyObjects) then {continue}; + _ctrlTree tvDelete [_i, _j, _k]; + }; + + if (_ctrlTree tvCount [_i, _j] == 0) then { + _ctrlTree tvDelete [_i, _j]; + }; + }; + + if (_ctrlTree tvCount [_i] == 0) then { + _ctrlTree tvDelete [_i]; + }; }; }; From 5e6348eac38007addd0141ecab3401b3bb74adfe Mon Sep 17 00:00:00 2001 From: mharis001 Date: Wed, 13 Nov 2024 08:30:45 -0500 Subject: [PATCH 2/2] Micro optimization --- addons/editor/XEH_preStart.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/editor/XEH_preStart.sqf b/addons/editor/XEH_preStart.sqf index c4373a963..2350b3182 100644 --- a/addons/editor/XEH_preStart.sqf +++ b/addons/editor/XEH_preStart.sqf @@ -3,7 +3,8 @@ #include "XEH_PREP.hpp" // Get faction names for west, east, independent, and civilian sides -private _factionNames = configProperties [configFile >> "CfgFactionClasses", "isClass _x"] select { +private _cfgFactionClasses = configFile >> "CfgFactionClasses"; +private _factionNames = configProperties [_cfgFactionClasses, "isClass _x"] select { getNumber (_x >> "side") in [0, 1, 2, 3] } apply { getText (_x >> "displayName") @@ -13,7 +14,6 @@ private _factionNames = configProperties [configFile >> "CfgFactionClasses", "is // the empty tree and, if we delete the entire faction node, then there is no way to place them. private _forcedEmptyFactions = []; private _forcedEmptyObjects = createHashMap; -private _cfgFactionClasses = configFile >> "CfgFactionClasses"; { if (