From 84d801a45ac0382af70b2c667fac0415b1c78b71 Mon Sep 17 00:00:00 2001 From: jaynus Date: Fri, 3 Apr 2015 09:49:41 -0700 Subject: [PATCH] Added: ace_fcs_forceUpdate event for forcing the FCS to update from self-designate Merged: in-vehicle interact for laser designator Changed: Perf. tweaks on laser update times. --- addons/fcs/XEH_clientInit.sqf | 3 ++ addons/fcs/XEH_preInit.sqf | 1 + addons/fcs/functions/fnc_keyUp.sqf | 15 ++++++++-- addons/fcs/functions/fnc_onForceUpdate.sqf | 7 +++++ .../functions/fnc_laserHudDesignateOn.sqf | 28 +++++++++++++++++-- 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 addons/fcs/functions/fnc_onForceUpdate.sqf diff --git a/addons/fcs/XEH_clientInit.sqf b/addons/fcs/XEH_clientInit.sqf index 17faa70f17..49f04d44e7 100644 --- a/addons/fcs/XEH_clientInit.sqf +++ b/addons/fcs/XEH_clientInit.sqf @@ -5,3 +5,6 @@ GVAR(time) = 0; GVAR(position) = [0,0,0]; #include "initKeybinds.sqf" + +// Register event for global updates +[QGVAR(forceUpdate), FUNC(onForceUpdate)] call ace_common_fnc_addEventHandler \ No newline at end of file diff --git a/addons/fcs/XEH_preInit.sqf b/addons/fcs/XEH_preInit.sqf index 78a2fd091c..8fdc43df11 100644 --- a/addons/fcs/XEH_preInit.sqf +++ b/addons/fcs/XEH_preInit.sqf @@ -10,6 +10,7 @@ PREP(firedEH); PREP(getAngle); PREP(getRange); PREP(handleAirBurstAmmunitionPFH); +PREP(onForceUpdate); PREP(keyDown); PREP(keyUp); PREP(reset); diff --git a/addons/fcs/functions/fnc_keyUp.sqf b/addons/fcs/functions/fnc_keyUp.sqf index d33bd08893..f0b1f1b137 100644 --- a/addons/fcs/functions/fnc_keyUp.sqf +++ b/addons/fcs/functions/fnc_keyUp.sqf @@ -12,7 +12,7 @@ #include "script_component.hpp" -private ["_vehicle", "_turret", "_turretConfig", "_distance", "_magazines"]; +private ["_vehicle", "_turret", "_turretConfig", "_distance", "_magazines", "_userChange"]; _vehicle = _this select 0; _turret = _this select 1; @@ -46,7 +46,9 @@ if (_weaponDirection isEqualTo [0,0,0]) then { // dummy value for non main turr _angleTarget = asin (_weaponDirection select 2); if (count _this > 2) then { - _distance = _this select 2; + if((_this select 2) > -1) then { + _distance = _this select 2; + }; }; if (!(isNil QGVAR(backgroundCalculation)) and {!(scriptDone GVAR(backgroundCalculation))}) then { @@ -160,4 +162,11 @@ _FCSElevation = []; [_vehicle, format ["%1_%2", QGVAR(Elevation), _turret], _FCSElevation] call EFUNC(common,setVariablePublic); [_vehicle, format ["%1_%2", QGVAR(Azimuth), _turret], _FCSAzimuth] call EFUNC(common,setVariablePublic); -[format ["%1: %2", localize "STR_ACE_FCS_ZeroedTo", _distance]] call EFUNC(common,displayTextStructured); +_userChange = true; +if( (count _this) > 3) then { + _userChange = _this select 3; +}; + +if(_userChange) then { + [format ["%1: %2", localize "STR_ACE_FCS_ZeroedTo", _distance]] call EFUNC(common,displayTextStructured); +}; \ No newline at end of file diff --git a/addons/fcs/functions/fnc_onForceUpdate.sqf b/addons/fcs/functions/fnc_onForceUpdate.sqf new file mode 100644 index 0000000000..c911fc38de --- /dev/null +++ b/addons/fcs/functions/fnc_onForceUpdate.sqf @@ -0,0 +1,7 @@ +#include "script_component.hpp" + +if !([ACE_player, vehicle ACE_player, []] call EFUNC(common,canInteractWith)) exitWith {false}; +if !((!GVAR(enabled) && FUNC(canUseFCS)) || FUNC(canUseRangefinder)) exitWith {false}; + +[vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex), -1, false] call FUNC(keyDown); +[vehicle ACE_player, [ACE_player] call EFUNC(common,getTurretIndex), -1, false] call FUNC(keyUp); \ No newline at end of file diff --git a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf index a2f3c5f871..417744fd46 100644 --- a/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf +++ b/addons/laser_selfdesignate/functions/fnc_laserHudDesignateOn.sqf @@ -3,6 +3,8 @@ TRACE_1("enter", _this); +#define FCS_UPDATE_DELAY 2.0 + FUNC(magnitude) = { _this distance [0, 0, 0] }; @@ -17,11 +19,16 @@ FUNC(mat_normalize3d) = { }; FUNC(laserHudDesignatePFH) = { - private["_args", "_laserTarget", "_shooter", "_vehicle", "_weapon", "_gunnerInfo", "_turret", "_pov", "_gunBeg", "_gunEnd", "_povPos", "_povDir", "_result", "_resultPositions", "_firstResult"]; + private["_args", "_laserTarget", "_shooter", "_vehicle", "_weapon", "_gunnerInfo", "_turret", "_pov", "_gunBeg", "_gunEnd", "_povPos", "_povDir", "_result", "_resultPositions", "_firstResult", "_forceUpdateTime"]; _args = _this select 0; _laserTarget = _args select 0; _shooter = _args select 1; + if( (count _args) < 3) then { + _args set[2, diag_tickTime + FCS_UPDATE_DELAY]; + }; + _forceUpdateTime = _args select 2; + _vehicle = vehicle _shooter; _weapon = currentWeapon _vehicle; @@ -50,14 +57,29 @@ FUNC(laserHudDesignatePFH) = { // Just regular use of lasers will commonly make them move this much, // but not across multiple close frames. // This loses accuracy a little, but saves position updates per frame. - //if( ((getPosASL _laserTarget) distance _pos) > 0.5) then { + TRACE_5("", diag_tickTime, _forceUpdateTime, getPosASL _laserTarget, _pos, ((getPosASL _laserTarget) distance _pos)); + + if(diag_tickTime > _forceUpdateTime) then { + TRACE_1("FCS Update", ""); + ["ace_fcs_forceUpdate", []] call ace_common_fnc_localEvent; + }; + + if( diag_tickTime > _forceUpdateTime || ((getPosASL _laserTarget) distance _pos) > 0.5) then { + TRACE_1("LaserPos Update", ""); _laserTarget setPosATL (ASLToATL _pos); - //}; + + }; + + if(diag_tickTime > _forceUpdateTime) then { + _args set[3, diag_tickTime + FCS_UPDATE_DELAY]; + }; #ifdef DEBUG_MODE_FULL drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], ASLToATL _pos, 0.75, 0.75, 0, "", 0.5, 0.025, "TahomaB"]; #endif }; }; + + _this set[0, _args]; }; private "_laserTarget";