Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View Distance Module #1063

Merged
merged 32 commits into from
May 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c2bb638
Added required files for new module
simonamdev May 7, 2015
2c8dddf
Adding required files
simonamdev May 8, 2015
6b604c1
First working version
simonamdev May 8, 2015
a5d68f1
Added working limiter (config based)
simonamdev May 8, 2015
bb625aa
Used ACE common function instead of hint
simonamdev May 8, 2015
5732015
Added moduleViewDistance file
simonamdev May 8, 2015
6cda97e
Adding required files for module integration
simonamdev May 8, 2015
45992e5
All working except module returning any.
simonamdev May 8, 2015
0b41377
Cleaned up code
simonamdev May 8, 2015
96e1e9c
Added name + email to authors.txt
simonamdev May 8, 2015
ae1628e
Renamed init file for neatness
simonamdev May 9, 2015
9e40e16
Adjusted XEH_preinit accordingly
simonamdev May 9, 2015
7201a23
Adjusted post init, removed redundant settings
simonamdev May 9, 2015
bba216e
Rewrote switch statement
simonamdev May 9, 2015
2dfaaa0
Reworked limiting system
simonamdev May 9, 2015
f64f76e
Fixed wrong file name
simonamdev May 9, 2015
a9d6fbd
Attempting to fix module value not being read
simonamdev May 9, 2015
f4d7c68
Attempted fix #2
simonamdev May 9, 2015
cad8628
Fixed module value not overriding.
simonamdev May 9, 2015
737b1cc
Renamed variable limit to limitViewDistance
simonamdev May 9, 2015
69648f0
Added adaptive view distance depending on vehicle
simonamdev May 10, 2015
c05a91f
Suppress prompts when changing vehicle.
simonamdev May 10, 2015
2ce1336
Removed terrain grid related configs
simonamdev May 10, 2015
6a66818
Replaced player with ACE_player
simonamdev May 10, 2015
283768f
Fixed code style in switch statement
simonamdev May 10, 2015
495e94f
Merged fnc_init.sqf into XEH_postInit.sqf
simonamdev May 10, 2015
cb64f7d
Adjusted PBOPREFIX
simonamdev May 10, 2015
d8cce9e
Removed redundant settings
simonamdev May 14, 2015
7fe73c2
Added Object View Distance Coefficient setting
simonamdev May 14, 2015
853333a
Added new function, updated settings
simonamdev May 14, 2015
3480168
Integrated new function into module
simonamdev May 14, 2015
8c7d752
Made final adjustments
simonamdev May 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ Bla1337
nikolauska <nikolauska1@gmail.com>
adam3adam <br.ada@seznam.cz>
Professor <lukas.trneny@wo.cz>
Winter <simon@agius-muscat.net>
1 change: 1 addition & 0 deletions addons/viewdistance/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\ace\addons\viewdistance
42 changes: 42 additions & 0 deletions addons/viewdistance/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class ACE_Settings {
class GVAR(viewDistanceOnFoot) {
typeName = "SCALAR";
isClientSettable = 1;
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 = "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";
value = 10000; // Value, NOT index. 10000 is the maximum in A3
displayName = "View Distance Limit";
description = "Limit for client's view distance set here and can overridden by module";
};
class GVAR(objectViewDistanceCoeff) {
typeName = "SCALAR";
isClientSettable = 1;
value = 0; // index. Actual coefficient is given by functions/fnc_returnObjectCoeff.sqf
values[] = {"Off","Very Low","Low","Medium","High","Very High"};
displayName = "Dynamic Object View Distance";
description = "Sets the object view distance as a coefficient of the view distance.";
};
};

