mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-28 08:33:34 +00:00
dynamic buffer size for RAMTileRenderer.cpp is working
This commit is contained in:
@@ -18,29 +18,34 @@ namespace ComSquare::Debugger
|
||||
buffer({{0}})
|
||||
{}
|
||||
|
||||
/* void prepVector(std::vector<std::vector<uint32_t>> &vector, int nbColumns)
|
||||
void prepVector(std::vector<std::vector<uint32_t>> &vector, int nbColumns)
|
||||
{
|
||||
std::vector<std::vector<uint32_t>> vec(1 * PPU::Tile::NbPixelsHeight, std::vector<uint32_t>(nbColumns * PPU::Tile::NbPixelsWidth, 0));
|
||||
vector = vec;
|
||||
return;
|
||||
std::vector<uint32_t> pixelLine(static_cast<unsigned int>(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<std::vector<uint32_t>> row;
|
||||
std::vector<std::vector<uint32_t>> 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;
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace ComSquare::Debugger
|
||||
PPU::TileRenderer _tileRenderer;
|
||||
public:
|
||||
//! @brief internal buffer
|
||||
std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||
//std::array<std::array<uint32_t, 1024>, 1024> buffer;
|
||||
std::vector<std::vector<uint32_t>> buffer;
|
||||
//! @brief Set the palette to use for render (index of palette)
|
||||
void setPaletteIndex(int paletteIndex);
|
||||
//! @brief Set the bpp to render graphics
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int16_t> samples)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user