diff --git a/addons/viewdistance/ACE_Settings.hpp b/addons/viewdistance/ACE_Settings.hpp index 6572e4790e..46f7a8955a 100644 --- a/addons/viewdistance/ACE_Settings.hpp +++ b/addons/viewdistance/ACE_Settings.hpp @@ -1,11 +1,27 @@ class ACE_Settings { - class GVAR(viewDistance) { + class GVAR(viewDistanceOnFoot) { typeName = "SCALAR"; isClientSettable = 1; - value = 11; // index, NOT value // not sure what to set this to. + value = 11; // index, NOT value // Can set it to client's actual viewdistance in the init function once ACE_Settings supports numbers (if ever). values[] = {"1500","2000","2500","3000","3500","4000","5000","6000","7000","8000","9000","10000"}; // Values also need to be changed in functions/fnc_returnValue.sqf - displayName = "Change View Distance"; - description = "Changes in game view distance"; + displayName = "Client View Distance (On Foot)"; + description = "Changes in game view distance when the player is on foot."; + }; + class GVAR(viewDistanceLandVehicle) { + typeName = "SCALAR"; + isClientSettable = 1; + value = 11; // index, NOT value + values[] = {"1500","2000","2500","3000","3500","4000","5000","6000","7000","8000","9000","10000"}; // Values also need to be changed in functions/fnc_returnValue.sqf + displayName = "Client View Distance (Land Vehicle)"; + description = "Changes in game view distance when the player is in a land vehicle."; + }; + class GVAR(viewDistanceAirVehicle) { + typeName = "SCALAR"; + isClientSettable = 1; + value = 11; // index, NOT value + values[] = {"1500","2000","2500","3000","3500","4000","5000","6000","7000","8000","9000","10000"}; // Values also need to be changed in functions/fnc_returnValue.sqf + displayName = "Client View Distance (Air Vehicle)"; + description = "Changes in game view distance when the player is in an air vehicle."; }; class GVAR(limitViewDistance) { typeName = "SCALAR"; @@ -13,6 +29,18 @@ class ACE_Settings { displayName = "View Distance Limit"; description = "Limit for client's view distance set here and can overridden by module"; }; + class GVAR(terrainGrid) { + typeName = "SCALAR"; + value = 10; // MP default as found in: https://community.bistudio.com/wiki/setTerrainGrid + displayName = "Client Terrain Grid"; + description = "Changes in game terrain grid"; + }; + class GVAR(shadows) { + typeName = "SCALAR"; + value = 200; // MP default as found in: https://community.bistudio.com/wiki/setObjectViewDistance + displayName = "Client Shadows distance"; + description = "Changes in game shadows"; + }; }; // To do: include string table style displayName & description. \ No newline at end of file diff --git a/addons/viewdistance/CfgVehicles.hpp b/addons/viewdistance/CfgVehicles.hpp index 2a2f85e611..99897f5441 100644 --- a/addons/viewdistance/CfgVehicles.hpp +++ b/addons/viewdistance/CfgVehicles.hpp @@ -11,10 +11,16 @@ class CfgVehicles { class Arguments { class moduleViewDistanceLimit { displayName = "View Distance Limit"; - description = "Sets the limit for how high clients can raise their view distance (< 10000)"; + description = "Sets the limit for how high clients can raise their view distance (<= 10000)"; typeName = "NUMBER"; defaultValue = 10000; }; + class moduleTerrainGridLimit { + displayName = "Terrain Grid Limit"; + description = "Sets the limit for how high clients can raise their terrain grid (<= 50)"; + typeName = "NUMBER"; + defaultValue = 50; // range is 3.125 - 50 Reference: https://community.bistudio.com/wiki/setTerrainGrid + }; }; }; }; \ No newline at end of file diff --git a/addons/viewdistance/XEH_preInit.sqf b/addons/viewdistance/XEH_preInit.sqf index 883e393c8a..a44fab6169 100644 --- a/addons/viewdistance/XEH_preInit.sqf +++ b/addons/viewdistance/XEH_preInit.sqf @@ -6,5 +6,6 @@ PREP(initModule); PREP(init); PREP(returnValue); PREP(changeViewDistance); +PREP(adaptViewDistance); ADDON = true; \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_adaptViewDistance.sqf b/addons/viewdistance/functions/fnc_adaptViewDistance.sqf new file mode 100644 index 0000000000..bc56955893 --- /dev/null +++ b/addons/viewdistance/functions/fnc_adaptViewDistance.sqf @@ -0,0 +1,35 @@ +/* + * Author: Winter + * Sets the player's current view distance according to whether s/he is on foot, in a land vehicle or in an air vehicle. + * + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_viewdistance_fnc_adaptViewDistance; + * + * Public: Yes + */ + +#include "script_component.hpp" + +private["_land_vehicle","_air_vehicle"]; + +_land_vehicle = (vehicle player) isKindOf "LandVehicle"; +_air_vehicle = (vehicle player) isKindOf "Air"; + +if (!_land_vehicle && !_air_vehicle) exitWith { + [GVAR(viewDistanceOnFoot),true] call FUNC(changeViewDistance); +}; + +if (_land_vehicle) exitWith { + [GVAR(viewDistanceLandVehicle),true] call FUNC(changeViewDistance); +}; + +if (_air_vehicle) exitWith { + [GVAR(viewDistanceAirVehicle),true] call FUNC(changeViewDistance); +}; \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_changeViewDistance.sqf b/addons/viewdistance/functions/fnc_changeViewDistance.sqf index f1274343d8..596c86d521 100644 --- a/addons/viewdistance/functions/fnc_changeViewDistance.sqf +++ b/addons/viewdistance/functions/fnc_changeViewDistance.sqf @@ -4,7 +4,8 @@ * * * Arguments: - * None + * 0: View Distance setting INDEX + * 1: Show Prompt * * Return Value: * None @@ -18,18 +19,24 @@ #include "script_component.hpp" private ["_text","_new_view_distance","_view_distance_limit"]; +PARAMS_2(_index_requested,_prompt); -// Change the received index number into an actual view distance: -_new_view_distance = [GVAR(viewDistance)] call FUNC(returnValue); +_new_view_distance = [_index_requested] call FUNC(returnValue); // change the index into an actual view distance value _view_distance_limit = GVAR(limitViewDistance); // Grab the limit if (_new_view_distance <= _view_distance_limit) then { - _text = composeText ["View distance successfully changed to: ",str(_new_view_distance)]; - [_text,1] call EFUNC(common,displayTextStructured); + if (_prompt) then { + _text = composeText ["View distance: ",str(_new_view_distance)]; + [_text,1] call EFUNC(common,displayTextStructured); + }; setViewDistance _new_view_distance; setObjectViewDistance (0.8 * _new_view_distance); // maybe make this 0.8 a constant? } else { - _text = composeText ["That option is not allowed! The limit is: ",str(_view_distance_limit)]; - [_text,1] call EFUNC(common,displayTextStructured); + if (_prompt) then { + _text = composeText ["That option is invalid! The limit is: ",str(_view_distance_limit)]; + [_text,1] call EFUNC(common,displayTextStructured); + setViewDistance _view_distance_limit; + setObjectViewDistance (0.8 * _view_distance_limit); // maybe make this 0.8 a constant? + }; }; \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_init.sqf b/addons/viewdistance/functions/fnc_init.sqf index 0d5ec7cf79..72fc2ee0e6 100644 --- a/addons/viewdistance/functions/fnc_init.sqf +++ b/addons/viewdistance/functions/fnc_init.sqf @@ -19,9 +19,19 @@ if (!hasInterface) exitWith {}; -// Set the EH which waits for the View Distance setting to be changed +if (viewDistance > GVAR(limitViewDistance)) then { + setViewDistance GVAR(limitViewDistance); // force the view distance down to the limit. + setObjectViewDistance (0.8 * GVAR(limitViewDistance)); +} else { + [] call FUNC(adaptViewDistance); // adapt view distance in the beginning according to whether client is on foot or vehicle. +}; + +// Set the EH which waits for any of the view distance settings to be changed (avoids the player having to enter or leave their vehicle for the changes to have effect.) ["SettingChanged",{ - if (_this select 0 == QGVAR(viewDistance)) then { - [] call FUNC(changeViewDistance); + if ((_this select 0 == QGVAR(viewDistanceOnFoot)) || (_this select 0 == QGVAR(viewDistanceLandVehicle)) || (_this select 0 == QGVAR(viewDistanceAirVehicle))) then { + [] call FUNC(adaptViewDistance); }; -},true] call ace_common_fnc_addEventHandler; \ No newline at end of file +},true] call ace_common_fnc_addEventHandler; + +// Set the EH which waits for a vehicle change to automatically swap to On Foot/In Land Vehicle/In Air Vehicle +["playerVehicleChanged",{[] call FUNC(adaptViewDistance)},true] call ace_common_fnc_addEventHandler; \ No newline at end of file