galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Settings.cpp
Go to the documentation of this file.
1
7
8#include <entt/locator/locator.hpp>
9
12
13#include "Settings.hpp"
14
15#ifdef GALAXY_WIN_PLATFORM
19#endif
20
21namespace galaxy
22{
24 {
25 auto& config = entt::locator<Config>::value();
26
27 config.restore<int>("width", 1920, "window");
28 config.restore<int>("height", 1080, "window");
29 config.restore<std::string>("title", "game", "window");
30 config.restore<bool>("vsync", false, "window");
31 config.restore<bool>("resizable", true, "window");
32 config.restore<bool>("decoration", true, "window");
33 config.restore<bool>("fullscreen", false, "window");
34 config.restore<bool>("maximized", false, "window");
35 config.restore<bool>("minimized", false, "window");
36 config.restore<bool>("borderless_fullscreen", false, "window");
37 config.restore<std::string>("icon", "", "window");
38 config.restore<bool>("on_top", false, "window");
39
40 config.restore<std::string>("assets_dir", "assets/", "fs");
41 config.restore<std::string>("asset_pack", "assets.galaxy", "fs");
42 config.restore<bool>("use_loose_assets", true, "fs");
43 config.restore<std::string>("assets_music", "music/", "fs");
44 config.restore<std::string>("assets_sfx", "sfx/", "fs");
45 config.restore<std::string>("assets_voice", "voice/", "fs");
46 config.restore<std::string>("assets_font", "fonts/", "fs");
47 config.restore<std::string>("assets_script", "scripts/", "fs");
48 config.restore<std::string>("assets_shaders", "shaders/", "fs");
49 config.restore<std::string>("assets_animation", "animations/", "fs");
50 config.restore<std::string>("assets_texture", "textures/", "fs");
51 config.restore<std::string>("assets_prefabs", "prefabs/", "fs");
52 config.restore<std::string>("assets_maps", "maps/", "fs");
53 config.restore<std::string>("assets_video", "video/", "fs");
54 config.restore<std::string>("assets_ui", "ui/", "fs");
55
56 config.restore<bool>("cursor_locked", false, "mouse");
57 config.restore<bool>("cursor_show", true, "mouse");
58
59 // config.restore<std::string>("cursor_icon", "", "mouse");
60 // config.restore<int>("x", 0, "mouse.cursor_hotspot");
61 // config.restore<int>("y", 0, "mouse.cursor_hotspot");
62
63 // config.restore<int>("audio_freq", 44100, "audio");
64
65 // config.restore<int>("ansiotrophy", 16, "graphics");
66 // config.restore<bool>("mipmap", true, "graphics");
67 // config.restore<std::string>("texture_filter", "NEAREST", "graphics");
68 // config.restore<int>("max_quads", 250, "graphics");
69
70 // config.restore<std::string>("version", "1.0", "meta");
71 // config.restore<std::string>("identifier", "com.galaxy.app", "meta");
72 // config.restore<std::string>("creator", "reworks", "meta");
73 // config.restore<std::string>("copyright", "2025+ reworks", "meta");
74 // config.restore<std::string>("website", "https://reworks-org.github.io/galaxy/", "meta");
75 // config.restore<std::string>("editor_dir", "editor/", "fs");
76
77 config.save();
78 }
79
81 {
82 auto& config = entt::locator<Config>::value();
83
84 s_window_width = *config.get<int>("width", "window");
85 s_window_height = *config.get<int>("height", "window");
86 s_title = *config.get<std::string>("title", "window");
87 s_vsync = *config.get<bool>("vsync", "window");
88 s_resizable = *config.get<bool>("resizable", "window");
89 s_decoration = *config.get<bool>("decoration", "window");
90 s_fullscreen = *config.get<bool>("fullscreen", "window");
91 s_maximized = *config.get<bool>("maximized", "window");
92 s_minimized = *config.get<bool>("minimized", "window");
93 s_borderless = *config.get<bool>("borderless_fullscreen", "window");
94 s_window_icon = *config.get<std::string>("icon", "window");
95 s_ontop = *config.get<bool>("on_top", "window");
96
97 s_assets_dir = *config.get<std::string>("assets_dir", "fs");
98 s_asset_pack = *config.get<std::string>("asset_pack", "fs");
99 s_use_loose_assets = *config.get<bool>("use_loose_assets", "fs");
100 s_assets_music = *config.get<std::string>("assets_music", "fs");
101 s_assets_sfx = *config.get<std::string>("assets_sfx", "fs");
102 s_assets_voice = *config.get<std::string>("assets_voice", "fs");
103 s_assets_font = *config.get<std::string>("assets_font", "fs");
104 s_assets_script = *config.get<std::string>("assets_script", "fs");
105 s_assets_shaders = *config.get<std::string>("assets_shaders", "fs");
106 s_assets_animation = *config.get<std::string>("assets_animation", "fs");
107 s_assets_texture = *config.get<std::string>("assets_texture", "fs");
108 s_assets_prefabs = *config.get<std::string>("assets_prefabs", "fs");
109 s_assets_maps = *config.get<std::string>("assets_maps", "fs");
110 s_assets_video = *config.get<std::string>("assets_video", "fs");
111 s_assets_ui = *config.get<std::string>("assets_ui", "fs");
112
113 s_cursor_locked = *config.get<bool>("cursor_locked", "mouse");
114 s_cursor_show = *config.get<bool>("cursor_show", "mouse");
115
116 // s_cursor_icon = *config.get<std::string>("cursor_icon", "mouse");
117 // s_cursor_hotspot.x = *config.get<int>("x", "mouse.cursor_hotspot");
118 // s_cursor_hotspot.y = *config.get<int>("y", "mouse.cursor_hotspot");
119
120 // s_audio_freq = *config.get<int>("audio_freq", "audio");
121
122 // s_ansio = *config.get<int>("ansiotrophy", "graphics");
123 // s_mipmap = *config.get<bool>("mipmap", "graphics");
124 // s_filtering = *config.get<std::string>("texture_filter", "graphics").and_then([](std::string_view filter) {
125 // return magic_enum::enum_cast<GLTextureFilter>(filter);
126 // });
127 // s_max_quads = *config.get<int>("max_quads", "graphics");
128
129 // s_version = *config.get<std::string>("version", "meta");
130 // s_identifier = *config.get<std::string>("identifier", "meta");
131 // s_creator = *config.get<std::string>("creator", "meta");
132 // s_copyright = *config.get<std::string>("copyright", "meta");
133 // s_website = *config.get<std::string>("website", "meta");
134 // s_editor_dir = *config.get<std::string>("editor_dir", "fs");
135 }
136
137 auto Settings::log_dir() noexcept -> const std::string&
138 {
139 static std::string log_dir = "logs/";
140 return log_dir;
141 }
142
143 auto Settings::window_width() noexcept -> int
144 {
145 return s_window_width;
146 }
147
148 auto Settings::window_height() noexcept -> int
149 {
150 return s_window_height;
151 }
152
153 auto Settings::title() noexcept -> const std::string&
154 {
155 return s_title;
156 }
157
158 auto Settings::vsync() noexcept -> bool
159 {
160 return s_vsync;
161 }
162
163 auto Settings::window_resizable() noexcept -> bool
164 {
165 return s_resizable;
166 }
167
168 auto Settings::decoration() noexcept -> bool
169 {
170 return s_decoration;
171 }
172
173 auto Settings::fullscreen() noexcept -> bool
174 {
175 return s_fullscreen;
176 }
177
178 auto Settings::maximized() noexcept -> bool
179 {
180 return s_maximized;
181 }
182
183 auto Settings::minimized() noexcept -> bool
184 {
185 return s_minimized;
186 }
187
188 auto Settings::borderless_fullscreen() noexcept -> bool
189 {
190 return s_borderless;
191 }
192
193 auto Settings::window_icon() noexcept -> const std::string&
194 {
195 return s_window_icon;
196 }
197
198 auto Settings::ontop() noexcept -> bool
199 {
200 return s_ontop;
201 }
202
203 auto Settings::root_dir() noexcept -> std::filesystem::path
204 {
205 return std::filesystem::current_path();
206 }
207
208 auto Settings::assets_dir() noexcept -> std::filesystem::path
209 {
210 return s_assets_dir;
211 }
212
213 auto Settings::asset_pack() noexcept -> const std::string&
214 {
215 return s_asset_pack;
216 }
217
218 auto Settings::use_loose_assets() noexcept -> bool
219 {
220 return s_use_loose_assets;
221 }
222
223 auto Settings::assets_dir_music() noexcept -> const std::string&
224 {
225 return s_assets_music;
226 }
227
228 auto Settings::assets_dir_sfx() noexcept -> const std::string&
229 {
230 return s_assets_sfx;
231 }
232
233 auto Settings::assets_dir_voice() noexcept -> const std::string&
234 {
235 return s_assets_voice;
236 }
237
238 auto Settings::assets_dir_font() noexcept -> const std::string&
239 {
240 return s_assets_font;
241 }
242
243 auto Settings::assets_dir_script() noexcept -> const std::string&
244 {
245 return s_assets_script;
246 }
247
248 auto Settings::assets_dir_shaders() noexcept -> const std::string&
249 {
250 return s_assets_shaders;
251 }
252
253 auto Settings::assets_dir_animation() noexcept -> const std::string&
254 {
255 return s_assets_animation;
256 }
257
258 auto Settings::assets_dir_texture() noexcept -> const std::string&
259 {
260 return s_assets_texture;
261 }
262
263 auto Settings::assets_dir_prefabs() noexcept -> const std::string&
264 {
265 return s_assets_prefabs;
266 }
267
268 auto Settings::assets_dir_maps() noexcept -> const std::string&
269 {
270 return s_assets_maps;
271 }
272
273 auto Settings::assets_dir_video() noexcept -> const std::string&
274 {
275 return s_assets_video;
276 }
277
278 auto Settings::assets_dir_ui() noexcept -> const std::string&
279 {
280 return s_assets_ui;
281 }
282
283 auto Settings::cursor_locked() noexcept -> bool
284 {
285 return s_cursor_locked;
286 }
287
288 auto Settings::cursor_show() noexcept -> bool
289 {
290 return s_cursor_show;
291 }
292} // namespace galaxy
293
294#ifdef GALAXY_WIN_PLATFORM
296#endif
297
298/*
299 auto Settings::cursor_icon() noexcept -> const std::string&
300 {
301 return s_cursor_icon;
302 }
303
304 auto Settings::cursor_hotspot() noexcept -> const glm::ivec2&
305 {
306 return s_cursor_hotspot;
307 }
308
309 auto Settings::audio_freq() noexcept -> int
310 {
311 return s_audio_freq;
312 }
313
314 auto Settings::ansiotrophy() noexcept -> int
315 {
316 return s_ansio;
317 }
318
319 auto Settings::mipmap() noexcept -> bool
320 {
321 return s_mipmap;
322 }
323
324 auto Settings::texture_filter() noexcept -> GLTextureFilter
325 {
326 return s_filtering;
327 }
328
329 auto Settings::max_quads() noexcept -> int
330 {
331 return s_max_quads;
332 }
333
334 auto Settings::version() noexcept -> const std::string&
335 {
336 return s_version;
337 }
338
339 auto Settings::identifier() noexcept -> const std::string&
340 {
341 return s_identifier;
342 }
343
344 auto Settings::creator() noexcept -> const std::string&
345 {
346 return s_creator;
347 }
348
349 auto Settings::copyright() noexcept -> const std::string&
350 {
351 return s_copyright;
352 }
353
354 auto Settings::website() noexcept -> const std::string&
355 {
356 return s_website;
357 }
358
359
360
361
362 auto Settings::editor_dir() noexcept -> std::filesystem::path
363 {
364 return s_editor_dir;
365 }
366
367
368*/
#define GALAXY_DISABLE_WARNING_POP
Definition Pragma.hpp:60
#define GALAXY_DISABLE_WARNING(x)
Definition Pragma.hpp:61
#define GALAXY_DISABLE_WARNING_PUSH
Macro for windows platform detection.
Definition Pragma.hpp:59
Application.hpp galaxy.
STL namespace.
static bool s_vsync
Definition Settings.hpp:286
static auto window_icon() noexcept -> const std::string &
Window icon file in vfs.
Definition Settings.cpp:193
static std::string s_asset_pack
Definition Settings.hpp:297
static auto root_dir() noexcept -> std::filesystem::path
Current root directory of application, unless it has been changed.
Definition Settings.cpp:203
static std::string s_title
Definition Settings.hpp:285
static std::string s_assets_video
Definition Settings.hpp:309
static std::string s_assets_prefabs
Definition Settings.hpp:307
static std::string s_assets_music
Definition Settings.hpp:299
static auto window_height() noexcept -> int
Window creation height.
Definition Settings.cpp:148
static auto log_dir() noexcept -> const std::string &
Current root directory of application, unless it has been changed.
Definition Settings.cpp:137
static auto fullscreen() noexcept -> bool
Is window started fullscreen.
Definition Settings.cpp:173
static auto assets_dir_prefabs() noexcept -> const std::string &
Prefab asset location.
Definition Settings.cpp:263
static auto assets_dir_texture() noexcept -> const std::string &
Textures asset location.
Definition Settings.cpp:258
static auto vsync() noexcept -> bool
Vsync control.
Definition Settings.cpp:158
static auto minimized() noexcept -> bool
Is window started minimized?
Definition Settings.cpp:183
static auto assets_dir_voice() noexcept -> const std::string &
Voice asset location.
Definition Settings.cpp:233
static auto cursor_locked() noexcept -> bool
Is the cursor grabbed.
Definition Settings.cpp:283
static int s_window_height
Definition Settings.hpp:284
static auto window_width() noexcept -> int
Window creation width.
Definition Settings.cpp:143
static bool s_use_loose_assets
Definition Settings.hpp:298
static auto assets_dir_shaders() noexcept -> const std::string &
Shaders asset location.
Definition Settings.cpp:248
static std::string s_assets_sfx
Definition Settings.hpp:300
static bool s_borderless
Definition Settings.hpp:292
static bool s_cursor_locked
Definition Settings.hpp:312
static std::string s_assets_script
Definition Settings.hpp:303
static auto assets_dir_ui() noexcept -> const std::string &
UI asset location.
Definition Settings.cpp:278
static auto set_settings_from_config() -> void
Set all our settings using the provided config file.
Definition Settings.cpp:80
static auto use_loose_assets() noexcept -> bool
Should asset data be read from pack or assets dir.
Definition Settings.cpp:218
static std::string s_assets_texture
Definition Settings.hpp:306
static bool s_resizable
Definition Settings.hpp:287
static auto assets_dir_animation() noexcept -> const std::string &
Animation data location.
Definition Settings.cpp:253
static auto assets_dir_script() noexcept -> const std::string &
Scripts asset location.
Definition Settings.cpp:243
static auto assets_dir_music() noexcept -> const std::string &
Music asset location.
Definition Settings.cpp:223
static bool s_decoration
Definition Settings.hpp:288
static int s_window_width
Definition Settings.hpp:283
static auto window_resizable() noexcept -> bool
Is the window resizable.
Definition Settings.cpp:163
static bool s_fullscreen
Definition Settings.hpp:289
static auto maximized() noexcept -> bool
Is window started maximized?
Definition Settings.cpp:178
static auto title() noexcept -> const std::string &
Game title.
Definition Settings.cpp:153
static std::string s_assets_voice
Definition Settings.hpp:301
static auto cursor_show() noexcept -> bool
Is the mouse cursor visible or not.
Definition Settings.cpp:288
static auto assets_dir() noexcept -> std::filesystem::path
Main data directory.
Definition Settings.cpp:208
static auto ontop() noexcept -> bool
Should the window always be on top.
Definition Settings.cpp:198
static auto asset_pack() noexcept -> const std::string &
Name of packed assets file.
Definition Settings.cpp:213
static std::filesystem::path s_assets_dir
Definition Settings.hpp:296
static auto borderless_fullscreen() noexcept -> bool
Is window in borderless fullscreen?
Definition Settings.cpp:188
static std::string s_assets_maps
Definition Settings.hpp:308
static auto assets_dir_sfx() noexcept -> const std::string &
SFX asset location.
Definition Settings.cpp:228
static auto assets_dir_maps() noexcept -> const std::string &
Maps asset location.
Definition Settings.cpp:268
static bool s_maximized
Definition Settings.hpp:290
static std::string s_assets_shaders
Definition Settings.hpp:304
static bool s_cursor_show
Definition Settings.hpp:313
static std::string s_assets_animation
Definition Settings.hpp:305
static auto set_config_to_default() -> void
Restore all config settings to default.
Definition Settings.cpp:23
static std::string s_assets_font
Definition Settings.hpp:302
static std::string s_assets_ui
Definition Settings.hpp:310
static auto assets_dir_video() noexcept -> const std::string &
Video asset location.
Definition Settings.cpp:273
static bool s_minimized
Definition Settings.hpp:291
static bool s_ontop
Definition Settings.hpp:294
static auto assets_dir_font() noexcept -> const std::string &
Font asset location.
Definition Settings.cpp:238
static auto decoration() noexcept -> bool
Controls if a window has a border around it (including titlebar).
Definition Settings.cpp:168
static std::string s_window_icon
Definition Settings.hpp:293