From 056904fab333a7a0af76008e59f9348f2f40681a Mon Sep 17 00:00:00 2001 From: Timerix Date: Tue, 30 Jul 2024 20:18:54 +0300 Subject: [PATCH] SDL_TRY --- src/gui/exceptions.hpp | 3 +-- src/gui/gui.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/gui/exceptions.hpp b/src/gui/exceptions.hpp index 4a36225..d94385f 100644 --- a/src/gui/exceptions.hpp +++ b/src/gui/exceptions.hpp @@ -11,7 +11,6 @@ public: SDLException_(const std::string& _file, const std::string& _func, int line_n); }; -#define SDL_TRY_ZERO(FUNC_CALL) if(FUNC_CALL != 0) throw SDLException(); -#define SDL_TRY_ONE(FUNC_CALL) if(FUNC_CALL != 1) throw SDLException(); +#define SDL_TRY(EXPR) if(EXPR) throw SDLException(); } \ No newline at end of file diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 24a40fa..523b123 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -16,16 +16,16 @@ f32 GUI::getDPI(){ } void GUI::init(const char* window_title){ - SDL_TRY_ZERO(SDL_Init(SDL_INIT_VIDEO)); + SDL_TRY(SDL_Init(SDL_INIT_VIDEO)); SDL_version v; SDL_GetVersion(&v); kprintf("SDL version: %u.%u.%u\n", v.major, v.minor, v.patch); // GL 3.0 + GLSL 130 const char* glsl_version = "#version 130"; - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0)); - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)); - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)); - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0)); // From 2.0.18: Enable native IME. #ifdef SDL_HINT_IME_SHOW_UI @@ -33,9 +33,9 @@ void GUI::init(const char* window_title){ #endif // Create window with graphics context - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)); - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)); - SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)); + SDL_TRY( SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)); SDL_WindowFlags window_flags = (SDL_WindowFlags)( SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | @@ -48,8 +48,8 @@ void GUI::init(const char* window_title){ gl_context = SDL_GL_CreateContext(sdl_window); if(gl_context == nullptr) throw SDLException(); - SDL_TRY_ZERO( SDL_GL_MakeCurrent(sdl_window, gl_context)); - SDL_TRY_ZERO( SDL_GL_SetSwapInterval(1)); // Enable vsync + SDL_TRY( SDL_GL_MakeCurrent(sdl_window, gl_context)); + SDL_TRY( SDL_GL_SetSwapInterval(1)); // Enable vsync // Setup Dear ImGui context IMGUI_CHECKVERSION(); @@ -88,7 +88,7 @@ void GUI::poll_events(u16& frame_updates_requested, bool wait){ SDL_Event event; if(wait){ // waits for first event in cpu-efficient way - SDL_TRY_ONE(SDL_WaitEvent(&event)); + SDL_TRY(SDL_WaitEvent(&event) != 1); } // dont wait for event else if(!SDL_PollEvent(&event))