diff --git a/src/SelbaWard/FrameTransition.hpp b/src/SelbaWard/FrameTransition.hpp index e1d5db5..c2562df 100644 --- a/src/SelbaWard/FrameTransition.hpp +++ b/src/SelbaWard/FrameTransition.hpp @@ -40,7 +40,7 @@ namespace selbaward { -// SW Frame Transition v1.0.1 +// SW Frame Transition v1.0.2 class FrameTransition : public sf::Drawable, public sf::Transformable { public: @@ -278,7 +278,7 @@ class FrameTransition : public sf::Drawable, public sf::Transformable mutable bool m_isUpdateRequired; mutable std::vector m_vertices; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_update() const; void priv_updateFromTexCrop() const; void priv_updateFromZoom() const; diff --git a/src/SelbaWard/PixelDisplay.cpp b/src/SelbaWard/PixelDisplay.cpp index 09ddb67..0f86cc2 100644 --- a/src/SelbaWard/PixelDisplay.cpp +++ b/src/SelbaWard/PixelDisplay.cpp @@ -56,48 +56,48 @@ inline unsigned char randomByte() } template -void shiftVectorDown(std::vector& vector, const unsigned int amount, const unsigned int startIndex, unsigned int numberOfElements) +void shiftVectorDown(std::vector& vector, const std::size_t amount, const std::size_t startIndex, std::size_t numberOfElements) { if ((numberOfElements == 0u) || (startIndex + numberOfElements > vector.size())) - numberOfElements = static_cast(vector.size()) - startIndex; + numberOfElements = vector.size() - startIndex; for (unsigned int i{ 0u }; i < numberOfElements - amount; ++i) vector[startIndex + i] = vector[startIndex + i + amount]; } template -void shiftVectorUp(std::vector& vector, const unsigned int amount, const unsigned int startIndex, unsigned int numberOfElements) +void shiftVectorUp(std::vector& vector, const std::size_t amount, const std::size_t startIndex, std::size_t numberOfElements) { if ((numberOfElements == 0u) || (startIndex + numberOfElements > vector.size())) - numberOfElements = static_cast(vector.size()) - startIndex; + numberOfElements = vector.size() - startIndex; for (unsigned int i{ 0u }; i < numberOfElements - amount; ++i) vector[startIndex + numberOfElements - i - 1u] = vector[startIndex + numberOfElements - (i + amount) - 1u]; } template -void shiftVectorWrapDown(std::vector& vector, const unsigned int amount, const unsigned int startIndex, unsigned int numberOfElements) +void shiftVectorWrapDown(std::vector& vector, const std::size_t amount, const std::size_t startIndex, std::size_t numberOfElements) { if ((numberOfElements == 0u) || (startIndex + numberOfElements > vector.size())) - numberOfElements = static_cast(vector.size()) - startIndex; + numberOfElements = vector.size() - startIndex; std::vector tempPixels(amount); - for (unsigned int i{ 0u }; i < amount; ++i) + for (std::size_t i{ 0u }; i < amount; ++i) tempPixels[i] = vector[startIndex + i]; - for (unsigned int i{ 0u }; i < numberOfElements - amount; ++i) + for (std::size_t i{ 0u }; i < numberOfElements - amount; ++i) vector[startIndex + i] = vector[startIndex + i + amount]; - for (unsigned int i{ 0u }; i < amount; ++i) + for (std::size_t i{ 0u }; i < amount; ++i) vector[startIndex + numberOfElements - amount + i] = tempPixels[i]; } template -void shiftVectorWrapUp(std::vector& vector, const unsigned int amount, const unsigned int startIndex, unsigned int numberOfElements) +void shiftVectorWrapUp(std::vector& vector, const std::size_t amount, const std::size_t startIndex, std::size_t numberOfElements) { if ((numberOfElements == 0u) || (startIndex + numberOfElements > vector.size())) - numberOfElements = static_cast(vector.size()) - startIndex; + numberOfElements = vector.size() - startIndex; std::vector tempPixels(amount); - for (unsigned int i{ 0u }; i < amount; ++i) + for (std::size_t i{ 0u }; i < amount; ++i) tempPixels[i] = vector[startIndex + numberOfElements - amount + i]; - for (unsigned int i{ 0u }; i < numberOfElements - amount; ++i) + for (std::size_t i{ 0u }; i < numberOfElements - amount; ++i) vector[startIndex + numberOfElements - i - 1u] = vector[startIndex + numberOfElements - (i + amount) - 1u]; - for (unsigned int i{ 0u }; i < amount; ++i) + for (std::size_t i{ 0u }; i < amount; ++i) vector[startIndex + i] = tempPixels[i]; } @@ -107,12 +107,12 @@ namespace selbaward { PixelDisplay::PixelDisplay() - : m_vertices() - , m_resolution(320u, 240u) - , m_size(640.f, 480.f) + : m_vertices{} + , m_resolution{ 320u, 240u } + , m_size{ 640.f, 480.f } , m_palette(16u) - , m_pixels() - , m_buffers() + , m_pixels{} + , m_buffers{} { priv_updateVertices(); m_pixels.resize(m_resolution.x * m_resolution.y); @@ -127,45 +127,45 @@ void PixelDisplay::setSize(const sf::Vector2f size) priv_updateVertices(); } -void PixelDisplay::setResolution(const sf::Vector2u resolution) +void PixelDisplay::setResolution(const sf::Vector2 resolution) { m_resolution = resolution; m_pixels.resize(m_resolution.x * m_resolution.y); priv_updateVertices(); } -void PixelDisplay::setPaletteSize(const unsigned int numberOfColors) +void PixelDisplay::setPaletteSize(const std::size_t numberOfColors) { m_palette.resize(numberOfColors); } -void PixelDisplay::setColor(const unsigned int color, const sf::Color rgb) +void PixelDisplay::setColor(const std::size_t color, const sf::Color rgb) { assert(color < m_palette.size()); m_palette[color] = rgb; priv_updatePixels(); } -void PixelDisplay::setPixel(const unsigned int index, const unsigned int color) +void PixelDisplay::setPixel(const std::size_t index, const std::size_t color) { assert(index < m_pixels.size()); m_pixels[index] = color; priv_updatePixel(index); } -void PixelDisplay::setPixels(const char* colors, const unsigned int numberOfColors, const unsigned int startIndex) +void PixelDisplay::setPixels(const char* colors, const std::size_t numberOfColors, const std::size_t startIndex) { assert(startIndex < m_pixels.size()); setPixels(reinterpret_cast(colors), numberOfColors, startIndex); } -void PixelDisplay::getPixels(char* colors, const unsigned int numberOfColors, const unsigned int startIndex) const +void PixelDisplay::getPixels(char* colors, const std::size_t numberOfColors, const std::size_t startIndex) const { assert(startIndex < m_pixels.size()); getPixels(reinterpret_cast(colors), numberOfColors, startIndex); } -void PixelDisplay::fill(const unsigned int color) +void PixelDisplay::fill(const std::size_t color) { assert(color < m_palette.size()); for (auto& pixel : m_pixels) @@ -186,169 +186,169 @@ void PixelDisplay::randomize() priv_updatePixels(); } -void PixelDisplay::shiftLeft(const unsigned int amount, const unsigned int startIndex, const unsigned int numberOfPixels) +void PixelDisplay::shiftLeft(const std::size_t amount, const std::size_t startIndex, const std::size_t numberOfPixels) { assert(startIndex < m_pixels.size()); shiftVectorWrapDown(m_pixels, amount, startIndex, numberOfPixels); priv_updatePixels(); } -void PixelDisplay::shiftRight(const unsigned int amount, const unsigned int startIndex, const unsigned int numberOfPixels) +void PixelDisplay::shiftRight(const std::size_t amount, const std::size_t startIndex, const std::size_t numberOfPixels) { assert(startIndex < m_pixels.size()); shiftVectorWrapUp(m_pixels, amount, startIndex, numberOfPixels); priv_updatePixels(); } -void PixelDisplay::scrollUp(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollUp(const std::size_t color, const std::size_t amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; + const std::size_t index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; m_pixels[index] = (y == rectangle.size.y - 1u) ? color : m_pixels[index + m_resolution.x]; } } priv_updatePixels(); } -void PixelDisplay::scrollDown(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollDown(const std::size_t color, const std::size_t amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; + const std::size_t index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; m_pixels[index] = (y == rectangle.size.y - 1u) ? color : m_pixels[index - m_resolution.x]; } } priv_updatePixels(); } -void PixelDisplay::scrollLeft(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollLeft(const std::size_t color, const std::size_t amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - const unsigned int firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; + const std::size_t firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; shiftVectorDown(m_pixels, amount, firstPixelIndex, rectangle.size.x); m_pixels[firstPixelIndex + rectangle.size.x - 1u] = color; } priv_updatePixels(); } -void PixelDisplay::scrollRight(const unsigned int color, const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollRight(const std::size_t color, const std::size_t amount, sf::IntRect selectionRectangle) { assert(color < m_palette.size()); assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - const unsigned int firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; + const std::size_t firstPixelIndex{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x }; shiftVectorUp(m_pixels, amount, firstPixelIndex, rectangle.size.x); m_pixels[firstPixelIndex] = color; } priv_updatePixels(); } -void PixelDisplay::scrollWrapUp(const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollWrapUp(const std::size_t amount, sf::IntRect selectionRectangle) { assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - std::vector tempRow(rectangle.size.x); - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + std::vector tempRow(rectangle.size.x); + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) tempRow[x] = m_pixels[rectangle.position.y * m_resolution.x + rectangle.position.x + x]; - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; + const std::size_t index{ (rectangle.position.y + y) * m_resolution.x + rectangle.position.x + x }; m_pixels[index] = (y == rectangle.size.y - 1u) ? tempRow[x] : m_pixels[index + m_resolution.x]; } } priv_updatePixels(); } -void PixelDisplay::scrollWrapDown(const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollWrapDown(const std::size_t amount, sf::IntRect selectionRectangle) { assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - std::vector tempRow(rectangle.size.x); - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + std::vector tempRow(rectangle.size.x); + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) tempRow[x] = m_pixels[(rectangle.position.y + rectangle.size.y - 1u) * m_resolution.x + rectangle.position.x + x]; - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < rectangle.size.x; ++x) + for (std::size_t x{ 0u }; x < rectangle.size.x; ++x) { - const unsigned int index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; + const std::size_t index{ (rectangle.position.y + rectangle.size.y - y - 1u) * m_resolution.x + rectangle.position.x + x }; m_pixels[index] = (y == rectangle.size.y - 1u) ? tempRow[x] : m_pixels[index - m_resolution.x]; } } priv_updatePixels(); } -void PixelDisplay::scrollWrapLeft(const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollWrapLeft(const std::size_t amount, sf::IntRect selectionRectangle) { assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) shiftVectorWrapDown(m_pixels, amount, (rectangle.position.y + y) * m_resolution.x + rectangle.position.x, rectangle.size.x); priv_updatePixels(); } -void PixelDisplay::scrollWrapRight(const unsigned int amount, sf::IntRect selectionRectangle) +void PixelDisplay::scrollWrapRight(const std::size_t amount, sf::IntRect selectionRectangle) { assert(selectionRectangle.position.x < static_cast(m_resolution.x)); assert(selectionRectangle.position.y < static_cast(m_resolution.y)); if (selectionRectangle.size.x == 0u) - selectionRectangle.size.x = m_resolution.x - selectionRectangle.position.x; + selectionRectangle.size.x = static_cast(m_resolution.x - selectionRectangle.position.x); if (selectionRectangle.size.y == 0u) - selectionRectangle.size.y = m_resolution.y - selectionRectangle.position.y; - for (unsigned int y{ 0u }; y < static_cast(selectionRectangle.size.y); ++y) + selectionRectangle.size.y = static_cast(m_resolution.y - selectionRectangle.position.y); + for (std::size_t y{ 0u }; y < static_cast(selectionRectangle.size.y); ++y) shiftVectorWrapUp(m_pixels, amount, (selectionRectangle.position.y + y) * m_resolution.x + selectionRectangle.position.x, selectionRectangle.size.x); priv_updatePixels(); } @@ -359,7 +359,7 @@ void PixelDisplay::setPalette(const std::vector& colors) priv_updatePixels(); } -void PixelDisplay::removeColor(const unsigned int color) +void PixelDisplay::removeColor(const std::size_t color) { assert(color < m_palette.size()); m_palette.erase(m_palette.begin() + color); @@ -371,40 +371,40 @@ void PixelDisplay::addRgb(const sf::Color rgb) m_palette.emplace_back(rgb); } -void PixelDisplay::cyclePaletteDown(const unsigned int amount, const unsigned int firstColor, const unsigned int numberOfColors) +void PixelDisplay::cyclePaletteDown(const std::size_t amount, const std::size_t firstColor, const std::size_t numberOfColors) { assert(firstColor < m_palette.size()); shiftVectorWrapDown(m_palette, amount, firstColor, numberOfColors); priv_updatePixels(); } -void PixelDisplay::cyclePaletteUp(const unsigned int amount, const unsigned int firstColor, const unsigned int numberOfColors) +void PixelDisplay::cyclePaletteUp(const std::size_t amount, const std::size_t firstColor, const std::size_t numberOfColors) { assert(firstColor < m_palette.size()); shiftVectorWrapUp(m_palette, amount, firstColor, numberOfColors); priv_updatePixels(); } -unsigned int PixelDisplay::copy() +std::size_t PixelDisplay::copy() { m_buffers.push_back({ m_resolution.x, m_pixels }); - return static_cast(m_buffers.size()) - 1u; + return m_buffers.size() - 1u; } -void PixelDisplay::copy(const unsigned int index) +void PixelDisplay::copy(const std::size_t index) { assert(index < m_buffers.size()); m_buffers[index] = { m_resolution.x, m_pixels }; } -unsigned int PixelDisplay::copy(const sf::IntRect selectionRectangle) +std::size_t PixelDisplay::copy(const sf::IntRect selectionRectangle) { m_buffers.emplace_back(); priv_copyToBufferFromSelectionRectangle(m_buffers.back(), selectionRectangle); - return static_cast(m_buffers.size()) - 1u; + return m_buffers.size() - 1u; } -void PixelDisplay::copy(const unsigned int index, const sf::IntRect selectionRectangle) +void PixelDisplay::copy(const std::size_t index, const sf::IntRect selectionRectangle) { assert(index < m_buffers.size()); priv_copyToBufferFromSelectionRectangle(m_buffers[index], selectionRectangle); @@ -416,7 +416,7 @@ void PixelDisplay::paste(const sf::Vector2i offset) priv_pasteOffsetBuffer(m_buffers.back(), offset); } -void PixelDisplay::paste(const unsigned int index, const sf::Vector2i offset) +void PixelDisplay::paste(const std::size_t index, const sf::Vector2i offset) { assert(index < m_buffers.size()); priv_pasteOffsetBuffer(m_buffers[index], offset); @@ -428,25 +428,25 @@ void PixelDisplay::removeBuffer() m_buffers.pop_back(); } -void PixelDisplay::removeBuffer(const unsigned int index) +void PixelDisplay::removeBuffer(const std::size_t index) { assert(m_buffers.size() != 0u); m_buffers.erase(m_buffers.begin() + index); } -unsigned int PixelDisplay::addBuffer(const sf::Vector2u size) +std::size_t PixelDisplay::addBuffer(const sf::Vector2 size) { - const unsigned int newBufferIndex{ static_cast(m_buffers.size()) }; + const std::size_t newBufferIndex{ m_buffers.size() }; m_buffers.emplace_back(); - resizeBuffer(static_cast(m_buffers.size()) - 1u, size); + resizeBuffer(m_buffers.size() - 1u, size); return newBufferIndex; } -void PixelDisplay::resizeBuffer(const unsigned int index, const sf::Vector2u size) +void PixelDisplay::resizeBuffer(const std::size_t index, const sf::Vector2 size) { assert(index < m_buffers.size()); Buffer& buffer{ m_buffers[index] }; - const unsigned int newNumberOfPixels{ size.x * size.y }; + const std::size_t newNumberOfPixels{ size.x * size.y }; if (buffer.pixels.empty()) { buffer.pixels.resize(newNumberOfPixels, 0u); @@ -454,12 +454,12 @@ void PixelDisplay::resizeBuffer(const unsigned int index, const sf::Vector2u siz return; } - const unsigned int currentBufferHeight{ static_cast(buffer.pixels.size()) / buffer.width }; + const std::size_t currentBufferHeight{ buffer.pixels.size() / buffer.width }; if (size.x < buffer.width) { - for (unsigned int i{ 0u }; i < size.x * currentBufferHeight; ++i) + for (std::size_t i{ 0u }; i < size.x * currentBufferHeight; ++i) { - const unsigned int targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; + const std::size_t targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; buffer.pixels[i] = buffer.pixels[targetIndex]; } buffer.pixels.resize(size.x * currentBufferHeight); @@ -472,19 +472,19 @@ void PixelDisplay::resizeBuffer(const unsigned int index, const sf::Vector2u siz { if (i % size.x >= buffer.width) { - buffer.pixels[i] = 0u; + buffer.pixels[static_cast(i)] = 0u; continue; } - const unsigned int targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; - buffer.pixels[i] = buffer.pixels[targetIndex]; + const std::size_t targetIndex{ static_cast((i / size.x) * buffer.width + (i % size.x)) }; + buffer.pixels[static_cast(i)] = buffer.pixels[targetIndex]; } buffer.width = size.x; } if (size.y < currentBufferHeight) { - for (unsigned int i{ 0u }; i < newNumberOfPixels; ++i) + for (std::size_t i{ 0u }; i < newNumberOfPixels; ++i) { - const unsigned int targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; + const std::size_t targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; buffer.pixels[i] = buffer.pixels[targetIndex]; } buffer.pixels.resize(newNumberOfPixels); @@ -496,20 +496,20 @@ void PixelDisplay::resizeBuffer(const unsigned int index, const sf::Vector2u siz { if (i / size.x >= currentBufferHeight) { - buffer.pixels[i] = 0u; + buffer.pixels[static_cast(i)] = 0u; continue; } - const unsigned int targetIndex{ (i / size.x) * buffer.width + (i % size.x) }; - buffer.pixels[i] = buffer.pixels[targetIndex]; + const std::size_t targetIndex{ static_cast((i / size.x) * buffer.width + (i % size.x)) }; + buffer.pixels[static_cast(i)] = buffer.pixels[targetIndex]; } } } -sf::Vector2u PixelDisplay::getSizeOfBuffer(const unsigned int index) const +sf::Vector2 PixelDisplay::getSizeOfBuffer(const std::size_t index) const { assert(index < m_buffers.size()); const Buffer& buffer{ m_buffers[index] }; - return{ static_cast(buffer.pixels.size()) % buffer.width, static_cast(buffer.pixels.size()) / buffer.width }; + return{ buffer.pixels.size() % buffer.width, buffer.pixels.size() / buffer.width }; } @@ -531,9 +531,9 @@ void PixelDisplay::draw(sf::RenderTarget& target, sf::RenderStates states) const void PixelDisplay::priv_updateVertices() { m_vertices.resize(m_resolution.x * m_resolution.y * 6u); - for (unsigned int y{ 0u }; y < m_resolution.y; ++y) + for (std::size_t y{ 0u }; y < m_resolution.y; ++y) { - for (unsigned int x{ 0u }; x < m_resolution.x; ++x) + for (std::size_t x{ 0u }; x < m_resolution.x; ++x) { const sf::Vector2f topLeft{ m_size.x * x / m_resolution.x, m_size.y * y / m_resolution.y }; const sf::Vector2f bottomRight{ m_size.x * (x + 1u) / m_resolution.x, m_size.y * (y + 1u) / m_resolution.y }; @@ -549,14 +549,14 @@ void PixelDisplay::priv_updateVertices() void PixelDisplay::priv_updatePixels() { - const unsigned int numberOfPixels{ static_cast(m_pixels.size()) }; - for (unsigned int i{ 0u }; i < numberOfPixels; ++i) + const std::size_t numberOfPixels{ m_pixels.size() }; + for (std::size_t i{ 0u }; i < numberOfPixels; ++i) priv_updatePixel(i); } -void PixelDisplay::priv_updatePixel(const unsigned int index) +void PixelDisplay::priv_updatePixel(const std::size_t index) { - const unsigned int baseVertexIndex{ index * 6u }; + const std::size_t baseVertexIndex{ index * 6u }; const sf::Color rgb{ m_palette[m_pixels[index]] }; m_vertices[baseVertexIndex + 0u].color = rgb; m_vertices[baseVertexIndex + 1u].color = rgb; @@ -566,20 +566,20 @@ void PixelDisplay::priv_updatePixel(const unsigned int index) m_vertices[baseVertexIndex + 5u].color = rgb; } -unsigned int PixelDisplay::priv_getRandomColor() const +std::size_t PixelDisplay::priv_getRandomColor() const { - return std::uniform_int_distribution(0u, static_cast(m_palette.size()) - 1u)(randomGenerator); + return std::uniform_int_distribution(0u, m_palette.size() - 1u)(randomGenerator); } void PixelDisplay::priv_copyToBufferFromSelectionRectangle(Buffer& buffer, const sf::IntRect& selectionRectangle) { assert(priv_isSelectionRectangleFullyContained(selectionRectangle)); buffer.width = selectionRectangle.size.x; - buffer.pixels.resize(selectionRectangle.size.x * selectionRectangle.size.y); - sf::Rect rectangle(selectionRectangle); - for (unsigned int y{ 0u }; y < rectangle.size.y; ++y) + buffer.pixels.resize(static_cast(selectionRectangle.size.x * selectionRectangle.size.y)); + sf::Rect rectangle(selectionRectangle); + for (std::size_t y{ 0u }; y < rectangle.size.y; ++y) { - for (unsigned int x{ 0u }; x < buffer.width; ++x) + for (std::size_t x{ 0u }; x < buffer.width; ++x) buffer.pixels[y * buffer.width + x] = m_pixels[(y + rectangle.position.y) * buffer.width + (x + rectangle.position.x)]; } } @@ -587,24 +587,24 @@ void PixelDisplay::priv_copyToBufferFromSelectionRectangle(Buffer& buffer, const void PixelDisplay::priv_pasteOffsetBuffer(const Buffer& buffer, const sf::Vector2i& offset) { //const unsigned int bufferHeight{ buffer.pixels.size() / buffer.width }; - for (unsigned int i{ 0u }; i < buffer.pixels.size(); ++i) + for (std::size_t i{ 0u }; i < buffer.pixels.size(); ++i) { const sf::Vector2i destination{ static_cast(i % buffer.width) + offset.x, static_cast(i / buffer.width) + offset.y }; if (destination.x < 0 || destination.y < 0 || destination.x >= static_cast(m_resolution.x) || destination.y >= static_cast(m_resolution.y)) continue; - m_pixels[destination.y * m_resolution.x + destination.x] = buffer.pixels[i]; + m_pixels[static_cast(destination.y * m_resolution.x + destination.x)] = buffer.pixels[i]; } priv_updatePixels(); } -bool PixelDisplay::priv_isSelectionRectangleFullyContained(const sf::IntRect& selectionRectangle) +bool PixelDisplay::priv_isSelectionRectangleFullyContained(const sf::IntRect& selectionRectangle) const { return (selectionRectangle.position.x >= 0 && selectionRectangle.position.y >= 0 && selectionRectangle.size.x >= 0 && selectionRectangle.size.y >= 0 && - static_cast(selectionRectangle.position.x + selectionRectangle.size.x) <= m_resolution.x && - static_cast(selectionRectangle.position.y + selectionRectangle.size.y) <= m_resolution.y); + static_cast(selectionRectangle.position.x + selectionRectangle.size.x) <= m_resolution.x && + static_cast(selectionRectangle.position.y + selectionRectangle.size.y) <= m_resolution.y); } } // namespace selbaward diff --git a/src/SelbaWard/PixelDisplay.hpp b/src/SelbaWard/PixelDisplay.hpp index 241bd26..4e08dd9 100644 --- a/src/SelbaWard/PixelDisplay.hpp +++ b/src/SelbaWard/PixelDisplay.hpp @@ -44,87 +44,87 @@ class PixelDisplay : public sf::Drawable, public sf::Transformable public: PixelDisplay(); - unsigned int getIndex(sf::Vector2u location) const { return m_resolution.x * location.y + location.x; } + std::size_t getIndex(sf::Vector2 location) const { return m_resolution.x * location.y + location.x; } void setSize(sf::Vector2f size); - void setResolution(sf::Vector2u resolution); - sf::Vector2u getResolution() const { return m_resolution; } + void setResolution(sf::Vector2 resolution); + sf::Vector2 getResolution() const { return m_resolution; } sf::Vector2f getSize() const { return m_size; } - void setPixel(unsigned int index, unsigned int color); + void setPixel(std::size_t index, std::size_t color); template - void setPixels(const T* colors, unsigned int numberOfColors, unsigned int startIndex); - void setPixels(const char* colors, unsigned int numberOfColors, unsigned int startIndex); + void setPixels(const T* colors, std::size_t numberOfColors, std::size_t startIndex); + void setPixels(const char* colors, std::size_t numberOfColors, std::size_t startIndex); template - void getPixels(T* colors, unsigned int numberOfColors, unsigned int startIndex) const; - void getPixels(char* colors, unsigned int numberOfColors, unsigned int startIndex) const; + void getPixels(T* colors, std::size_t numberOfColors, std::size_t startIndex) const; + void getPixels(char* colors, std::size_t numberOfColors, std::size_t startIndex) const; - void fill(unsigned int color); + void fill(std::size_t color); void clear(); void randomize(); // manual shifting/scrolling - void shiftLeft(unsigned int amount = 1u, unsigned int startIndex = 0u, unsigned int numberOfPixels = 0u); - void shiftRight(unsigned int amount = 1u, unsigned int startIndex = 0u, unsigned int numberOfPixels = 0u); - void scrollUp(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollDown(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollLeft(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollRight(unsigned int color = 0u, unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollWrapUp(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollWrapDown(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollWrapLeft(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); - void scrollWrapRight(unsigned int amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void shiftLeft(std::size_t amount = 1u, std::size_t startIndex = 0u, std::size_t numberOfPixels = 0u); + void shiftRight(std::size_t amount = 1u, std::size_t startIndex = 0u, std::size_t numberOfPixels = 0u); + void scrollUp(std::size_t color = 0u, std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollDown(std::size_t color = 0u, std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollLeft(std::size_t color = 0u, std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollRight(std::size_t color = 0u, std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapUp(std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapDown(std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapLeft(std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); + void scrollWrapRight(std::size_t amount = 1u, sf::IntRect selectionRectangle = { { 0, 0 }, { 0, 0 } }); // palette void setPalette(const std::vector& palette); - void setPaletteSize(unsigned int numberOfColors); - void setColor(unsigned int color, sf::Color rgb); - void removeColor(unsigned int color); + void setPaletteSize(std::size_t numberOfColors); + void setColor(std::size_t color, sf::Color rgb); + void removeColor(std::size_t color); void addRgb(sf::Color rgb); - void cyclePaletteDown(unsigned int amount = 1u, unsigned int firstColor = 0u, unsigned int numberOfColors = 0u); // first colour and last colour of range to cycle - void cyclePaletteUp(unsigned int amount = 1u, unsigned int firstColor = 0u, unsigned int numberOfColors = 0u); // first colour and last colour of range to cycle + void cyclePaletteDown(std::size_t amount = 1u, std::size_t firstColor = 0u, std::size_t numberOfColors = 0u); // first colour and last colour of range to cycle + void cyclePaletteUp(std::size_t amount = 1u, std::size_t firstColor = 0u, std::size_t numberOfColors = 0u); // first colour and last colour of range to cycle std::size_t getPaletteSize() const { return m_palette.size(); }; - sf::Color getRgb(unsigned int color) const { return m_palette[color]; } + sf::Color getRgb(std::size_t color) const { return m_palette[color]; } // buffers (clipboards/"screenshots"/captures) - unsigned int copy(); // returns index of buffer - unsigned int copy(sf::IntRect selectionRectangle); // returns index of buffer + std::size_t copy(); // returns index of buffer + std::size_t copy(sf::IntRect selectionRectangle); // returns index of buffer void paste(sf::Vector2i offset = { 0, 0 }); // replace with last saved buffer void removeBuffer(); // removes last saved buffer - void copy(unsigned int index); // copies over (replaces) an existing buffer - void copy(unsigned int index, sf::IntRect selectionRectangle); - void paste(unsigned int index, sf::Vector2i offset = { 0, 0 }); // replace with saved buffer - void removeBuffer(unsigned int index); // as usual, when one buffer is removed, the indices of all following buffers are decreased + void copy(std::size_t index); // copies over (replaces) an existing buffer + void copy(std::size_t index, sf::IntRect selectionRectangle); + void paste(std::size_t index, sf::Vector2i offset = { 0, 0 }); // replace with saved buffer + void removeBuffer(std::size_t index); // as usual, when one buffer is removed, the indices of all following buffers are decreased void removeAllBuffers() { m_buffers.clear(); } - unsigned int addBuffer(sf::Vector2u size = { 1u, 1u }); // returns index of new buffer - void resizeBuffer(unsigned int index, sf::Vector2u size); - unsigned int getNumberOfBuffers() const { return static_cast(m_buffers.size()); } - sf::Vector2u getSizeOfBuffer(unsigned int index) const; + std::size_t addBuffer(sf::Vector2 size = { 1u, 1u }); // returns index of new buffer + void resizeBuffer(std::size_t index, sf::Vector2 size); + std::size_t getNumberOfBuffers() const { return m_buffers.size(); } + sf::Vector2 getSizeOfBuffer(std::size_t index) const; private: - sf::Vector2u m_resolution; + sf::Vector2 m_resolution; sf::Vector2f m_size; - std::vector m_pixels; + std::vector m_pixels; std::vector m_palette; std::vector m_vertices; // buffers struct Buffer { - unsigned int width; - std::vector pixels; + std::size_t width{}; + std::vector pixels{}; }; std::vector m_buffers; void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateVertices(); void priv_updatePixels(); - void priv_updatePixel(const unsigned int index); - unsigned int priv_getRandomColor() const; + void priv_updatePixel(const std::size_t index); + std::size_t priv_getRandomColor() const; void priv_copyToBufferFromSelectionRectangle(Buffer& buffer, const sf::IntRect& selectionRectangle); void priv_pasteOffsetBuffer(const Buffer& buffer, const sf::Vector2i& offset); - bool priv_isSelectionRectangleFullyContained(const sf::IntRect& selectionRectangle); + bool priv_isSelectionRectangleFullyContained(const sf::IntRect& selectionRectangle) const; }; @@ -134,17 +134,17 @@ class PixelDisplay : public sf::Drawable, public sf::Transformable template -void PixelDisplay::setPixels(const T* colors, const unsigned int numberOfColors, const unsigned int startIndex) +void PixelDisplay::setPixels(const T* colors, const std::size_t numberOfColors, const std::size_t startIndex) { - for (unsigned int i{ 0u }; i < numberOfColors; ++i) - m_pixels[startIndex + i] = static_cast(colors[i]); + for (std::size_t i{ 0u }; i < numberOfColors; ++i) + m_pixels[startIndex + i] = static_cast(colors[i]); priv_updatePixels(); } template -void PixelDisplay::getPixels(T* colors, const unsigned int numberOfColors, const unsigned int startIndex) const +void PixelDisplay::getPixels(T* colors, const std::size_t numberOfColors, const std::size_t startIndex) const { - for (unsigned int i{ 0u }; i < numberOfColors; ++i) + for (std::size_t i{ 0u }; i < numberOfColors; ++i) colors[i] = static_cast(m_pixels[startIndex + i]); } diff --git a/src/SelbaWard/Starfield3d.cpp b/src/SelbaWard/Starfield3d.cpp index 202faf9..5662b83 100644 --- a/src/SelbaWard/Starfield3d.cpp +++ b/src/SelbaWard/Starfield3d.cpp @@ -244,7 +244,7 @@ void Starfield3d::draw(sf::RenderTarget& target, sf::RenderStates states) const states.transform *= getTransform(); const std::size_t size{ m_vertices.size() }; - if (size > 0) + if (size > 0u) target.draw(m_vertices.data(), size, m_primitiveType, states); } diff --git a/src/SelbaWard/Starfield3d.hpp b/src/SelbaWard/Starfield3d.hpp index 9e4d0a6..440d99d 100644 --- a/src/SelbaWard/Starfield3d.hpp +++ b/src/SelbaWard/Starfield3d.hpp @@ -40,7 +40,7 @@ namespace selbaward { -// SW Starfield3d v1.0.2 +// SW Starfield3d v1.0.3 class Starfield3d : public sf::Drawable, public sf::Transformable { public: @@ -93,7 +93,7 @@ class Starfield3d : public sf::Drawable, public sf::Transformable Back, }; - virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; + void draw(sf::RenderTarget& target, sf::RenderStates states) const override; void priv_updateVertices() const; sf::Vector2f priv_projectPoint(sf::Vector3f point) const;