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<eviction_settings>{}
106 .type("eviction_settings"_hs)
108 entt::attribute{"name", "eviction_settings"},
109 entt::attribute{"pretty_name", "GPU Eviction / Paging"},
110 })
111 .data<&eviction_settings::enabled>("enabled"_hs)
113 entt::attribute{"name", "enabled"},
114 entt::attribute{"pretty_name", "Enabled"},
115 entt::attribute{"tooltip", "Evict GPU resources each frame to keep memory under the budget. "
116 "Evicted resources are restored automatically on next use."},
117 })
118 .data<&eviction_settings::auto_budget>("auto_budget"_hs)
120 entt::attribute{"name", "auto_budget"},
121 entt::attribute{"pretty_name", "Auto Budget (GPU Memory)"},
122 entt::attribute{"tooltip", "Derive the budget from the backend's reported GPU memory. "
123 "Falls back to the manual budget when no limit is reported."},
124 })
125 .data<&eviction_settings::budget_fraction>("budget_fraction"_hs)
127 entt::attribute{"name", "budget_fraction"},
128 entt::attribute{"pretty_name", "Budget %"},
129 entt::attribute{"min", 0.1f},
130 entt::attribute{"max", 1.0f},
131 entt::attribute{"step", 0.01f},
132 entt::attribute{"tooltip", "Start evicting once GPU usage exceeds this fraction of the maximum."},
133 })
134 .data<&eviction_settings::target_fraction>("target_fraction"_hs)
136 entt::attribute{"name", "target_fraction"},
137 entt::attribute{"pretty_name", "Target %"},
138 entt::attribute{"min", 0.1f},
139 entt::attribute{"max", 1.0f},
140 entt::attribute{"step", 0.01f},
141 entt::attribute{"tooltip", "Evict down to this fraction of the maximum (hysteresis; keep < budget)."},
142 })
143 .data<&eviction_settings::manual_budget_mb>("manual_budget_mb"_hs)
145 entt::attribute{"name", "manual_budget_mb"},
146 entt::attribute{"pretty_name", "Manual Budget (MiB)"},
147 entt::attribute{"min", 16},
148 entt::attribute{"max", 1024*32},
149 entt::attribute{"tooltip", "Budget compared against evictable resident bytes when not using auto budget."},
150 })
151 .data<&eviction_settings::strategy>("strategy"_hs)
153 entt::attribute{"name", "strategy"},
154 entt::attribute{"pretty_name", "Strategy"},
155 entt::attribute{"min", 0},
156 entt::attribute{"max", 3},
157 entt::attribute{"tooltip", "Victim selection policy: 0=LRU, 1=LFU, 2=Largest first, 3=Age TTL."},
158 })
159 .data<&eviction_settings::min_age_frames>("min_age_frames"_hs)
161 entt::attribute{"name", "min_age_frames"},
162 entt::attribute{"pretty_name", "Min Age (frames)"},
163 entt::attribute{"min", 0},
164 entt::attribute{"max", 600},
165 entt::attribute{"tooltip", "Resources used within this many frames are never evicted (anti-thrash)."},
166 })
167 .data<&eviction_settings::max_evictions>("max_evictions"_hs)
169 entt::attribute{"name", "max_evictions"},
170 entt::attribute{"pretty_name", "Max Evictions / Frame"},
171 entt::attribute{"min", 0},
172 entt::attribute{"max", 1024},
173 entt::attribute{"tooltip", "Caps how many resources may be evicted per frame (0 = unlimited)."},
174 });
175}
176
178{
179 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
180 try_save(ar, ser20::make_nvp("auto_budget", obj.auto_budget));
181 try_save(ar, ser20::make_nvp("budget_fraction", obj.budget_fraction));
182 try_save(ar, ser20::make_nvp("target_fraction", obj.target_fraction));
183 try_save(ar, ser20::make_nvp("manual_budget_mb", obj.manual_budget_mb));
184 try_save(ar, ser20::make_nvp("strategy", obj.strategy));
185 try_save(ar, ser20::make_nvp("min_age_frames", obj.min_age_frames));
186 try_save(ar, ser20::make_nvp("max_evictions", obj.max_evictions));
187}
188
190{
191 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
192 try_load(ar, ser20::make_nvp("auto_budget", obj.auto_budget));
193 try_load(ar, ser20::make_nvp("budget_fraction", obj.budget_fraction));
194 try_load(ar, ser20::make_nvp("target_fraction", obj.target_fraction));
195 try_load(ar, ser20::make_nvp("manual_budget_mb", obj.manual_budget_mb));
196 try_load(ar, ser20::make_nvp("strategy", obj.strategy));
197 try_load(ar, ser20::make_nvp("min_age_frames", obj.min_age_frames));
198 try_load(ar, ser20::make_nvp("max_evictions", obj.max_evictions));
199}
200
202{
203 entt::meta_factory<settings::graphics_settings>{}
204 .type("graphics_settings"_hs)
206 entt::attribute{"name", "graphics_settings"},
207 entt::attribute{"pretty_name", "Graphics Settings"},
208 })
209 .data<&settings::graphics_settings::eviction>("eviction"_hs)
211 entt::attribute{"name", "eviction"},
212 entt::attribute{"pretty_name", "GPU Eviction / Paging"},
213 entt::attribute{"tooltip", "Controls automatic eviction/paging of GPU resources to stay under budget."},
214 });
215}
216
218{
219 try_save(ar, ser20::make_nvp("eviction", obj.eviction));
220}
221
223{
224 try_load(ar, ser20::make_nvp("eviction", obj.eviction));
225}
226
228{
229 entt::meta_factory<settings::splash_logo_entry>{}
230 .type("splash_logo_entry"_hs)
232 entt::attribute{"name", "splash_logo_entry"},
233 entt::attribute{"pretty_name", "Logo"},
234 })
235 .data<&settings::splash_logo_entry::logo>("logo"_hs)
237 entt::attribute{"name", "logo"},
238 entt::attribute{"pretty_name", "Logo"},
239 entt::attribute{"tooltip", "Texture asset displayed during the splash sequence."},
240 })
241 .data<&settings::splash_logo_entry::duration_sec>("duration_sec"_hs)
243 entt::attribute{"name", "duration_sec"},
244 entt::attribute{"pretty_name", "Duration (s)"},
245 entt::attribute{"min", 0.0f},
246 entt::attribute{"max", 30.0f},
247 entt::attribute{"step", 0.1f},
248 });
249}
250
252{
253 try_save(ar, ser20::make_nvp("logo", obj.logo));
254 try_save(ar, ser20::make_nvp("duration_sec", obj.duration_sec));
255}
256
258{
259 try_load(ar, ser20::make_nvp("logo", obj.logo));
260 try_load(ar, ser20::make_nvp("duration_sec", obj.duration_sec));
261}
262
264{
265 entt::meta_factory<settings::splash_settings>{}
266 .type("splash_settings"_hs)
268 entt::attribute{"name", "splash_settings"},
269 entt::attribute{"pretty_name", "Splash Screen"},
270 })
271 .data<&settings::splash_settings::enabled>("enabled"_hs)
273 entt::attribute{"name", "enabled"},
274 entt::attribute{"pretty_name", "Show Splash Screen"},
275 entt::attribute{"tooltip", "Display a splash screen when entering play mode before the game starts."},
276 })
277 .data<&settings::splash_settings::show_made_with>("show_made_with"_hs)
279 entt::attribute{"name", "show_made_with"},
280 entt::attribute{"pretty_name", "Show Made With Unravel"},
281 entt::attribute{"tooltip", "Append the engine branding logo to the splash sequence."},
282 })
283 .data<&settings::splash_settings::fade_in_sec>("fade_in_sec"_hs)
285 entt::attribute{"name", "fade_in_sec"},
286 entt::attribute{"pretty_name", "Fade In (s)"},
287 entt::attribute{"min", 0.0f},
288 entt::attribute{"max", 5.0f},
289 entt::attribute{"step", 0.05f},
290 })
291 .data<&settings::splash_settings::fade_out_sec>("fade_out_sec"_hs)
293 entt::attribute{"name", "fade_out_sec"},
294 entt::attribute{"pretty_name", "Fade Out (s)"},
295 entt::attribute{"min", 0.0f},
296 entt::attribute{"max", 5.0f},
297 entt::attribute{"step", 0.05f},
298 })
299 .data<&settings::splash_settings::logos>("logos"_hs)
301 entt::attribute{"name", "logos"},
302 entt::attribute{"pretty_name", "Logos"},
303 entt::attribute{"tooltip", "Project logos shown sequentially before play begins."},
304 });
305}
306
308{
309 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
310 try_save(ar, ser20::make_nvp("show_made_with", obj.show_made_with));
311 try_save(ar, ser20::make_nvp("fade_in_sec", obj.fade_in_sec));
312 try_save(ar, ser20::make_nvp("fade_out_sec", obj.fade_out_sec));
313 try_save(ar, ser20::make_nvp("logos", obj.logos));
314}
315
317{
318 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
319 try_load(ar, ser20::make_nvp("show_made_with", obj.show_made_with));
320 try_load(ar, ser20::make_nvp("fade_in_sec", obj.fade_in_sec));
321 try_load(ar, ser20::make_nvp("fade_out_sec", obj.fade_out_sec));
322 try_load(ar, ser20::make_nvp("logos", obj.logos));
323}
324
326{
327
328 entt::meta_factory<settings::standalone_settings>{}
329 .type("standalone_settings"_hs)
331 entt::attribute{"name", "standalone_settings"},
332 entt::attribute{"pretty_name", "Standalone Settings"},
333 })
334 .data<&settings::standalone_settings::startup_scene>("startup_scene"_hs)
336 entt::attribute{"name", "startup_scene"},
337 entt::attribute{"pretty_name", "Startup Scene"},
338 entt::attribute{"tooltip", "The scene to load first."},
339 });
340}
341
343{
344 try_save(ar, ser20::make_nvp("startup_scene", obj.startup_scene));
345}
346
348{
349 try_load(ar, ser20::make_nvp("startup_scene", obj.startup_scene));
350}
351
353{
354 entt::meta_factory<settings::time_settings>{}
355 .type("time_settings"_hs)
357 entt::attribute{"name", "time_settings"},
358 entt::attribute{"pretty_name", "Time Settings"},
359 })
360 .data<&settings::time_settings::fixed_timestep>("fixed_timestep"_hs)
362 entt::attribute{"name", "fixed_timestep"},
363 entt::attribute{"pretty_name", "Fixed Timestep"},
364 entt::attribute{"step", 0.001f},
365 entt::attribute{"tooltip", "A framerate-idependent interval which dictates when physics calculations and FixedUpdate events are performed."},
366 })
367 .data<&settings::time_settings::max_fixed_steps>("max_fixed_steps"_hs)
369 entt::attribute{"name", "max_fixed_steps"},
370 entt::attribute{"pretty_name", "Max Fixed Steps"},
371 entt::attribute{"tooltip", "A cap for framerate-idependent worst case scenario. No more than this much fixed updates per frame."},
372 });
373}
374
376{
377 try_save(ar, ser20::make_nvp("fixed_timestep", obj.fixed_timestep));
378 try_save(ar, ser20::make_nvp("max_fixed_steps", obj.max_fixed_steps));
379}
380
382{
383 try_load(ar, ser20::make_nvp("fixed_timestep", obj.fixed_timestep));
384 try_load(ar, ser20::make_nvp("max_fixed_steps", obj.max_fixed_steps));
385}
386
388{
389 entt::meta_factory<settings::layer_settings>{}
390 .type("layer_settings"_hs)
392 entt::attribute{"name", "layer_settings"},
393 entt::attribute{"pretty_name", "Layer Settings"},
394 })
395 .data<&settings::layer_settings::layers>("layers"_hs)
397 entt::attribute{"name", "layers"},
398 entt::attribute{"pretty_name", "Layers"},
399 entt::attribute{"readonly_count", get_reserved_layers().size()},
400 entt::attribute{"tooltip", ""},
401 });
402}
403
405{
406 try_save(ar, ser20::make_nvp("layers", obj.layers));
407}
408
410{
411 try_load(ar, ser20::make_nvp("layers", obj.layers));
412}
413
415{
416 try_save(ar, ser20::make_nvp("actions", obj.actions));
417}
418
420{
421 try_load(ar, ser20::make_nvp("actions", obj.actions));
422}
423
424
426{
427 try_save(ar, ser20::make_nvp("name", obj.name));
428 try_save(ar, ser20::make_nvp("width", obj.width));
429 try_save(ar, ser20::make_nvp("height", obj.height));
430 try_save(ar, ser20::make_nvp("aspect", obj.aspect));
431}
432
434{
435 try_load(ar, ser20::make_nvp("name", obj.name));
436 try_load(ar, ser20::make_nvp("width", obj.width));
437 try_load(ar, ser20::make_nvp("height", obj.height));
438 try_load(ar, ser20::make_nvp("aspect", obj.aspect));
439}
440
442{
443 try_save(ar, ser20::make_nvp("resolutions", obj.resolutions));
444 try_save(ar, ser20::make_nvp("current_resolution", obj.current_resolution));
445}
446
448{
449 try_load(ar, ser20::make_nvp("resolutions", obj.resolutions));
450 try_load(ar, ser20::make_nvp("current_resolution", obj.current_resolution));
451}
452
454{
455 entt::meta_factory<settings::resolution_settings::resolution>{}
456 .type("resolution"_hs)
458 entt::attribute{"name", "resolution"},
459 entt::attribute{"pretty_name", "Resolution"},
460 })
461 .data<&settings::resolution_settings::resolution::name>("name"_hs)
463 entt::attribute{"name", "name"},
464 entt::attribute{"pretty_name", "Name"},
465 entt::attribute{"tooltip", "Display name for this resolution"},
466 })
467 .data<&settings::resolution_settings::resolution::width>("width"_hs)
469 entt::attribute{"name", "width"},
470 entt::attribute{"pretty_name", "Width"},
471 entt::attribute{"min", 0},
472 entt::attribute{"tooltip", "Width in pixels (0 for free aspect)"},
473 })
474 .data<&settings::resolution_settings::resolution::height>("height"_hs)
476 entt::attribute{"name", "height"},
477 entt::attribute{"pretty_name", "Height"},
478 entt::attribute{"min", 0},
479 entt::attribute{"tooltip", "Height in pixels (0 for free aspect)"},
480 })
481 .data<&settings::resolution_settings::resolution::aspect>("aspect"_hs)
483 entt::attribute{"name", "aspect"},
484 entt::attribute{"pretty_name", "Aspect Ratio"},
485 entt::attribute{"min", 0.0f},
486 entt::attribute{"tooltip", "Aspect ratio (0 for free aspect)"},
487 });
488}
489
491{
492 entt::meta_factory<settings::resolution_settings>{}
493 .type("resolution_settings"_hs)
495 entt::attribute{"name", "resolution_settings"},
496 entt::attribute{"pretty_name", "Resolution Settings"},
497 })
498 .data<&settings::resolution_settings::resolutions>("resolutions"_hs)
500 entt::attribute{"name", "resolutions"},
501 entt::attribute{"pretty_name", "Resolutions"},
502 entt::attribute{"tooltip", "List of available resolutions"},
503 })
504 .data<&settings::resolution_settings::current_resolution>("current_resolution"_hs)
506 entt::attribute{"name", "current_resolution"},
507 entt::attribute{"pretty_name", "Current Resolution"},
508 entt::attribute{"tooltip", "The current resolution to use"},
509 });
510}
511
513{
514
515 entt::meta_factory<settings>{}
516 .type("settings"_hs)
518 entt::attribute{"name", "settings"},
519 entt::attribute{"pretty_name", "Settings"},
520 })
521 .data<&settings::app>("app"_hs)
523 entt::attribute{"name", "app"},
524 entt::attribute{"pretty_name", "Application"},
525 entt::attribute{"tooltip", "Missing..."},
526 })
527 .data<&settings::graphics>("graphics"_hs)
529 entt::attribute{"name", "graphics"},
530 entt::attribute{"pretty_name", "Graphics"},
531 entt::attribute{"tooltip", "Missing..."},
532 })
533 .data<&settings::splash>("splash"_hs)
535 entt::attribute{"name", "splash"},
536 entt::attribute{"pretty_name", "Splash Screen"},
537 entt::attribute{"tooltip", "Play mode splash screen shown before the game starts."},
538 })
539 .data<&settings::standalone>("standalone"_hs)
541 entt::attribute{"name", "standalone"},
542 entt::attribute{"pretty_name", "Standalone"},
543 entt::attribute{"tooltip", "Missing..."},
544 })
545 .data<&settings::resolution>("resolution"_hs)
547 entt::attribute{"name", "resolution"},
548 entt::attribute{"pretty_name", "Resolution"},
549 entt::attribute{"tooltip", "Resolution settings for the project"},
550 });
551}
552
554{
555 try_save(ar, ser20::make_nvp("app", obj.app));
556 try_save(ar, ser20::make_nvp("assets", obj.assets));
557 try_save(ar, ser20::make_nvp("graphics", obj.graphics));
558 try_save(ar, ser20::make_nvp("splash", obj.splash));
559 try_save(ar, ser20::make_nvp("standalone", obj.standalone));
560 try_save(ar, ser20::make_nvp("layer", obj.layer));
561 try_save(ar, ser20::make_nvp("input", obj.input));
562 try_save(ar, ser20::make_nvp("time", obj.time));
563 try_save(ar, ser20::make_nvp("resolutions", obj.resolution));
564}
567
569{
570 try_load(ar, ser20::make_nvp("app", obj.app));
571 try_load(ar, ser20::make_nvp("assets", obj.assets));
572 try_load(ar, ser20::make_nvp("graphics", obj.graphics));
573 try_load(ar, ser20::make_nvp("splash", obj.splash));
574 try_load(ar, ser20::make_nvp("standalone", obj.standalone));
575 try_load(ar, ser20::make_nvp("layer", obj.layer));
576 try_load(ar, ser20::make_nvp("input", obj.input));
577 try_load(ar, ser20::make_nvp("time", obj.time));
578 try_load(ar, ser20::make_nvp("resolutions", obj.resolution));
579}
582
583void save_to_file(const std::string& absolute_path, const settings& obj)
584{
585 std::ofstream stream(absolute_path);
586 if(stream.good())
587 {
588 auto ar = ser20::create_oarchive_associative(stream);
589 try_save(ar, ser20::make_nvp("settings", obj));
590 }
591}
592
593void save_to_file_bin(const std::string& absolute_path, const settings& obj)
594{
595 std::ofstream stream(absolute_path, std::ios::binary);
596 if(stream.good())
597 {
598 ser20::oarchive_binary_t ar(stream);
599 try_save(ar, ser20::make_nvp("settings", obj));
600 }
601}
602
603auto load_from_file(const std::string& absolute_path, settings& obj) -> bool
604{
605 std::ifstream stream(absolute_path);
606 if(stream.good())
607 {
608 auto ar = ser20::create_iarchive_associative(stream);
609 return try_load(ar, ser20::make_nvp("settings", obj));
610 }
611
612 return false;
613}
614
615auto load_from_file_bin(const std::string& absolute_path, settings& obj) -> bool
616{
617 std::ifstream stream(absolute_path, std::ios::binary);
618 if(stream.good())
619 {
620 ser20::iarchive_binary_t ar(stream);
621 return try_load(ar, ser20::make_nvp("settings", obj));
622 }
623
624 return false;
625}
626
627} // 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:149
#define REFLECT_INLINE(cls)
Definition reflection.h:144
#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
Definition settings.h:43