@@ -403,16 +403,59 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd)
403
403
// Main code
404
404
int main (int , char **)
405
405
{
406
+ Zest::Profiler::Init ();
407
+
406
408
// Setup SDL
407
409
if (!SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMEPAD) != 0 )
408
410
{
409
411
printf (" Error: SDL_Init(): %s\n " , SDL_GetError ());
410
412
return -1 ;
411
413
}
412
414
415
+ Zest::runtree_init (SDL_GetBasePath (), ZING_ROOT);
416
+ auto settings_path = Zest::file_init_settings (" zing" , Zest::runtree_find_path (" settings/settings.toml" ), fs::path (" settings" ) / " settings.toml" );
417
+ auto im_settings_path = Zest::file_init_settings (" zing" , Zest::runtree_find_path (" settings/imgui.ini" ), fs::path (" settings" ) / " imgui.ini" );
418
+ auto & settings = Zest::GlobalSettingsManager::Instance ();
419
+ Zing::audio_add_settings_hooks ();
420
+ settings.Load (settings_path);
421
+
422
+ auto windowSize = settings.GetVec2f (Zest::g_window, Zest::s_windowSize);
423
+ auto windowPosition = settings.GetVec2i (Zest::g_window, Zest::s_windowPosition);
424
+
425
+ if (windowSize.x == 0 || windowSize.y == 0 )
426
+ {
427
+ windowSize.x = 1280 ;
428
+ windowSize.y = 720 ;
429
+ }
430
+
431
+ if (windowPosition.x == 0 || windowPosition.y == 0 )
432
+ {
433
+ windowPosition.x = SDL_WINDOWPOS_CENTERED;
434
+ windowPosition.y = SDL_WINDOWPOS_CENTERED;
435
+ }
436
+
437
+ int count = 0 ;
438
+ auto pDisplays = SDL_GetDisplays (&count);
439
+
440
+ if (count > 0 )
441
+ {
442
+ auto display = pDisplays[0 ];
443
+ SDL_Rect bounds;
444
+ SDL_GetDisplayBounds (display, &bounds);
445
+ windowSize.x = std::clamp (windowSize.x , 100 .0f , float (bounds.w ));
446
+ windowSize.y = std::clamp (windowSize.y , 100 .0f , float (bounds.h ));
447
+ }
448
+
449
+ bool max = settings.GetBool (Zest::g_window, Zest::b_windowMaximized);
450
+
413
451
// Create window with Vulkan graphics context
414
452
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN);
415
- SDL_Window* window = SDL_CreateWindow (" Dear ImGui SDL3+Vulkan example" , 1280 , 720 , window_flags);
453
+ if (max)
454
+ {
455
+ window_flags |= SDL_WINDOW_MAXIMIZED;
456
+ }
457
+
458
+ SDL_Window* window = SDL_CreateWindow (" Dear ImGui SDL3+Vulkan example" , int (windowSize.x ), int (windowSize.y ), window_flags);
416
459
if (window == nullptr )
417
460
{
418
461
printf (" Error: SDL_CreateWindow(): %s\n " , SDL_GetError ());
@@ -489,6 +532,9 @@ int main(int, char**)
489
532
bool done = false ;
490
533
while (!done)
491
534
{
535
+ Zest::Profiler::NewFrame ();
536
+ PROFILE_NAME_THREAD (UI);
537
+
492
538
// Poll and handle events (inputs, window resize, etc.)
493
539
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
494
540
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
@@ -586,15 +632,26 @@ int main(int, char**)
586
632
// Cleanup
587
633
err = vkDeviceWaitIdle (g_Device);
588
634
check_vk_result (err);
635
+
636
+ demo_cleanup ();
637
+
589
638
ImGui_ImplVulkan_Shutdown ();
590
639
ImGui_ImplSDL3_Shutdown ();
591
640
ImGui::DestroyContext ();
592
641
593
642
CleanupVulkanWindow ();
594
643
CleanupVulkan ();
595
644
645
+ SDL_GetWindowSize (window, &w, &h);
646
+ settings.Set (Zest::g_window, Zest::s_windowSize, glm::vec2 (w, h));
647
+
648
+ SDL_GetWindowPosition (window, &w, &h);
649
+ settings.Set (Zest::g_window, Zest::s_windowPosition, glm::ivec2 (w, h));
650
+ settings.Set (Zest::g_window, Zest::b_windowMaximized, bool (SDL_GetWindowFlags (window) & SDL_WINDOW_MAXIMIZED));
651
+
596
652
SDL_DestroyWindow (window);
597
653
SDL_Quit ();
598
654
655
+ Zest::Profiler::Finish ();
599
656
return 0 ;
600
657
}
0 commit comments