mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-05 23:06:19 +00:00
transforming the addBuffer function into a templated function to save time with level etc
This commit is contained in:
@@ -110,12 +110,11 @@ namespace ComSquare::PPU
|
||||
|
||||
|
||||
//! @brief Add a bg buffer to another buffer
|
||||
template <std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y>
|
||||
template <int levelLow, int levelHigh, std::size_t DEST_SIZE_X, std::size_t DEST_SIZE_Y>
|
||||
static void mergeBackgroundBuffer(std::array<std::array<uint32_t, DEST_SIZE_Y>, DEST_SIZE_X> &bufferDest,
|
||||
std::array<std::array<unsigned char, DEST_SIZE_Y>, DEST_SIZE_X> &pixelDestinationLevelMap,
|
||||
const Background &backgroundSrc,
|
||||
int levelLow,
|
||||
int levelHigh)
|
||||
const Background &backgroundSrc
|
||||
)
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <bitset>
|
||||
#include "PPU.hpp"
|
||||
#include "Exceptions/InvalidAddress.hpp"
|
||||
#include "PPU/Background.hpp"
|
||||
#include "Models/Vector2.hpp"
|
||||
|
||||
namespace ComSquare::PPU::Utils::Debug {
|
||||
@@ -570,27 +571,30 @@ namespace ComSquare::PPU
|
||||
// the starting palette index isn't implemented
|
||||
switch (this->_registers._bgmode.bgMode) {
|
||||
case 0:
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg4NoPriority], {0, 15});
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3NoPriority], {10, 16});
|
||||
this->addToMainSubScreen<0, 15>(this->_backgrounds[BgName::bg4NoPriority]);
|
||||
this->addToMainSubScreen<10, 16>(this->_backgrounds[BgName::bg3NoPriority]);
|
||||
//sprites priority 0
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg4Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
//sprites priority 1
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2NoPriority], {20, 35});
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1NoPriority], {30, 36});
|
||||
this->addToMainSubScreen<20, 35>(this->_backgrounds[BgName::bg2NoPriority]);
|
||||
this->addToMainSubScreen<30, 36>(this->_backgrounds[BgName::bg1NoPriority]);
|
||||
//sprites priority 2
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
//sprites priority 3
|
||||
break;
|
||||
case 1:
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg3NoPriority], {0, this->_registers._bgmode.mode1Bg3PriorityBit ? 30 : 5});
|
||||
if (!this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
this->addToMainSubScreen<0, 5>(this->_backgrounds[BgName::bg3NoPriority]);
|
||||
else
|
||||
this->addToMainSubScreen<0, 30>(this->_backgrounds[BgName::bg3NoPriority]);
|
||||
//sprites priority 0
|
||||
// if (!this->_registers._bgmode.mode1Bg3PriorityBit)
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg3Priority]);
|
||||
//sprites priority 1
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg2NoPriority], {10, 25});
|
||||
this->addToMainSubScreen(this->_backgrounds[BgName::bg1NoPriority], {20, 26});
|
||||
this->addToMainSubScreen<10, 25>(this->_backgrounds[BgName::bg2NoPriority]);
|
||||
this->addToMainSubScreen<20, 26>(this->_backgrounds[BgName::bg1NoPriority]);
|
||||
//sprites priority 2
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg2Priority]);
|
||||
// this->addToMainSubScreen(this->_backgrounds[BgName::bg1Priority]);
|
||||
@@ -654,16 +658,6 @@ namespace ComSquare::PPU
|
||||
}
|
||||
}
|
||||
|
||||
void PPU::addToMainSubScreen(Background &bg, const Vector2<int> &level)
|
||||
{
|
||||
if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U))) {
|
||||
Background::mergeBackgroundBuffer(this->_mainScreen, this->_mainScreenLevelMap, bg, level.x, level.y);
|
||||
}
|
||||
if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U))) {
|
||||
Background::mergeBackgroundBuffer(this->_subScreen, this->_subScreenLevelMap, bg, level.x, level.y);
|
||||
}
|
||||
}
|
||||
|
||||
int PPU::getBgMode() const
|
||||
{
|
||||
return this->_registers._bgmode.bgMode;
|
||||
|
||||
@@ -624,7 +624,16 @@ namespace ComSquare::PPU
|
||||
//! @brief Render the Main and sub screen correctly
|
||||
void renderMainAndSubScreen();
|
||||
//! @brief Add a bg to the sub and/or main screen
|
||||
void addToMainSubScreen(Background &bg, const Vector2<int> &level);
|
||||
template<int levelLow, int levelHigh>
|
||||
void addToMainSubScreen(Background &bg)
|
||||
{
|
||||
if (this->_registers._t[0].raw & (1U << (bg.getBgNumber() - 1U))) {
|
||||
Background::mergeBackgroundBuffer<levelLow, levelHigh>(this->_mainScreen, this->_mainScreenLevelMap, bg);
|
||||
}
|
||||
if (this->_registers._t[1].raw & (1U << (bg.getBgNumber() - 1U))) {
|
||||
Background::mergeBackgroundBuffer<levelLow, levelHigh>(this->_subScreen, this->_subScreenLevelMap, bg);
|
||||
}
|
||||
}
|
||||
//! @brief Get the current background Mode
|
||||
[[nodiscard]] int getBgMode() const;
|
||||
//! @brief update the Vram buffer
|
||||
|
||||
@@ -646,6 +646,7 @@ TEST_CASE("render 8bpp", "[PPU][TileRenderer]")
|
||||
ComSquare::Ram::Ram vram(100, static_cast<ComSquare::Component>(0), "vramTest");
|
||||
ComSquare::Ram::Ram cgram(512, static_cast<ComSquare::Component>(0), "cgramTest");
|
||||
ComSquare::PPU::TileRenderer tileRenderer(vram, cgram);
|
||||
std::srand(std::time(nullptr));
|
||||
|
||||
tileRenderer.setBpp(8);
|
||||
tileRenderer.setPaletteIndex(0);
|
||||
|
||||
Reference in New Issue
Block a user