diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index 50b580e..d4f776a 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -102,7 +102,7 @@ namespace globalInputs else if (Input::get()->checkInput(InputAction::TOGGLE_PALETTE, REPEAT_FALSE)) { switchPalette(); - Notifier::get()->show({"PALETTE " + std::string(options.video.palette == Palette::ZXSPECTRUM ? "ZX SPECTRUM" : "ZX ARNE")}, NotificationText::CENTER); + //Notifier::get()->show({"PALETTE " + std::string(options.video.palette == Palette::ZXSPECTRUM ? "ZX SPECTRUM" : "ZX ARNE")}, NotificationText::CENTER); } } } \ No newline at end of file diff --git a/source/options.cpp b/source/options.cpp index 084a207..390ef4d 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -21,7 +21,7 @@ void initOptions() options = Options(); #ifdef DEBUG - options.section = SectionState(Section::ENDING2, Subsection::NONE); + options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO); options.console = true; #else options.section = SectionState(Section::LOGO, Subsection::LOGO_TO_INTRO); @@ -148,25 +148,25 @@ bool saveOptionsToFile(const std::string &file_path) file << "\n## VIDEO\n"; file << "# Modo de video: 0 = Ventana, 1 = Pantalla completa, 2 = Pantalla completa (escritorio)\n"; - file << "video.mode " << options.video.mode << "\n"; + file << "video.mode " << options.video.mode << "\n\n"; file << "# Filtro de pantalla: 0 = Nearest, 1 = Linear\n"; - file << "video.filter " << static_cast(options.video.filter) << "\n"; + file << "video.filter " << static_cast(options.video.filter) << "\n\n"; file << "# Shaders: 1 = Activado, 0 = Desactivado\n"; - file << "video.shaders " << boolToString(options.video.shaders) << "\n"; + file << "video.shaders " << boolToString(options.video.shaders) << "\n\n"; file << "# Sincronización vertical: 1 = Activado, 0 = Desactivado\n"; - file << "video.vertical_sync " << boolToString(options.video.vertical_sync) << "\n"; + file << "video.vertical_sync " << boolToString(options.video.vertical_sync) << "\n\n"; file << "# Escalado entero: 1 = Activado, 0 = Desactivado\n"; - file << "video.integer_scale " << boolToString(options.video.integer_scale) << "\n"; + file << "video.integer_scale " << boolToString(options.video.integer_scale) << "\n\n"; file << "# Mantener aspecto: 1 = Activado, 0 = Desactivado\n"; - file << "video.keep_aspect " << boolToString(options.video.keep_aspect) << "\n"; + file << "video.keep_aspect " << boolToString(options.video.keep_aspect) << "\n\n"; file << "# Borde: 1 = Activado, 0 = Desactivado\n"; - file << "video.border.enabled " << boolToString(options.video.border.enabled) << "\n"; + file << "video.border.enabled " << boolToString(options.video.border.enabled) << "\n\n"; file << "# Ancho del borde\n"; - file << "video.border.width " << options.video.border.width << "\n"; + file << "video.border.width " << options.video.border.width << "\n\n"; file << "# Alto del borde\n"; - file << "video.border.height " << options.video.border.height << "\n"; - file << "# Paleta: 0 = ZX Spectrum, 1 = ZX Arne\n"; - file << "video.palette " << static_cast(options.video.palette) << "\n"; + file << "video.border.height " << options.video.border.height << "\n\n"; + file << "# Paleta:\n"; + file << "video.palette " << options.video.palette << "\n"; // Cierra el fichero file.close(); @@ -263,10 +263,10 @@ bool setOptions(const std::string &var, const std::string &value) }}, {"video.palette", [](const std::string &v) { - int val = safeStoi(v, static_cast(DEFAULT_PALETTE)); - if (val == static_cast(Palette::ZXSPECTRUM) || val == static_cast(Palette::ZXARNE)) + std::string val = v; + if (val == "arreglar" || val == "esto") { - options.video.palette = static_cast(val); + options.video.palette = val; } else { diff --git a/source/options.h b/source/options.h index f2edc34..d6e97d7 100644 --- a/source/options.h +++ b/source/options.h @@ -75,7 +75,7 @@ constexpr int DEFAULT_MUSIC_VOLUME = 80; constexpr bool DEFAULT_MUSIC_ENABLED = true; // Musica habilitada por defecto constexpr int DEFAULT_AUDIO_VOLUME = 100; // Volumen por defecto constexpr bool DEFAULT_AUDIO_ENABLED = true; // Audio por defecto -constexpr Palette DEFAULT_PALETTE = Palette::ZXSPECTRUM; // Paleta por defecto +constexpr const char *DEFAULT_PALETTE = "zx-spectrum"; // Paleta por defecto constexpr Section DEFAULT_SECTION = Section::LOGO; // Sección por defecto constexpr Subsection DEFAULT_SUBSECTION = Subsection::LOGO_TO_INTRO; // Subsección por defecto constexpr ControlScheme DEFAULT_CONTROL_SCHEME = ControlScheme::CURSOR; // Control por defecto @@ -265,7 +265,7 @@ struct OptionsVideo bool integer_scale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa bool keep_aspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa Border border; // Borde de la pantalla - Palette palette; // Paleta de colores a usar en el juego + std::string palette; // Paleta de colores a usar en el juego // Constructor por defecto OptionsVideo() @@ -279,7 +279,7 @@ struct OptionsVideo palette(DEFAULT_PALETTE) {} // Constructor - OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, Palette p) + OptionsVideo(Uint32 m, ScreenFilter f, bool vs, bool s, bool is, bool ka, Border b, std::string p) : mode(m), filter(f), vertical_sync(vs), diff --git a/source/resource.cpp b/source/resource.cpp index 0a0b48a..628e263 100644 --- a/source/resource.cpp +++ b/source/resource.cpp @@ -20,28 +20,16 @@ struct JA_Sound_t; // lines 13-13 Resource *Resource::resource_ = nullptr; // [SINGLETON] Crearemos el objeto screen con esta función estática -void Resource::init() -{ - Resource::resource_ = new Resource(); -} +void Resource::init() { Resource::resource_ = new Resource(); } // [SINGLETON] Destruiremos el objeto screen con esta función estática -void Resource::destroy() -{ - delete Resource::resource_; -} +void Resource::destroy() { delete Resource::resource_; } // [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él -Resource *Resource::get() -{ - return Resource::resource_; -} +Resource *Resource::get() { return Resource::resource_; } // Constructor -Resource::Resource() -{ - load(); -} +Resource::Resource() { load(); } // Vacia todos los vectores de recursos void Resource::clear() @@ -49,6 +37,7 @@ void Resource::clear() clearSounds(); clearMusics(); surfaces_.clear(); + palettes_.clear(); text_files_.clear(); texts_.clear(); animations_.clear(); @@ -64,6 +53,7 @@ void Resource::load() loadSounds(); loadMusics(); loadSurfaces(); + loadPalettes(); loadTextFiles(); loadAnimations(); loadTileMaps(); @@ -109,7 +99,7 @@ JA_Music_t *Resource::getMusic(const std::string &name) throw std::runtime_error("Música no encontrada: " + name); } -// Obtiene la textura a partir de un nombre +// Obtiene la surface a partir de un nombre std::shared_ptr Resource::getSurface(const std::string &name) { auto it = std::find_if(surfaces_.begin(), surfaces_.end(), [&name](const auto &t) @@ -124,6 +114,21 @@ std::shared_ptr Resource::getSurface(const std::string &name) throw std::runtime_error("Imagen no encontrada: " + name); } +// Obtiene la paleta a partir de un nombre +Palette Resource::getPalette(const std::string &name) +{ + auto it = std::find_if(palettes_.begin(), palettes_.end(), [&name](const auto &t) + { return t.name == name; }); + + if (it != palettes_.end()) + { + return it->palette; + } + + std::cerr << "Error: Paleta no encontrada " << name << std::endl; + throw std::runtime_error("Paleta no encontrada: " + name); +} + // Obtiene el fichero de texto a partir de un nombre std::shared_ptr Resource::getTextFile(const std::string &name) { @@ -252,6 +257,21 @@ void Resource::loadSurfaces() } } +// Carga las paletas +void Resource::loadPalettes() +{ + std::cout << "\n>> PALETTES" << std::endl; + auto list = Asset::get()->getListByType(AssetType::PALETTE); + palettes_.clear(); + + for (const auto &l : list) + { + auto name = getFileName(l); + palettes_.emplace_back(ResourcePalette(name, loadPalette(l))); + updateLoadingProgress(); + } +} + // Carga los ficheros de texto void Resource::loadTextFiles() { diff --git a/source/resource.h b/source/resource.h index e2365f3..7147430 100644 --- a/source/resource.h +++ b/source/resource.h @@ -43,6 +43,17 @@ struct ResourceSurface : name(name), surface(surface) {} }; +// Estructura para almacenar objetos Palette y su nombre +struct ResourcePalette +{ + std::string name; // Nombre de la surface + Palette palette; // Paleta + + // Constructor + ResourcePalette(const std::string &name, Palette palette) + : name(name), palette(palette) {} +}; + // Estructura para almacenar ficheros TextFile y su nombre struct ResourceTextFile { @@ -134,6 +145,7 @@ private: std::vector sounds_; // Vector con los sonidos std::vector musics_; // Vector con las musicas std::vector surfaces_; // Vector con las surfaces + std::vector palettes_; // Vector con las paletas std::vector text_files_; // Vector con los ficheros de texto std::vector texts_; // Vector con los objetos de texto std::vector animations_; // Vector con las animaciones @@ -151,6 +163,9 @@ private: // Carga las surfaces void loadSurfaces(); + // Carga las paletas + void loadPalettes(); + // Carga los ficheros de texto void loadTextFiles(); @@ -217,6 +232,9 @@ public: // Obtiene la surface a partir de un nombre std::shared_ptr getSurface(const std::string &name); + // Obtiene la paleta a partir de un nombre + Palette getPalette(const std::string &name); + // Obtiene el fichero de texto a partir de un nombre std::shared_ptr getTextFile(const std::string &name); diff --git a/source/screen.cpp b/source/screen.cpp index 01c413c..d17ef93 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -14,6 +14,7 @@ #include "options.h" #include "mouse.h" #include "surface.h" +#include "resource.h" // [SINGLETON] Screen *Screen::screen_ = nullptr; @@ -395,6 +396,6 @@ void Screen::nextPalette() current_palette_ = 0; } - game_surface_->loadPalette(palettes_.at(current_palette_)); - border_surface_->loadPalette(palettes_.at(current_palette_)); + game_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_))); + border_surface_->loadPalette(Resource::get()->getPalette(palettes_.at(current_palette_))); } \ No newline at end of file diff --git a/source/surface.cpp b/source/surface.cpp index b3d3e0a..0bf96d5 100644 --- a/source/surface.cpp +++ b/source/surface.cpp @@ -11,6 +11,43 @@ #include "screen.h" #include "gif.h" // for LoadGif, LoadPalette +// Carga una paleta desde un archivo +Palette loadPalette(const std::string &file_path) +{ + // Abrir el archivo en modo binario + std::ifstream file(file_path, std::ios::binary | std::ios::ate); + if (!file.is_open()) + { + throw std::runtime_error("Error opening file: " + file_path); + } + + // Leer el contenido del archivo en un buffer + std::streamsize size = file.tellg(); + file.seekg(0, std::ios::beg); + + std::vector buffer(size); + if (!file.read(reinterpret_cast(buffer.data()), size)) + { + throw std::runtime_error("Error reading file: " + file_path); + } + + // Cargar la paleta usando los datos del buffer + std::unique_ptr pal(LoadPalette(buffer.data())); + if (pal == nullptr) + { + throw std::runtime_error("Error loading palette from file: " + file_path); + } + + // Crear la paleta y copiar los datos + Palette palette; + std::copy(pal.get(), pal.get() + palette.size(), palette.begin()); + + // Mensaje de depuración + printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); + + return palette; +} + // Constructor Surface::Surface(int w, int h) : surface_data_(std::make_shared(w, h)), @@ -60,33 +97,13 @@ SurfaceData Surface::loadSurface(const std::string &file_path) // Carga una paleta desde un archivo void Surface::loadPalette(const std::string &file_path) { - // Abrir el archivo en modo binario - std::ifstream file(file_path, std::ios::binary | std::ios::ate); - if (!file.is_open()) - { - throw std::runtime_error("Error opening file: " + file_path); - } + palette_ = ::loadPalette(file_path); +} - // Leer el contenido del archivo en un buffer - std::streamsize size = file.tellg(); - file.seekg(0, std::ios::beg); - - std::vector buffer(size); - if (!file.read(reinterpret_cast(buffer.data()), size)) - { - throw std::runtime_error("Error reading file: " + file_path); - } - - // Cargar la paleta usando los datos del buffer - std::unique_ptr pal(LoadPalette(buffer.data())); - if (pal == nullptr) - { - throw std::runtime_error("Error loading palette from file: " + file_path); - } - - // Copiar los datos de la paleta al std::array - printWithDots("Palette : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]"); - std::copy(pal.get(), pal.get() + palette_.size(), palette_.begin()); +// Carga una paleta desde otra paleta +void Surface::loadPalette(Palette palette) +{ + palette_ = palette; } // Establece un color en la paleta diff --git a/source/surface.h b/source/surface.h index 76aae66..4b2a8a0 100644 --- a/source/surface.h +++ b/source/surface.h @@ -6,6 +6,11 @@ #include #include +// Alias +using Palette = std::array; + +Palette loadPalette(const std::string &file_path); + struct SurfaceData { Uint8 *data; // Listado de indices de la paleta que conforman la imagen almacenada @@ -61,7 +66,7 @@ class Surface { private: std::shared_ptr surface_data_; // Datos a dibujar - std::array palette_; // Paleta para volcar la SurfaceData a una Textura + Palette palette_; // Paleta para volcar la SurfaceData a una Textura int transparent_color_; // Indice de la paleta que se omite en la copia de datos public: @@ -77,6 +82,7 @@ public: // Carga una paleta desde un archivo void loadPalette(const std::string &file_path); + void loadPalette(Palette palette); // Copia una región de la SurfaceData de origen a la SurfaceData de destino void render(int dx, int dy, int sx, int sy, int w, int h); diff --git a/source/texture.cpp b/source/texture.cpp index a7e9f7a..cf212f0 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,12 +1,12 @@ #include "texture.h" -#include // for SDL_GetError -#include // for SDL_CreateRGBSurfaceWithFormatFrom -#include // for basic_ostream, operator<<, endl, cout -#include // for runtime_error -#include // for char_traits, operator<<, string, opera... -#include // for vector -#include "utils.h" // for getFileName, Color, printWithDots +#include // for SDL_GetError +#include // for SDL_CreateRGBSurfaceWithFormatFrom +#include // for basic_ostream, operator<<, endl, cout +#include // for runtime_error +#include // for char_traits, operator<<, string, opera... +#include // for vector +#include "utils.h" // for getFileName, Color, printWithDots #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // para stbi_failure_reason, stbi_image_free @@ -27,22 +27,6 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) { loadFromFile(path_); } - - // .gif - /*else if (extension == "gif") - { - // Crea la surface desde un fichero - surface_ = loadSurface(path_); - - // Añade la propia paleta del fichero a la lista - addPaletteFromFile(path_); - // setPaletteColor(0, 0, 0x00000000); - - // Crea la textura, establece el BlendMode y copia la surface a la textura - createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING); - SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND); - flipSurface(); - }*/ } } @@ -50,7 +34,6 @@ Texture::Texture(SDL_Renderer *renderer, const std::string &path) Texture::~Texture() { unloadTexture(); - // unloadSurface(); palettes_.clear(); } @@ -58,7 +41,9 @@ Texture::~Texture() bool Texture::loadFromFile(const std::string &file_path) { if (file_path.empty()) + { return false; + } int req_format = STBI_rgb_alpha; int width, height, orig_format; @@ -75,18 +60,10 @@ bool Texture::loadFromFile(const std::string &file_path) int depth, pitch; Uint32 pixel_format; - /*if (req_format == STBI_rgb) - { - depth = 24; - pitch = 3 * width; // 3 bytes por pixel * pixels por linea - pixel_format = SDL_PIXELFORMAT_RGB24; - } - else*/ - { // STBI_rgb_alpha (RGBA) - depth = 32; - pitch = 4 * width; - pixel_format = SDL_PIXELFORMAT_RGBA32; - } + // STBI_rgb_alpha (RGBA) + depth = 32; + pitch = 4 * width; + pixel_format = SDL_PIXELFORMAT_RGBA32; // Limpia unloadTexture(); @@ -157,26 +134,14 @@ void Texture::unloadTexture() } // Establece el color para la modulacion -void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue) -{ - SDL_SetTextureColorMod(texture_, red, green, blue); -} -void Texture::setColor(Color color) -{ - SDL_SetTextureColorMod(texture_, color.r, color.g, color.b); -} +void Texture::setColor(Uint8 red, Uint8 green, Uint8 blue) { SDL_SetTextureColorMod(texture_, red, green, blue); } +void Texture::setColor(Color color) { SDL_SetTextureColorMod(texture_, color.r, color.g, color.b); } // Establece el blending -void Texture::setBlendMode(SDL_BlendMode blending) -{ - SDL_SetTextureBlendMode(texture_, blending); -} +void Texture::setBlendMode(SDL_BlendMode blending) { SDL_SetTextureBlendMode(texture_, blending); } // Establece el alpha para la modulación -void Texture::setAlpha(Uint8 alpha) -{ - SDL_SetTextureAlphaMod(texture_, alpha); -} +void Texture::setAlpha(Uint8 alpha) { SDL_SetTextureAlphaMod(texture_, alpha); } // Renderiza la textura en un punto específico void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip) @@ -207,177 +172,19 @@ void Texture::render(int x, int y, SDL_Rect *clip, float zoomW, float zoomH, dou } // Establece la textura como objetivo de renderizado -void Texture::setAsRenderTarget(SDL_Renderer *renderer) -{ - SDL_SetRenderTarget(renderer, texture_); -} +void Texture::setAsRenderTarget(SDL_Renderer *renderer) { SDL_SetRenderTarget(renderer, texture_); } // Obtiene el ancho de la imagen -int Texture::getWidth() -{ - return width_; -} +int Texture::getWidth() { return width_; } // Obtiene el alto de la imagen -int Texture::getHeight() -{ - return height_; -} +int Texture::getHeight() { return height_; } // Recarga la textura -bool Texture::reLoad() -{ - return loadFromFile(path_); -} +bool Texture::reLoad() { return loadFromFile(path_); } // Obtiene la textura -SDL_Texture *Texture::getSDLTexture() -{ - return texture_; -} - -// Desencadenar la superficie actual -/*void Texture::unloadSurface() -{ - surface_.reset(); // Resetea el shared_ptr - width_ = 0; - height_ = 0; -}*/ - -// Crea una surface desde un fichero .gif -/*std::shared_ptr Texture::loadSurface(const std::string &file_path) -{ - // Desencadenar la superficie actual - unloadSurface(); - - // Abrir el archivo usando std::ifstream para manejo automático del recurso - std::ifstream file(file_path, std::ios::binary | std::ios::ate); - if (!file) - { - std::cerr << "Error: Fichero no encontrado " << file_path << std::endl; - throw std::runtime_error("Fichero no encontrado: " + file_path); - } - - // Obtener el tamaño del archivo - std::streamsize size = file.tellg(); - file.seekg(0, std::ios::beg); - - // Leer el contenido del archivo en un buffer - std::vector buffer(size); - if (!file.read(reinterpret_cast(buffer.data()), size)) - { - std::cerr << "Error al leer el fichero " << file_path << std::endl; - throw std::runtime_error("Error al leer el fichero: " + file_path); - } - - // Cerrar el archivo (automáticamente manejado por std::ifstream) - file.close(); - - // Llamar a la función LoadGif - Uint16 w, h; - Uint8 *rawPixels = LoadGif(buffer.data(), &w, &h); - if (!rawPixels) - { - return nullptr; - } - - // Crear un std::shared_ptr con std::make_shared para pixels - auto pixels = std::shared_ptr(rawPixels, std::default_delete()); - auto surface = std::make_shared(w, h, pixels); - - // Actualizar la anchura y altura - width_ = w; - height_ = h; - - return surface; -}*/ - -// Vuelca la surface en la textura -/*void Texture::flipSurface() -{ - // Limpia la textura - auto temp = SDL_GetRenderTarget(renderer_); - SDL_SetRenderTarget(renderer_, texture_); - SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0); - SDL_RenderClear(renderer_); - SDL_SetRenderTarget(renderer_, temp); - - // Vuelca los datos - Uint32 *pixels; - int pitch; - SDL_LockTexture(texture_, nullptr, reinterpret_cast(&pixels), &pitch); - for (int i = 0; i < width_ * height_; ++i) - { - pixels[i] = palettes_[current_palette_][surface_->data[i]]; - } - SDL_UnlockTexture(texture_); -}*/ - -// Establece un color de la paleta -/*void Texture::setPaletteColor(int palette, int index, Uint32 color) -{ - palettes_.at(palette)[index] = color; -}*/ - -// Carga una paleta desde un fichero -/*std::vector Texture::loadPaletteFromFile(const std::string &file_path) -{ - std::vector palette; - - std::ifstream file(file_path, std::ios::binary | std::ios::ate); - if (!file) - { - std::cerr << "Error: Fichero no encontrado " << getFileName(file_path) << std::endl; - throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path)); - } - else - { - printWithDots("Image : ", getFileName(file_path), "[ LOADED ]"); - } - - auto size = file.tellg(); - file.seekg(0, std::ios::beg); - - std::vector buffer(size); - if (!file.read(reinterpret_cast(buffer.data()), size)) - { - std::cerr << "Error: No se pudo leer completamente el fichero " << getFileName(file_path) << std::endl; - throw std::runtime_error("Error al leer el fichero: " + getFileName(file_path)); - } - - const auto pal = LoadPalette(buffer.data()); - if (!pal) - { - return palette; - } - - for (int i = 0; i < 256; ++i) - { - palette.push_back((pal[i] << 8) + 255); - } - - return palette; -}*/ - -// Añade una paleta a la lista -/*void Texture::addPaletteFromFile(const std::string &path) -{ - palettes_.emplace_back(loadPaletteFromFile(path)); - setPaletteColor((int)palettes_.size() - 1, 0, 0x00000000); -} - -// Cambia la paleta de la textura -void Texture::setPalette(int palette) -{ - if (palette < (int)palettes_.size()) - { - current_palette_ = palette; - flipSurface(); - } -}*/ +SDL_Texture *Texture::getSDLTexture() { return texture_; } // Obtiene el renderizador -SDL_Renderer *Texture::getRenderer() -{ - return renderer_; -} \ No newline at end of file +SDL_Renderer *Texture::getRenderer() { return renderer_; } \ No newline at end of file diff --git a/source/texture.h b/source/texture.h index a9435de..d65d594 100644 --- a/source/texture.h +++ b/source/texture.h @@ -9,47 +9,22 @@ #include // for vector struct Color; // lines 11-11 -// Definiciones de tipos -/*struct Surface -{ - std::shared_ptr data; - Uint16 w, h; - - // Constructor - Surface(Uint16 width, Uint16 height, std::shared_ptr pixels) - : data(pixels), w(width), h(height) {} -};*/ - class Texture { private: // Objetos y punteros SDL_Renderer *renderer_; // Renderizador donde dibujar la textura SDL_Texture *texture_ = nullptr; // La textura - //std::shared_ptr surface_ = nullptr; // Surface para usar imagenes en formato gif con paleta // Variables std::string path_; // Ruta de la imagen de la textura int width_ = 0; // Ancho de la imagen int height_ = 0; // Alto de la imagen std::vector> palettes_; // Vector con las diferentes paletas - int current_palette_ = 0; // Indice de la paleta en uso - - // Crea una surface desde un fichero .gif - // std::shared_ptr loadSurface(const std::string &file_name); - - // Vuelca la surface en la textura - // void flipSurface(); - - // Carga una paleta desde un fichero - // std::vector loadPaletteFromFile(const std::string &file_name); // Libera la memoria de la textura void unloadTexture(); - // Desencadenar la superficie actual - // void unloadSurface(); - public: // Constructor explicit Texture(SDL_Renderer *renderer, const std::string &path = std::string()); @@ -91,15 +66,6 @@ public: // Obtiene la textura SDL_Texture *getSDLTexture(); - // Añade una paleta a la lista - // void addPaletteFromFile(const std::string &path); - - // Establece un color de la paleta - // void setPaletteColor(int palette, int index, Uint32 color); - - // Cambia la paleta de la textura - // void setPalette(int palette); - // Obtiene el renderizador SDL_Renderer *getRenderer(); }; \ No newline at end of file diff --git a/source/utils.h b/source/utils.h index cb5adf8..a7d5aee 100644 --- a/source/utils.h +++ b/source/utils.h @@ -6,13 +6,6 @@ #include // for string #include // for vector -// Tipos de paleta -enum class Palette : int -{ - ZXSPECTRUM, - ZXARNE -}; - // Estructura para definir un circulo struct Circle { @@ -97,7 +90,6 @@ bool checkCollision(const SDL_Point &p, const LineDiagonal &l); void normalizeLine(LineDiagonal &l); // Devuelve un Color a partir de un string -Color stringToColor(Palette pal, const std::string &str); Uint8 stringToColor(const std::string &str); // Convierte una cadena a un entero de forma segura