Unravel Engine C++ Reference
Loading...
Searching...
No Matches
settings.cpp
Go to the documentation of this file.
1#include "settings.hpp"
2
3#include <fstream>
11
12namespace unravel
13{
14
16{
17 entt::meta_factory<settings::app_settings>{}
18 .type("app_settings"_hs)
20 entt::attribute{"name", "app_settings"},
21 entt::attribute{"pretty_name", "Application Settings"},
22 })
23 .data<&settings::app_settings::company>("company"_hs)
25 entt::attribute{"name", "company"},
26 entt::attribute{"pretty_name", "Company"},
27 entt::attribute{"tooltip", "Missing..."},
28 })
29 .data<&settings::app_settings::product>("product"_hs)
31 entt::attribute{"name", "product"},
32 entt::attribute{"pretty_name", "Product"},
33 entt::attribute{"tooltip", "Missing..."},
34 })
35 .data<&settings::app_settings::version>("version"_hs)
37 entt::attribute{"name", "version"},
38 entt::attribute{"pretty_name", "Version"},
39 entt::attribute{"tooltip", "Missing..."},
40 });
41}
42
44{
45 try_save(ar, ser20::make_nvp("company", obj.company));
46 try_save(ar, ser20::make_nvp("product", obj.product));
47 try_save(ar, ser20::make_nvp("version", obj.version));
48}
49
51{
52 try_load(ar, ser20::make_nvp("company", obj.company));
53 try_load(ar, ser20::make_nvp("product", obj.product));
54 try_load(ar, ser20::make_nvp("version", obj.version));
55}
56
57
59{
60 entt::meta_factory<settings::asset_settings::texture_importer_settings>{}
61 .type("texture_importer_settings"_hs)
63 entt::attribute{"name", "texture_importer_settings"},
64 entt::attribute{"pretty_name", "Texture Importer Settings"},
65 })
66 .data<&settings::asset_settings::texture_importer_settings::default_max_size>("default_max_size"_hs)
68 entt::attribute{"name", "default_max_size"},
69 entt::attribute{"pretty_name", "Default Max Size"},
70 entt::attribute{"tooltip", "The default maximum size for textures."},
71 })
72 .data<&settings::asset_settings::texture_importer_settings::default_compression>("default_compression"_hs)
74 entt::attribute{"name", "default_compression"},
75 entt::attribute{"pretty_name", "Default Compression"},
76 entt::attribute{"tooltip", "The default compression for textures."},
77 });
78}
79
81{
82 try_save(ar, ser20::make_nvp("default_max_size", obj.default_max_size));
83 try_save(ar, ser20::make_nvp("default_compression", obj.default_compression));
84}
85
87{
88 try_load(ar, ser20::make_nvp("default_max_size", obj.default_max_size));
89 try_load(ar, ser20::make_nvp("default_compression", obj.default_compression));
90}
91
93{
94 try_save(ar, ser20::make_nvp("texture", obj.texture));
95}
96
98{
99 try_load(ar, ser20::make_nvp("texture", obj.texture));
100}
101
102
104{
105 entt::meta_factory<settings::graphics_settings>{}
106 .type("graphics_settings"_hs)
108 entt::attribute{"name", "graphics_settings"},
109 entt::attribute{"pretty_name", "Graphics Settings"},
110 });
111}
112
114{
115 // try_save(ar, ser20::make_nvp("company", obj.company));
116 // try_save(ar, ser20::make_nvp("product", obj.product));
117 // try_save(ar, ser20::make_nvp("version", obj.version));
118}
119
121{
122 // try_load(ar, ser20::make_nvp("company", obj.company));
123 // try_load(ar, ser20::make_nvp("product", obj.product));
124 // try_load(ar, ser20::make_nvp("version", obj.version));
125}
126
128{
129
130 entt::meta_factory<settings::standalone_settings>{}
131 .type("standalone_settings"_hs)
133 entt::attribute{"name", "standalone_settings"},
134 entt::attribute{"pretty_name", "Standalone Settings"},
135 })
136 .data<&settings::standalone_settings::startup_scene>("startup_scene"_hs)
138 entt::attribute{"name", "startup_scene"},
139 entt::attribute{"pretty_name", "Startup Scene"},
140 entt::attribute{"tooltip", "The scene to load first."},
141 });
142}
143
145{
146 try_save(ar, ser20::make_nvp("startup_scene", obj.startup_scene));
147}
148
150{
151 try_load(ar, ser20::make_nvp("startup_scene", obj.startup_scene));
152}
153
155{
156 entt::meta_factory<settings::time_settings>{}
157 .type("time_settings"_hs)
159 entt::attribute{"name", "time_settings"},
160 entt::attribute{"pretty_name", "Time Settings"},
161 })
162 .data<&settings::time_settings::fixed_timestep>("fixed_timestep"_hs)
164 entt::attribute{"name", "fixed_timestep"},
165 entt::attribute{"pretty_name", "Fixed Timestep"},
166 entt::attribute{"step", 0.001f},
167 entt::attribute{"tooltip", "A framerate-idependent interval which dictates when physics calculations and FixedUpdate events are performed."},
168 })
169 .data<&settings::time_settings::max_fixed_steps>("max_fixed_steps"_hs)
171 entt::attribute{"name", "max_fixed_steps"},
172 entt::attribute{"pretty_name", "Max Fixed Steps"},
173 entt::attribute{"tooltip", "A cap for framerate-idependent worst case scenario. No more than this much fixed updates per frame."},
174 });
175}
176
178{
179 try_save(ar, ser20::make_nvp("fixed_timestep", obj.fixed_timestep));
180 try_save(ar, ser20::make_nvp("max_fixed_steps", obj.max_fixed_steps));
181}
182
184{
185 try_load(ar, ser20::make_nvp("fixed_timestep", obj.fixed_timestep));
186 try_load(ar, ser20::make_nvp("max_fixed_steps", obj.max_fixed_steps));
187}
188
190{
191 entt::meta_factory<settings::layer_settings>{}
192 .type("layer_settings"_hs)
194 entt::attribute{"name", "layer_settings"},
195 entt::attribute{"pretty_name", "Layer Settings"},
196 })
197 .data<&settings::layer_settings::layers>("layers"_hs)
199 entt::attribute{"name", "layers"},
200 entt::attribute{"pretty_name", "Layers"},
201 entt::attribute{"readonly_count", get_reserved_layers().size()},
202 entt::attribute{"tooltip", ""},
203 });
204}
205
207{
208 try_save(ar, ser20::make_nvp("layers", obj.layers));
209}
210
212{
213 try_load(ar, ser20::make_nvp("layers", obj.layers));
214}
215
217{
218 try_save(ar, ser20::make_nvp("actions", obj.actions));
219}
220
222{
223 try_load(ar, ser20::make_nvp("actions", obj.actions));
224}
225
226
228{
229 try_save(ar, ser20::make_nvp("name", obj.name));
230 try_save(ar, ser20::make_nvp("width", obj.width));
231 try_save(ar, ser20::make_nvp("height", obj.height));
232 try_save(ar, ser20::make_nvp("aspect", obj.aspect));
233}
234
236{
237 try_load(ar, ser20::make_nvp("name", obj.name));
238 try_load(ar, ser20::make_nvp("width", obj.width));
239 try_load(ar, ser20::make_nvp("height", obj.height));
240 try_load(ar, ser20::make_nvp("aspect", obj.aspect));
241}
242
244{
245 try_save(ar, ser20::make_nvp("resolutions", obj.resolutions));
246 try_save(ar, ser20::make_nvp("current_resolution", obj.current_resolution));
247}
248
250{
251 try_load(ar, ser20::make_nvp("resolutions", obj.resolutions));
252 try_load(ar, ser20::make_nvp("current_resolution", obj.current_resolution));
253}
254
256{
257 entt::meta_factory<settings::resolution_settings::resolution>{}
258 .type("resolution"_hs)
260 entt::attribute{"name", "resolution"},
261 entt::attribute{"pretty_name", "Resolution"},
262 })
263 .data<&settings::resolution_settings::resolution::name>("name"_hs)
265 entt::attribute{"name", "name"},
266 entt::attribute{"pretty_name", "Name"},
267 entt::attribute{"tooltip", "Display name for this resolution"},
268 })
269 .data<&settings::resolution_settings::resolution::width>("width"_hs)
271 entt::attribute{"name", "width"},
272 entt::attribute{"pretty_name", "Width"},
273 entt::attribute{"min", 0},
274 entt::attribute{"tooltip", "Width in pixels (0 for free aspect)"},
275 })
276 .data<&settings::resolution_settings::resolution::height>("height"_hs)
278 entt::attribute{"name", "height"},
279 entt::attribute{"pretty_name", "Height"},
280 entt::attribute{"min", 0},
281 entt::attribute{"tooltip", "Height in pixels (0 for free aspect)"},
282 })
283 .data<&settings::resolution_settings::resolution::aspect>("aspect"_hs)
285 entt::attribute{"name", "aspect"},
286 entt::attribute{"pretty_name", "Aspect Ratio"},
287 entt::attribute{"min", 0.0f},
288 entt::attribute{"tooltip", "Aspect ratio (0 for free aspect)"},
289 });
290}
291
293{
294 entt::meta_factory<settings::resolution_settings>{}
295 .type("resolution_settings"_hs)
297 entt::attribute{"name", "resolution_settings"},
298 entt::attribute{"pretty_name", "Resolution Settings"},
299 })
300 .data<&settings::resolution_settings::resolutions>("resolutions"_hs)
302 entt::attribute{"name", "resolutions"},
303 entt::attribute{"pretty_name", "Resolutions"},
304 entt::attribute{"tooltip", "List of available resolutions"},
305 })
306 .data<&settings::resolution_settings::current_resolution>("current_resolution"_hs)
308 entt::attribute{"name", "current_resolution"},
309 entt::attribute{"pretty_name", "Current Resolution"},
310 entt::attribute{"tooltip", "The current resolution to use"},
311 });
312}
313
315{
316
317 entt::meta_factory<settings>{}
318 .type("settings"_hs)
320 entt::attribute{"name", "settings"},
321 entt::attribute{"pretty_name", "Settings"},
322 })
323 .data<&settings::app>("app"_hs)
325 entt::attribute{"name", "app"},
326 entt::attribute{"pretty_name", "Application"},
327 entt::attribute{"tooltip", "Missing..."},
328 })
329 .data<&settings::graphics>("graphics"_hs)
331 entt::attribute{"name", "graphics"},
332 entt::attribute{"pretty_name", "Graphics"},
333 entt::attribute{"tooltip", "Missing..."},
334 })
335 .data<&settings::standalone>("standalone"_hs)
337 entt::attribute{"name", "standalone"},
338 entt::attribute{"pretty_name", "Standalone"},
339 entt::attribute{"tooltip", "Missing..."},
340 })
341 .data<&settings::resolution>("resolution"_hs)
343 entt::attribute{"name", "resolution"},
344 entt::attribute{"pretty_name", "Resolution"},
345 entt::attribute{"tooltip", "Resolution settings for the project"},
346 });
347}
348
350{
351 try_save(ar, ser20::make_nvp("app", obj.app));
352 try_save(ar, ser20::make_nvp("assets", obj.assets));
353 try_save(ar, ser20::make_nvp("graphics", obj.graphics));
354 try_save(ar, ser20::make_nvp("standalone", obj.standalone));
355 try_save(ar, ser20::make_nvp("layer", obj.layer));
356 try_save(ar, ser20::make_nvp("input", obj.input));
357 try_save(ar, ser20::make_nvp("time", obj.time));
358 try_save(ar, ser20::make_nvp("resolutions", obj.resolution));
359}
362
364{
365 try_load(ar, ser20::make_nvp("app", obj.app));
366 try_load(ar, ser20::make_nvp("assets", obj.assets));
367 try_load(ar, ser20::make_nvp("graphics", obj.graphics));
368 try_load(ar, ser20::make_nvp("standalone", obj.standalone));
369 try_load(ar, ser20::make_nvp("layer", obj.layer));
370 try_load(ar, ser20::make_nvp("input", obj.input));
371 try_load(ar, ser20::make_nvp("time", obj.time));
372 try_load(ar, ser20::make_nvp("resolutions", obj.resolution));
373}
376
377void save_to_file(const std::string& absolute_path, const settings& obj)
378{
379 std::ofstream stream(absolute_path);
380 if(stream.good())
381 {
382 auto ar = ser20::create_oarchive_associative(stream);
383 try_save(ar, ser20::make_nvp("settings", obj));
384 }
385}
386
387void save_to_file_bin(const std::string& absolute_path, const settings& obj)
388{
389 std::ofstream stream(absolute_path, std::ios::binary);
390 if(stream.good())
391 {
392 ser20::oarchive_binary_t ar(stream);
393 try_save(ar, ser20::make_nvp("settings", obj));
394 }
395}
396
397auto load_from_file(const std::string& absolute_path, settings& obj) -> bool
398{
399 std::ifstream stream(absolute_path);
400 if(stream.good())
401 {
402 auto ar = ser20::create_iarchive_associative(stream);
403 return try_load(ar, ser20::make_nvp("settings", obj));
404 }
405
406 return false;
407}
408
409auto load_from_file_bin(const std::string& absolute_path, settings& obj) -> bool
410{
411 std::ifstream stream(absolute_path, std::ios::binary);
412 if(stream.good())
413 {
414 ser20::iarchive_binary_t ar(stream);
415 return try_load(ar, ser20::make_nvp("settings", obj));
416 }
417
418 return false;
419}
420
421} // namespace unravel
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto create_oarchive_associative(std::ostream &stream)
BinaryInputArchive iarchive_binary_t
auto create_iarchive_associative(std::istream &stream)
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
auto get_reserved_layers() -> const std::vector< std::string > &
Definition layer_mask.cpp:6
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT(cls)
Definition reflection.h:133
#define REFLECT_INLINE(cls)
Definition reflection.h:128
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
#define LOAD_INLINE(cls)
#define SAVE_INLINE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool