mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-03 10:26:36 +00:00
Cleaning up
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
// Created by anonymus-raccoon on 1/28/20.
|
// Created by anonymus-raccoon on 1/28/20.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include "Ram.hpp"
|
#include "Ram.hpp"
|
||||||
#include "../Exceptions/InvalidAddress.hpp"
|
#include "../Exceptions/InvalidAddress.hpp"
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ namespace ComSquare::Ram
|
|||||||
: _size(size)
|
: _size(size)
|
||||||
{
|
{
|
||||||
this->_data = new uint8_t[size];
|
this->_data = new uint8_t[size];
|
||||||
|
std::memset(this->_data, 0, size * sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ram::~Ram()
|
Ram::~Ram()
|
||||||
|
|||||||
@@ -12,52 +12,58 @@
|
|||||||
|
|
||||||
namespace ComSquare::Renderer
|
namespace ComSquare::Renderer
|
||||||
{
|
{
|
||||||
|
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
|
||||||
|
{
|
||||||
|
sf::Image icon;
|
||||||
|
this->shouldExit = false;
|
||||||
|
this->_videoMode = {width, height, 32};
|
||||||
|
this->_window.create(this->_videoMode, "ComSquare Emulator", sf::Style::Default);
|
||||||
|
if (icon.loadFromFile("../ressources/Logo.png"))
|
||||||
|
this->_window.setIcon(314, 314, icon.getPixelsPtr());
|
||||||
|
this->_window.setFramerateLimit(maxFPS);
|
||||||
|
this->_texture.create(width, height);
|
||||||
|
this->_sprite.setTexture(this->_texture);
|
||||||
|
this->_pixelBuffer = new sf::Color[height * width];
|
||||||
|
}
|
||||||
|
|
||||||
|
SFRenderer::~SFRenderer()
|
||||||
|
{
|
||||||
|
delete []this->_pixelBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SFRenderer::setWindowName(std::string newWindowName)
|
void SFRenderer::setWindowName(std::string newWindowName)
|
||||||
{
|
{
|
||||||
this->window.setTitle(newWindowName + " - ComSquare");
|
this->_window.setTitle(newWindowName + " - ComSquare");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFRenderer::drawScreen()
|
void SFRenderer::drawScreen()
|
||||||
{
|
{
|
||||||
this->texture.update(reinterpret_cast<sf::Uint8 *>(this->pixelBuffer));
|
this->_texture.update(reinterpret_cast<sf::Uint8 *>(this->_pixelBuffer));
|
||||||
this->sprite.setTexture(this->texture);
|
this->_sprite.setTexture(this->_texture);
|
||||||
this->window.draw(this->sprite);
|
this->_window.draw(this->_sprite);
|
||||||
this->window.display();
|
this->_window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFRenderer::putPixel(unsigned y, unsigned x, uint32_t rgba)
|
void SFRenderer::putPixel(unsigned y, unsigned x, uint32_t rgba)
|
||||||
{
|
{
|
||||||
if (x >= this->videoMode.width)
|
if (x >= this->_videoMode.width)
|
||||||
throw InvalidPixelPosition("Width", x, this->videoMode.width);
|
throw InvalidPixelPosition("Width", x, this->_videoMode.width);
|
||||||
if (y >= this->videoMode.height)
|
if (y >= this->_videoMode.height)
|
||||||
throw InvalidPixelPosition("Height", y, this->videoMode.height);
|
throw InvalidPixelPosition("Height", y, this->_videoMode.height);
|
||||||
|
|
||||||
sf::Color pixels;
|
sf::Color pixels;
|
||||||
pixels.r = rgba >> 24U;
|
pixels.r = rgba >> 24U;
|
||||||
pixels.g = rgba >> 16U;
|
pixels.g = rgba >> 16U;
|
||||||
pixels.b = rgba >> 8U;
|
pixels.b = rgba >> 8U;
|
||||||
pixels.a = rgba >> 0U;
|
pixels.a = rgba >> 0U;
|
||||||
this->pixelBuffer[this->videoMode.width * y + x] = pixels;
|
this->_pixelBuffer[this->_videoMode.width * y + x] = pixels;
|
||||||
}
|
|
||||||
|
|
||||||
SFRenderer::SFRenderer(unsigned int height, unsigned int width, int maxFPS)
|
|
||||||
{
|
|
||||||
sf::Image icon;
|
|
||||||
this->shouldExit = false;
|
|
||||||
this->videoMode = {width, height, 32};
|
|
||||||
this->window.create(this->videoMode, "ComSquare Emulator", sf::Style::Default);
|
|
||||||
if (icon.loadFromFile("../ressources/Logo.png"))
|
|
||||||
this->window.setIcon(314, 314, icon.getPixelsPtr());
|
|
||||||
this->window.setFramerateLimit(maxFPS);
|
|
||||||
this->texture.create(width, height);
|
|
||||||
this->sprite.setTexture(this->texture);
|
|
||||||
this->pixelBuffer = new sf::Color[height * width];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFRenderer::getEvents()
|
void SFRenderer::getEvents()
|
||||||
{
|
{
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (this->window.pollEvent(event)) {
|
while (this->_window.pollEvent(event)) {
|
||||||
if (event.type == sf::Event::Closed) {
|
if (event.type == sf::Event::Closed) {
|
||||||
this->shouldExit = true;
|
this->shouldExit = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ namespace ComSquare::Renderer
|
|||||||
class SFRenderer : public IRenderer {
|
class SFRenderer : public IRenderer {
|
||||||
private:
|
private:
|
||||||
//! @brief The Renderer for the window.
|
//! @brief The Renderer for the window.
|
||||||
sf::RenderWindow window;
|
sf::RenderWindow _window;
|
||||||
//! @brief Video Mode containing the height and width of the window.
|
//! @brief Video Mode containing the height and width of the window.
|
||||||
sf::VideoMode videoMode;
|
sf::VideoMode _videoMode;
|
||||||
//! @brief The image that contain all of the pixels
|
//! @brief The image that contain all of the pixels
|
||||||
sf::Color *pixelBuffer;
|
sf::Color *_pixelBuffer;
|
||||||
//! @brief The sprite to render the array of pixels
|
//! @brief The sprite to render the array of pixels
|
||||||
sf::Sprite sprite;
|
sf::Sprite _sprite;
|
||||||
//! @brief The texture to render the array of pixels
|
//! @brief The texture to render the array of pixels
|
||||||
sf::Texture texture;
|
sf::Texture _texture;
|
||||||
public:
|
public:
|
||||||
//! @brief Set a new name to the window, if there is already a name it will be overwrite.
|
//! @brief Set a new name to the window, if there is already a name it will be overwrite.
|
||||||
//! @param newWindowName new title for the window.
|
//! @param newWindowName new title for the window.
|
||||||
@@ -55,7 +55,7 @@ namespace ComSquare::Renderer
|
|||||||
SFRenderer(unsigned int height, unsigned int width, int maxFPS);
|
SFRenderer(unsigned int height, unsigned int width, int maxFPS);
|
||||||
SFRenderer(const SFRenderer &) = delete;
|
SFRenderer(const SFRenderer &) = delete;
|
||||||
SFRenderer &operator=(const SFRenderer &) = delete;
|
SFRenderer &operator=(const SFRenderer &) = delete;
|
||||||
~SFRenderer() = default;
|
~SFRenderer();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user