diff --git a/addons/viewdistance/ACE_Settings.hpp b/addons/viewdistance/ACE_Settings.hpp index 28ed7471ca..524f580c78 100644 --- a/addons/viewdistance/ACE_Settings.hpp +++ b/addons/viewdistance/ACE_Settings.hpp @@ -39,7 +39,7 @@ class ACE_Settings { typeName = "SCALAR"; isClientSettable = 1; value = 0; // index. Actual coefficient is given by functions/fnc_returnObjectCoeff.sqf - values[] = {CSTRING(object_off),CSTRING(object_verylow),CSTRING(object_low),CSTRING(object_medium),CSTRING(object_high),CSTRING(object_veryhigh)}; + values[] = {CSTRING(object_off),CSTRING(object_verylow),CSTRING(object_low),CSTRING(object_medium),CSTRING(object_high),CSTRING(object_veryhigh),CSTRING(object_fovBased)}; displayName = CSTRING(object_DisplayName); description = CSTRING(object_Description); }; diff --git a/addons/viewdistance/XEH_preInit.sqf b/addons/viewdistance/XEH_preInit.sqf index ab41b37ef7..8237a97cb9 100644 --- a/addons/viewdistance/XEH_preInit.sqf +++ b/addons/viewdistance/XEH_preInit.sqf @@ -2,10 +2,11 @@ ADDON = false; -PREP(initModule); -PREP(returnValue); -PREP(returnObjectCoeff); -PREP(changeViewDistance); PREP(adaptViewDistance); +PREP(changeViewDistance); +PREP(initModule); +PREP(returnObjectCoeff); +PREP(returnValue); +PREP(setFovBasedOvdPFH); ADDON = true; diff --git a/addons/viewdistance/config.cpp b/addons/viewdistance/config.cpp index a1afbcc93f..2de8b2c954 100644 --- a/addons/viewdistance/config.cpp +++ b/addons/viewdistance/config.cpp @@ -6,7 +6,7 @@ class CfgPatches { weapons[] = {}; requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"ace_common"}; - author[] = {"Winter"}; + author[] = {"Winter", "Jonpas", "Arkhir"}; authorUrl = "https://github.com/Winter259"; VERSION_CONFIG; }; @@ -14,4 +14,4 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "ACE_Settings.hpp" -#include "CfgVehicles.hpp" \ No newline at end of file +#include "CfgVehicles.hpp" diff --git a/addons/viewdistance/functions/fnc_changeViewDistance.sqf b/addons/viewdistance/functions/fnc_changeViewDistance.sqf index 604a086ec3..dabef97297 100644 --- a/addons/viewdistance/functions/fnc_changeViewDistance.sqf +++ b/addons/viewdistance/functions/fnc_changeViewDistance.sqf @@ -14,10 +14,9 @@ * * Public: No */ - #include "script_component.hpp" -private ["_text","_new_view_distance","_view_distance_limit","_object_view_distance_coeff"]; +private ["_text", "_new_view_distance", "_view_distance_limit", "_object_view_distance_coeff"]; params ["_index_requested", "_show_prompt"]; @@ -27,19 +26,34 @@ _view_distance_limit = GVAR(limitViewDistance); // Grab the limit setViewDistance (_new_view_distance min _view_distance_limit); -if (_object_view_distance_coeff > 0) then { - setObjectViewDistance (_object_view_distance_coeff * viewDistance); +if (typeName _object_view_distance_coeff == "SCALAR") then { + if (_object_view_distance_coeff > 0) then { + setObjectViewDistance (_object_view_distance_coeff * viewDistance); + } else { + // Restore correct view distance when changing from FoV Based to Off + // Restoring directly inside PFH's self-exit resulted in the need of selecting another option to take effect + setObjectViewDistance GVAR(fovBasedPFHminimalViewDistance); + }; +} else { + if (isNil QGVAR(fovBasedPFHminimalViewDistance)) then { + GVAR(fovBasedPFHminimalViewDistance) = getObjectViewDistance select 0; // Minimal view distance holder and PFH isRunning variable + [FUNC(setFovBasedOvdPFH), 0, []] call CBA_fnc_addPerFrameHandler; + }; }; if (_show_prompt) then { - _text = if (_new_view_distance <= _view_distance_limit) then { - format ["%1 %2m", (localize "STR_ACE_ViewDistance_infotext"), str(viewDistance)]; - } else { - format ["%1 %2m", (localize "STR_ACE_ViewDistance_invalid"), str(viewDistance)]; - }; - if (GVAR(objectViewDistanceCoeff) > 0) then { - _text = _text + format ["
%1 %2%3", (localize "STR_ACE_ViewDistance_objectinfotext"), str(_object_view_distance_coeff * 100),"%"]; + // FoV Based or % + if (GVAR(objectViewDistanceCoeff) == 6) then { + _text = format ["%1 %2
Min. %3
Max. %4
", localize LSTRING(objectinfotext), localize LSTRING(object_fovBased), GVAR(fovBasedPFHminimalViewDistance), viewDistance]; + } else { + _text = if (_new_view_distance <= _view_distance_limit) then { + format ["%1 %2m", localize LSTRING(infotext), viewDistance]; + } else { + format ["%1 %2m", localize LSTRING(invalid), viewDistance]; + }; + _text = _text + format ["
%1 %2%3", localize LSTRING(objectinfotext), _object_view_distance_coeff * 100, "%"]; + }; + [parseText _text, 2] call EFUNC(common,displayTextStructured); }; - [parseText _text,2] call EFUNC(common,displayTextStructured); }; diff --git a/addons/viewdistance/functions/fnc_returnObjectCoeff.sqf b/addons/viewdistance/functions/fnc_returnObjectCoeff.sqf index 5941256ffc..e9838a0c8d 100644 --- a/addons/viewdistance/functions/fnc_returnObjectCoeff.sqf +++ b/addons/viewdistance/functions/fnc_returnObjectCoeff.sqf @@ -27,6 +27,7 @@ _return = switch (_index) do { case 3: {0.60}; // Medium case 4: {0.80}; // High case 5: {1.00}; // Very High + case 6: {"fov"}; // FoV Based default {0.50}; // something broke if this returns }; diff --git a/addons/viewdistance/functions/fnc_setFovBasedOvdPFH.sqf b/addons/viewdistance/functions/fnc_setFovBasedOvdPFH.sqf new file mode 100644 index 0000000000..b6e2ce1e5a --- /dev/null +++ b/addons/viewdistance/functions/fnc_setFovBasedOvdPFH.sqf @@ -0,0 +1,36 @@ +/* + * Author: Jonpas + * Sets Object View Distance dynamically based on current Field of View, between Object View Distance (minimal value) and View Distance (maximum value) set before this PFH starts. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_viewdistance_fnc_setFovBasedObjectViewDistance + * + * Public: No + */ +#include "script_component.hpp" + +params ["_args", "_idPFH"]; + +// Remove PFH and set Object View Distance back to what it was before +if (GVAR(objectViewDistanceCoeff) < 6) exitWith { + [_idPFH] call CBA_fnc_removePerFrameHandler; + GVAR(fovBasedPFHminimalViewDistance) = nil; +}; + +private ["_zoom"]; +_zoom = (call CBA_fnc_getFov) select 1; + +if (_zoom > 0.94) then { + // Dynamically set Object View Distance based on player's Zoom Level and View Distance + setObjectViewDistance ((_zoom/34.98 * (viewDistance - GVAR(fovBasedPFHminimalViewDistance))) + GVAR(fovBasedPFHminimalViewDistance)); +} else { + setObjectViewDistance GVAR(fovBasedPFHminimalViewDistance); +}; + +TRACE_2("FoV Based",getObjectViewDistance select 0,_zoom); diff --git a/addons/viewdistance/stringtable.xml b/addons/viewdistance/stringtable.xml index b77b955573..07bf980df3 100644 --- a/addons/viewdistance/stringtable.xml +++ b/addons/viewdistance/stringtable.xml @@ -114,7 +114,7 @@ Distância de visão dinâmica dos objetos - Sets the object view distance as a coefficient of the view distance. + Sets the object view distance as a coefficient of the view distance or based on field of view. FoV Based's lowest and highest value is the value which is set when enabling the option. Zmienia zasięg rysowania obiektów jako mnożnik zasięgu widzenia. Establece la distancia de visión de objetos como un coeficiente de la distancia de visión. Nastaví objekt dohlednosti jako koeficient dohlednosti. @@ -169,6 +169,9 @@ Sehr hoch Muito alto + + FoV Based + View Distance: Zasięg widzenia: