From 66bb51fa6148d6910da054bacd4fcbd2fa7b5bab Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 21 Jan 2019 20:44:55 +0100 Subject: Inlined functions and fix debug header --- debug.hpp | 107 +++++++++++++++++++++++++-------------------------- include/video.hpp | 7 ++-- include/wrapsdl2.hpp | 4 +- video.cpp | 12 +++--- 4 files changed, 63 insertions(+), 67 deletions(-) diff --git a/debug.hpp b/debug.hpp index c53fc45..a45df38 100644 --- a/debug.hpp +++ b/debug.hpp @@ -4,72 +4,71 @@ #include #ifdef DEBUG - #ifdef __builtin_strrchr - #define __FILENAME__ (\ - __builtin_strrchr(__FILE__, '/') ? \ - __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + #define __FILENAME__ (\ + __builtin_strrchr(__FILE__, '/') ? \ + __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) - #define npdebug_fname(); { \ - std::cerr << "[" << __FILENAME__ << ":" << __LINE__ << "] "; \ - } + #define npdebug_prep(); { \ + std::cerr << "[" << __FILENAME__ \ + << ":" << __LINE__ \ + << ", " << __func__ \ + << "] " ; \ + } - #define npdebug(...); { \ - npdebug_fname(); \ - np::va_debug(__VA_ARGS__); \ - } - #else - #define npdebug(...); np::va_debug(__VA_ARGS__); - #endif + #define npdebug(...); { \ + npdebug_prep(); \ + np::va_debug(__VA_ARGS__); \ + } - namespace np { - template - inline void va_debug(Args&... args) { - (std::cerr << ... << args) << std::endl; - } + namespace np { + template + inline void va_debug(Args&... args) { + (std::cerr << ... << args) << std::endl; + } - template - void range_debug(const T& t) { - range_debug("", t); - } + template + void range_debug(const T& t) { + range_debug("", t); + } - template - void range_debug(const std::string& msg, const T& t) { - std::string out; - for (auto elem : t) - out += elem += ", "; + template + void range_debug(const std::string& msg, const T& t) { + std::string out; + for (auto elem : t) + out += elem += ", "; - npdebug(msg, out); - } + npdebug(msg, out); + } - template - T inspect(const T& t) { - npdebug(t); - return t; - } + template + T inspect(const T& t) { + npdebug(t); + return t; + } - template - T inspect(const std::string& msg, const T& t) { - npdebug(msg, t); - return t; - } - } + template + T inspect(const std::string& msg, const T& t) { + npdebug(msg, t); + return t; + } + } #else - #define npdebug(...) {} + #define npdebug(...) {} - namespace np { - template - inline void va_debug(Args&... args) {} + namespace np { + template + inline void va_debug(Args&... args) {} - template - inline void range_debug(const T& t) {} + template + inline void range_debug(const T& t) {} - template - inline void range_debug(const std::string& msg, const T& t) {} + template + inline void range_debug(const std::string& msg, const T& t) {} - template - T inspect(const T& t) { return t; } + template + T inspect(const T& t) { return t; } - template - T inspect(const std::string& msg, const T& t) { return t; } - } + template + T inspect(const std::string& msg, const T& t) { return t; } + } #endif diff --git a/include/video.hpp b/include/video.hpp index 3c2a238..2749d11 100644 --- a/include/video.hpp +++ b/include/video.hpp @@ -24,10 +24,9 @@ namespace wrapsdl2 { void open(); void close(); - - void show(); - void hide(); - void raise(); + inline void show() { SDL_ShowWindow(m_window); } + inline void hide() { SDL_HideWindow(m_window); } + inline void raise() { SDL_RaiseWindow(m_window); } // getters bool is_open(); diff --git a/include/wrapsdl2.hpp b/include/wrapsdl2.hpp index 847ed99..2f28890 100644 --- a/include/wrapsdl2.hpp +++ b/include/wrapsdl2.hpp @@ -9,11 +9,11 @@ namespace wrapsdl2 { void quit(void); namespace util { - constexpr bool sdl_bool(SDL_bool b) { + constexpr inline bool sdl_bool(SDL_bool b) { return b == SDL_TRUE; } - constexpr SDL_bool sdl_bool(bool b) { + constexpr inline SDL_bool sdl_bool(bool b) { return (b) ? SDL_TRUE : SDL_FALSE; } } diff --git a/video.cpp b/video.cpp index f58b171..71544fe 100644 --- a/video.cpp +++ b/video.cpp @@ -39,9 +39,13 @@ window::window(const std::string& title, std::size_t width, std::size_t height) window::~window() { if (m_renderer != NULL) SDL_DestroyRenderer(m_renderer); + else + npdebug("warning: m_renderer is NULL") if (m_window != NULL) SDL_DestroyWindow(m_window); + else + npdebug("warning: m_window is NULL") } @@ -55,18 +59,12 @@ void window::close() { m_open = false; } -void window::show() { SDL_ShowWindow(m_window); } -void window::hide() { SDL_HideWindow(m_window); } -void window::raise() { SDL_RaiseWindow(m_window); } - bool window::is_open() { return m_open; } bool window::is_visible() { - std::uint32_t flags = SDL_GetWindowFlags(m_window); - - return flags & SDL_WINDOW_SHOWN; + return SDL_WINDOW_SHOWN & SDL_GetWindowFlags(m_window); } void window::update() { -- cgit v1.2.1