From eadcd8236649bfc4e73fdde5535a5ac102144ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Badano?= Date: Mon, 9 Feb 2015 23:00:40 -0300 Subject: [PATCH] scopes: fixed errors, throttled sync of scope adjustment to all client and local calculation of deflections. --- addons/scopes/CfgEventHandlers.hpp | 2 +- addons/scopes/RscTitles.hpp | 2 +- addons/scopes/XEH_postInit.sqf | 2 ++ addons/scopes/XEH_preInit.sqf | 1 + addons/scopes/functions/fnc_adjustScope.sqf | 22 +++++++--------- .../scopes/functions/fnc_canAdjustScope.sqf | 7 ++--- addons/scopes/functions/fnc_firedEH.sqf | 14 ++++++---- .../scopes/functions/fnc_inventoryCheck.sqf | 9 ++++--- addons/scopes/functions/fnc_showZeroing.sqf | 26 +++++++++++++++++++ addons/scopes/scripts/script_component.hpp | 1 - addons/scopes/scripts/zeroingOnLoad.sqf | 20 -------------- 11 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 addons/scopes/functions/fnc_showZeroing.sqf delete mode 100644 addons/scopes/scripts/script_component.hpp delete mode 100644 addons/scopes/scripts/zeroingOnLoad.sqf diff --git a/addons/scopes/CfgEventHandlers.hpp b/addons/scopes/CfgEventHandlers.hpp index 204f2e267e..286a08598d 100644 --- a/addons/scopes/CfgEventHandlers.hpp +++ b/addons/scopes/CfgEventHandlers.hpp @@ -13,7 +13,7 @@ class Extended_PostInit_EventHandlers { class Extended_Fired_EventHandlers { class CAManBase { class ADDON { - clientFired = QUOTE(if (_this select 0 == ACE_player) then { _this call FUNC(firedEH);};); + fired = QUOTE(_this call FUNC(firedEH);); }; }; }; diff --git a/addons/scopes/RscTitles.hpp b/addons/scopes/RscTitles.hpp index 79de7e8214..9da0a04a14 100644 --- a/addons/scopes/RscTitles.hpp +++ b/addons/scopes/RscTitles.hpp @@ -4,7 +4,7 @@ class RscTitles { movingEnable = 0; enableSimulation = 1; enableDisplay = 1; - onLoad = QUOTE(_this spawn compile preprocessFileLineNumbers QUOTE(QUOTE(PATHTOF(scripts\zeroingOnLoad.sqf))); uiNamespace setVariable [ARR_2('ACE_Scopes_Debug', _this)];); + onLoad = QUOTE(uiNamespace setVariable [ARR_2(QUOTE(QGVAR(ZeroingDisplay)),_this select 0)];); duration = 1e+011; fadein = 0; fadeout = 0; diff --git a/addons/scopes/XEH_postInit.sqf b/addons/scopes/XEH_postInit.sqf index b7fd4bfc3a..30cc7d9384 100644 --- a/addons/scopes/XEH_postInit.sqf +++ b/addons/scopes/XEH_postInit.sqf @@ -15,6 +15,8 @@ if !(hasInterface) exitWith {}; while {True} do { waitUntil {[ACE_player, 0,0] call FUNC(canAdjustScope)}; _layer cutRsc [QGVAR(Zeroing), "PLAIN", 0, false]; + call FUNC(showZeroing); + sleep 3; _layer cutFadeOut 2; diff --git a/addons/scopes/XEH_preInit.sqf b/addons/scopes/XEH_preInit.sqf index 9dc7450c94..b0c4a50c1c 100644 --- a/addons/scopes/XEH_preInit.sqf +++ b/addons/scopes/XEH_preInit.sqf @@ -8,6 +8,7 @@ PREP(firedEH); PREP(getOptics); PREP(hideZeroing); PREP(inventoryCheck); +PREP(showZeroing); GVAR(fadeScript) = scriptNull; diff --git a/addons/scopes/functions/fnc_adjustScope.sqf b/addons/scopes/functions/fnc_adjustScope.sqf index 7db640590a..b50da5322b 100644 --- a/addons/scopes/functions/fnc_adjustScope.sqf +++ b/addons/scopes/functions/fnc_adjustScope.sqf @@ -12,7 +12,7 @@ */ #include "script_component.hpp" - + private ["_unit", "_weapons", "_zeroing", "_pitchbankyaw", "_pitch", "_bank", "_yaw", "_hint"]; _unit = _this select 0; @@ -23,15 +23,18 @@ _weapons = [ handgunWeapon _unit ]; -if (isNil QGVAR(Adjustment)) then { - GVAR(Adjustment) = [[0,0], [0,0], [0,0]]; +_adjustment = _unit getVariable QGVAR(Adjustment); +if (isNil "_adjustment") then { + _adjustment = [[0,0], [0,0], [0,0]]; }; -_zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon _unit)); +_zeroing = _adjustment select (_weapons find (currentWeapon _unit)); _zeroing set [0, (round (((_zeroing select 0) + (_this select 1)) * 10)) / 10]; _zeroing set [1, (round (((_zeroing select 1) + (_this select 2)) * 10)) / 10]; -GVAR(Adjustment) set [_weapons find (currentWeapon _unit), _zeroing]; +_adjustment set [_weapons find (currentWeapon _unit), _zeroing]; +_unit setVariable [QGVAR(Adjustment), _adjustment]; +[_unit, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable); playSound (["ACE_Scopes_Click_1", "ACE_Scopes_Click_2", "ACE_Scopes_Click_3"] select floor random 3); @@ -46,14 +49,6 @@ if (cameraView == "GUNNER") then { [_unit, _pitch, _bank, _yaw] call EFUNC(common,setPitchBankYaw) }; -_display = uiNamespace getVariable [QGVAR(ZeroingDisplay), displayNull]; -if !(isNull _display) then { - _vertical = _display displayCtrl 925002; - _horizontal = _display displayCtrl 925003; - _vertical ctrlSetText (str (_zeroing select 1)); - _horizontal ctrlSetText (str (_zeroing select 0)); -}; - if (!isNull (missionNamespace getVariable [QGVAR(fadeScript), scriptNull])) then { terminate GVAR(fadeScript); }; @@ -61,6 +56,7 @@ if (cameraView != "GUNNER") then { GVAR(fadeScript) = 0 spawn { _layer = [QGVAR(Zeroing)] call BIS_fnc_rscLayer; _layer cutRsc [QGVAR(Zeroing), "PLAIN", 0, false]; + call FUNC(showZeroing); sleep 3; _layer cutFadeOut 2; }; diff --git a/addons/scopes/functions/fnc_canAdjustScope.sqf b/addons/scopes/functions/fnc_canAdjustScope.sqf index 8aea2ff9e4..3bf4a74e21 100644 --- a/addons/scopes/functions/fnc_canAdjustScope.sqf +++ b/addons/scopes/functions/fnc_canAdjustScope.sqf @@ -25,15 +25,16 @@ _weapons = [ if !(currentWeapon _unit in _weapons) exitWith {false}; -if (isNil QGVAR(Adjustment)) then { - GVAR(Adjustment) = [[0,0], [0,0], [0,0]]; +_adjustment = _unit getVariable QGVAR(Adjustment); +if (isNil "_adjustment") then { + _adjustment = [[0,0], [0,0], [0,0]]; }; if (isNil QGVAR(Optics)) then { GVAR(Optics) = ["", "", ""]; }; -_zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon _unit)); +_zeroing = _adjustment select (_weapons find (currentWeapon _unit)); _zeroX = (_zeroing select 0) + (_this select 1); _zeroY = (_zeroing select 1) + (_this select 2); diff --git a/addons/scopes/functions/fnc_firedEH.sqf b/addons/scopes/functions/fnc_firedEH.sqf index 4414f617d6..097a81fca6 100644 --- a/addons/scopes/functions/fnc_firedEH.sqf +++ b/addons/scopes/functions/fnc_firedEH.sqf @@ -1,5 +1,5 @@ /* - * Author: KoffeinFlummi + * Author: KoffeinFlummi and CAA-Picard * * Adjusts the flight path of the bullet according to the zeroing * @@ -12,13 +12,17 @@ #include "script_component.hpp" -private ["_unit", "_weaponType", "_ammoType", "_magazineType", "_round", "_weapons", "_zeroing", "_direction", "_azimuth", "_altitude", "_velocity"]; +private ["_unit", "_weaponType", "_round", "_weapons", "_zeroing", "_adjustment"]; _unit = _this select 0; + +_adjustment = _unit getVariable QGVAR(Adjustment); +if (isNil "_adjustment") exitWith {}; + +if !([_unit] call EFUNC(common,isPlayer)) exitWith {}; + _weaponType = _this select 1; -_ammoType = _this select 4; _round = _this select 5; -_magazineType = _this select 6; _weapons = [ primaryWeapon _unit, @@ -27,7 +31,7 @@ _weapons = [ ]; if !(_weaponType in _weapons) exitWith {}; -_zeroing = GVAR(Adjustment) select (_weapons find _weaponType); +_zeroing = _adjustment select (_weapons find _weaponType); // convert zeroing from mils to degrees _zeroing = [_zeroing, {_this * 0.05625}] call EFUNC(common,map); diff --git a/addons/scopes/functions/fnc_inventoryCheck.sqf b/addons/scopes/functions/fnc_inventoryCheck.sqf index 23971098d6..1e1efa2c14 100644 --- a/addons/scopes/functions/fnc_inventoryCheck.sqf +++ b/addons/scopes/functions/fnc_inventoryCheck.sqf @@ -10,13 +10,16 @@ if (isNil QGVAR(Optics)) then { GVAR(Optics) = ["", "", ""]; }; -if (isNil QGVAR(Adjustment)) then { - GVAR(Adjustment) = [[0,0], [0,0], [0,0]]; +_adjustment = ACE_player getVariable QGVAR(Adjustment); +if (isNil "_adjustment") then { + ACE_player setVariable [QGVAR(Adjustment), [[0,0], [0,0], [0,0]]]; + [ACE_player, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable); }; { if (_new select _forEachIndex != _x) then { - GVAR(Adjustment) set [_forEachIndex, [0,0]]; + _adjustment set [_forEachIndex, [0,0]]; + [ACE_player, QGVAR(Adjustment), 0.5] call EFUNC(common,throttledPublicVariable); }; } forEach GVAR(Optics); diff --git a/addons/scopes/functions/fnc_showZeroing.sqf b/addons/scopes/functions/fnc_showZeroing.sqf new file mode 100644 index 0000000000..76d4927ae9 --- /dev/null +++ b/addons/scopes/functions/fnc_showZeroing.sqf @@ -0,0 +1,26 @@ + +#include "script_component.hpp" + +disableSerialization; + +_display = uiNamespace getVariable [QGVAR(ZeroingDisplay), displayNull]; +if (isNull _display) exitWith {}; + +_weapons = [ + primaryWeapon ACE_player, + secondaryWeapon ACE_player, + handgunWeapon ACE_player +]; + +if !((currentWeapon ACE_player) in _weapons) exitWith {}; + +_adjustment = ACE_player getVariable QGVAR(Adjustment); +if (isNil "_adjustment") then { + _adjustment = [[0,0], [0,0], [0,0]]; +}; + +_zeroing = _adjustment select (_weapons find (currentWeapon ACE_player)); +_vertical = _display displayCtrl 925002; +_horizontal = _display displayCtrl 925003; +_vertical ctrlSetText (str (_zeroing select 1)); +_horizontal ctrlSetText (str (_zeroing select 0)); diff --git a/addons/scopes/scripts/script_component.hpp b/addons/scopes/scripts/script_component.hpp deleted file mode 100644 index acca51b4b5..0000000000 --- a/addons/scopes/scripts/script_component.hpp +++ /dev/null @@ -1 +0,0 @@ -#include "\z\ace\addons\scopes\script_component.hpp" diff --git a/addons/scopes/scripts/zeroingOnLoad.sqf b/addons/scopes/scripts/zeroingOnLoad.sqf deleted file mode 100644 index 591b5fc07b..0000000000 --- a/addons/scopes/scripts/zeroingOnLoad.sqf +++ /dev/null @@ -1,20 +0,0 @@ -#include "script_component.hpp" - -disableSerialization; - -_display = _this select 0; -uiNamespace setVariable [QGVAR(ZeroingDisplay, _display]; -_vertical = _display displayCtrl 925002; -_horizontal = _display displayCtrl 925003; - -_weapons = [ - primaryWeapon player, - secondaryWeapon player, - handgunWeapon player -]; - -if ((currentWeapon ACE_player) in _weapons) then { - _zeroing = GVAR(Adjustment) select (_weapons find (currentWeapon ACE_player)); - _horizontal ctrlSetText (str (_zeroing select 0)); - _vertical ctrlSetText (str (_zeroing select 1)); -};