From f928f37e264bdbb7b476e1c4a5d9f8d958a0d7b3 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 20 Apr 2015 01:16:51 -0300 Subject: [PATCH] Eliminate interact_menu fps drops due to high nearby object counts. Instead of reanalizing every frame which actions points should be rendered based on distance, that job is now done only 5 times per second. The rest of the frames the action points from the last frame are rerendered.. Close #434 --- addons/interact_menu/XEH_preInit.sqf | 3 +++ .../interact_menu/functions/fnc_keyDown.sqf | 1 + .../functions/fnc_renderActionPoints.sqf | 19 +++++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/interact_menu/XEH_preInit.sqf b/addons/interact_menu/XEH_preInit.sqf index b4a3504cdd..747da7083e 100644 --- a/addons/interact_menu/XEH_preInit.sqf +++ b/addons/interact_menu/XEH_preInit.sqf @@ -49,4 +49,7 @@ GVAR(expandedTime) = diag_tickTime; GVAR(iconCtrls) = []; GVAR(iconCount) = 0; +GVAR(foundActions) = []; +GVAR(lastTimeSearchedActions) = -1000; + ADDON = true; diff --git a/addons/interact_menu/functions/fnc_keyDown.sqf b/addons/interact_menu/functions/fnc_keyDown.sqf index 47fdfb1951..123c1d45e2 100644 --- a/addons/interact_menu/functions/fnc_keyDown.sqf +++ b/addons/interact_menu/functions/fnc_keyDown.sqf @@ -29,6 +29,7 @@ if (_menuType == 0) then { }; GVAR(keyDownTime) = diag_tickTime; GVAR(openedMenuType) = _menuType; +GVAR(lastTimeSearchedActions) = -1000; GVAR(useCursorMenu) = (vehicle ACE_player != ACE_player) || visibleMap || diff --git a/addons/interact_menu/functions/fnc_renderActionPoints.sqf b/addons/interact_menu/functions/fnc_renderActionPoints.sqf index 6ed4b41de4..78d5418e5a 100644 --- a/addons/interact_menu/functions/fnc_renderActionPoints.sqf +++ b/addons/interact_menu/functions/fnc_renderActionPoints.sqf @@ -24,6 +24,9 @@ _fnc_renderNearbyActions = { _cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL); _cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos; + GVAR(foundActions) = []; + GVAR(lastTimeSearchedActions) = diag_tickTime; + _numInteractObjects = 0; _nearestObjects = nearestObjects [ACE_player, ["All"], 13]; { @@ -46,6 +49,7 @@ _fnc_renderNearbyActions = { _action = _x; if ([_target, _action] call FUNC(renderBaseMenu)) then { _numInteractions = _numInteractions + 1; + GVAR(foundActions) pushBack [_target, _action]; }; }; } forEach GVAR(objectActionList); @@ -57,6 +61,7 @@ _fnc_renderNearbyActions = { // Try to render the menu if ([_target, _action] call FUNC(renderBaseMenu)) then { _numInteractions = _numInteractions + 1; + GVAR(foundActions) pushBack [_target, _action]; }; } forEach _classActions; @@ -71,7 +76,11 @@ _fnc_renderNearbyActions = { } forEach _nearestObjects; }; - +_fnc_renderLastFrameActions = { + { + _x call FUNC(renderBaseMenu); + } forEach GVAR(foundActions); +}; _fnc_renderSelfActions = { _target = _this; @@ -109,7 +118,13 @@ _fnc_renderSelfActions = { if (GVAR(openedMenuType) == 0) then { if (vehicle ACE_player == ACE_player) then { - call _fnc_renderNearbyActions; + if (diag_tickTime > GVAR(lastTimeSearchedActions) + 0.20) then { + // Once every 0.2 secs, collect nearby objects active and visible action points and render them + call _fnc_renderNearbyActions; + } else { + // The rest of the frames just draw the same action points rendered the last frame + call _fnc_renderLastFrameActions; + }; } else { (vehicle ACE_player) call _fnc_renderSelfActions; };