Skip to content

Commit

Permalink
Refactor OpenXRay environment settings
Browse files Browse the repository at this point in the history
Future proof refactoring gives us ability to use openxray.ltx independently

Refactored main config files loading code
  • Loading branch information
Xottab-DUTY committed Dec 28, 2018
1 parent 01c0d5e commit e36b806
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
7 changes: 7 additions & 0 deletions res/gamedata/configs/openxray.ltx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[environment]
; Set to false if you want weather config defined sun movement
dynamic_sun_dir = true

; Defines sun movement direction
; Useless if dynamic_sun_dir is disabled
sun_dir_azimuth = 0.0
3 changes: 0 additions & 3 deletions res/gamedata/configs/system.ltx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
#include "localization.ltx"
#include "smart_cover.ltx"

[openxray]
dynamic_sun_dir = true

[zone_pick_dof]
near = -1500.0
far = 10.0
Expand Down
1 change: 1 addition & 0 deletions src/xrCore/xr_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

XRCORE_API CInifile const* pSettings = nullptr;
XRCORE_API CInifile const* pSettingsAuth = nullptr;
XRCORE_API CInifile const* pSettingsOpenXRay = nullptr;

#if defined(LINUX)
#include <stdint.h>
Expand Down
1 change: 1 addition & 0 deletions src/xrCore/xr_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@ class XRCORE_API CInifile
// Main configuration file
extern XRCORE_API CInifile const* pSettings;
extern XRCORE_API CInifile const* pSettingsAuth;
extern XRCORE_API CInifile const* pSettingsOpenXRay;

#endif //__XR_INI_H__
11 changes: 6 additions & 5 deletions src/xrEngine/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ CEnvironment::CEnvironment() : CurrentEnv(0), m_ambients_config(0)
CInifile* config =
new CInifile(FS.update_path(file_name, "$game_config$", "environment" DELIMITER "environment.ltx"), TRUE, TRUE, FALSE);

useDynamicSunDir = READ_IF_EXISTS(pSettings, r_bool, OPENXRAY_INI_SECTION, "dynamic_sun_dir", true);
sunDirAzimuth = READ_IF_EXISTS(pSettings, r_float, OPENXRAY_INI_SECTION, "sun_dir_azimuth", 0.0f);
clamp(sunDirAzimuth, 0.0f, 360.0f);
sunDirAzimuth *= (PI / 180.0f);

// params
p_var_alt = deg2rad(config->r_float("environment", "altitude"));
p_var_long = deg2rad(config->r_float("environment", "delta_longitude"));
Expand All @@ -121,6 +116,12 @@ CEnvironment::CEnvironment() : CurrentEnv(0), m_ambients_config(0)
p_fog_color = config->r_float("environment", "fog_color");

xr_delete(config);

// OpenXRay environment configuration
useDynamicSunDir = READ_IF_EXISTS(pSettingsOpenXRay, r_bool, "environment", "dynamic_sun_dir", true);
sunDirAzimuth = READ_IF_EXISTS(pSettingsOpenXRay, r_float, "environment", "sun_dir_azimuth", 0.0f);
clamp(sunDirAzimuth, 0.0f, 360.0f);
sunDirAzimuth *= (PI / 180.0f);
}

CEnvironment::~CEnvironment()
Expand Down
29 changes: 17 additions & 12 deletions src/xrEngine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,31 @@ struct PathIncludePred
};
}

ENGINE_API void InitSettings()
template <typename T>
void InitConfig(T& config, pcstr name, bool fatal = true,
bool readOnly = true, bool loadAtStart = true, bool saveAtEnd = true,
u32 sectCount = 0, const CInifile::allow_include_func_t& allowIncludeFunc = nullptr)
{
string_path fname;
FS.update_path(fname, "$game_config$", "system.ltx");
#ifdef DEBUG
Msg("Updated path to system.ltx is %s", fname);
#endif
pSettings = new CInifile(fname, TRUE);
CHECK_OR_EXIT(pSettings->section_count(),
FS.update_path(fname, "$game_config$", name);
config = new CInifile(fname, readOnly, loadAtStart, saveAtEnd, sectCount, allowIncludeFunc);

CHECK_OR_EXIT(config->section_count() || !fatal,
make_string("Cannot find file %s.\nReinstalling application may fix this problem.", fname));
}

ENGINE_API void InitSettings()
{
xr_auth_strings_t ignoredPaths, checkedPaths;
fill_auth_check_params(ignoredPaths, checkedPaths); //TODO port xrNetServer to Linux
PathIncludePred includePred(&ignoredPaths);
CInifile::allow_include_func_t includeFilter;
includeFilter.bind(&includePred, &PathIncludePred::IsIncluded);
pSettingsAuth = new CInifile(fname, TRUE, TRUE, FALSE, 0, includeFilter);
FS.update_path(fname, "$game_config$", "game.ltx");
pGameIni = new CInifile(fname, TRUE);
CHECK_OR_EXIT(pGameIni->section_count(),
make_string("Cannot find file %s.\nReinstalling application may fix this problem.", fname));

InitConfig(pSettings, "system.ltx");
InitConfig(pSettingsAuth, "system.ltx", true, true, true, false, 0, includeFilter);
InitConfig(pSettingsOpenXRay, "openxray.ltx", false, true, true, false);
InitConfig(pGameIni, "game.ltx");
}

ENGINE_API void InitConsole()
Expand Down

0 comments on commit e36b806

Please sign in to comment.