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 23 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\blank
46 changes: 46 additions & 0 deletions addons/viewdistance/ACE_Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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(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.
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;
};
};
};
};
3 changes: 3 additions & 0 deletions addons/viewdistance/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

[] call FUNC(init);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If FUNC(init) is only ever supposed to be called once and on postInit, the contents of it might as well be in postInit?

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(init);
PREP(returnValue);
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: Yes
*/

#include "script_component.hpp"

PARAMS_1(_show_prompt);

private["_land_vehicle","_air_vehicle"];

_land_vehicle = (vehicle player) isKindOf "LandVehicle";
_air_vehicle = (vehicle player) isKindOf "Air";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

player should be ACE_player


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);
};
42 changes: 42 additions & 0 deletions addons/viewdistance/functions/fnc_changeViewDistance.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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: Yes
*/

#include "script_component.hpp"

private ["_text","_new_view_distance","_view_distance_limit"];
PARAMS_2(_index_requested,_prompt);

_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 {
if (_prompt) then {
_text = composeText ["View distance successfully changed to: ",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 {
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?
};
};
37 changes: 37 additions & 0 deletions addons/viewdistance/functions/fnc_init.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Author: Winter
* Assigns the Event Handler which triggers when a player adjusts their view distance in the menu
*
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_viewdistance_fnc_initViewDistance;
*
* Public: Yes
*/

#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 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;
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)];
41 changes: 41 additions & 0 deletions addons/viewdistance/functions/fnc_returnValue.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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: Yes
*/

#include "script_component.hpp"

PARAMS_1(_index);

private ["_return"];

_return = switch (_index) do
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust to match our style:

_return = switch (_index) do {

Also use 4 spaces for indentation.

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"