Skip to content

Commit 372f384

Browse files
committed
Fix setup
1 parent 99aadb2 commit 372f384

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

app/main.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,59 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd)
403403
// Main code
404404
int main(int, char**)
405405
{
406+
Zest::Profiler::Init();
407+
406408
// Setup SDL
407409
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD) != 0)
408410
{
409411
printf("Error: SDL_Init(): %s\n", SDL_GetError());
410412
return -1;
411413
}
412414

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+
413451
// Create window with Vulkan graphics context
414452
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);
416459
if (window == nullptr)
417460
{
418461
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
@@ -489,6 +532,9 @@ int main(int, char**)
489532
bool done = false;
490533
while (!done)
491534
{
535+
Zest::Profiler::NewFrame();
536+
PROFILE_NAME_THREAD(UI);
537+
492538
// Poll and handle events (inputs, window resize, etc.)
493539
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
494540
// - 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**)
586632
// Cleanup
587633
err = vkDeviceWaitIdle(g_Device);
588634
check_vk_result(err);
635+
636+
demo_cleanup();
637+
589638
ImGui_ImplVulkan_Shutdown();
590639
ImGui_ImplSDL3_Shutdown();
591640
ImGui::DestroyContext();
592641

593642
CleanupVulkanWindow();
594643
CleanupVulkan();
595644

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+
596652
SDL_DestroyWindow(window);
597653
SDL_Quit();
598654

655+
Zest::Profiler::Finish();
599656
return 0;
600657
}

0 commit comments

Comments
 (0)