PCG-FPS  v2 m0.22.4
Simple First Person Shooter with Procedurally Generated Level
Settings.h
Go to the documentation of this file.
1 #ifndef SKR_FPS2_SETTINGS_H
2 #define SKR_FPS2_SETTINGS_H
3 
4 #include "..\..\pch.h"
5 
6 #include <string>
7 #include <unordered_map>
8 #include <vector>
9 
10 namespace skr
11 {
12 namespace fps2
13 {
16 
17  class Settings
18  {
19  private:
22  Settings(){};
23 
25  Settings(const Settings&) = delete;
26 
28  Settings operator=(const Settings&) = delete;
29 
32  std::string _settingsFilePath = "settings.cfg";
33  public:
36  static Settings& GetInstance();
37 
38 #pragma region Integer type Settings
39  public:
41  enum struct SettingUInt32t
42  {
43  SCR_WIDTH,
44  SCR_HEIGHT,
45  RNG_MODE,
46  RNG_SEED
47  };
48 
49 #pragma warning(disable:4251) // only using types from standard library, warning can be ignored. Source: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4251
50 
52  std::unordered_map<SettingUInt32t, uint32_t> _settings_uint32t
53  {
58  };
59 
60  private:
61  // using this manually maintained mapping tables is a dirty hack
62  // using compile-time reflection would be better, but also requires a lot of work up front, currently not worth it with the limited amount of settings
63 
65  typedef std::unordered_map<std::string, SettingUInt32t> StringToSettingIntMap;
66 
68  static const std::unordered_map<std::string, SettingUInt32t> MapStringToSettingInt;
69 
71  typedef std::unordered_map<SettingUInt32t, std::string> SettingIntToStringMap;
72 
74  static const std::unordered_map<SettingUInt32t, std::string> MapSettingIntToString;
75 
76 #pragma warning(default:4251)
77 #pragma endregion
78 
79 #pragma region Float type Settings
80  public:
82  enum struct SettingFloat
83  {
84  RND_NEAR,
85  RND_FAR
86  };
87 
88 #pragma warning(disable:4251) // only using types from standard library, warning can be ignored. Source: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4251
89 
91  std::unordered_map<SettingFloat, float> _settings_float
92  {
93  {SettingFloat::RND_NEAR, 0.1f},
94  {SettingFloat::RND_FAR, 300.0f}
95  };
96 
97  private:
98  // using this manually maintained mapping tables is a dirty hack
99  // using compile-time reflection would be better, but also requires a lot of work up front, currently not worth it with the limited amount of settings
100 
102  typedef std::unordered_map<SettingFloat, std::string> SettingFloatToStringMap;
103 
105  static const std::unordered_map<SettingFloat, std::string> MapSettingFloatToString;
106 
108  typedef std::unordered_map<std::string, SettingFloat> StringToSettingFloatMap;
109 
111  static const std::unordered_map<std::string, SettingFloat> MapStringToSettingFloat;
112 
113 #pragma warning(default:4251)
114 #pragma endregion
115 
116 #pragma region Boolean type Settings
117 
118  public:
120  enum struct SettingBool
121  {
122  RND_VSYNC,
123  RNG_PRINTSEED,
126  };
127 
128 #pragma warning(disable:4251) // only using types from standard library, warning can be ignored. Source: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4251
129 
131  std::unordered_map<SettingBool, bool> _settings_bool
132  {
133  {SettingBool::RND_VSYNC, false},
137  };
138 
139  private:
140  // using this manually maintained mapping tables is a dirty hack
141  // using compile-time reflection would be better, but also requires a lot of work up front, currently not worth it with the limited amount of settings
142 
144  typedef std::unordered_map<SettingBool, std::string> SettingBoolToStringMap;
145 
147  static const std::unordered_map<SettingBool, std::string> MapSettingBoolToString;
148 
150  typedef std::unordered_map<std::string, SettingBool> StringToSettinBoolMap;
151 
153  static const std::unordered_map<std::string, SettingBool> MapStringToSettingBool;
154 #pragma warning(default:4251)
155 
156 #pragma endregion
157 
158 #pragma region RunTime Settings
159  public:
161  enum struct RuntimeBoolSetting
162  {
163  GhostMode,
165  MoveLights,
168  };
169 
171  std::unordered_map<RuntimeBoolSetting, bool> _runtime_bool
172  {
178  };
179 
181  enum struct ShadowType
182  {
183  Off,
184  ShadowMapping,
187  };
188 
190 
191 #pragma endregion
192 
193  public:
196  bool WriteSettingsToFile();
197 
201  bool WriteSettingsToFile(const std::string path);
202 
205  bool ReadSettingsFromFile();
206 
210  bool ReadSettingsFromFile(const std::string path);
211 
215  std::string PrintSettingsToString();
216 
217  private:
222  bool GetSettingsFromFile(const std::string path, std::vector<std::string>& settings);
223 
228  bool SetSettingsFromString(std::vector<std::string> settings);
229 
233  std::string GetHumanReadableBool(bool v);
234  };
235 
236 }
237 }
238 
239 #endif // !SKR_FPS2_SETTINGS_H
skr::fps2::Settings::SettingBool::RND_GAMMACORRECTION
@ RND_GAMMACORRECTION
use gamma correction of/off
skr::fps2::Settings::ShadowType::ShadowMappingPCFDisk
@ ShadowMappingPCFDisk
shadow mapping with Percentage-closer filtering with fixed samples
skr::fps2::Settings::operator=
Settings operator=(const Settings &)=delete
copy assignment constructor is deleted
skr::fps2::Settings::SettingBoolToStringMap
std::unordered_map< SettingBool, std::string > SettingBoolToStringMap
typedef mapping a setting of type boolean to a string
Definition: Settings.h:144
skr::fps2::Settings
managing and handling of settings for program
Definition: Settings.h:18
skr::fps2::Settings::SettingBool::RNG_PRINTSEED
@ RNG_PRINTSEED
print seed to cmd and log on/off
skr::fps2::Settings::Settings
Settings(const Settings &)=delete
copy constructor is deleted
skr::fps2::Settings::_shadowRenderingMode
ShadowType _shadowRenderingMode
type of shadow mapping currently used
Definition: Settings.h:189
skr::fps2::Settings::MapSettingIntToString
static const std::unordered_map< SettingUInt32t, std::string > MapSettingIntToString
mapping table for settings of type unsigned integer to a string
Definition: Settings.h:74
skr::fps2::Settings::_settingsFilePath
std::string _settingsFilePath
Definition: Settings.h:32
skr::fps2::Settings::StringToSettinBoolMap
std::unordered_map< std::string, SettingBool > StringToSettinBoolMap
typedef mapping a string to a setting of type boolean
Definition: Settings.h:150
skr::fps2::Settings::SettingUInt32t
SettingUInt32t
identifiers for settings of type unsigned integer
Definition: Settings.h:42
skr::fps2::Settings::StringToSettingFloatMap
std::unordered_map< std::string, SettingFloat > StringToSettingFloatMap
typedef to map a string to a setting of type float
Definition: Settings.h:108
skr::fps2::Settings::SettingFloat::RND_NEAR
@ RND_NEAR
distance of near plane
skr::fps2::Settings::MapStringToSettingFloat
static const std::unordered_map< std::string, SettingFloat > MapStringToSettingFloat
mapping table from a string to setting of type float
Definition: Settings.h:111
skr::fps2::Settings::Settings
Settings()
default constructor empty as OpenGL-Renderer object is a global object an requiers one at launch,...
Definition: Settings.h:22
skr::fps2::Settings::RuntimeBoolSetting
RuntimeBoolSetting
identifiers for settings of type bool only relevant during runtime, they are not written to the setti...
Definition: Settings.h:162
skr::fps2::Settings::_settings_uint32t
std::unordered_map< SettingUInt32t, uint32_t > _settings_uint32t
map keeping settings of type unsigned integer and their values
Definition: Settings.h:53
skr::fps2::Settings::MapSettingFloatToString
static const std::unordered_map< SettingFloat, std::string > MapSettingFloatToString
mapping table from a setting of type float to a string
Definition: Settings.h:105
skr::fps2::Settings::RuntimeBoolSetting::GhostMode
@ GhostMode
flag indicating if ghost mode is active (no collision + fly)
skr::fps2::Settings::SettingUInt32t::SCR_WIDTH
@ SCR_WIDTH
viewport width
skr::fps2::Settings::SettingUInt32t::RNG_MODE
@ RNG_MODE
mode of procedural generation
skr::fps2::Settings::PrintSettingsToString
std::string PrintSettingsToString()
write all settings into a single string used to write everything in one big chunk
Definition: Settings.cpp:166
skr::fps2::Settings::GetSettingsFromFile
bool GetSettingsFromFile(const std::string path, std::vector< std::string > &settings)
read settings from a file into a list of strings
Definition: Settings.cpp:199
skr::fps2::Settings::RuntimeBoolSetting::UseNormalMapping
@ UseNormalMapping
flag indicating if normal mapping is active
skr::fps2::Settings::SettingBool::RND_VSYNC
@ RND_VSYNC
vertical synchronization on/off
skr::fps2::Settings::SettingBool
SettingBool
identifiers for settings of type boolean
Definition: Settings.h:121
skr::fps2::Settings::RuntimeBoolSetting::MoveLights
@ MoveLights
flag indicating if lights are moving or static
skr::fps2::Settings::_settings_bool
std::unordered_map< SettingBool, bool > _settings_bool
map keeping settings of type boolean and their values
Definition: Settings.h:132
skr::fps2::Settings::MapSettingBoolToString
static const std::unordered_map< SettingBool, std::string > MapSettingBoolToString
mapping table to map a setting of type boolean to a string
Definition: Settings.h:147
skr::fps2::Settings::SettingFloatToStringMap
std::unordered_map< SettingFloat, std::string > SettingFloatToStringMap
typedef to map a setting of type flaot to a string
Definition: Settings.h:102
skr::fps2::Settings::_runtime_bool
std::unordered_map< RuntimeBoolSetting, bool > _runtime_bool
map keeping settings of type bool only relevant during runtime
Definition: Settings.h:172
skr::fps2::Settings::ShadowType::ShadowMappingPCF
@ ShadowMappingPCF
shadow mapping with Percentage-closer filtering
skr::fps2::Settings::SettingUInt32t::SCR_HEIGHT
@ SCR_HEIGHT
viewport height
skr::fps2::Settings::ShadowType::ShadowMapping
@ ShadowMapping
simple shadow mapping
skr::fps2::Settings::GetHumanReadableBool
std::string GetHumanReadableBool(bool v)
Get boolean value in human readable form: true/false instead of 1/0.
Definition: Settings.cpp:272
skr::fps2::Settings::RuntimeBoolSetting::DrawBoundingBox
@ DrawBoundingBox
flag indicating if bounding boxes of geometry are draw
skr::fps2::Settings::MapStringToSettingBool
static const std::unordered_map< std::string, SettingBool > MapStringToSettingBool
mapping table from a string to a setting of type boolean
Definition: Settings.h:153
skr::fps2::Settings::RuntimeBoolSetting::DrawDebugLight
@ DrawDebugLight
flag indicating to draw a cube at position of every light
skr
Definition: AssetPath.h:10
skr::fps2::Settings::SettingBool::RND_COLORCODEDROOMS
@ RND_COLORCODEDROOMS
color code rooms on/off
skr::fps2::Settings::SettingUInt32t::RNG_SEED
@ RNG_SEED
seed for random number generator used in procedural generation
skr::fps2::Settings::SettingFloat::RND_FAR
@ RND_FAR
distance of far plane
skr::fps2::Settings::SettingIntToStringMap
std::unordered_map< SettingUInt32t, std::string > SettingIntToStringMap
typedef to map settings of type unsigned integer to a string
Definition: Settings.h:71
skr::fps2::Settings::ReadSettingsFromFile
bool ReadSettingsFromFile()
read settings from path set in _settingsFilePath
Definition: Settings.cpp:130
skr::fps2::Settings::MapStringToSettingInt
static const std::unordered_map< std::string, SettingUInt32t > MapStringToSettingInt
mapping table for string to setting of type unsinged integer
Definition: Settings.h:68
skr::fps2::Settings::StringToSettingIntMap
std::unordered_map< std::string, SettingUInt32t > StringToSettingIntMap
typedef to map a string to a setting of type unsigned integer
Definition: Settings.h:65
skr::fps2::Settings::SetSettingsFromString
bool SetSettingsFromString(std::vector< std::string > settings)
set settings from a list of strings goes through a list of settings, one per element,...
Definition: Settings.cpp:223
skr::fps2::Settings::GetInstance
static Settings & GetInstance()
Get only instance of this class Implements Scott Meyers' singleton pattern.
Definition: Settings.cpp:60
skr::fps2::Settings::ShadowType::Off
@ Off
shadow mapping off
skr::fps2::Settings::_settings_float
std::unordered_map< SettingFloat, float > _settings_float
map keeping settings of type float and their values
Definition: Settings.h:92
skr::fps2::Settings::WriteSettingsToFile
bool WriteSettingsToFile()
write settings to path in _settingsFilePath
Definition: Settings.cpp:66
skr::fps2::Settings::ShadowType
ShadowType
type identifies for shadow mapping types
Definition: Settings.h:182
skr::fps2::Settings::SettingFloat
SettingFloat
identifies for settings of type float
Definition: Settings.h:83