diff --git a/framework/CfgFunctions.hpp b/framework/CfgFunctions.hpp index 744bea3..e6b146d 100644 --- a/framework/CfgFunctions.hpp +++ b/framework/CfgFunctions.hpp @@ -120,6 +120,7 @@ class DOUBLES(PREFIX,performance) { class addServerStatsPFH {}; class calculateServerStats {}; class addEmptyGroupCleanupPFH {}; + class addDeadUnitCleanupPFH {}; }; }; diff --git a/framework/init/functions/fn_initServer.sqf b/framework/init/functions/fn_initServer.sqf index 9523875..80478d1 100644 --- a/framework/init/functions/fn_initServer.sqf +++ b/framework/init/functions/fn_initServer.sqf @@ -21,6 +21,23 @@ _curators = allMissionObjects "ModuleCurator_F"; _x removeCuratorAddons ["A3_Modules_F_Curator_Lightning"]; } foreach _curators; +// add dead unit time marking for custom garbage cleanup function +addMissionEventHandler ["EntityKilled", { + params ["_unit", "_killer", "_instigator", "_useEffects"]; + + if not (_unit isKindOf "CAManBase") exitWith {}; + + if not (isInRemainsCollector _unit) exitWith {}; + + // format["%1 from group %2 died at %3", _unit, group _unit, [datetime] call BIS_fnc_timeToString] remoteExec ["systemChat"]; + _unit setVariable["milsim_death_time", time]; + // _unit addEventHandler ["Deleted", { + // params ["_entity"]; + // isGC = _entity getVariable["milsim_garbage_collected", false]; + // format["%1 from was deleted by custom gc: %2", _entity, str isGC ] remoteExec ["systemChat"]; + // }]; +}]; + // declare init complete to other modules missionNamespace setVariable [QGVARMAIN(complete), true, true]; diff --git a/framework/performance/functions/fn_addCBASettings.sqf b/framework/performance/functions/fn_addCBASettings.sqf index 947c1cb..cbe5fc7 100644 --- a/framework/performance/functions/fn_addCBASettings.sqf +++ b/framework/performance/functions/fn_addCBASettings.sqf @@ -1,5 +1,9 @@ #include "..\script_component.hpp" +//--------------------- +// Garbage Collection +//--------------------- + [ QGVAR(emptyGroupCleanup_enable), "CHECKBOX", @@ -22,6 +26,28 @@ } ] call CBA_fnc_addSetting; +[ + QGVAR(deadUnitCleanup_enable), + "CHECKBOX", + "Dead Unit Cleanup Enabled", + [QUOTE(SETTINGS_GROUP_NAME), QUOTE(COMPONENT_BEAUTIFIED)], + true, + true, + { + params ["_value"]; + [ + QGVAR(deadUnitCleanup_enable), + _value + ] call EFUNC(common,logSettingChanged); + + if (!isNull (missionNamespace getVariable [QGVAR(deadUnitCleanupPFH), locationNull])) then { + deleteLocation GVAR(deadUnitCleanupPFH); + }; + + call FUNC(addDeadUnitCleanupPFH); + } +] call CBA_fnc_addSetting; + //--------------------- // Server CPS //--------------------- diff --git a/framework/performance/functions/fn_addDeadUnitCleanupPFH.sqf b/framework/performance/functions/fn_addDeadUnitCleanupPFH.sqf new file mode 100644 index 0000000..c71be7a --- /dev/null +++ b/framework/performance/functions/fn_addDeadUnitCleanupPFH.sqf @@ -0,0 +1,55 @@ +#include "..\script_component.hpp" + +[ + LEVEL_INFO, + QUOTE(COMPONENT), + "Initializing dead unit deletion PFH", + [] +] call EFUNC(common,log); + +GVAR(deadUnitCleanupPFH) = [ + { + _maxTime = getMissionConfigValue ["corpseRemovalMaxTime", 300] * 1.5; + _maxDead = getMissionConfigValue ["corpseLimit", 80]; + + // _dead = allDead select { (_x isKindOf "CAManBase") and ( ( (time - (_x getVariable ["milsim_death_time", time] ) ) > (_maxTime * 1.5) ) ) }; + // _dead = _dead apply { [ (time - (_x getVariable ["milsim_death_time", time] ) ), _x ] }; + + _dead = []; + { + if not (_x isKindOf "CAManBase") then { continue }; + if not (isInRemainsCollector _x) then { continue }; + _dead pushBack [time - (_x getVariable ["milsim_death_time", time] ), _x]; + } forEach allDead; + + _dead sort false; + _toDelete = 0 max ( (count _dead ) - _maxDead ); + _dead = _dead select [0, _toDelete]; + { + _unit = _x#1; + // _unit setVariable ["milsim_garbage_collected", true]; + deleteVehicle (_unit); + } foreach _dead; + }, + 180, + [], + { // on creation + [ + LEVEL_INFO, + QUOTE(COMPONENT), + "dead unit deletion PFH loaded", + [] + ] call EFUNC(common,log); + }, + { // on deletion + [ + LEVEL_INFO, + QUOTE(COMPONENT), + "dead unit deletion PFH unloaded", + [] + ] call EFUNC(common,log); + }, + { (missionNamespace getVariable [QGVAR(deadUnitCleanup_enable), false]) }, + { false }, + [] +] call CBA_fnc_createPerFrameHandlerObject;