From b336a637690d98db0caa3341d564f502276f12f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 6 Jul 2021 22:21:11 +0200 Subject: [PATCH] moving addBuffer to utils --- sources/PPU/PPU.cpp | 8 ++++---- sources/PPU/PPU.hpp | 12 ------------ sources/PPU/PPUUtils.hpp | 13 +++++++++++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index ce13521..a0e58c8 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -311,8 +311,8 @@ namespace ComSquare::PPU (void)cycles; this->renderMainAndSubScreen(); - this->addBuffer(this->_screen, this->_subScreen); - this->addBuffer(this->_screen, this->_mainScreen); + Utils::addBuffer(this->_screen, this->_subScreen); + Utils::addBuffer(this->_screen, this->_mainScreen); //this->_backgrounds[2].renderBackground(); //add_buffer(this->_screen, this->_backgrounds[2].buffer); for (unsigned long i = 0; i < this->_screen.size(); i++) { @@ -656,9 +656,9 @@ namespace ComSquare::PPU void PPU::addToMainSubScreen(Background &bg) { if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U))) - this->addBuffer(this->_mainScreen, bg.buffer); + Utils::addBuffer(this->_mainScreen, bg.buffer); if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U))) - this->addBuffer(this->_subScreen, bg.buffer); + Utils::addBuffer(this->_subScreen, bg.buffer); } int PPU::getBgMode() const diff --git a/sources/PPU/PPU.hpp b/sources/PPU/PPU.hpp index 873bc91..175eb04 100644 --- a/sources/PPU/PPU.hpp +++ b/sources/PPU/PPU.hpp @@ -624,18 +624,6 @@ namespace ComSquare::PPU Vector2 getBackgroundMirroring(int bgNumber) const; //! @brief Render the Main and sub screen correctly void renderMainAndSubScreen(); - //! @brief Add a bg buffer to another buffer - template - void addBuffer(std::array, DEST_SIZE_X> &bufferDest, - const std::array, SRC_SIZE_X> &bufferSrc) - { - for (unsigned long i = 0; i < bufferSrc.size(); i++) { - for (unsigned long j = 0; j < bufferSrc[i].size(); j++) { - if (bufferSrc[i][j] > 0xFF) // 0xFF correspond to a black pixel with full brightness - bufferDest[i][j] = bufferSrc[i][j]; - } - } - } //! @brief Add a bg to the sub and/or main screen void addToMainSubScreen(Background &bg); //! @brief Get the current background Mode diff --git a/sources/PPU/PPUUtils.hpp b/sources/PPU/PPUUtils.hpp index 9d749a6..cb88312 100644 --- a/sources/PPU/PPUUtils.hpp +++ b/sources/PPU/PPUUtils.hpp @@ -78,5 +78,18 @@ namespace ComSquare::PPU::Utils std::reverse(array.begin() + offset.x, array.begin() + offset.x + size.x); } + //! @brief Add a bg buffer to another buffer + template + static void addBuffer(std::array, DEST_SIZE_X> &bufferDest, + const std::array, SRC_SIZE_X> &bufferSrc) + { + for (unsigned long i = 0; i < bufferSrc.size(); i++) { + for (unsigned long j = 0; j < bufferSrc[i].size(); j++) { + if (bufferSrc[i][j] > 0xFF) // 0xFF correspond to a black pixel with full brightness + bufferDest[i][j] = bufferSrc[i][j]; + } + } + } + } #endif //COMSQUARE_PPU_UTILS_HPP \ No newline at end of file