12#include <ShellScalingApi.h>
15#ifdef WIN32_LEAN_AND_MEAN
16#undef WIN32_LEAN_AND_MEAN
18#include <SDL2/SDL_syswm.h>
23#include <mimalloc-new-delete.h>
27 _declspec(dllexport)
DWORD NvOptimusEnablement = 0x00000001;
28 _declspec(dllexport)
DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
31LRESULT
DlgProc([[maybe_unused]] HWND hWnd, [[maybe_unused]] UINT uMsg, [[maybe_unused]] WPARAM wParam, [[maybe_unused]] LPARAM lParam)
noexcept
38 static std::string GetLastErrorText() noexcept
41 DWORD errorMessageID = ::GetLastError();
42 if ( errorMessageID == 0 )
47 LPSTR messageBuffer =
nullptr;
51 size_t size = FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
52 NULL, errorMessageID, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), (LPSTR)&messageBuffer, 0, NULL );
55 std::string message( messageBuffer, size );
58 LocalFree( messageBuffer );
70 SDL_SysWMinfo wmInfo = {};
71 SDL_VERSION(&wmInfo.version);
72 SDL_GetWindowWMInfo(
static_cast<SDL_Window*
>(window), &wmInfo);
73 handleOut._handle = wmInfo.info.win.window;
78 if (condition && IsDebuggerPresent())
89 if (FAILED( SetProcessDpiAwareness( PROCESS_PER_MONITOR_DPI_AWARE ) ))
91 std::cerr << GetLastErrorText();
97 MEMORYSTATUSEX status;
98 status.dwLength =
sizeof(status);
99 const BOOL infoStatus = GlobalMemoryStatusEx(&status);
101 if (infoStatus != FALSE)
103 info._availableRamInBytes = status.ullAvailPhys;
115 constexpr DWORD MS_VC_EXCEPTION = 0x406D1388;
118 typedef struct tagTHREADNAME_INFO
151 static void SetThreadName(
const U32 threadID,
const std::string_view threadName)
noexcept
155 THREADNAME_INFO info;
156 info.dwType = 0x1000;
157 info.szName = threadName.data();
158 info.dwThreadID = threadID;
163 RaiseException(MS_VC_EXCEPTION, 0,
sizeof(info) /
sizeof(ULONG_PTR), (ULONG_PTR*)&info);
165 __except (EXCEPTION_EXECUTE_HANDLER)
171 void SetThreadName(
const std::string_view threadName)
noexcept
176 bool CallSystemCmd(
const std::string_view cmd,
const std::string_view args)
179 ZeroMemory(&si,
sizeof(si));
182 PROCESS_INFORMATION pi;
183 ZeroMemory(&pi,
sizeof(pi));
186 char* lpCommandLine =
const_cast<char*
>(commandLine.c_str());
188 const BOOL ret = CreateProcess(
nullptr, lpCommandLine,
nullptr,
nullptr, FALSE, 0,
nullptr,
nullptr, &si, &pi);
190 CloseHandle(pi.hProcess);
191 CloseHandle(pi.hThread);
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
void GetWindowHandle(void *window, WindowHandle &handleOut) noexcept
F32 PlatformDefaultDPI() noexcept
void SetThreadName(std::string_view threadName) noexcept
bool CallSystemCmd(std::string_view cmd, std::string_view args)
void SetThreadPriorityInternal(pthread_t thread, const ThreadPriority priority)
bool DebugBreak(const bool condition) noexcept
void SetThreadPriority(ThreadPriority priority)
void EnforceDPIScaling() noexcept
bool GetAvailableMemory(SysInfo &info)
static NO_INLINE void errorfn(const char *format, T &&... args)