From 7507648ad80868615007d83990cfb33e5a67724e Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 01:03:03 +0200 Subject: [PATCH 1/6] add window api --- Engine/src/delta/platform/os_internal.h | 5 ++ Engine/src/delta/platform/os_win32.cpp | 80 +++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/Engine/src/delta/platform/os_internal.h b/Engine/src/delta/platform/os_internal.h index ac6c713..390cc6e 100644 --- a/Engine/src/delta/platform/os_internal.h +++ b/Engine/src/delta/platform/os_internal.h @@ -71,4 +71,9 @@ namespace delta::platform void Sync_SignalSemaphore(SemaphoreHandle sem); void Sync_WaitSemaphore(SemaphoreHandle sem); void Sync_Sleep(uint32_t milliseconds); + + // Window API + struct Window; + + Window* Window_Create(); } diff --git a/Engine/src/delta/platform/os_win32.cpp b/Engine/src/delta/platform/os_win32.cpp index df4806b..cb835f3 100644 --- a/Engine/src/delta/platform/os_win32.cpp +++ b/Engine/src/delta/platform/os_win32.cpp @@ -419,6 +419,86 @@ namespace delta::platform { Sleep(milliseconds); } + + struct Window + { + HWND hwnd; + }; + + static LRESULT CALLBACK DltWindowProc(HWND hwnd, UINT umesg, WPARAM wparam, LPARAM lparam) + { + switch (umesg) + { + case WM_CLOSE: + // DestroyWindow(hwnd); + return 0; + default: + return DefWindowProcA(hwnd, umesg, wparam, lparam); + } + } + + Window* Window_Create() + { + Window* window = new(delta::Engine::AllocationType::PERSISTENT) Window(); + + static constexpr const char MAIN_WND_CLASS_NAME[] = "DltWindow"; + HINSTANCE hInstance = GetModuleHandleA(nullptr); + + STARTUPINFOA startupInfo = { sizeof(STARTUPINFOA) }; + GetStartupInfoA(&startupInfo); + int nCmdShow = (startupInfo.dwFlags & STARTF_USESHOWWINDOW) ? startupInfo.wShowWindow : SW_SHOWDEFAULT; + + const WNDCLASSEXA wc = + { + .cbSize = sizeof(WNDCLASSEXA), + .style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC, + .lpfnWndProc = DltWindowProc, + .cbClsExtra = 0, + .cbWndExtra = 0, + .hInstance = hInstance, + .hCursor = LoadCursorA(nullptr, IDC_ARROW), + .hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH), + .lpszClassName = MAIN_WND_CLASS_NAME + }; + + if (!RegisterClassExA(&wc)) + { + [[maybe_unused]] DWORD e = GetLastError(); + return nullptr; + } + + uint32_t clientWidth = 1280; + uint32_t clientHeight = 720; + + RECT wr = { 0, 0, static_cast(clientWidth), static_cast(clientHeight) }; + DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE; + + AdjustWindowRect(&wr, windowStyle, FALSE); + + window->hwnd = CreateWindowExA( + 0, + MAIN_WND_CLASS_NAME, + "Delta Engine", + windowStyle, + CW_USEDEFAULT, CW_USEDEFAULT, + wr.right - wr.left, + wr.bottom - wr.top, + nullptr, + nullptr, + hInstance, + nullptr + ); + + if (!window->hwnd) + { + return nullptr; + } + + ShowWindow(window->hwnd, nCmdShow); + UpdateWindow(window->hwnd); + + return window; + } } #endif From 92466b51ad9e8a4c9ba43d251c0d5e44d1976f70 Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 01:18:30 +0200 Subject: [PATCH 2/6] make hInstance and startupInfo global --- Engine/src/delta/platform/os_win32.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Engine/src/delta/platform/os_win32.cpp b/Engine/src/delta/platform/os_win32.cpp index cb835f3..169e4c0 100644 --- a/Engine/src/delta/platform/os_win32.cpp +++ b/Engine/src/delta/platform/os_win32.cpp @@ -152,11 +152,18 @@ namespace delta::platform return true; } + // TODO: Move this variables to the reasonable place + static HINSTANCE s_hInstance = nullptr; + static STARTUPINFOA s_StartupInfo = { sizeof(STARTUPINFOA) }; + void Initialize() { memset(&g_osInfo, 0u, sizeof(OSInfo)); fetchCpuidValues(); + s_hInstance = GetModuleHandleA(nullptr); + GetStartupInfoA(&s_StartupInfo); + SYSTEM_INFO info; GetSystemInfo(&info); @@ -420,11 +427,15 @@ namespace delta::platform Sleep(milliseconds); } + // ------------------------------------------ WINDOW API ------------------------------------------ + struct Window { HWND hwnd; }; + static constexpr const char MAIN_WND_CLASS_NAME[] = "DltWindow"; + static LRESULT CALLBACK DltWindowProc(HWND hwnd, UINT umesg, WPARAM wparam, LPARAM lparam) { switch (umesg) @@ -439,10 +450,10 @@ namespace delta::platform Window* Window_Create() { + assert(s_hInstance); Window* window = new(delta::Engine::AllocationType::PERSISTENT) Window(); - static constexpr const char MAIN_WND_CLASS_NAME[] = "DltWindow"; - HINSTANCE hInstance = GetModuleHandleA(nullptr); + int nCmdShow = (s_StartupInfo.dwFlags & STARTF_USESHOWWINDOW) ? s_StartupInfo.wShowWindow : SW_SHOWDEFAULT; STARTUPINFOA startupInfo = { sizeof(STARTUPINFOA) }; GetStartupInfoA(&startupInfo); @@ -455,7 +466,7 @@ namespace delta::platform .lpfnWndProc = DltWindowProc, .cbClsExtra = 0, .cbWndExtra = 0, - .hInstance = hInstance, + .hInstance = s_hInstance, .hCursor = LoadCursorA(nullptr, IDC_ARROW), .hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH), .lpszClassName = MAIN_WND_CLASS_NAME @@ -485,7 +496,7 @@ namespace delta::platform wr.bottom - wr.top, nullptr, nullptr, - hInstance, + s_hInstance, nullptr ); From a5e71e5ba7a02216e7fb92411894556bfcd6ab16 Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 01:18:52 +0200 Subject: [PATCH 3/6] window lifetime functions --- Engine/src/delta/platform/os_internal.h | 2 ++ Engine/src/delta/platform/os_win32.cpp | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Engine/src/delta/platform/os_internal.h b/Engine/src/delta/platform/os_internal.h index 390cc6e..6549aed 100644 --- a/Engine/src/delta/platform/os_internal.h +++ b/Engine/src/delta/platform/os_internal.h @@ -76,4 +76,6 @@ namespace delta::platform struct Window; Window* Window_Create(); + void Window_ProcessEvents(); + void Window_Destroy(Window* window); } diff --git a/Engine/src/delta/platform/os_win32.cpp b/Engine/src/delta/platform/os_win32.cpp index 169e4c0..2093ca9 100644 --- a/Engine/src/delta/platform/os_win32.cpp +++ b/Engine/src/delta/platform/os_win32.cpp @@ -455,10 +455,6 @@ namespace delta::platform int nCmdShow = (s_StartupInfo.dwFlags & STARTF_USESHOWWINDOW) ? s_StartupInfo.wShowWindow : SW_SHOWDEFAULT; - STARTUPINFOA startupInfo = { sizeof(STARTUPINFOA) }; - GetStartupInfoA(&startupInfo); - int nCmdShow = (startupInfo.dwFlags & STARTF_USESHOWWINDOW) ? startupInfo.wShowWindow : SW_SHOWDEFAULT; - const WNDCLASSEXA wc = { .cbSize = sizeof(WNDCLASSEXA), @@ -510,6 +506,27 @@ namespace delta::platform return window; } + + void Window_ProcessEvents() + { + MSG msg = {}; + while (PeekMessageA(&msg, nullptr, 0, 0, PM_REMOVE)) + { + if (msg.message == WM_QUIT) + { + // TODO: Handle this + } + + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + } + + void Window_Destroy(Window* window) + { + DestroyWindow(window->hwnd); + UnregisterClassA(MAIN_WND_CLASS_NAME, s_hInstance); + } } #endif From ed56396dfce9177532f41a5052d4abc99d0c5f28 Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 19:17:55 +0200 Subject: [PATCH 4/6] platform header mess fix --- Engine/CMakeLists.txt | 3 +- Engine/include/delta/core/engine.h | 2 ++ Engine/include/delta/platform/os.h | 26 +------------- Engine/include/delta/platform/os_types.h | 36 +++++++++++++++++++ Engine/src/delta/core/ThreadContext.cpp | 2 +- Engine/src/delta/platform/os_internal.h | 22 +----------- Engine/src/delta/platform/os_internal_types.h | 27 ++++++++++++++ 7 files changed, 70 insertions(+), 48 deletions(-) create mode 100644 Engine/include/delta/platform/os_types.h create mode 100644 Engine/src/delta/platform/os_internal_types.h diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt index d056fcf..b0afb61 100644 --- a/Engine/CMakeLists.txt +++ b/Engine/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(ProjectDelta SHARED "include/delta/definitions.h" "src/delta/platform/os_internal.h" "src/delta/platform/os_win32.cpp" + "include/delta/platform/os_types.h" "include/delta/platform/os.h" "include/delta/pch.h" "src/delta/pch.h" @@ -31,7 +32,7 @@ add_library(ProjectDelta SHARED "src/delta/core/MemoryConfig.cpp" "src/delta/core/Worker.h" "src/delta/core/Worker.cpp" -) + "src/delta/platform/os_internal_types.h") target_compile_definitions(ProjectDelta PRIVATE DLT_EXPORT_SYMBOLS diff --git a/Engine/include/delta/core/engine.h b/Engine/include/delta/core/engine.h index 40fc429..b021679 100644 --- a/Engine/include/delta/core/engine.h +++ b/Engine/include/delta/core/engine.h @@ -15,11 +15,13 @@ */ #include +#include namespace delta::Engine { struct Context { + delta::platform::WindowHandle window; bool isRunning; }; diff --git a/Engine/include/delta/platform/os.h b/Engine/include/delta/platform/os.h index 75e1525..a92fcb6 100644 --- a/Engine/include/delta/platform/os.h +++ b/Engine/include/delta/platform/os.h @@ -15,34 +15,10 @@ */ #pragma once +#include namespace delta::platform { - struct OSInfo - { - const char* cpuArchitecture; - - uint32_t cpuPhysicalCoreCount; - uint32_t cpuLogicalProcessorCount; - uint32_t osPageSize; - - char cpuBrandString[sizeof(int) * 12 + 1]; - char cpuManufacturerId[13]; - - bool cpuHasSMT; - bool cpuHasAVX2; - bool cpuHasAVX512f; - bool cpuHasAVX512cd; - bool cpuHasAVX512er; - bool cpuHasAVX512pf; - }; - - struct MemoryStatus - { - uint64_t physicalInstalled; - uint64_t physicalFree; - }; - DLT_API const OSInfo* getOSInfo() noexcept; DLT_API MemoryStatus getMemoryStatus(); } diff --git a/Engine/include/delta/platform/os_types.h b/Engine/include/delta/platform/os_types.h new file mode 100644 index 0000000..151f302 --- /dev/null +++ b/Engine/include/delta/platform/os_types.h @@ -0,0 +1,36 @@ +#pragma once + +#define DLT_DEFINE_HANDLE(name)\ + struct name;\ + using name##Handle = name*;\ + inline constexpr name##Handle INVALID_##name##_HANDLE = nullptr + +namespace delta::platform +{ + DLT_DEFINE_HANDLE(Window); + + struct OSInfo + { + const char* cpuArchitecture; + + uint32_t cpuPhysicalCoreCount; + uint32_t cpuLogicalProcessorCount; + uint32_t osPageSize; + + char cpuBrandString[sizeof(int) * 12 + 1]; + char cpuManufacturerId[13]; + + bool cpuHasSMT; + bool cpuHasAVX2; + bool cpuHasAVX512f; + bool cpuHasAVX512cd; + bool cpuHasAVX512er; + bool cpuHasAVX512pf; + }; + + struct MemoryStatus + { + uint64_t physicalInstalled; + uint64_t physicalFree; + }; +} diff --git a/Engine/src/delta/core/ThreadContext.cpp b/Engine/src/delta/core/ThreadContext.cpp index 8e3019c..e1baf12 100644 --- a/Engine/src/delta/core/ThreadContext.cpp +++ b/Engine/src/delta/core/ThreadContext.cpp @@ -156,7 +156,7 @@ namespace delta::core WorkerExecutionContext& ctx = GetExecutionContext(i); ctx.generic.type = ThreadType::WORKER; ctx.generic.threadIx = i; - ctx.generic.threadHandle = delta::platform::INVALID_THREAD_HANDLE; // Initialized when thread starts + ctx.generic.threadHandle = delta::platform::INVALID_Thread_HANDLE; // Initialized when thread starts ctx.isAsleep.store(false, std::memory_order_relaxed); ctx.shouldClose.store(false, std::memory_order_relaxed); ctx.sleepSemaphore = delta::platform::Sync_CreateSemaphore(); diff --git a/Engine/src/delta/platform/os_internal.h b/Engine/src/delta/platform/os_internal.h index 6549aed..69d8942 100644 --- a/Engine/src/delta/platform/os_internal.h +++ b/Engine/src/delta/platform/os_internal.h @@ -15,6 +15,7 @@ */ #pragma once +#include namespace delta::platform { @@ -31,28 +32,12 @@ namespace delta::platform bool Memory_ElevateLockLimit(size_t maxBytesToLock); // Timer API - struct Timer_Internal; - struct Timer - { - alignas(8) uint8_t opaqueData[32]; - }; - void Timer_Initialize(Timer* timer); int64_t Timer_GetTimestamp(); double Timer_TicksToMilliseconds(const Timer* timer, int64_t startTicks, int64_t endTicks); double Timer_TicksToMicroseconds(const Timer* timer, int64_t startTicks, int64_t endTicks); // Thread API - struct Thread; - using ThreadHandle = Thread*; - inline constexpr ThreadHandle INVALID_THREAD_HANDLE = nullptr; // random number 696767 - - struct ThreadCreateInfo - { - void (*fn)(void*); - void* args; - }; - uint32_t Thread_GetCurrentId(); uint32_t Thread_GetId(ThreadHandle thread); ThreadHandle Thread_GetCurrentHandle(); @@ -63,9 +48,6 @@ namespace delta::platform void Thread_JoinMultiple(ThreadHandle* threads, uint32_t count); // Sync API - struct Semaphore; - using SemaphoreHandle = Semaphore*; - SemaphoreHandle Sync_CreateSemaphore(); void Sync_DestroySemaphore(SemaphoreHandle sem); void Sync_SignalSemaphore(SemaphoreHandle sem); @@ -73,8 +55,6 @@ namespace delta::platform void Sync_Sleep(uint32_t milliseconds); // Window API - struct Window; - Window* Window_Create(); void Window_ProcessEvents(); void Window_Destroy(Window* window); diff --git a/Engine/src/delta/platform/os_internal_types.h b/Engine/src/delta/platform/os_internal_types.h new file mode 100644 index 0000000..864a8ef --- /dev/null +++ b/Engine/src/delta/platform/os_internal_types.h @@ -0,0 +1,27 @@ +#pragma once +#include + +namespace delta::platform +{ + // Timer API + struct Timer_Internal; + struct Timer + { + alignas(8) uint8_t opaqueData[32]; + }; + + // Thread API + DLT_DEFINE_HANDLE(Thread); + + struct ThreadCreateInfo + { + void (*fn)(void*); + void* args; + }; + + // Sync API + DLT_DEFINE_HANDLE(Semaphore); + + // Window API + // Window defined in the public header +} From f410d7e802ad4f8551847f6b5bfc6e5f5ec773f2 Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 19:28:43 +0200 Subject: [PATCH 5/6] expose Window_SetTitle function --- Engine/include/delta/platform/os.h | 5 +++++ Engine/src/delta/core/engine.cpp | 7 ++++++- Engine/src/delta/platform/os_win32.cpp | 5 +++++ Examples/HelloWorldGame/game.cpp | 17 +---------------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Engine/include/delta/platform/os.h b/Engine/include/delta/platform/os.h index a92fcb6..fb17395 100644 --- a/Engine/include/delta/platform/os.h +++ b/Engine/include/delta/platform/os.h @@ -19,6 +19,11 @@ namespace delta::platform { + // General + // TODO: Change names to the adequate ones DLT_API const OSInfo* getOSInfo() noexcept; DLT_API MemoryStatus getMemoryStatus(); + + // Window API + DLT_API void Window_SetTitle(WindowHandle window, const char* newTitle); } diff --git a/Engine/src/delta/core/engine.cpp b/Engine/src/delta/core/engine.cpp index bfdcdc7..c135e11 100644 --- a/Engine/src/delta/core/engine.cpp +++ b/Engine/src/delta/core/engine.cpp @@ -43,18 +43,23 @@ namespace delta::Engine delta::platform::ThreadHandle th = delta::platform::Thread_GetCurrentHandle(); delta::platform::Thread_AssignPhysicalCore(th, 0); delta::core::Worker_Init(totalThreads-1); + + context.window = delta::platform::Window_Create(); } void Update(Context& context) { // blah blah blah // do something - delta::platform::Sync_Sleep(100); + + delta::platform::Window_ProcessEvents(); + delta::platform::Sync_Sleep(10); delta::core::ThreadArena_Reset(delta::core::GetTransientArena()); } void Shutdown(Context& context) { + Engine::Free(context.window); delta::core::Worker_Shutdown(); delta::core::ThreadContext_Shutdown(); delta::core::MemoryConfig_Shutdown(); diff --git a/Engine/src/delta/platform/os_win32.cpp b/Engine/src/delta/platform/os_win32.cpp index 2093ca9..a2ac708 100644 --- a/Engine/src/delta/platform/os_win32.cpp +++ b/Engine/src/delta/platform/os_win32.cpp @@ -527,6 +527,11 @@ namespace delta::platform DestroyWindow(window->hwnd); UnregisterClassA(MAIN_WND_CLASS_NAME, s_hInstance); } + + void Window_SetTitle(WindowHandle window, const char* newTitle) + { + SetWindowTextA(window->hwnd, newTitle); + } } #endif diff --git a/Examples/HelloWorldGame/game.cpp b/Examples/HelloWorldGame/game.cpp index 44bb162..7a1cdc9 100644 --- a/Examples/HelloWorldGame/game.cpp +++ b/Examples/HelloWorldGame/game.cpp @@ -38,22 +38,7 @@ extern "C" void GAME_API Game_OnInit(delta::Engine::Context* context) { const OSInfo* info = delta::platform::getOSInfo(); - - std::cout << "Initializing game\n"; - std::cout << "System Info:\n"; - std::cout << - "\tOS Page Size: " << info->osPageSize << " bytes\n" << - "\tCPU Architecture: " << info->cpuArchitecture << "\n" << - "\tCPU Manufacturer: " << info->cpuManufacturerId << "\n" << - "\tCPU Model: " << info->cpuBrandString << "\n" << - "\tCPU Physical Cores: " << info->cpuPhysicalCoreCount << "\n" << - "\tCPU Logical Cores: " << info->cpuLogicalProcessorCount << "\n" << - "\tCPU Has SMT: " << STDOUT_BOOL_FORMAT(info->cpuHasSMT) << "\n" << - "\tAVX2 Available: " << STDOUT_BOOL_FORMAT(info->cpuHasAVX2) << "\n" << - "\tAVX512 Foundation Available: " << STDOUT_BOOL_FORMAT(info->cpuHasAVX512f) << "\n" << - "\tAVX512 Conflict Detection Available: " << STDOUT_BOOL_FORMAT(info->cpuHasAVX512cd) << "\n" << - "\tAVX512 Exponential and Reciprocal Available: " << STDOUT_BOOL_FORMAT(info->cpuHasAVX512er) << "\n" << - "\tAVX512 Prefetch Available: " << STDOUT_BOOL_FORMAT(info->cpuHasAVX512pf) << "\n"; + delta::platform::Window_SetTitle(context->window, "Hello World Game"); } void GAME_API Game_OnUpdate(delta::Engine::Context* context) From 7cd511e63b09fb89f0ccc035af493e70228dda94 Mon Sep 17 00:00:00 2001 From: YasInvolved Date: Tue, 2 Jun 2026 22:17:17 +0200 Subject: [PATCH 6/6] expand the win32 api a little with new window functions --- Engine/include/delta/platform/os.h | 6 +++ Engine/src/delta/core/engine.cpp | 2 + Engine/src/delta/platform/os_internal.h | 5 ++- Engine/src/delta/platform/os_win32.cpp | 51 +++++++++++++++++++++---- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Engine/include/delta/platform/os.h b/Engine/include/delta/platform/os.h index fb17395..7a29f01 100644 --- a/Engine/include/delta/platform/os.h +++ b/Engine/include/delta/platform/os.h @@ -26,4 +26,10 @@ namespace delta::platform // Window API DLT_API void Window_SetTitle(WindowHandle window, const char* newTitle); + DLT_API void Window_Show(WindowHandle window); + DLT_API void Window_Hide(WindowHandle window); + DLT_API void Window_SetSize(WindowHandle window, uint32_t w, uint32_t h); + DLT_API void Window_SetPos(WindowHandle window, uint32_t x, uint32_t y); + DLT_API void Window_ShowCursor(WindowHandle window); + DLT_API void Window_HideCursor(WindowHandle window); } diff --git a/Engine/src/delta/core/engine.cpp b/Engine/src/delta/core/engine.cpp index c135e11..8790ef9 100644 --- a/Engine/src/delta/core/engine.cpp +++ b/Engine/src/delta/core/engine.cpp @@ -45,6 +45,8 @@ namespace delta::Engine delta::core::Worker_Init(totalThreads-1); context.window = delta::platform::Window_Create(); + delta::platform::Window_Show(context.window); + delta::platform::Window_Win32_Update(context.window); } void Update(Context& context) diff --git a/Engine/src/delta/platform/os_internal.h b/Engine/src/delta/platform/os_internal.h index 69d8942..c9332be 100644 --- a/Engine/src/delta/platform/os_internal.h +++ b/Engine/src/delta/platform/os_internal.h @@ -55,7 +55,8 @@ namespace delta::platform void Sync_Sleep(uint32_t milliseconds); // Window API - Window* Window_Create(); + WindowHandle Window_Create(); + void Window_Win32_Update(WindowHandle window); void Window_ProcessEvents(); - void Window_Destroy(Window* window); + void Window_Destroy(WindowHandle window); } diff --git a/Engine/src/delta/platform/os_win32.cpp b/Engine/src/delta/platform/os_win32.cpp index a2ac708..9c1d05c 100644 --- a/Engine/src/delta/platform/os_win32.cpp +++ b/Engine/src/delta/platform/os_win32.cpp @@ -25,6 +25,9 @@ #define CHECK_CPUID_FLAG(register, flag) ((register & (1 << flag)) != 0) +_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +_declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; + namespace delta::platform { static OSInfo g_osInfo; @@ -448,10 +451,10 @@ namespace delta::platform } } - Window* Window_Create() + WindowHandle Window_Create() { assert(s_hInstance); - Window* window = new(delta::Engine::AllocationType::PERSISTENT) Window(); + WindowHandle window = new(delta::Engine::AllocationType::PERSISTENT) Window(); int nCmdShow = (s_StartupInfo.dwFlags & STARTF_USESHOWWINDOW) ? s_StartupInfo.wShowWindow : SW_SHOWDEFAULT; @@ -478,7 +481,7 @@ namespace delta::platform uint32_t clientHeight = 720; RECT wr = { 0, 0, static_cast(clientWidth), static_cast(clientHeight) }; - DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE; + static constexpr DWORD windowStyle = WS_OVERLAPPEDWINDOW; AdjustWindowRect(&wr, windowStyle, FALSE); @@ -501,12 +504,14 @@ namespace delta::platform return nullptr; } - ShowWindow(window->hwnd, nCmdShow); - UpdateWindow(window->hwnd); - return window; } + void Window_Win32_Update(WindowHandle window) + { + UpdateWindow(window->hwnd); + } + void Window_ProcessEvents() { MSG msg = {}; @@ -522,7 +527,7 @@ namespace delta::platform } } - void Window_Destroy(Window* window) + void Window_Destroy(WindowHandle window) { DestroyWindow(window->hwnd); UnregisterClassA(MAIN_WND_CLASS_NAME, s_hInstance); @@ -532,6 +537,38 @@ namespace delta::platform { SetWindowTextA(window->hwnd, newTitle); } + + void Window_Show(WindowHandle window) + { + ShowWindow(window->hwnd, SW_SHOW); + } + + void Window_Hide(WindowHandle window) + { + ShowWindow(window->hwnd, SW_HIDE); + } + + void Window_SetSize(WindowHandle window, uint32_t w, uint32_t h) + { + static constexpr UINT FLAGS = SWP_NOMOVE | SWP_NOZORDER | SWP_SHOWWINDOW; + SetWindowPos(window->hwnd, nullptr, 0, 0, w, h, FLAGS); + } + + void Window_SetPos(WindowHandle window, uint32_t x, uint32_t y) + { + static constexpr UINT FLAGS = SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW; + SetWindowPos(window->hwnd, nullptr, x, y, 0, 0, FLAGS); + } + + void Window_ShowCursor(WindowHandle window) + { + ShowCursor(TRUE); + } + + void Window_HideCursor(WindowHandle window) + { + ShowCursor(FALSE); + } } #endif