From 484ea7f246f11ab97c224b070e175c2cbe2a4060 Mon Sep 17 00:00:00 2001 From: w3irDv <170813473+w3irDv@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:52:19 +0200 Subject: [PATCH] eliminate temp buffer variables/simplify initscreen calls --- include/utils/DrawUtils.h | 3 --- src/utils/DrawUtils.cpp | 46 +++++++++------------------------------ 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/include/utils/DrawUtils.h b/include/utils/DrawUtils.h index 10a5bf3..725eb76 100644 --- a/include/utils/DrawUtils.h +++ b/include/utils/DrawUtils.h @@ -39,8 +39,6 @@ class DrawUtils { static void LogConsoleFree(); - static void initBuffers(void *tvBuffer, void *drcBuffer); - static void beginDraw(); static void endDraw(); @@ -92,7 +90,6 @@ class DrawUtils { static uint8_t *tvBuffer; static uint8_t *drcBuffer; - static void *sBufferTV, *sBufferDRC; static uint32_t sBufferSizeTV, sBufferSizeDRC; static BOOL sConsoleHasForeground; }; diff --git a/src/utils/DrawUtils.cpp b/src/utils/DrawUtils.cpp index 9c8085f..078b3c9 100644 --- a/src/utils/DrawUtils.cpp +++ b/src/utils/DrawUtils.cpp @@ -26,18 +26,13 @@ bool DrawUtils::isBackBuffer; uint8_t *DrawUtils::tvBuffer = nullptr; uint8_t *DrawUtils::drcBuffer = nullptr; -/* -uint32_t DrawUtils::sBufferSizeTV = 0; -uint32_t DrawUtils::sBufferSizeDRC = 0; -*/ +uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0; +BOOL DrawUtils::sConsoleHasForeground = TRUE; + static SFT pFont = {}; static Color font_col(0xFFFFFFFF); -void *DrawUtils::sBufferTV = NULL, *DrawUtils::sBufferDRC = NULL; -uint32_t DrawUtils::sBufferSizeTV = 0, DrawUtils::sBufferSizeDRC = 0; -BOOL DrawUtils::sConsoleHasForeground = TRUE; - uint32_t DrawUtils::initScreen() { @@ -45,45 +40,36 @@ DrawUtils::initScreen() MEMRecordStateForFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG); if (sBufferSizeTV) { - sBufferTV = MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4); + DrawUtils::tvBuffer = static_cast(MEMAllocFromFrmHeapEx(heap, sBufferSizeTV, 4)); } if (sBufferSizeDRC) { - sBufferDRC = MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4); + DrawUtils::drcBuffer = static_cast(MEMAllocFromFrmHeapEx(heap, sBufferSizeDRC, 4)); } sConsoleHasForeground = TRUE; - OSScreenSetBufferEx(SCREEN_TV, sBufferTV); - OSScreenSetBufferEx(SCREEN_DRC, sBufferDRC); - DrawUtils::initBuffers(sBufferTV, sBufferDRC); + OSScreenSetBufferEx(SCREEN_TV, DrawUtils::tvBuffer); + OSScreenSetBufferEx(SCREEN_DRC, DrawUtils::drcBuffer); - for (int i = 0; i<2; i++) // both buffers to black - { - DrawUtils::clear(COLOR_BLACK); - DrawUtils::endDraw(); - } + DrawUtils::endDraw(); // flip buffers DrawUtils::setRedraw(true); // force a redraw when reentering return 0; + } uint32_t DrawUtils::deinitScreen() { - for (int i = 0; i<2; i++) // both buffers to black - { - DrawUtils::clear(COLOR_BLACK); - DrawUtils::endDraw(); - } - MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1); MEMFreeByStateToFrmHeap(heap, CONSOLE_FRAME_HEAP_TAG); sConsoleHasForeground = FALSE; return 0; + } @@ -123,11 +109,6 @@ void DrawUtils::setRedraw(bool value) { redraw = value; } -void DrawUtils::initBuffers(void *sBufferTV_, void *sBufferDRC_) { - DrawUtils::tvBuffer = (uint8_t *) sBufferTV_; - DrawUtils::drcBuffer = (uint8_t *) sBufferDRC_; -} - void DrawUtils::beginDraw() { uint32_t pixel = *(uint32_t *) tvBuffer; @@ -144,13 +125,6 @@ void DrawUtils::beginDraw() { } void DrawUtils::endDraw() { - // OSScreenFlipBuffersEx already flushes the cache? - // DCFlushRange(tvBuffer, sBufferSizeTV); - // DCFlushRange(drcBuffer, sBufferSizeDRC); - - DCFlushRange(sBufferTV, sBufferSizeTV); - DCFlushRange(sBufferDRC, sBufferSizeDRC); - OSScreenFlipBuffersEx(SCREEN_DRC); OSScreenFlipBuffersEx(SCREEN_TV); }