From b6df1547e24534a7008353b6bce439fe631e7949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 15 Jan 2026 20:13:42 -0500 Subject: [PATCH] refactor(framework): create debug output ostream that redirects to a null stream if `TB_EXT_FRAMEWORK_DEBUG` isn't defined or is set to 0 --- CMakeLists.txt | 2 ++ framework/CMakeLists.txt | 3 +++ framework/debug.cpp | 5 +++++ framework/include/public/toon_boom/ext/util.hpp | 15 +++++++++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 framework/debug.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 412113e..f036069 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ if(NOT DEFINED QT6_ROOT_DIR) message(FATAL_ERROR "QT6_ROOT_DIR is not defined. Please set the QT6_ROOT_DIR variable to the root directory of the Qt 6 installation.") endif() +option(TOON_BOOM_EXTENSION_FRAMEWORK_DEBUG "Enable debug output" ON) + include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) list(APPEND CMAKE_PREFIX_PATH ${QT6_ROOT_DIR}) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index dc05a7d..a7d0ffe 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -19,6 +19,9 @@ list(FILTER FRAMEWORK_SOURCES EXCLUDE REGEX "/(out|build|cmake-build-|CMakeFiles file(COPY "${QT5_ROOT_DIR}/include/QtScript" DESTINATION ${CMAKE_BINARY_DIR}/include) find_package(minhook CONFIG REQUIRED) function(link_libs_and_set_properties target_name) + if(TOON_BOOM_EXTENSION_FRAMEWORK_DEBUG) + target_compile_definitions(${target_name} PUBLIC TB_EXT_FRAMEWORK_DEBUG=1) + endif() target_compile_features(${target_name} PUBLIC cxx_std_20) target_include_directories(${target_name} PUBLIC "${CMAKE_BINARY_DIR}/include") target_link_libraries(${target_name} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/QtScript.lib") diff --git a/framework/debug.cpp b/framework/debug.cpp new file mode 100644 index 0000000..5f551e9 --- /dev/null +++ b/framework/debug.cpp @@ -0,0 +1,5 @@ +#include "include/public/toon_boom/ext/util.hpp" + + std::ostream devnull(new NullBuffer()); + + std::ostream& out = TB_EXT_FRAMEWORK_DEBUG ? std::cout : devnull; diff --git a/framework/include/public/toon_boom/ext/util.hpp b/framework/include/public/toon_boom/ext/util.hpp index 3159b4a..3f9d826 100644 --- a/framework/include/public/toon_boom/ext/util.hpp +++ b/framework/include/public/toon_boom/ext/util.hpp @@ -1,7 +1,18 @@ #pragma once #include +#include +#include -std::string addrToHex(void* addr); +#if !defined(TB_EXT_FRAMEWORK_DEBUG) +#define TB_EXT_FRAMEWORK_DEBUG 0 +#endif +struct NullBuffer : std::streambuf { + int overflow(int c) { return c; } +}; -std::string constAddrToHex(const void* addr); \ No newline at end of file +std::string addrToHex(void *addr); + +std::string constAddrToHex(const void *addr); + +extern std::ostream &out;