From ec68583a4b60546b8e9272acea9916835aaf0b57 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 19:48:02 -0500 Subject: [PATCH 1/9] Merge latest LUS --- src/graphic/Fast3D/Fast3dWindow.cpp | 44 ++++++- src/graphic/Fast3D/Fast3dWindow.h | 5 + src/graphic/Fast3D/gfx_dxgi.cpp | 123 +++++++++++++------- src/graphic/Fast3D/gfx_sdl2.cpp | 109 ++++++++++++----- src/graphic/Fast3D/gfx_window_manager_api.h | 8 ++ src/window/Window.h | 12 ++ 6 files changed, 224 insertions(+), 77 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 44ba7a416..798454578 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -62,13 +62,14 @@ void Fast3dWindow::Init() { uint32_t width, height; int32_t posX, posY; - isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", false) || gameMode; + isFullscreen = + Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; posX = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", 100); posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); if (isFullscreen) { - width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", gameMode ? 1280 : 1920); - height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", gameMode ? 800 : 1080); + width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", 1920); + height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", 1080); } else { width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Width", 640); height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Height", 480); @@ -162,7 +163,7 @@ uint32_t Fast3dWindow::GetWidth() { uint32_t width, height; int32_t posX, posY; mWindowManagerApi->get_dimensions(&width, &height, &posX, &posY); - return width; + return width; } uint32_t Fast3dWindow::GetHeight() { @@ -172,6 +173,39 @@ uint32_t Fast3dWindow::GetHeight() { return height; } +void Fast3dWindow::SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) { + mWindowManagerApi->set_dimensions(width, height, posX, posY); + SaveWindowToConfig(); +} + +void Fast3dWindow::SetCurrentDimensions(uint32_t width, uint32_t height) { + SetCurrentDimensions(width, height, GetPosX(), GetPosY()); +} + +void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) { + auto conf = Ship::Context::GetInstance()->GetConfig(); + if (!isFullscreen) { + conf->SetInt("Window.Width", (int32_t)width); + conf->SetInt("Window.Height", (int32_t)height); + conf->SetInt("Window.PositionX", posX); + conf->SetInt("Window.PositionY", posY); + } else { + conf->SetInt("Window.Fullscreen.Width", (int32_t)width); + conf->SetInt("Window.Fullscreen.Height", (int32_t)height); + } + mWindowManagerApi->set_fullscreen(isFullscreen); + mWindowManagerApi->set_dimensions(width, height, posX, posY); + SaveWindowToConfig(); +} + +void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) { + SetCurrentDimensions(isFullscreen, width, height, GetPosX(), GetPosY()); +} + +Ship::WindowRect Fast3dWindow::GetPrimaryMonitorRect() { + return mWindowManagerApi->get_primary_monitor_rect(); +} + int32_t Fast3dWindow::GetPosX() { uint32_t width, height; int32_t posX, posY; @@ -248,8 +282,8 @@ void Fast3dWindow::SetMsaaLevel(uint32_t value) { } void Fast3dWindow::SetFullscreen(bool isFullscreen) { - SaveWindowToConfig(); mWindowManagerApi->set_fullscreen(isFullscreen); + SaveWindowToConfig(); } bool Fast3dWindow::IsFullscreen() { diff --git a/src/graphic/Fast3D/Fast3dWindow.h b/src/graphic/Fast3D/Fast3dWindow.h index 86676cf9d..254a2b2c6 100644 --- a/src/graphic/Fast3D/Fast3dWindow.h +++ b/src/graphic/Fast3D/Fast3dWindow.h @@ -19,6 +19,11 @@ class Fast3dWindow : public Ship::Window { void SetCursorVisibility(bool visible) override; uint32_t GetWidth() override; uint32_t GetHeight() override; + void SetCurrentDimensions(uint32_t width, uint32_t height) override; + void SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) override; + void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) override; + void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) override; + Ship::WindowRect GetPrimaryMonitorRect() override; int32_t GetPosX() override; int32_t GetPosY() override; void SetMousePos(Ship::Coords pos) override; diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index b607bffc5..2db8720b8 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -77,6 +77,8 @@ static struct { bool dropped_frame; std::tuple h_Monitor; // 0: Handle, 1: Display Monitor Rect, 2: Is_Primary std::vector> monitor_list; + std::vector monitor_rects; + size_t primary_monitor_index; bool zero_latency; double detected_hz; double display_period; // (1000 / dxgi.detected_hz) in ms @@ -128,37 +130,46 @@ static void apply_maximum_frame_latency(bool first) { dxgi.applied_maximum_frame_latency = dxgi.maximum_frame_latency; } -std::vector> GetMonitorList() { - std::vector> monitors; +void UpdateMonitorList() { + dxgi.monitor_list.clear(); + dxgi.monitor_rects.clear(); EnumDisplayMonitors( nullptr, nullptr, [](HMONITOR hmon, HDC hdc, LPRECT rc, LPARAM lp) { UNREFERENCED_PARAMETER(hdc); UNREFERENCED_PARAMETER(rc); + UNREFERENCED_PARAMETER(lp); bool isPrimary; MONITORINFOEX mi = {}; mi.cbSize = sizeof(MONITORINFOEX); GetMonitorInfo(hmon, &mi); - auto monitors = (std::vector>*)lp; if (mi.dwFlags == MONITORINFOF_PRIMARY) { isPrimary = TRUE; } else { isPrimary = FALSE; } - monitors->push_back({ hmon, mi.rcMonitor, isPrimary }); + + dxgi.monitor_list.push_back({ hmon, mi.rcMonitor, isPrimary }); + dxgi.monitor_rects.push_back( + { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom} + ); + if (isPrimary) { + dxgi.primary_monitor_index = dxgi.monitor_rects.size() - 1; + } + return TRUE; }, - (LPARAM)&monitors); - return monitors; + (LPARAM)nullptr + ); } // Uses coordinates to get a Monitor handle from a list -bool GetMonitorAtCoords(std::vector> MonitorList, int x, int y, UINT cx, UINT cy, +bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, std::tuple& MonitorInfo) { RECT wr = { x, y, (x + cx), (y + cy) }; std::tuple primary; - for (std::tuple i : MonitorList) { + for (std::tuple i : dxgi.monitor_list) { if (PtInRect(&get<1>(i), POINT((x + (cx / 2)), (y + (cy / 2))))) { MonitorInfo = i; return true; @@ -171,7 +182,7 @@ bool GetMonitorAtCoords(std::vector> MonitorLis LONG area; LONG lastArea = 0; std::tuple biggest; - for (std::tuple i : MonitorList) { + for (std::tuple i : dxgi.monitor_list) { if (IntersectRect(&intersection, &get<1>(i), &wr)) { area = (intersection.right - intersection.left) * (intersection.bottom - intersection.top); if (area > lastArea) { @@ -188,6 +199,34 @@ bool GetMonitorAtCoords(std::vector> MonitorLis return false; } +static void apply_window_dimensions() { + RECT wr = { dxgi.posX, dxgi.posY, dxgi.posX + static_cast(dxgi.current_width), + dxgi.posY + static_cast(dxgi.current_height) }; + if (!dxgi.is_full_screen) { + // Set in window mode with the last saved position and size + SetWindowLongPtr(dxgi.h_wnd, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW); + + if (dxgi.last_maximized_state) { + SetWindowPos(dxgi.h_wnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); + ShowWindow(dxgi.h_wnd, SW_MAXIMIZE); + } else { + AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); + SetWindowPos(dxgi.h_wnd, NULL, wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top, SWP_FRAMECHANGED); + ShowWindow(dxgi.h_wnd, SW_RESTORE); + } + } else { + // Save if window is maximized or not + WINDOWPLACEMENT window_placement; + window_placement.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(dxgi.h_wnd, &window_placement); + dxgi.last_maximized_state = window_placement.showCmd == SW_SHOWMAXIMIZED; + + // Set borderless full screen to that monitor + SetWindowLongPtr(dxgi.h_wnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); + SetWindowPos(dxgi.h_wnd, HWND_TOP, wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top, SWP_FRAMECHANGED); + } +} + static void toggle_borderless_window_full_screen(bool enable, bool call_callback) { // Windows 7 + flip mode + waitable object can't go to exclusive fullscreen, // so do borderless instead. If DWM is enabled, this means we get one monitor @@ -198,52 +237,37 @@ static void toggle_borderless_window_full_screen(bool enable, bool call_callback return; } - if (!enable) { - // Set in window mode with the last saved position and size - SetWindowLongPtr(dxgi.h_wnd, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW); + auto conf = Ship::Context::GetInstance()->GetConfig(); - if (dxgi.last_maximized_state) { - SetWindowPos(dxgi.h_wnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE); - ShowWindow(dxgi.h_wnd, SW_MAXIMIZE); - } else { + if (!enable) { + if (!dxgi.last_maximized_state) { std::tuple Monitor; - auto conf = Ship::Context::GetInstance()->GetConfig(); dxgi.current_width = conf->GetInt("Window.Width", 640); dxgi.current_height = conf->GetInt("Window.Height", 480); dxgi.posX = conf->GetInt("Window.PositionX", 100); dxgi.posY = conf->GetInt("Window.PositionY", 100); - if (!GetMonitorAtCoords(dxgi.monitor_list, dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, Monitor)) { // Fallback to default when out of bounds. dxgi.posX = 100; dxgi.posY = 100; } - RECT wr = { dxgi.posX, dxgi.posY, dxgi.posX + static_cast(dxgi.current_width), - dxgi.posY + static_cast(dxgi.current_height) }; - AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); - SetWindowPos(dxgi.h_wnd, NULL, wr.left, wr.top, wr.right - wr.left, wr.bottom - wr.top, SWP_FRAMECHANGED); - ShowWindow(dxgi.h_wnd, SW_RESTORE); } - - dxgi.is_full_screen = false; } else { + dxgi.current_width = conf->GetInt("Window.Fullscreen.Width", 1920); + dxgi.current_height = conf->GetInt("Window.Fullscreen.Height", 1080); + dxgi.posX = 0; + dxgi.posY = 0; + // Save if window is maximized or not WINDOWPLACEMENT window_placement; window_placement.length = sizeof(WINDOWPLACEMENT); GetWindowPlacement(dxgi.h_wnd, &window_placement); dxgi.last_maximized_state = window_placement.showCmd == SW_SHOWMAXIMIZED; + } - // We already know on what monitor we are (gets it on init or move) - // Get info from that monitor - RECT r = get<1>(dxgi.h_Monitor); + dxgi.is_full_screen = enable; - // Set borderless full screen to that monitor - SetWindowLongPtr(dxgi.h_wnd, GWL_STYLE, WS_VISIBLE | WS_POPUP); - // OTRTODO: This should be setting the resolution from config. - dxgi.current_width = r.right - r.left; - dxgi.current_height = r.bottom - r.top; - SetWindowPos(dxgi.h_wnd, HWND_TOP, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_FRAMECHANGED); - dxgi.is_full_screen = true; - } + apply_window_dimensions(); if (dxgi.on_fullscreen_changed != nullptr && call_callback) { dxgi.on_fullscreen_changed(enable); @@ -344,7 +368,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_SIZE: dxgi.current_width = LOWORD(l_param); dxgi.current_height = HIWORD(l_param); - GetMonitorAtCoords(dxgi.monitor_list, dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; @@ -354,7 +378,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_MOVE: dxgi.posX = GET_X_LPARAM(l_param); dxgi.posY = GET_Y_LPARAM(l_param); - GetMonitorAtCoords(dxgi.monitor_list, dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; @@ -433,8 +457,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; case WM_DISPLAYCHANGE: - dxgi.monitor_list = GetMonitorList(); - GetMonitorAtCoords(dxgi.monitor_list, dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + UpdateMonitorList(); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor); GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); break; @@ -502,10 +526,10 @@ void gfx_dxgi_init(const char* game_name, const char* gfx_api_name, bool start_i AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); dxgi.current_width = wr.right - wr.left; dxgi.current_height = wr.bottom - wr.top; - dxgi.monitor_list = GetMonitorList(); + UpdateMonitorList(); dxgi.posX = posX; dxgi.posY = posY; - if (!GetMonitorAtCoords(dxgi.monitor_list, dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor)) { dxgi.posX = 100; dxgi.posY = 100; @@ -643,6 +667,19 @@ static void gfx_dxgi_get_dimensions(uint32_t* width, uint32_t* height, int32_t* *posY = dxgi.posY; } +static void gfx_dxgi_set_dimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) { + dxgi.current_width = width; + dxgi.current_height = height; + dxgi.posX = posX; + dxgi.posY = posY; + + apply_window_dimensions(); +} + +static Ship::WindowRect gfx_dxgi_get_primary_monitor_rect() { + return dxgi.monitor_rects[dxgi.primary_monitor_index]; +} + static void gfx_dxgi_handle_events() { MSG msg; while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { @@ -1057,6 +1094,8 @@ extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = { gfx_dxgi_init, gfx_dxgi_set_mouse_capture, gfx_dxgi_is_mouse_captured, gfx_dxgi_get_dimensions, + gfx_dxgi_set_dimensions, + gfx_dxgi_get_primary_monitor_rect, gfx_dxgi_handle_events, gfx_dxgi_start_frame, gfx_dxgi_swap_buffers_begin, diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index a4027d647..54f12399f 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -49,6 +49,8 @@ static float mouse_wheel_y = 0.0f; // OTRTODO: These are redundant. Info can be queried from SDL. static int window_width = DESIRED_SCREEN_WIDTH; static int window_height = DESIRED_SCREEN_HEIGHT; +static int window_posx = 100; +static int window_posy = 100; static bool fullscreen_state; static bool is_running = true; static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); @@ -57,6 +59,8 @@ static bool (*on_key_up_callback)(int scancode); static void (*on_all_keys_up_callback)(); static bool (*on_mouse_button_down_callback)(int btn); static bool (*on_mouse_button_up_callback)(int btn); +static void (*on_all_keys_up_callback)(void); +static void gfx_sdl_set_dimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY); #ifdef _WIN32 LONG_PTR SDL_WndProc; @@ -220,45 +224,64 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { { SDL_SCANCODE_KP_7, S { SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE }, { SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN } }; -static void set_fullscreen(bool on, bool call_callback) { - if (fullscreen_state == on) { - return; - } - int display_in_use = SDL_GetWindowDisplayIndex(wnd); - if (display_in_use < 0) { - SPDLOG_WARN("Can't detect on which monitor we are. Probably out of display area?"); - SPDLOG_WARN(SDL_GetError()); - } - if (on) { - // OTRTODO: Get mode from config. +static void apply_window_dimensions() { + if (fullscreen_state) { SDL_DisplayMode mode; + + int display_in_use = SDL_GetWindowDisplayIndex(wnd); + if (display_in_use < 0) { + SPDLOG_WARN("Can't detect on which monitor we are. Probably out of display area? ({})", SDL_GetError()); + } + if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { - SDL_SetWindowDisplayMode(wnd, &mode); + mode.w = window_width; + mode.h = window_height; + mode.driverdata = nullptr; + mode.format = 0; + mode.refresh_rate = 0; + + if (SDL_SetWindowDisplayMode(wnd, &mode) != 0) { + SPDLOG_ERROR("Failed to set SDL Window display Mode: ({})", SDL_GetError()); + } + } else { - SPDLOG_ERROR(SDL_GetError()); + SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } } else { - auto conf = Ship::Context::GetInstance()->GetConfig(); + SDL_SetWindowPosition(wnd, window_posx, window_posy); + SDL_SetWindowSize(wnd, window_width, window_height); + } +} + +static void set_fullscreen(bool on, bool call_callback) { + if (fullscreen_state == on) { + return; + } + + auto conf = Ship::Context::GetInstance()->GetConfig(); + if (!on) { window_width = conf->GetInt("Window.Width", 640); window_height = conf->GetInt("Window.Height", 480); - int32_t posX = conf->GetInt("Window.PositionX", 100); - int32_t posY = conf->GetInt("Window.PositionY", 100); - if (display_in_use < 0) { // Fallback to default if out of bounds - posX = 100; - posY = 100; - } - SDL_SetWindowPosition(wnd, posX, posY); - SDL_SetWindowSize(wnd, window_width, window_height); + window_posx = conf->GetInt("Window.PositionX", 100); + window_posy = conf->GetInt("Window.PositionY", 100); + } else { + window_width = conf->GetInt("Window.Fullscreen.Width", 1920); + window_height = conf->GetInt("Window.Fullscreen.Height", 1080); + window_posx = 0; + window_posy = 0; } + + SDL_SetCursor(SDL_DISABLE); + bool original_state = fullscreen_state; + fullscreen_state = on; + apply_window_dimensions(); if (SDL_SetWindowFullscreen(wnd, on ? (CVarGetInteger(CVAR_SDL_WINDOWED_FULLSCREEN, 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN) - : 0) >= 0) { - fullscreen_state = on; - } else { - SPDLOG_ERROR("Failed to switch from or to fullscreen mode."); - SPDLOG_ERROR(SDL_GetError()); + : 0) != 0) { + fullscreen_state = original_state; + SPDLOG_ERROR("Failed to switch from or to fullscreen mode {}.", SDL_GetError()); } if (on_fullscreen_changed_callback != NULL && call_callback) { @@ -311,9 +334,6 @@ static LRESULT CALLBACK gfx_sdl_wnd_proc(HWND h_wnd, UINT message, WPARAM w_para static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool start_in_fullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) { - window_width = width; - window_height = height; - #if SDL_VERSION_ATLEAST(2, 24, 0) /* fix DPI scaling issues on Windows */ SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS, "permonitorv2"); @@ -386,6 +406,8 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s posY = 100; } + gfx_sdl_set_dimensions(width, height, posX, posY); + if (use_opengl) { SDL_GL_GetDrawableSize(wnd, &window_width, &window_height); @@ -494,6 +516,31 @@ static void gfx_sdl_get_dimensions(uint32_t* width, uint32_t* height, int32_t* p SDL_GetWindowPosition(wnd, static_cast(posX), static_cast(posY)); } +static void gfx_sdl_set_dimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) { + window_width = width; + window_height = height; + window_posx = posX; + window_posy = posY; + + apply_window_dimensions(); +} + +static Ship::WindowRect gfx_sdl_get_primary_monitor_rect() { + SDL_DisplayMode mode; + + int display_in_use = SDL_GetWindowDisplayIndex(wnd); + if (display_in_use < 0) { + SPDLOG_WARN("Can't detect on which monitor we are. Probably out of display area? ({})", SDL_GetError()); + } + + if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { + return {0, 0, mode.w, mode.h}; + } else { + SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); + } + return { 0, 0, 0, 0 }; +} + static int translate_scancode(int scancode) { if (scancode < 512) { return sdl_to_lus_table[scancode]; @@ -708,6 +755,8 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init, gfx_sdl_set_mouse_capture, gfx_sdl_is_mouse_captured, gfx_sdl_get_dimensions, + gfx_sdl_set_dimensions, + gfx_sdl_get_primary_monitor_rect, gfx_sdl_handle_events, gfx_sdl_start_frame, gfx_sdl_swap_buffers_begin, diff --git a/src/graphic/Fast3D/gfx_window_manager_api.h b/src/graphic/Fast3D/gfx_window_manager_api.h index 9fd3555db..050776474 100644 --- a/src/graphic/Fast3D/gfx_window_manager_api.h +++ b/src/graphic/Fast3D/gfx_window_manager_api.h @@ -1,6 +1,7 @@ #ifndef GFX_WINDOW_MANAGER_API_H #define GFX_WINDOW_MANAGER_API_H +#include "window/Window.h" #include #include @@ -28,6 +29,13 @@ struct GfxWindowManagerAPI { void (*swap_buffers_begin)(); void (*swap_buffers_end)(); double (*get_time)(); // For debug + void (*set_dimensions)(uint32_t width, uint32_t height, int32_t posX, int32_t posY); + Ship::WindowRect (*get_primary_monitor_rect)(void); + void (*handle_events)(void); + bool (*start_frame)(void); + void (*swap_buffers_begin)(void); + void (*swap_buffers_end)(void); + double (*get_time)(void); // For debug void (*set_target_fps)(int fps); void (*set_maximum_frame_latency)(int latency); const char* (*get_key_name)(int scancode); diff --git a/src/window/Window.h b/src/window/Window.h index 708b29bfe..9894d57dd 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -22,6 +22,13 @@ struct CoordsF { float y; }; +struct WindowRect { + int32_t Left; + int32_t Top; + int32_t Right; + int32_t Bottom; +}; + class Config; class Window { @@ -39,6 +46,11 @@ class Window { virtual void SetCursorVisibility(bool visible) = 0; virtual uint32_t GetWidth() = 0; virtual uint32_t GetHeight() = 0; + virtual void SetCurrentDimensions(uint32_t width, uint32_t height) = 0; + virtual void SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; + virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) = 0; + virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; + virtual WindowRect GetPrimaryMonitorRect() = 0; virtual int32_t GetPosX() = 0; virtual int32_t GetPosY() = 0; virtual void SetMousePos(Coords pos) = 0; From 2e096476a00c42fb1af9335bbaa805011560412e Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 19:58:32 -0500 Subject: [PATCH 2/9] Run clang-format --- src/graphic/Fast3D/Fast3dWindow.cpp | 8 ++++---- src/graphic/Fast3D/gfx_direct3d12.cpp | 8 ++++---- src/graphic/Fast3D/gfx_dxgi.cpp | 23 ++++++++--------------- src/graphic/Fast3D/gfx_sdl2.cpp | 7 +++---- src/window/Window.h | 3 ++- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 798454578..e134f464b 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -62,8 +62,7 @@ void Fast3dWindow::Init() { uint32_t width, height; int32_t posX, posY; - isFullscreen = - Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; + isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; posX = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", 100); posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); @@ -163,7 +162,7 @@ uint32_t Fast3dWindow::GetWidth() { uint32_t width, height; int32_t posX, posY; mWindowManagerApi->get_dimensions(&width, &height, &posX, &posY); - return width; + return width; } uint32_t Fast3dWindow::GetHeight() { @@ -182,7 +181,8 @@ void Fast3dWindow::SetCurrentDimensions(uint32_t width, uint32_t height) { SetCurrentDimensions(width, height, GetPosX(), GetPosY()); } -void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) { +void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, + int32_t posY) { auto conf = Ship::Context::GetInstance()->GetConfig(); if (!isFullscreen) { conf->SetInt("Window.Width", (int32_t)width); diff --git a/src/graphic/Fast3D/gfx_direct3d12.cpp b/src/graphic/Fast3D/gfx_direct3d12.cpp index 441929e1c..85059f11f 100644 --- a/src/graphic/Fast3D/gfx_direct3d12.cpp +++ b/src/graphic/Fast3D/gfx_direct3d12.cpp @@ -183,7 +183,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE get_cpu_descriptor_handle(ComPtrGetCPUDescriptorHandleForHeapStart; void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*fun)(D3D12_CPU_DESCRIPTOR_HANDLE * out) = - (void(STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_CPU_DESCRIPTOR_HANDLE * out)) fn; + (void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_CPU_DESCRIPTOR_HANDLE * out)) fn; D3D12_CPU_DESCRIPTOR_HANDLE handle; (heap.Get()->*fun)(&handle); return handle; @@ -197,7 +197,7 @@ static D3D12_GPU_DESCRIPTOR_HANDLE get_gpu_descriptor_handle(ComPtrGetGPUDescriptorHandleForHeapStart; void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*fun)(D3D12_GPU_DESCRIPTOR_HANDLE * out) = - (void(STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_GPU_DESCRIPTOR_HANDLE * out)) fn; + (void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_GPU_DESCRIPTOR_HANDLE * out)) fn; D3D12_GPU_DESCRIPTOR_HANDLE handle; (heap.Get()->*fun)(&handle); return handle; @@ -212,8 +212,8 @@ static D3D12_RESOURCE_ALLOCATION_INFO get_resource_allocation_info(const D3D12_R auto fn = d3d.device->GetResourceAllocationInfo; void (STDMETHODCALLTYPE ID3D12Device::*fun)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs) = - (void(STDMETHODCALLTYPE ID3D12Device::*)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, - UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs)) fn; + (void (STDMETHODCALLTYPE ID3D12Device::*)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, + UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs)) fn; D3D12_RESOURCE_ALLOCATION_INFO out; (d3d.device.Get()->*fun)(&out, 0, 1, resource_desc); return out; diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 2db8720b8..23aded4e0 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -149,24 +149,21 @@ void UpdateMonitorList() { } else { isPrimary = FALSE; } - + dxgi.monitor_list.push_back({ hmon, mi.rcMonitor, isPrimary }); dxgi.monitor_rects.push_back( - { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom} - ); + { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom }); if (isPrimary) { dxgi.primary_monitor_index = dxgi.monitor_rects.size() - 1; } return TRUE; }, - (LPARAM)nullptr - ); + (LPARAM) nullptr); } // Uses coordinates to get a Monitor handle from a list -bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, - std::tuple& MonitorInfo) { +bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, std::tuple& MonitorInfo) { RECT wr = { x, y, (x + cx), (y + cy) }; std::tuple primary; for (std::tuple i : dxgi.monitor_list) { @@ -368,8 +365,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_SIZE: dxgi.current_width = LOWORD(l_param); dxgi.current_height = HIWORD(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -378,8 +374,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_MOVE: dxgi.posX = GET_X_LPARAM(l_param); dxgi.posY = GET_Y_LPARAM(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -458,8 +453,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; case WM_DISPLAYCHANGE: UpdateMonitorList(); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - dxgi.h_Monitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor); GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); break; case WM_SETFOCUS: @@ -529,8 +523,7 @@ void gfx_dxgi_init(const char* game_name, const char* gfx_api_name, bool start_i UpdateMonitorList(); dxgi.posX = posX; dxgi.posY = posY; - if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - dxgi.h_Monitor)) { + if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor)) { dxgi.posX = 100; dxgi.posY = 100; } diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index 54f12399f..eae4c9883 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -224,7 +224,6 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { { SDL_SCANCODE_KP_7, S { SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE }, { SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN } }; - static void apply_window_dimensions() { if (fullscreen_state) { SDL_DisplayMode mode; @@ -244,7 +243,7 @@ static void apply_window_dimensions() { if (SDL_SetWindowDisplayMode(wnd, &mode) != 0) { SPDLOG_ERROR("Failed to set SDL Window display Mode: ({})", SDL_GetError()); } - + } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } @@ -260,7 +259,7 @@ static void set_fullscreen(bool on, bool call_callback) { } auto conf = Ship::Context::GetInstance()->GetConfig(); - if (!on) { + if (!on) { window_width = conf->GetInt("Window.Width", 640); window_height = conf->GetInt("Window.Height", 480); window_posx = conf->GetInt("Window.PositionX", 100); @@ -534,7 +533,7 @@ static Ship::WindowRect gfx_sdl_get_primary_monitor_rect() { } if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { - return {0, 0, mode.w, mode.h}; + return { 0, 0, mode.w, mode.h }; } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } diff --git a/src/window/Window.h b/src/window/Window.h index 9894d57dd..31ab769b5 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -49,7 +49,8 @@ class Window { virtual void SetCurrentDimensions(uint32_t width, uint32_t height) = 0; virtual void SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) = 0; - virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; + virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, + int32_t posY) = 0; virtual WindowRect GetPrimaryMonitorRect() = 0; virtual int32_t GetPosX() = 0; virtual int32_t GetPosY() = 0; From 6c96eacda81b97578869645530aecb447126401d Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 20:04:11 -0500 Subject: [PATCH 3/9] Fixes bad merge --- src/graphic/Fast3D/gfx_window_manager_api.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/graphic/Fast3D/gfx_window_manager_api.h b/src/graphic/Fast3D/gfx_window_manager_api.h index 050776474..bca57cb6e 100644 --- a/src/graphic/Fast3D/gfx_window_manager_api.h +++ b/src/graphic/Fast3D/gfx_window_manager_api.h @@ -24,11 +24,6 @@ struct GfxWindowManagerAPI { void (*set_mouse_capture)(bool capture); bool (*is_mouse_captured)(); void (*get_dimensions)(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY); - void (*handle_events)(); - bool (*start_frame)(); - void (*swap_buffers_begin)(); - void (*swap_buffers_end)(); - double (*get_time)(); // For debug void (*set_dimensions)(uint32_t width, uint32_t height, int32_t posX, int32_t posY); Ship::WindowRect (*get_primary_monitor_rect)(void); void (*handle_events)(void); From b2fc462d4f8cb2ea1b7b5ade3e570e325d47a22b Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 20:07:03 -0500 Subject: [PATCH 4/9] Fixes bad merge --- src/graphic/Fast3D/gfx_sdl2.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index eae4c9883..b348b9e04 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -59,7 +59,6 @@ static bool (*on_key_up_callback)(int scancode); static void (*on_all_keys_up_callback)(); static bool (*on_mouse_button_down_callback)(int btn); static bool (*on_mouse_button_up_callback)(int btn); -static void (*on_all_keys_up_callback)(void); static void gfx_sdl_set_dimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY); #ifdef _WIN32 From 64f9c510289c868b7aad7c131f390c987e9d5060 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 20:08:18 -0500 Subject: [PATCH 5/9] Revert "Run clang-format" This reverts commit 2e096476a00c42fb1af9335bbaa805011560412e. --- src/graphic/Fast3D/Fast3dWindow.cpp | 8 ++++---- src/graphic/Fast3D/gfx_direct3d12.cpp | 8 ++++---- src/graphic/Fast3D/gfx_dxgi.cpp | 23 +++++++++++++++-------- src/graphic/Fast3D/gfx_sdl2.cpp | 7 ++++--- src/window/Window.h | 3 +-- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index e134f464b..798454578 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -62,7 +62,8 @@ void Fast3dWindow::Init() { uint32_t width, height; int32_t posX, posY; - isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; + isFullscreen = + Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; posX = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", 100); posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); @@ -162,7 +163,7 @@ uint32_t Fast3dWindow::GetWidth() { uint32_t width, height; int32_t posX, posY; mWindowManagerApi->get_dimensions(&width, &height, &posX, &posY); - return width; + return width; } uint32_t Fast3dWindow::GetHeight() { @@ -181,8 +182,7 @@ void Fast3dWindow::SetCurrentDimensions(uint32_t width, uint32_t height) { SetCurrentDimensions(width, height, GetPosX(), GetPosY()); } -void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, - int32_t posY) { +void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) { auto conf = Ship::Context::GetInstance()->GetConfig(); if (!isFullscreen) { conf->SetInt("Window.Width", (int32_t)width); diff --git a/src/graphic/Fast3D/gfx_direct3d12.cpp b/src/graphic/Fast3D/gfx_direct3d12.cpp index 85059f11f..441929e1c 100644 --- a/src/graphic/Fast3D/gfx_direct3d12.cpp +++ b/src/graphic/Fast3D/gfx_direct3d12.cpp @@ -183,7 +183,7 @@ static D3D12_CPU_DESCRIPTOR_HANDLE get_cpu_descriptor_handle(ComPtrGetCPUDescriptorHandleForHeapStart; void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*fun)(D3D12_CPU_DESCRIPTOR_HANDLE * out) = - (void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_CPU_DESCRIPTOR_HANDLE * out)) fn; + (void(STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_CPU_DESCRIPTOR_HANDLE * out)) fn; D3D12_CPU_DESCRIPTOR_HANDLE handle; (heap.Get()->*fun)(&handle); return handle; @@ -197,7 +197,7 @@ static D3D12_GPU_DESCRIPTOR_HANDLE get_gpu_descriptor_handle(ComPtrGetGPUDescriptorHandleForHeapStart; void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*fun)(D3D12_GPU_DESCRIPTOR_HANDLE * out) = - (void (STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_GPU_DESCRIPTOR_HANDLE * out)) fn; + (void(STDMETHODCALLTYPE ID3D12DescriptorHeap::*)(D3D12_GPU_DESCRIPTOR_HANDLE * out)) fn; D3D12_GPU_DESCRIPTOR_HANDLE handle; (heap.Get()->*fun)(&handle); return handle; @@ -212,8 +212,8 @@ static D3D12_RESOURCE_ALLOCATION_INFO get_resource_allocation_info(const D3D12_R auto fn = d3d.device->GetResourceAllocationInfo; void (STDMETHODCALLTYPE ID3D12Device::*fun)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs) = - (void (STDMETHODCALLTYPE ID3D12Device::*)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, - UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs)) fn; + (void(STDMETHODCALLTYPE ID3D12Device::*)(D3D12_RESOURCE_ALLOCATION_INFO * out, UINT visibleMask, + UINT numResourceDescs, const D3D12_RESOURCE_DESC* pResourceDescs)) fn; D3D12_RESOURCE_ALLOCATION_INFO out; (d3d.device.Get()->*fun)(&out, 0, 1, resource_desc); return out; diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 23aded4e0..2db8720b8 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -149,21 +149,24 @@ void UpdateMonitorList() { } else { isPrimary = FALSE; } - + dxgi.monitor_list.push_back({ hmon, mi.rcMonitor, isPrimary }); dxgi.monitor_rects.push_back( - { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom }); + { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom} + ); if (isPrimary) { dxgi.primary_monitor_index = dxgi.monitor_rects.size() - 1; } return TRUE; }, - (LPARAM) nullptr); + (LPARAM)nullptr + ); } // Uses coordinates to get a Monitor handle from a list -bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, std::tuple& MonitorInfo) { +bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, + std::tuple& MonitorInfo) { RECT wr = { x, y, (x + cx), (y + cy) }; std::tuple primary; for (std::tuple i : dxgi.monitor_list) { @@ -365,7 +368,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_SIZE: dxgi.current_width = LOWORD(l_param); dxgi.current_height = HIWORD(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -374,7 +378,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_MOVE: dxgi.posX = GET_X_LPARAM(l_param); dxgi.posY = GET_Y_LPARAM(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -453,7 +458,8 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; case WM_DISPLAYCHANGE: UpdateMonitorList(); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + dxgi.h_Monitor); GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); break; case WM_SETFOCUS: @@ -523,7 +529,8 @@ void gfx_dxgi_init(const char* game_name, const char* gfx_api_name, bool start_i UpdateMonitorList(); dxgi.posX = posX; dxgi.posY = posY; - if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor)) { + if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, + dxgi.h_Monitor)) { dxgi.posX = 100; dxgi.posY = 100; } diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index b348b9e04..a8eaeb39c 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -223,6 +223,7 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { { SDL_SCANCODE_KP_7, S { SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE }, { SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN } }; + static void apply_window_dimensions() { if (fullscreen_state) { SDL_DisplayMode mode; @@ -242,7 +243,7 @@ static void apply_window_dimensions() { if (SDL_SetWindowDisplayMode(wnd, &mode) != 0) { SPDLOG_ERROR("Failed to set SDL Window display Mode: ({})", SDL_GetError()); } - + } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } @@ -258,7 +259,7 @@ static void set_fullscreen(bool on, bool call_callback) { } auto conf = Ship::Context::GetInstance()->GetConfig(); - if (!on) { + if (!on) { window_width = conf->GetInt("Window.Width", 640); window_height = conf->GetInt("Window.Height", 480); window_posx = conf->GetInt("Window.PositionX", 100); @@ -532,7 +533,7 @@ static Ship::WindowRect gfx_sdl_get_primary_monitor_rect() { } if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { - return { 0, 0, mode.w, mode.h }; + return {0, 0, mode.w, mode.h}; } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } diff --git a/src/window/Window.h b/src/window/Window.h index 31ab769b5..9894d57dd 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -49,8 +49,7 @@ class Window { virtual void SetCurrentDimensions(uint32_t width, uint32_t height) = 0; virtual void SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) = 0; - virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, - int32_t posY) = 0; + virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; virtual WindowRect GetPrimaryMonitorRect() = 0; virtual int32_t GetPosX() = 0; virtual int32_t GetPosY() = 0; From af82ccaba445e8cf24637811e0eb1c2f563a9622 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 20:08:40 -0500 Subject: [PATCH 6/9] Run clang-format --- src/graphic/Fast3D/Fast3dWindow.cpp | 8 ++++---- src/graphic/Fast3D/gfx_dxgi.cpp | 23 ++++++++--------------- src/graphic/Fast3D/gfx_sdl2.cpp | 7 +++---- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 798454578..e134f464b 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -62,8 +62,7 @@ void Fast3dWindow::Init() { uint32_t width, height; int32_t posX, posY; - isFullscreen = - Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; + isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; posX = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", 100); posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); @@ -163,7 +162,7 @@ uint32_t Fast3dWindow::GetWidth() { uint32_t width, height; int32_t posX, posY; mWindowManagerApi->get_dimensions(&width, &height, &posX, &posY); - return width; + return width; } uint32_t Fast3dWindow::GetHeight() { @@ -182,7 +181,8 @@ void Fast3dWindow::SetCurrentDimensions(uint32_t width, uint32_t height) { SetCurrentDimensions(width, height, GetPosX(), GetPosY()); } -void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) { +void Fast3dWindow::SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, + int32_t posY) { auto conf = Ship::Context::GetInstance()->GetConfig(); if (!isFullscreen) { conf->SetInt("Window.Width", (int32_t)width); diff --git a/src/graphic/Fast3D/gfx_dxgi.cpp b/src/graphic/Fast3D/gfx_dxgi.cpp index 2db8720b8..23aded4e0 100644 --- a/src/graphic/Fast3D/gfx_dxgi.cpp +++ b/src/graphic/Fast3D/gfx_dxgi.cpp @@ -149,24 +149,21 @@ void UpdateMonitorList() { } else { isPrimary = FALSE; } - + dxgi.monitor_list.push_back({ hmon, mi.rcMonitor, isPrimary }); dxgi.monitor_rects.push_back( - { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom} - ); + { mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom }); if (isPrimary) { dxgi.primary_monitor_index = dxgi.monitor_rects.size() - 1; } return TRUE; }, - (LPARAM)nullptr - ); + (LPARAM) nullptr); } // Uses coordinates to get a Monitor handle from a list -bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, - std::tuple& MonitorInfo) { +bool GetMonitorAtCoords(int x, int y, UINT cx, UINT cy, std::tuple& MonitorInfo) { RECT wr = { x, y, (x + cx), (y + cy) }; std::tuple primary; for (std::tuple i : dxgi.monitor_list) { @@ -368,8 +365,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_SIZE: dxgi.current_width = LOWORD(l_param); dxgi.current_height = HIWORD(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -378,8 +374,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par case WM_MOVE: dxgi.posX = GET_X_LPARAM(l_param); dxgi.posY = GET_Y_LPARAM(l_param); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - newMonitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, newMonitor); if (get<0>(newMonitor) != get<0>(dxgi.h_Monitor)) { dxgi.h_Monitor = newMonitor; GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); @@ -458,8 +453,7 @@ static LRESULT CALLBACK gfx_dxgi_wnd_proc(HWND h_wnd, UINT message, WPARAM w_par break; case WM_DISPLAYCHANGE: UpdateMonitorList(); - GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - dxgi.h_Monitor); + GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor); GetMonitorHzPeriod(dxgi.h_Monitor, dxgi.detected_hz, dxgi.display_period); break; case WM_SETFOCUS: @@ -529,8 +523,7 @@ void gfx_dxgi_init(const char* game_name, const char* gfx_api_name, bool start_i UpdateMonitorList(); dxgi.posX = posX; dxgi.posY = posY; - if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, - dxgi.h_Monitor)) { + if (!GetMonitorAtCoords(dxgi.posX, dxgi.posY, dxgi.current_width, dxgi.current_height, dxgi.h_Monitor)) { dxgi.posX = 100; dxgi.posY = 100; } diff --git a/src/graphic/Fast3D/gfx_sdl2.cpp b/src/graphic/Fast3D/gfx_sdl2.cpp index a8eaeb39c..b348b9e04 100644 --- a/src/graphic/Fast3D/gfx_sdl2.cpp +++ b/src/graphic/Fast3D/gfx_sdl2.cpp @@ -223,7 +223,6 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { { SDL_SCANCODE_KP_7, S { SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_DELETE }, { SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN } }; - static void apply_window_dimensions() { if (fullscreen_state) { SDL_DisplayMode mode; @@ -243,7 +242,7 @@ static void apply_window_dimensions() { if (SDL_SetWindowDisplayMode(wnd, &mode) != 0) { SPDLOG_ERROR("Failed to set SDL Window display Mode: ({})", SDL_GetError()); } - + } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } @@ -259,7 +258,7 @@ static void set_fullscreen(bool on, bool call_callback) { } auto conf = Ship::Context::GetInstance()->GetConfig(); - if (!on) { + if (!on) { window_width = conf->GetInt("Window.Width", 640); window_height = conf->GetInt("Window.Height", 480); window_posx = conf->GetInt("Window.PositionX", 100); @@ -533,7 +532,7 @@ static Ship::WindowRect gfx_sdl_get_primary_monitor_rect() { } if (SDL_GetDesktopDisplayMode(display_in_use, &mode) >= 0) { - return {0, 0, mode.w, mode.h}; + return { 0, 0, mode.w, mode.h }; } else { SPDLOG_ERROR("Failed to get SDL Desktop Display Mode: ({})", SDL_GetError()); } From ee112d962dd4b4e26574da5ca83dd705e8a70964 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 6 Jan 2025 20:11:34 -0500 Subject: [PATCH 7/9] run clang-format --- src/window/Window.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/window/Window.h b/src/window/Window.h index 9894d57dd..31ab769b5 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -49,7 +49,8 @@ class Window { virtual void SetCurrentDimensions(uint32_t width, uint32_t height) = 0; virtual void SetCurrentDimensions(uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height) = 0; - virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, int32_t posY) = 0; + virtual void SetCurrentDimensions(bool isFullscreen, uint32_t width, uint32_t height, int32_t posX, + int32_t posY) = 0; virtual WindowRect GetPrimaryMonitorRect() = 0; virtual int32_t GetPosX() = 0; virtual int32_t GetPosY() = 0; From 956915b81bc919ff7f323c810f83c6b83dd11f14 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 20 Jan 2025 11:24:54 -0500 Subject: [PATCH 8/9] Fixes default to boolean --- src/graphic/Fast3D/Fast3dWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index e134f464b..2410c834f 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -62,7 +62,7 @@ void Fast3dWindow::Init() { uint32_t width, height; int32_t posX, posY; - isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", 0) || gameMode; + isFullscreen = Ship::Context::GetInstance()->GetConfig()->GetBool("Window.Fullscreen.Enabled", false) || gameMode; posX = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionX", 100); posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); From 4877a9c186f8bc8ad4b28c5acadf8134ed962709 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Mon, 20 Jan 2025 11:26:09 -0500 Subject: [PATCH 9/9] Uses original gameMode default sizes. --- src/graphic/Fast3D/Fast3dWindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphic/Fast3D/Fast3dWindow.cpp b/src/graphic/Fast3D/Fast3dWindow.cpp index 2410c834f..9d7b8c919 100644 --- a/src/graphic/Fast3D/Fast3dWindow.cpp +++ b/src/graphic/Fast3D/Fast3dWindow.cpp @@ -67,8 +67,8 @@ void Fast3dWindow::Init() { posY = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.PositionY", 100); if (isFullscreen) { - width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", 1920); - height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", 1080); + width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Width", gameMode ? 1280 : 1920); + height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Fullscreen.Height", gameMode ? 800 : 1080); } else { width = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Width", 640); height = Ship::Context::GetInstance()->GetConfig()->GetInt("Window.Height", 480);