splitting more conveniently drawTile function

This commit is contained in:
Clément Le Bihan
2021-07-06 23:13:37 +02:00
parent 6e37b8f250
commit 213f1608a7
4 changed files with 30 additions and 14 deletions
+19 -10
View File
@@ -57,15 +57,8 @@ namespace ComSquare::PPU
}
}
void Background::_drawBgTile(uint16_t data, Vector2<int> pos)
void Background::_drawTileFromMemoryToTileBuffer(const Utils::TileData &tileData)
{
union Utils::TileMapData tileData;
tileData.raw = data;
if (tileData.tilePriority != this->_priority)
return;
uint16_t graphicAddress;
Vector2i tileOffset = {0, 0};
// X horizontal
@@ -84,6 +77,17 @@ namespace ComSquare::PPU
tileOffset.x = 0;
tileOffset.y++;
}
}
void Background::_drawTile(uint16_t data, Vector2<int> pos)
{
union Utils::TileData tileData;
tileData.raw = data;
//if (tileData.tilePriority != this->_priority)
// return;
this->_drawTileFromMemoryToTileBuffer(tileData);
// todo check why i need to invert vertical and horizontal flips
if (tileData.verticalFlip)
@@ -107,8 +111,8 @@ namespace ComSquare::PPU
// TODO function to read 2 bytes (LSB order or bits reversed)
tileMapValue = this->_vram->read(vramAddress);
tileMapValue += this->_vram->read(vramAddress + 1) << 8U;
_drawBgTile(tileMapValue, {(pos.x * this->_characterNbPixels.x) + offset.x,
(pos.y * this->_characterNbPixels.y) + offset.y});
this->_drawTile(tileMapValue, {(pos.x * this->_characterNbPixels.x) + offset.x,
(pos.y * this->_characterNbPixels.y) + offset.y});
vramAddress += 2;
if (pos.x % 31 == 0 && pos.x) {
pos.y++;
@@ -162,4 +166,9 @@ namespace ComSquare::PPU
{
return this->_priority;
}
bool Background::isPriorityPixel(int y, int x) const
{
return this->tilesPriority[y / this->_characterNbPixels.y][x / this->_characterNbPixels.x];
}
}