// To do: include string table style displayName & description.
12 changes: 12 additions & 0 deletions addons/viewdistance/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
20 changes: 20 additions & 0 deletions addons/viewdistance/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class CfgVehicles {
class ACE_Module;
class GVAR(ModuleSettings) : ACE_Module {
author = "$STR_ACE_Common_ACETeam";
category = "ACE";
function = QUOTE(DFUNC(initModule));
displayName = "View Distance Limiter";
scope = 2;
isGlobal = 1;
//icon = ""; // needs an icon
class Arguments {
class moduleViewDistanceLimit {
displayName = "View Distance Limit";
description = "Sets the limit for how high clients can raise their view distance (<= 10000)";
typeName = "NUMBER";
defaultValue = 10000;
};
};
};
};
27 changes: 27 additions & 0 deletions addons/viewdistance/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"

if (!hasInterface) exitWith {};

if (viewDistance > GVAR(limitViewDistance)) then {
setViewDistance GVAR(limitViewDistance); // force the view distance down to the limit.
setObjectViewDistance (0.8 * GVAR(limitViewDistance));
} else {
[true] 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 a vehicle for the changes to have effect.
["SettingChanged",{
if ((_this select 0 == QGVAR(viewDistanceOnFoot)) || (_this select 0 == QGVAR(viewDistanceLandVehicle)) || (_this select 0 == QGVAR(viewDistanceAirVehicle))) then {
[true] call FUNC(adaptViewDistance);
};
},true] call ace_common_fnc_addEventHandler;

// Set the EH which waits for the Object View Distance coefficient to be changed, so that the effect is show immediately
["SettingChanged",{
if (_this select 0 == QGVAR(objectViewDistanceCoeff)) then {
[true] call FUNC(adaptViewDistance);
};
},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",{[false] call FUNC(adaptViewDistance)},true] call ace_common_fnc_addEventHandler;
11 changes: 11 additions & 0 deletions addons/viewdistance/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "script_component.hpp"

ADDON = false;

PREP(initModule);
PREP(returnValue);
PREP(returnObjectCoeff);
PREP(changeViewDistance);
PREP(adaptViewDistance);

ADDON = true;
17 changes: 17 additions & 0 deletions addons/viewdistance/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author[] = {"Winter"};
authorUrl = "https://github.com/Winter259";
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
#include "ACE_Settings.hpp"
#include "CfgVehicles.hpp"
37 changes: 37 additions & 0 deletions addons/viewdistance/functions/fnc_adaptViewDistance.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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:
* 0: Show Prompt <BOOL>
*
* Return Value:
* None
*
* Example:
* [] call ace_viewdistance_fnc_adaptViewDistance;
*
* Public: No
*/

#include "script_component.hpp"

PARAMS_1(_show_prompt);

private["_land_vehicle","_air_vehicle"];

_land_vehicle = (vehicle ACE_player) isKindOf "LandVehicle";
_air_vehicle = (vehicle ACE_player) isKindOf "Air";

if (!_land_vehicle && !_air_vehicle) exitWith {
[GVAR(viewDistanceOnFoot),_show_prompt] call FUNC(changeViewDistance);
};

if (_land_vehicle) exitWith {
[GVAR(viewDistanceLandVehicle),_show_prompt] call FUNC(changeViewDistance);
};

if (_air_vehicle) exitWith {
[GVAR(viewDistanceAirVehicle),_show_prompt] call FUNC(changeViewDistance);
};
48 changes: 48 additions & 0 deletions addons/viewdistance/functions/fnc_changeViewDistance.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Author: Winter
* Sets the player's current view distance according to allowed values.
*
*
* Arguments:
* 0: View Distance setting INDEX <SCALAR>
* 1: Show Prompt <BOOL>
*
* Return Value:
* None
*
* Example:
* [] call ace_viewdistance_fnc_changeViewDistance;
*
* Public: No
*/

#include "script_component.hpp"

private ["_text","_new_view_distance","_view_distance_limit","_object_view_distance_coeff"];

PARAMS_2(_index_requested,_show_prompt);

_new_view_distance = [_index_requested] call FUNC(returnValue); // changes the setting index into an actual view distance value
_object_view_distance_coeff = [GVAR(objectViewDistanceCoeff)] call FUNC(returnObjectCoeff); // changes the setting index into a coefficient.
_view_distance_limit = GVAR(limitViewDistance); // Grab the limit

if (_new_view_distance <= _view_distance_limit) then {
if (_show_prompt) then {
_text = parseText format ["<t align='center'>View Distance: %1<br />Object View Distance Coefficient: %2</t>",str(_new_view_distance),str(_object_view_distance_coeff)];
[_text,2] call EFUNC(common,displayTextStructured);
};
setViewDistance _new_view_distance;
if (_object_view_distance_coeff > 0) then {
setObjectViewDistance (_object_view_distance_coeff * _new_view_distance);
};
}
else {
if (_show_prompt) then {
_text = parseText format ["<t align='center'>That option is invalid! The limit is: %1<br />Object View Distance Coefficient: %2</t>",str(_view_distance_limit),str(_object_view_distance_coeff)];
[_text,2] call EFUNC(common,displayTextStructured);
};
setViewDistance _view_distance_limit;
if (_object_view_distance_coeff > 0) then {
setObjectViewDistance (_object_view_distance_coeff * _view_distance_limit);
};
};
28 changes: 28 additions & 0 deletions addons/viewdistance/functions/fnc_initModule.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Author: Winter
* Initialises the view distance limiter module
*
*
* Arguments:
* 0: logic <OBJECT>
* 1: Synchronised Units <ARRAY>
* 2: Module Activated <BOOL>
*
* Return Value:
* None
*
*/

#include "script_component.hpp"

if (!isServer) exitWith {};

PARAMS_3(_logic,_units,_activated);

if (!_activated) exitWith {
diag_log text "[ACE]: View Distance Limit Module is placed but NOT active.";
};

[_logic, QGVAR(limitViewDistance),"moduleViewDistanceLimit"] call EFUNC(common,readSettingFromModule);

diag_log format ["[ACE]: View Distance Limit Module Initialized. Limit set by module: %1",GVAR(limitViewDistance)];
34 changes: 34 additions & 0 deletions addons/viewdistance/functions/fnc_returnObjectCoeff.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Author: Winter
* Returns the object view distance coefficient according to the given index
*
*
* Arguments:
* 0: Object View Distance setting Index <SCALAR>
*
* Return Value:
* Object View Distance <SCALAR>
*
* Example:
* [2] call ace_viewdistance_fnc_returnObjectCoeff;
*
* Public: No
*/

#include "script_component.hpp"

PARAMS_1(_index);

private ["_return"];

_return = switch (_index) do {
case 0: {0.00}; // Off
case 1: {0.20}; // Very Low
case 2: {0.40}; // Low
case 3: {0.60}; // Medium
case 4: {0.80}; // High
case 5: {1.00}; // Very High
default {0.50}; // something broke if this returns
};

_return;
40 changes: 40 additions & 0 deletions addons/viewdistance/functions/fnc_returnValue.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Author: Winter
* Returns the view distance value according to the given index
*
*
* Arguments:
* 0: View Distance Index <SCALAR>
*
* Return Value:
* View Distance <SCALAR>
*
* Example:
* [2] call ace_viewdistance_fnc_returnViewDistanceValue;
*
* Public: No
*/

#include "script_component.hpp"

PARAMS_1(_index);

private ["_return"];

_return = switch (_index) do {
case 0: {1500};
case 1: {2000};
case 2: {2500};
case 3: {3000};
case 4: {3500};
case 5: {4000};
case 6: {5000};
case 7: {6000};
case 8: {7000};
case 9: {8000};
case 10: {9000};
case 11: {10000};
default {1000};
};

_return;
1 change: 1 addition & 0 deletions addons/viewdistance/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "\z\ace\addons\viewdistance\script_component.hpp"
12 changes: 12 additions & 0 deletions addons/viewdistance/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#define COMPONENT viewdistance
#include "\z\ace\addons\main\script_mod.hpp"

#ifdef DEBUG_ENABLED_VIEWDISTANCE
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_VIEWDISTANCE
#define DEBUG_SETTINGS DEBUG_SETTINGS_VIEWDISTANCE
#endif

#include "\z\ace\addons\main\script_macros.hpp"