diff --git a/sources/Debugger/TileViewer/RAMTileRenderer.cpp b/sources/Debugger/TileViewer/RAMTileRenderer.cpp index c8f9661..7dc27bc 100644 --- a/sources/Debugger/TileViewer/RAMTileRenderer.cpp +++ b/sources/Debugger/TileViewer/RAMTileRenderer.cpp @@ -18,29 +18,34 @@ namespace ComSquare::Debugger buffer({{0}}) {} -/* void prepVector(std::vector> &vector, int nbColumns) + void prepVector(std::vector> &vector, int nbColumns) { + std::vector> vec(1 * PPU::Tile::NbPixelsHeight, std::vector(nbColumns * PPU::Tile::NbPixelsWidth, 0)); + vector = vec; + return; std::vector pixelLine(static_cast(nbColumns), 0); + vector.reserve(8); for (int i = 0; i < 8; i++) { vector.push_back(pixelLine); } - }*/ + } void RAMTileRenderer::render() { + this->buffer.clear(); int bufX = 0; int bufY = 0; int nbTilesDrawn = 0; int resetX = bufX; int nbLinesDrawn = 0; - for (auto &i : this->buffer) - i.fill(0); + //for (auto &i : this->buffer) + // i.fill(0); uint24_t limit = std::fmin(this->_ram.getSize(), this->_renderSize) + this->_ramOffset; - //std::vector> row; + std::vector> row; - //prepVector(row, this->_nbColumns); + prepVector(row, this->_nbColumns); for (uint24_t i = this->_ramOffset; i < limit; i += PPU::Tile::BaseByteSize * this->_bpp, nbTilesDrawn++) { if (bufX > 1024 || bufY > 1024) break; @@ -55,17 +60,17 @@ namespace ComSquare::Debugger nbTilesDrawn = 0; nbLinesDrawn++; resetX = 0; - bufX = resetX; - bufY += PPU::Tile::NbPixelsHeight; - //bufX = 0; - //bufY = 0; - //this->buffer.insert(this->buffer.end(), row.begin(), row.end()); - //prepVector(row, this->_nbColumns); + //bufX = resetX; + //bufY += PPU::Tile::NbPixelsHeight; + bufX = 0; + bufY = 0; + this->buffer.insert(this->buffer.end(), row.begin(), row.end()); + prepVector(row, this->_nbColumns); } for (const auto &raw : this->_tileRenderer.buffer) { for (const auto &pixel : raw) { - this->buffer[bufX++][bufY] = pixel; + row[bufY][bufX++] = pixel; } bufY++; bufX = resetX; diff --git a/sources/Debugger/TileViewer/RAMTileRenderer.hpp b/sources/Debugger/TileViewer/RAMTileRenderer.hpp index d41bc9f..eb0ad57 100644 --- a/sources/Debugger/TileViewer/RAMTileRenderer.hpp +++ b/sources/Debugger/TileViewer/RAMTileRenderer.hpp @@ -28,7 +28,8 @@ namespace ComSquare::Debugger PPU::TileRenderer _tileRenderer; public: //! @brief internal buffer - std::array, 1024> buffer; + //std::array, 1024> buffer; + std::vector> buffer; //! @brief Set the palette to use for render (index of palette) void setPaletteIndex(int paletteIndex); //! @brief Set the bpp to render graphics diff --git a/sources/Debugger/TileViewer/TileViewer.cpp b/sources/Debugger/TileViewer/TileViewer.cpp index 7b22df7..12db102 100644 --- a/sources/Debugger/TileViewer/TileViewer.cpp +++ b/sources/Debugger/TileViewer/TileViewer.cpp @@ -118,7 +118,7 @@ namespace ComSquare::Debugger int j = 0; for (const auto &row : this->_ramTileRenderer.buffer) { for (const auto &pixel : row) { - this->_renderer->putPixel(j++, i, pixel); + this->_renderer->putPixel(i, j++, pixel); } j = 0; i++; diff --git a/sources/Renderer/IRenderer.hpp b/sources/Renderer/IRenderer.hpp index 2430565..7429e42 100644 --- a/sources/Renderer/IRenderer.hpp +++ b/sources/Renderer/IRenderer.hpp @@ -25,11 +25,11 @@ namespace ComSquare //! @param width The new width of the renderer in pixels virtual void setSize(unsigned width, unsigned height) = 0; - //! @brief Set a pixel to the coordinates x, y with the color rgba - //! @param x The x position of the window (0, 0 is the top left corner). - //! @param y The y position of the window (0, 0 is the top left corner). - //! @param rgba The color of the pixel (red, green, blue, alpha). - virtual void putPixel(unsigned x, unsigned y, uint32_t rgba) = 0; + //! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba. + //! @param horizontalPosition horizontal index. + //! @param verticalPosition vertical index. + //! @param rgba The color of the pixel. + virtual void putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) = 0; //! @brief Use this function to create the window. //! @param snes The snes game object (to call the update method). diff --git a/sources/Renderer/NoRenderer.hpp b/sources/Renderer/NoRenderer.hpp index 1e91531..0904f9f 100644 --- a/sources/Renderer/NoRenderer.hpp +++ b/sources/Renderer/NoRenderer.hpp @@ -21,7 +21,7 @@ namespace ComSquare::Renderer //! @param X horizontal index. //! @param Y vertical index. //! @param rgba The color of the pixel. - void putPixel(unsigned y, unsigned x, uint32_t rgba) override; + void putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) override; //! @brief Playing all samples from buffer //! @param samples Buffer containing samples //! @param sampleCount number of samples inside buffer diff --git a/sources/Renderer/QtRenderer/QtSFML.cpp b/sources/Renderer/QtRenderer/QtSFML.cpp index 877e342..6db328e 100644 --- a/sources/Renderer/QtRenderer/QtSFML.cpp +++ b/sources/Renderer/QtRenderer/QtSFML.cpp @@ -31,9 +31,9 @@ namespace ComSquare::Renderer this->_sfWidget = new QtFullSFML(snes, this->_window, QPoint(0, 0), QSize(this->_window->width(), this->_window->height()), maxFPS); } - void QtSFML::putPixel(unsigned y, unsigned x, uint32_t rgba) + void QtSFML::putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) { - this->_sfWidget->putPixel(y, x, rgba); + this->_sfWidget->putPixel(verticalPosition, horizontalPosition, rgba); } void QtSFML::playAudio(std::span samples) diff --git a/sources/Renderer/QtRenderer/QtSFML.hpp b/sources/Renderer/QtRenderer/QtSFML.hpp index e454ecc..f34fd12 100644 --- a/sources/Renderer/QtRenderer/QtSFML.hpp +++ b/sources/Renderer/QtRenderer/QtSFML.hpp @@ -73,7 +73,7 @@ namespace ComSquare::Renderer //! @param X horizontal index. //! @param Y vertical index. //! @param rgba The color of the pixel. - void putPixel(unsigned y, unsigned x, uint32_t rgba) override; + void putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) override; //! @brief This function doesn't do anything because QT internally handle drawing to the screen. void drawScreen() override; //! @brief Playing all samples from buffer diff --git a/sources/Renderer/SFRenderer.cpp b/sources/Renderer/SFRenderer.cpp index 30ee8a4..127f37b 100644 --- a/sources/Renderer/SFRenderer.cpp +++ b/sources/Renderer/SFRenderer.cpp @@ -59,14 +59,14 @@ namespace ComSquare::Renderer this->_sound.play(); } - void SFRenderer::putPixel(unsigned y, unsigned x, uint32_t rgba) + void SFRenderer::putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) { - if (x >= this->_videoMode.width) - throw InvalidPixelPosition("Width", x, this->_videoMode.width); - if (y >= this->_videoMode.height) - throw InvalidPixelPosition("Height", y, this->_videoMode.height); + if (verticalPosition >= this->_videoMode.width) + throw InvalidPixelPosition("Width", verticalPosition, this->_videoMode.width); + if (horizontalPosition >= this->_videoMode.height) + throw InvalidPixelPosition("Height", horizontalPosition, this->_videoMode.height); - this->_pixelBuffer[this->_videoMode.width * y + x] = sf::Color(rgba); + this->_pixelBuffer[this->_videoMode.width * verticalPosition + horizontalPosition] = sf::Color(rgba); } void SFRenderer::getEvents() diff --git a/sources/Renderer/SFRenderer.hpp b/sources/Renderer/SFRenderer.hpp index 910ca1a..7215baa 100644 --- a/sources/Renderer/SFRenderer.hpp +++ b/sources/Renderer/SFRenderer.hpp @@ -53,10 +53,10 @@ namespace ComSquare::Renderer //! @param width The new width of the renderer in pixels void setSize(unsigned width, unsigned height) override; //! @brief Add a pixel to the buffer to the coordinates x, y with the color rgba. - //! @param X horizontal index. - //! @param Y vertical index. + //! @param horizontalPosition horizontal index. + //! @param verticalPosition vertical index. //! @param rgba The color of the pixel. - void putPixel(unsigned y, unsigned x, uint32_t rgba) override; + void putPixel(unsigned verticalPosition, unsigned horizontalPosition, uint32_t rgba) override; //! @brief Playing all samples from buffer //! @param samples Buffer containing samples //! @param sampleCount number of samples inside buffer