forked from jaildesigner-jailgames/jaildoctors_dilemma
afegit gif.cpp i jail_shader.cpp desde coffee_crisis_arcade_edition
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "utils.h"
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_FLIP_NONE, SDL_RendererFlip, SDL_Re...
|
||||
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint16, Uint32
|
||||
#include <array> // Para array
|
||||
#include <memory> // Para default_delete, shared_ptr, __shared_pt...
|
||||
#include <numeric> // Para iota
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para move
|
||||
#include "utils.h" // Para PaletteColor
|
||||
|
||||
// Alias
|
||||
using Palette = std::array<Uint32, 256>;
|
||||
@@ -20,53 +22,30 @@ Palette readPalFile(const std::string &file_path);
|
||||
|
||||
struct SurfaceData
|
||||
{
|
||||
Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada
|
||||
Uint16 width; // Ancho de la imagen
|
||||
Uint16 height; // Alto de la imagen
|
||||
std::shared_ptr<Uint8[]> data; // Usa std::shared_ptr para gestión automática
|
||||
Uint16 width; // Ancho de la imagen
|
||||
Uint16 height; // Alto de la imagen
|
||||
|
||||
// Constructor por defecto
|
||||
SurfaceData() : data(nullptr), width(0), height(0) {}
|
||||
|
||||
// Constructor que inicializa dimensiones y asigna memoria
|
||||
SurfaceData(Uint16 w, Uint16 h)
|
||||
: data(new Uint8[w * h]()), width(w), height(h) {}
|
||||
: data(std::shared_ptr<Uint8[]>(new Uint8[w * h](), std::default_delete<Uint8[]>())), width(w), height(h) {}
|
||||
|
||||
// Constructor para inicializar directamente con datos
|
||||
SurfaceData(Uint16 w, Uint16 h, Uint8 *pixels)
|
||||
: data(pixels), width(w), height(h) {}
|
||||
SurfaceData(Uint16 w, Uint16 h, std::shared_ptr<Uint8[]> pixels)
|
||||
: data(std::move(pixels)), width(w), height(h) {}
|
||||
|
||||
// Destructor para liberar memoria
|
||||
~SurfaceData() { delete[] data; }
|
||||
// Constructor de movimiento
|
||||
SurfaceData(SurfaceData &&other) noexcept = default;
|
||||
|
||||
// Evita copias accidentales (opcional para mayor seguridad)
|
||||
// Operador de movimiento
|
||||
SurfaceData &operator=(SurfaceData &&other) noexcept = default;
|
||||
|
||||
// Evita copias accidentales
|
||||
SurfaceData(const SurfaceData &) = delete;
|
||||
SurfaceData &operator=(const SurfaceData &) = delete;
|
||||
|
||||
// Permite movimiento para evitar copias costosas
|
||||
SurfaceData(SurfaceData &&other) noexcept
|
||||
: data(other.data), width(other.width), height(other.height)
|
||||
{
|
||||
other.data = nullptr;
|
||||
other.width = 0;
|
||||
other.height = 0;
|
||||
}
|
||||
|
||||
SurfaceData &operator=(SurfaceData &&other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
delete[] data;
|
||||
|
||||
data = other.data;
|
||||
width = other.width;
|
||||
height = other.height;
|
||||
|
||||
other.data = nullptr;
|
||||
other.width = 0;
|
||||
other.height = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class Surface
|
||||
@@ -80,7 +59,7 @@ private:
|
||||
public:
|
||||
// Constructor
|
||||
Surface(int w, int h);
|
||||
Surface(const std::string &file_path);
|
||||
explicit Surface(const std::string &file_path);
|
||||
|
||||
// Destructor
|
||||
~Surface() = default;
|
||||
@@ -120,10 +99,10 @@ public:
|
||||
Uint8 getPixel(int x, int y);
|
||||
|
||||
// Dibuja un rectangulo relleno
|
||||
void fillRect(SDL_Rect *rect, Uint8 color);
|
||||
void fillRect(const SDL_Rect *rect, Uint8 color);
|
||||
|
||||
// Dibuja el borde de un rectangulo
|
||||
void drawRectBorder(SDL_Rect *rect, Uint8 color);
|
||||
void drawRectBorder(const SDL_Rect *rect, Uint8 color);
|
||||
|
||||
// Dibuja una linea
|
||||
void drawLine(int x1, int y1, int x2, int y2, Uint8 color);
|
||||
|
||||
Reference in New Issue
Block a user