Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Config.hpp
1#pragma once
2
3#include "Common.hpp"
4#include <vector>
5
9struct KeyValues {
10
11 std::string key;
12 std::vector<std::string> values;
13 std::vector<KeyValues> elements;
14
18 explicit KeyValues(const std::string & aKey);
19};
20
25class Config {
26public:
30 explicit Config(const std::vector<std::string> & argv);
31
36 bool showHelp();
37
38protected:
40 struct ArgumentInfo {
41
48 ArgumentInfo(const std::string & aname, const std::string & ashort, const std::string & adetails,
49 const std::vector<std::string> & avalues);
50
51 std::string nameLong;
52 std::string nameShort;
53 std::string details;
54 std::vector<std::string> values;
55 };
56
60 const std::vector<KeyValues> & arguments() const;
61
65 void registerSection(const std::string & name);
66
74 void registerArgument(const std::string & longName, const std::string & shortName, const std::string & details, const std::vector<std::string> & params = {});
75
83 void registerArgument(const std::string & longName, const std::string & shortName, const std::string & details, const std::string & param);
84
85private:
91 static void parseFromFile(const std::string & filePath, std::vector<KeyValues> & arguments);
92
98 static void parseFromArgs(const std::vector<std::string> & argv, std::vector<KeyValues> & arguments);
99
101 std::vector<KeyValues> _rawArguments;
102
104 std::vector<ArgumentInfo> _infos;
105
106 bool _showHelp = false;
107};
108
113class RenderingConfig : public Config {
114public:
118 explicit RenderingConfig(const std::vector<std::string> & argv);
119
123 glm::vec2 renderingResolution();
124
126 const size_t version = 1;
127
129 bool vsync = true;
130
132 int rate = 60;
133
135 bool fullscreen = false;
136
138 unsigned int initialWidth = 1000;
139
141 unsigned int initialHeight = 750;
142
146
148 bool forceAspectRatio = false;
149
151 glm::vec2 screenResolution = glm::vec2(800.0f, 600.0f);
152
154 glm::ivec4 windowFrame = glm::vec4(0, 0, 800, 600);
155
157 std::string resourcesPath;
158
160 bool trackDebug = true;
161};
Contains configurable elements as attributes, populated from the command line, a configuration file o...
Definition: Config.hpp:25
static void parseFromFile(const std::string &filePath, std::vector< KeyValues > &arguments)
Definition: Config.cpp:79
const std::vector< KeyValues > & arguments() const
Definition: Config.cpp:63
bool _showHelp
Should the help be displayed.
Definition: Config.hpp:106
bool showHelp()
Definition: Config.cpp:148
static void parseFromArgs(const std::vector< std::string > &argv, std::vector< KeyValues > &arguments)
Definition: Config.cpp:124
void registerSection(const std::string &name)
Definition: Config.cpp:67
std::vector< ArgumentInfo > _infos
Store informations about each argument, for displaying the help message.
Definition: Config.hpp:104
void registerArgument(const std::string &longName, const std::string &shortName, const std::string &details, const std::vector< std::string > &params={})
Definition: Config.cpp:71
std::vector< KeyValues > _rawArguments
Store the internal parsed (keys, [values]) extracted from a file or the command-line.
Definition: Config.hpp:101
Configuration containing parameters for windows and renderers.
Definition: Config.hpp:113
const size_t version
The configuration version number (unused).
Definition: Config.hpp:126
std::string resourcesPath
Extra resources directory.
Definition: Config.hpp:157
int rate
Prefered framerate.
Definition: Config.hpp:132
bool trackDebug
Should resource tracking and monitoring be enabled.
Definition: Config.hpp:160
glm::vec2 renderingResolution()
Definition: Config.cpp:233
bool vsync
Toggle V-Sync.
Definition: Config.hpp:129
glm::vec2 screenResolution
Size of the window in raw pixels, updated at launch based on screen density.
Definition: Config.hpp:151
int internalVerticalResolution
Internal vertical rendering resolution.
Definition: Config.hpp:145
unsigned int initialWidth
Initial width of the window in relative pixels.
Definition: Config.hpp:138
bool forceAspectRatio
Should the aspect ratio of the window be constrained.
Definition: Config.hpp:148
unsigned int initialHeight
Initial height of the window in relative pixels.
Definition: Config.hpp:141
bool fullscreen
Toggle fullscreen window.
Definition: Config.hpp:135
glm::ivec4 windowFrame
The last recorded window position and size on screen.
Definition: Config.hpp:154
Informations about an argument.
Definition: Config.hpp:40
std::string nameShort
The short argument name.
Definition: Config.hpp:52
std::string nameLong
The main argument name.
Definition: Config.hpp:51
std::string details
Argument description.
Definition: Config.hpp:53
std::vector< std::string > values
Zero, one or multiple argument parameters.
Definition: Config.hpp:54
Represent a key-values tuple.
Definition: Config.hpp:9
std::vector< std::string > values
A vector of values.
Definition: Config.hpp:12
std::string key
The key.
Definition: Config.hpp:11
std::vector< KeyValues > elements
A vector of child elements.
Definition: Config.hpp:13