From f1b03034743cd0019ebcc6db007842b71957882d Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 25 Mar 2025 14:13:58 +0100 Subject: [PATCH] migrant a SDL3 --- CMakeLists.txt | 20 +++++----- Makefile | 5 +-- source/animated_sprite.h | 2 +- source/background.cpp | 32 ++++++++-------- source/background.h | 18 ++++----- source/balloon.h | 4 +- source/balloon_manager.h | 6 +-- source/bullet.cpp | 2 +- source/bullet.h | 2 +- source/credits.cpp | 26 ++++++------- source/credits.h | 26 ++++++------- source/dbgtxt.cpp | 45 ---------------------- source/dbgtxt.h | 7 ---- source/define_buttons.cpp | 20 +++++----- source/define_buttons.h | 12 +++--- source/director.cpp | 66 ++++++++++++++++----------------- source/director.h | 4 +- source/fade.cpp | 22 +++++------ source/fade.h | 12 +++--- source/game.cpp | 14 +++---- source/game.h | 6 +-- source/game_logo.cpp | 2 +- source/global_events.cpp | 2 +- source/global_events.h | 2 +- source/global_inputs.cpp | 4 +- source/hiscore_table.cpp | 10 ++--- source/hiscore_table.h | 6 +-- source/input.cpp | 8 ++-- source/input.h | 20 +++++----- source/instructions.cpp | 14 +++---- source/instructions.h | 6 +-- source/intro.cpp | 16 ++++---- source/intro.h | 2 +- source/item.h | 4 +- source/jail_audio.cpp | 4 +- source/jail_audio.h | 4 +- source/jail_shader.cpp | 8 ++-- source/jail_shader.h | 4 +- source/logo.cpp | 4 +- source/logo.h | 4 +- source/manage_hiscore_table.cpp | 4 +- source/mouse.cpp | 4 +- source/mouse.h | 4 +- source/moving_sprite.h | 4 +- source/notifier.cpp | 4 +- source/notifier.h | 4 +- source/on_screen_help.cpp | 6 +-- source/on_screen_help.h | 4 +- source/options.cpp | 2 +- source/options.h | 4 +- source/param.h | 4 +- source/path_sprite.h | 2 +- source/player.cpp | 4 +- source/player.h | 4 +- source/scoreboard.cpp | 12 +++--- source/scoreboard.h | 8 ++-- source/screen.cpp | 28 +++++++------- source/screen.h | 26 ++++++------- source/sprite.h | 2 +- source/tabe.cpp | 2 +- source/tabe.h | 6 +-- source/text.cpp | 8 ++-- source/text.h | 2 +- source/texture.cpp | 4 +- source/texture.h | 10 ++--- source/tiled_bg.cpp | 4 +- source/tiled_bg.h | 4 +- source/title.cpp | 6 +-- source/title.h | 2 +- source/utils.cpp | 2 +- source/utils.h | 8 ++-- 71 files changed, 303 insertions(+), 360 deletions(-) delete mode 100644 source/dbgtxt.cpp delete mode 100644 source/dbgtxt.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 201500f..44b66bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # CMakeLists.txt cmake_minimum_required(VERSION 3.10) -project(coffee_crisis_arcade_edition VERSION 0.01) +project(coffee_crisis_arcade_edition VERSION 2.00) # Establece las políticas cmake_policy(SET CMP0072 NEW) @@ -31,18 +31,18 @@ if(NOT SOURCES) message(FATAL_ERROR "No se encontraron archivos fuente en ${DIR_SOURCES}. Verifica que el directorio existe y contiene archivos .cpp.") endif() -# Configuración de SDL2 -find_package(SDL2 REQUIRED) -if(SDL2_FOUND) - message(STATUS "SDL2 encontrado: ${SDL2_INCLUDE_DIRS}") - include_directories(${SDL2_INCLUDE_DIRS}) - link_directories(${SDL2_LIBDIR}) +# Configuración de SDL3 +find_package(SDL3 REQUIRED) +if(SDL3_FOUND) + message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}") + include_directories(${SDL3_INCLUDE_DIRS}) + link_directories(${SDL3_LIBDIR}) else() - message(FATAL_ERROR "SDL2 no encontrado") + message(FATAL_ERROR "SDL3 no encontrado") endif() -# Incluye rutas de SDL2 obtenidas con pkg-config -include_directories(/usr/local/include /usr/local/include/SDL2) +# Incluye rutas de SDL3 obtenidas con pkg-config +include_directories(/usr/local/include /usr/local/include/SDL3) link_directories(/usr/local/lib) # Definir las bibliotecas comunes diff --git a/Makefile b/Makefile index 637e1cf..0377933 100644 --- a/Makefile +++ b/Makefile @@ -29,16 +29,15 @@ ifeq ($(OS),Windows_NT) SOURCES := source/*.cpp CXXFLAGS := -std=c++20 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows CXXFLAGS_DEBUG := -std=c++20 -Wall -g - LDFLAGS := -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 + LDFLAGS := -lmingw32 -lws2_32 -lSDL3 -lopengl32 RM := del /Q MKDIR := mkdir else FixPath = $1 - SOURCES := $(shell find $(DIR_SOURCES) -name '*.cpp') SOURCES := source/*.cpp CXXFLAGS := -std=c++20 -Wall -Os -ffunction-sections -fdata-sections CXXFLAGS_DEBUG := -std=c++20 -Wall -g - LDFLAGS := -lSDL2 + LDFLAGS := -lSDL3 RMFILE := rm -f RMDIR := rm -rdf MKDIR := mkdir -p diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 0cd3279..fb15d37 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -1,6 +1,6 @@ #pragma once -#include // Para SDL_Rect +#include // Para SDL_Rect #include // Para shared_ptr #include // Para string #include // Para vector diff --git a/source/background.cpp b/source/background.cpp index f985435..c8ed159 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -1,6 +1,6 @@ #include "background.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para clamp, max #include #include "moving_sprite.h" // Para MovingSprite @@ -22,7 +22,7 @@ Background::Background() sun_texture_(Resource::get()->getTexture("game_sun.png")), moon_texture_(Resource::get()->getTexture("game_moon.png")), - rect_({0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2}), + rect_(SDL_FRect{0, 0, static_cast(gradients_texture_->getWidth() / 2), static_cast(gradients_texture_->getHeight() / 2)}), src_rect_({0, 0, 320, 240}), dst_rect_({0, 0, 320, 240}), base_(rect_.h), @@ -42,25 +42,25 @@ Background::Background() gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h}; gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h}; - const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4; - const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4; + const float TOP_CLOUDS_TEXTURE_HEIGHT = top_clouds_texture_->getHeight() / 4; + const float BOTTOM_CLOUDS_TEXTURE_HEIGHT = bottom_clouds_texture_->getHeight() / 4; for (int i = 0; i < 4; ++i) { - top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height}; - bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height}; + top_clouds_rect_[i] = {0, i * TOP_CLOUDS_TEXTURE_HEIGHT, top_clouds_texture_->getWidth(), TOP_CLOUDS_TEXTURE_HEIGHT}; + bottom_clouds_rect_[i] = {0, i * BOTTOM_CLOUDS_TEXTURE_HEIGHT, bottom_clouds_texture_->getWidth(), BOTTOM_CLOUDS_TEXTURE_HEIGHT}; } } // Crea los sprites { - const int top_clouds_y = base_ - 165; - const int bottom_clouds_y = base_ - 101; + const float TOP_CLOUDS_Y = base_ - 165; + const float BOTTOM_CLOUDS_Y = base_ - 101; - top_clouds_sprite_a_ = std::make_unique(top_clouds_texture_, (SDL_Rect){0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()}); - top_clouds_sprite_b_ = std::make_unique(top_clouds_texture_, (SDL_Rect){rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight()}); + top_clouds_sprite_a_ = std::make_unique(top_clouds_texture_, (SDL_Rect){0, TOP_CLOUDS_Y, rect_.w, top_clouds_texture_->getHeight()}); + top_clouds_sprite_b_ = std::make_unique(top_clouds_texture_, (SDL_Rect){rect_.w, TOP_CLOUDS_Y, rect_.w, top_clouds_texture_->getHeight()}); - bottom_clouds_sprite_a_ = std::make_unique(bottom_clouds_texture_, (SDL_Rect){0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()}); - bottom_clouds_sprite_b_ = std::make_unique(bottom_clouds_texture_, (SDL_Rect){rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight()}); + bottom_clouds_sprite_a_ = std::make_unique(bottom_clouds_texture_, (SDL_Rect){0, BOTTOM_CLOUDS_Y, rect_.w, bottom_clouds_texture_->getHeight()}); + bottom_clouds_sprite_b_ = std::make_unique(bottom_clouds_texture_, (SDL_Rect){rect_.w, BOTTOM_CLOUDS_Y, rect_.w, bottom_clouds_texture_->getHeight()}); buildings_sprite_ = std::make_unique(buildings_texture_); gradient_sprite_ = std::make_unique(gradients_texture_, 0, 0, rect_.w, rect_.h); @@ -220,10 +220,10 @@ void Background::fillCanvas() void Background::render() { // Fondo - SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_); + SDL_RenderTexture(renderer_, canvas_, &src_rect_, &dst_rect_); // Atenuación - SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_); + SDL_RenderTexture(renderer_, color_texture_, &src_rect_, &dst_rect_); } // Ajusta el valor de la variable @@ -245,7 +245,7 @@ void Background::setTransition(float value) } // Establece la posición del objeto -void Background::setPos(SDL_Rect pos) +void Background::setPos(SDL_FRect pos) { dst_rect_ = pos; diff --git a/source/background.h b/source/background.h index 0029ef4..1b71204 100644 --- a/source/background.h +++ b/source/background.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Texture, SDL_Renderer +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_Texture, SDL_Renderer #include // Para size_t #include // Para unique_ptr, shared_ptr #include // Para vector @@ -71,17 +71,17 @@ private: SDL_Texture *color_texture_; // Textura para atenuar el fondo // Variables - SDL_Rect gradient_rect_[4]; // Vector con las coordenadas de los 4 degradados para el cielo - SDL_Rect top_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de arriba - SDL_Rect bottom_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de abajo + SDL_FRect gradient_rect_[4]; // Vector con las coordenadas de los 4 degradados para el cielo + SDL_FRect top_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de arriba + SDL_FRect bottom_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de abajo int gradient_number_ = 0; // Indica el número de degradado de fondo que se va a dibujar int alpha_ = 0; // Transparencia entre los dos degradados float clouds_speed_ = 0; // Velocidad a la que se desplazan las nubes float transition_ = 0; // Nivel de transición del fondo 0..1 int counter_ = 0; // Contador interno - SDL_Rect rect_; // Tamaño del objeto fondo - SDL_Rect src_rect_; // Parte del objeto fondo que se va a dibujará en pantalla - SDL_Rect dst_rect_; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla + SDL_FRect rect_; // Tamaño del objeto fondo + SDL_FRect src_rect_; // Parte del objeto fondo que se va a dibujará en pantalla + SDL_FRect dst_rect_; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla int base_; // Linea de fondo coincidente con el area inferior de la zona de juego Color attenuate_color_; // Color para atenuar el fondo int alpha_color_text_; // Alpha para atenuar el fondo @@ -129,7 +129,7 @@ public: void render(); // Establece la posición del objeto - void setPos(SDL_Rect pos); + void setPos(SDL_FRect pos); // Ajusta el valor de la variable void setCloudsSpeed(float value); diff --git a/source/balloon.h b/source/balloon.h index 2f0da0a..89c4820 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para Uint8, Uint16, Uint32 +#include // Para SDL_Rect +#include // Para Uint8, Uint16, Uint32 #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 18eb4f5..a3fb7fc 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -1,6 +1,6 @@ #pragma once -#include // Para SDL_Rect +#include // Para SDL_Rect #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector @@ -32,7 +32,7 @@ private: bool power_ball_enabled_ = false; // Indica si hay una powerball ya activa int power_ball_counter_ = 0; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra int last_balloon_deploy_ = 0; // Guarda cual ha sido la última formación desplegada para no repetir; - SDL_Rect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos + SDL_FRect play_area_ = param.game.play_area.rect; // Zona por donde se moveran los globos bool creation_time_enabled_ = true; // Indica si los globos se crean con tiempo bool can_deploy_balloons_ = true; // Indica si creará globos @@ -124,7 +124,7 @@ public: // Setters void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; } void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); } - void setPlayArea(SDL_Rect play_area) { play_area_ = play_area; } + void setPlayArea(SDL_FRect play_area) { play_area_ = play_area; } void setCreationTimeEnabled(bool value) { creation_time_enabled_ = value; } void setDeployBalloons(bool value) { can_deploy_balloons_ = value; } }; \ No newline at end of file diff --git a/source/bullet.cpp b/source/bullet.cpp index 5140181..507bbba 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -1,5 +1,5 @@ #include "bullet.h" -#include // Para SDL_Rect +#include // Para SDL_Rect #include // Para unique_ptr, make_unique, shared_ptr #include "param.h" // Para Param, ParamGame, param #include "sprite.h" // Para Sprite diff --git a/source/bullet.h b/source/bullet.h index 4eb5688..b2ca7fe 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -1,6 +1,6 @@ #pragma once -#include // Para Uint8 +#include // Para Uint8 #include // Para shared_ptr, unique_ptr #include "sprite.h" // Para Sprite #include "utils.h" // Para Circle diff --git a/source/credits.cpp b/source/credits.cpp index 4ebdad7..cfc8e03 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,9 +1,9 @@ // IWYU pragma: no_include #include "credits.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PollEvent, SDL_Event, SDL_QUIT -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PollEvent, SDL_Event, SDL_QUIT +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks #include // Para max, min, clamp #include // Para abs #include // Para runtime_error @@ -123,7 +123,7 @@ void Credits::render() Screen::get()->start(); // Copia la textura con la zona de juego a la pantalla - SDL_RenderCopy(Screen::get()->getRenderer(), canvas_, nullptr, nullptr); + SDL_RenderTexture(Screen::get()->getRenderer(), canvas_, nullptr, nullptr); // Vuelca el contenido del renderizador en pantalla Screen::get()->render(); @@ -262,10 +262,10 @@ void Credits::fillCanvas() } // Dibuja los titulos de credito - SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_); + SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_); // Dibuja el mini_logo - SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); + SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); // Dibuja los rectangulos negros SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 0xFF); @@ -276,12 +276,12 @@ void Credits::fillCanvas() // Dibuja el rectangulo rojo SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0xFF, 0, 0, 0xFF); - SDL_RenderDrawRect(Screen::get()->getRenderer(), &red_rect); + SDL_RenderRect(Screen::get()->getRenderer(), &red_rect); // Si el mini_logo está en su destino, lo dibuja encima de lo anterior if (mini_logo_on_position_) { - SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); + SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); } // Dibuja el fade sobre el resto de elementos @@ -408,11 +408,11 @@ void Credits::updateBlackRects() if (counter_ % 4 == 0) { // Incrementa la altura del rectangulo superior - top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1); + top_black_rect_.h = std::min(static_cast(top_black_rect_.h) + 1, param.game.game_area.center_y - 1); // Incrementa la altura y modifica la posición del rectangulo inferior ++bottom_black_rect_.h; - bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1); + bottom_black_rect_.y = std::max(static_cast(bottom_black_rect_.y) - 1, param.game.game_area.center_y + 1); --current_step; setVolume(static_cast(initial_volume_ * current_step / steps_)); @@ -426,11 +426,11 @@ void Credits::updateBlackRects() constexpr int SPEED = 2; // Si los rectangulos izquierdo y derecho no han llegado al centro // Incrementa la anchura del rectangulo situado a la izquierda - left_black_rect_.w = std::min(left_black_rect_.w + SPEED, param.game.game_area.center_x); + left_black_rect_.w = std::min(static_cast(left_black_rect_.w) + SPEED, param.game.game_area.center_x); // Incrementa la anchura y modifica la posición del rectangulo situado a la derecha right_black_rect_.w += SPEED; - right_black_rect_.x = std::max(right_black_rect_.x - SPEED, param.game.game_area.center_x); + right_black_rect_.x = std::max(static_cast(right_black_rect_.x) - SPEED, param.game.game_area.center_x); --current_step; setVolume(static_cast(initial_volume_ * current_step / steps_)); diff --git a/source/credits.h b/source/credits.h index 3121af4..432a16b 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Texture -#include // Para Uint32 +#include // Para SDL_Rect +#include // Para SDL_Texture +#include // Para Uint32 #include // Para unique_ptr, shared_ptr #include // Para vector #include "options.h" // Para Options, OptionsAudio, OptionsMusic @@ -41,20 +41,20 @@ private: int steps_ = 0; // Cantidad de pasos a dar para ir reduciendo el audio // Rectangulos - SDL_Rect credits_rect_src_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (origen) - SDL_Rect credits_rect_dst_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (destino) - SDL_Rect mini_logo_rect_src_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (origen) - SDL_Rect mini_logo_rect_dst_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (destino) - SDL_Rect play_area_ = { + SDL_FRect credits_rect_src_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (origen) + SDL_FRect credits_rect_dst_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (destino) + SDL_FRect mini_logo_rect_src_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (origen) + SDL_FRect mini_logo_rect_dst_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (destino) + SDL_FRect play_area_ = { param.game.game_area.rect.x, param.game.game_area.rect.y + black_bars_size_, param.game.game_area.rect.w, PLAY_AREA_HEIGHT}; // Area visible para los creditos - SDL_Rect top_black_rect_ = {play_area_.x, param.game.game_area.rect.y, play_area_.w, black_bars_size_}; // Rectangulo negro superior - SDL_Rect bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_}; // Rectangulo negro inferior - SDL_Rect left_black_rect_ = {play_area_.x, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la izquierda - SDL_Rect right_black_rect_ = {play_area_.x + play_area_.w, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la derecha - SDL_Rect red_rect = play_area_; // Rectangulo rojo para delimitar la ventana + SDL_FRect top_black_rect_ = {play_area_.x, param.game.game_area.rect.y, play_area_.w, black_bars_size_}; // Rectangulo negro superior + SDL_FRect bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_}; // Rectangulo negro inferior + SDL_FRect left_black_rect_ = {play_area_.x, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la izquierda + SDL_FRect right_black_rect_ = {play_area_.x + play_area_.w, param.game.game_area.center_y - 1, 0, 2}; // Rectangulo negro situado a la derecha + SDL_FRect red_rect = play_area_; // Rectangulo rojo para delimitar la ventana // Actualiza las variables void update(); diff --git a/source/dbgtxt.cpp b/source/dbgtxt.cpp deleted file mode 100644 index 29d9282..0000000 --- a/source/dbgtxt.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "dbgtxt.h" -#include // Para SDL_Rect -#include // Para SDL_RWFromMem -#include // Para SDL_LoadBMP_RW - -namespace -{ - SDL_Texture *dbg_tex = nullptr; - SDL_Renderer *dbg_ren = nullptr; -} - -void dbg_init(SDL_Renderer *renderer) -{ - dbg_ren = renderer; - Uint8 font[448] = {0x42, 0x4D, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x01, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x18, 0xF3, 0x83, 0x83, 0xCF, 0x83, 0x87, 0x00, 0x00, 0xF3, 0x39, 0x39, 0xCF, 0x79, 0xF3, 0x00, 0x00, 0x01, 0xF9, 0x39, 0xCF, 0x61, 0xF9, 0x00, 0x00, 0x33, 0xF9, 0x03, 0xE7, 0x87, 0x81, 0x00, 0x00, 0x93, 0x03, 0x3F, 0xF3, 0x1B, 0x39, 0x00, 0x00, 0xC3, 0x3F, 0x9F, 0x39, 0x3B, 0x39, 0x00, 0x41, 0xE3, 0x03, 0xC3, 0x01, 0x87, 0x83, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xE7, 0x01, 0xC7, 0x81, 0x01, 0x83, 0x00, 0x00, 0xE7, 0x1F, 0x9B, 0xE7, 0x1F, 0x39, 0x00, 0x00, 0xE7, 0x8F, 0x39, 0xE7, 0x87, 0xF9, 0x00, 0x00, 0xC3, 0xC7, 0x39, 0xE7, 0xC3, 0xC3, 0x00, 0x00, 0x99, 0xE3, 0x39, 0xE7, 0xF1, 0xE7, 0x00, 0x00, 0x99, 0xF1, 0xB3, 0xC7, 0x39, 0xF3, 0x00, 0x00, 0x99, 0x01, 0xC7, 0xE7, 0x83, 0x81, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x83, 0xE7, 0x83, 0xEF, 0x39, 0x39, 0x00, 0x00, 0x39, 0xE7, 0x39, 0xC7, 0x11, 0x11, 0x00, 0x00, 0xF9, 0xE7, 0x39, 0x83, 0x01, 0x83, 0x00, 0x00, 0x83, 0xE7, 0x39, 0x11, 0x01, 0xC7, 0x00, 0x00, 0x3F, 0xE7, 0x39, 0x39, 0x29, 0x83, 0x00, 0x00, 0x33, 0xE7, 0x39, 0x39, 0x39, 0x11, 0x00, 0x00, 0x87, 0x81, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x39, 0x83, 0x3F, 0x85, 0x31, 0x00, 0x00, 0x39, 0x31, 0x39, 0x3F, 0x33, 0x23, 0x00, 0x00, 0x29, 0x21, 0x39, 0x03, 0x21, 0x07, 0x00, 0x00, 0x01, 0x01, 0x39, 0x39, 0x39, 0x31, 0x00, 0x00, 0x01, 0x09, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x11, 0x19, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x39, 0x39, 0x83, 0x03, 0x83, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xC1, 0x39, 0x81, 0x83, 0x31, 0x01, 0x00, 0x00, 0x99, 0x39, 0xE7, 0x39, 0x23, 0x3F, 0x00, 0x00, 0x39, 0x39, 0xE7, 0xF9, 0x07, 0x3F, 0x00, 0x00, 0x31, 0x01, 0xE7, 0xF9, 0x0F, 0x3F, 0x00, 0x00, 0x3F, 0x39, 0xE7, 0xF9, 0x27, 0x3F, 0x00, 0x00, 0x9F, 0x39, 0xE7, 0xF9, 0x33, 0x3F, 0x00, 0x00, 0xC1, 0x39, 0x81, 0xF9, 0x39, 0x3F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x03, 0xC3, 0x07, 0x01, 0x3F, 0x00, 0x00, 0x39, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0x01, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x39, 0x03, 0x3F, 0x39, 0x03, 0x03, 0x00, 0x00, 0x39, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x93, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0xC7, 0x03, 0xC3, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}; - dbg_tex = SDL_CreateTextureFromSurface(dbg_ren, SDL_LoadBMP_RW(SDL_RWFromMem(font, 448), 1)); -} - -void dbg_print(int x, int y, const char *text, Uint8 r, Uint8 g, Uint8 b) -{ - int cc = 0; - SDL_SetTextureColorMod(dbg_tex, r, g, b); - SDL_Rect src = {0, 0, 8, 8}; - SDL_Rect dst = {x, y, 8, 8}; - while (text[cc] != 0) - { - if (text[cc] != 32) - { - if (text[cc] >= 65) - { - src.x = ((text[cc] - 65) % 6) * 8; - src.y = ((text[cc] - 65) / 6) * 8; - } - else - { - src.x = ((text[cc] - 22) % 6) * 8; - src.y = ((text[cc] - 22) / 6) * 8; - } - - SDL_RenderCopy(dbg_ren, dbg_tex, &src, &dst); - } - cc++; - dst.x += 8; - } -} \ No newline at end of file diff --git a/source/dbgtxt.h b/source/dbgtxt.h deleted file mode 100644 index a4c105e..0000000 --- a/source/dbgtxt.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include // Para SDL_Renderer -#include // Para Uint8 - -void dbg_init(SDL_Renderer *renderer); -void dbg_print(int x, int y, const char *text, Uint8 r, Uint8 g, Uint8 b); diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index 82fa680..3e8e62d 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -35,7 +35,7 @@ void DefineButtons::render() } // Comprueba el botón que se ha pulsado -void DefineButtons::doControllerButtonDown(const SDL_ControllerButtonEvent &event) +void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event) { // Solo pilla botones del mando que toca if (input_->getJoyIndex(event.which) != static_cast(index_controller_)) @@ -43,7 +43,7 @@ void DefineButtons::doControllerButtonDown(const SDL_ControllerButtonEvent &even return; } - const auto button = static_cast(event.button); + const auto button = static_cast(event.button); if (checkButtonNotInUse(button)) { buttons_.at(index_button_).button = button; @@ -63,9 +63,9 @@ void DefineButtons::bindButtons() // Comprueba los eventos void DefineButtons::checkEvents(const SDL_Event &event) { - if (enabled_ && event.type == SDL_CONTROLLERBUTTONDOWN) + if (enabled_ && event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN) { - doControllerButtonDown(event.cbutton); + doControllerButtonDown(event.gbutton); } } @@ -119,7 +119,7 @@ void DefineButtons::saveBindingsToOptions() } // Comprueba que un botón no esté ya asignado -bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button) +bool DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) { for (const auto &b : buttons_) { @@ -135,9 +135,9 @@ bool DefineButtons::checkButtonNotInUse(SDL_GameControllerButton button) void DefineButtons::clearButtons() { buttons_.clear(); - buttons_.emplace_back(lang::getText(95), InputAction::FIRE_LEFT, SDL_CONTROLLER_BUTTON_INVALID); - buttons_.emplace_back(lang::getText(96), InputAction::FIRE_CENTER, SDL_CONTROLLER_BUTTON_INVALID); - buttons_.emplace_back(lang::getText(97), InputAction::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_INVALID); - buttons_.emplace_back(lang::getText(98), InputAction::START, SDL_CONTROLLER_BUTTON_INVALID); - buttons_.emplace_back(lang::getText(99), InputAction::SERVICE, SDL_CONTROLLER_BUTTON_INVALID); + buttons_.emplace_back(lang::getText(95), InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID); + buttons_.emplace_back(lang::getText(96), InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_INVALID); + buttons_.emplace_back(lang::getText(97), InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_INVALID); + buttons_.emplace_back(lang::getText(98), InputAction::START, SDL_GAMEPAD_BUTTON_INVALID); + buttons_.emplace_back(lang::getText(99), InputAction::SERVICE, SDL_GAMEPAD_BUTTON_INVALID); } \ No newline at end of file diff --git a/source/define_buttons.h b/source/define_buttons.h index 62bd975..0a8df66 100644 --- a/source/define_buttons.h +++ b/source/define_buttons.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_ControllerButtonEvent -#include // Para SDL_GameControllerButton +#include // Para SDL_ControllerButtonEvent +#include // Para SDL_GamepadButton #include // Para size_t #include // Para shared_ptr, unique_ptr #include // Para string @@ -14,10 +14,10 @@ struct DefineButtonsButton { std::string label; // Texto en pantalla para el botón InputAction input; // Input asociado - SDL_GameControllerButton button; // Botón del mando correspondiente + SDL_GamepadButton button; // Botón del mando correspondiente // Constructor - DefineButtonsButton(const std::string &lbl, InputAction inp, SDL_GameControllerButton btn) + DefineButtonsButton(const std::string &lbl, InputAction inp, SDL_GamepadButton btn) : label(lbl), input(inp), button(btn) {} }; @@ -42,7 +42,7 @@ private: void incIndexButton(); // Comprueba el botón que se ha pulsado - void doControllerButtonDown(const SDL_ControllerButtonEvent &event); + void doControllerButtonDown(const SDL_GamepadButtonEvent &event); // Asigna los botones definidos al input void bindButtons(); @@ -51,7 +51,7 @@ private: void saveBindingsToOptions(); // Comprueba que un botón no esté ya asignado - bool checkButtonNotInUse(SDL_GameControllerButton button); + bool checkButtonNotInUse(SDL_GamepadButton button); // Limpia la asignación de botones void clearButtons(); diff --git a/source/director.cpp b/source/director.cpp index 44dc86b..0605567 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -1,15 +1,15 @@ // IWYU pragma: no_include #include "director.h" -#include // Para SDL_Init, SDL_Quit, SDL_INIT_EV... -#include // Para AUDIO_S16 -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_GetError -#include // Para SDL_DISABLE -#include // Para SDL_CONTROLLER_BUTTON_B, SDL_CO... -#include // Para SDL_SetHint, SDL_HINT_RENDER_DR... -#include // Para SDL_ShowCursor -#include // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN -#include // Para Uint32, SDL_bool +#include // Para SDL_Init, SDL_Quit, SDL_INIT_EV... +#include // Para AUDIO_S16 +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_GetError +#include // Para SDL_DISABLE +#include // Para SDL_GAMEPAD_BUTTON_B, SDL_CO... +#include // Para SDL_SetHint, SDL_HINT_RENDER_DR... +#include // Para SDL_ShowCursor +#include // Para SDL_SCANCODE_0, SDL_SCANCODE_DOWN +#include // Para Uint32, SDL_bool #include // Para errno, EEXIST, EACCES, ENAMETOO... #include // Para printf, perror #include // Para mkdir, stat, S_IRWXU @@ -101,7 +101,7 @@ void Director::init() // Inicializa y crea el resto de objetos initSDL(); - SDL_ShowCursor(SDL_DISABLE); + SDL_HideCursor(); initJailAudio(); dbg_init(renderer_); lang::loadFromFile(getLangFile(static_cast(options.game.language))); @@ -202,19 +202,19 @@ void Director::bindInputs() for (int i = 0; i < NUM_GAMEPADS; ++i) { // Mando - Movimiento del jugador - Input::get()->bindGameControllerButton(i, InputAction::UP, SDL_CONTROLLER_BUTTON_DPAD_UP); - Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_CONTROLLER_BUTTON_DPAD_DOWN); - Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_CONTROLLER_BUTTON_DPAD_LEFT); - Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); + Input::get()->bindGameControllerButton(i, InputAction::UP, SDL_GAMEPAD_BUTTON_DPAD_UP); + Input::get()->bindGameControllerButton(i, InputAction::DOWN, SDL_GAMEPAD_BUTTON_DPAD_DOWN); + Input::get()->bindGameControllerButton(i, InputAction::LEFT, SDL_GAMEPAD_BUTTON_DPAD_LEFT); + Input::get()->bindGameControllerButton(i, InputAction::RIGHT, SDL_GAMEPAD_BUTTON_DPAD_RIGHT); - Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_CONTROLLER_BUTTON_X); - Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_CONTROLLER_BUTTON_Y); - Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_CONTROLLER_BUTTON_B); + Input::get()->bindGameControllerButton(i, InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST); + Input::get()->bindGameControllerButton(i, InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH); + Input::get()->bindGameControllerButton(i, InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST); - Input::get()->bindGameControllerButton(i, InputAction::START, SDL_CONTROLLER_BUTTON_START); + Input::get()->bindGameControllerButton(i, InputAction::START, SDL_GAMEPAD_BUTTON_START); // Mando - Control del programa - Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_CONTROLLER_BUTTON_BACK); + Input::get()->bindGameControllerButton(i, InputAction::SERVICE, SDL_GAMEPAD_BUTTON_BACK); } // Mapea las asignaciones a los botones desde el archivo de configuración, si se da el caso @@ -270,7 +270,7 @@ void Director::bindInputs() // Inicializa JailAudio void Director::initJailAudio() { - JA_Init(48000, AUDIO_S16, 2); + JA_Init(48000, SDL_AUDIO_S16LE, 2); if (options.audio.enabled) { JA_SetMusicVolume(to_JA_volume(options.audio.music.volume)); @@ -290,7 +290,7 @@ bool Director::initSDL() auto success = true; // Inicializa SDL - if (SDL_Init(SDL_INIT_EVERYTHING) < 0) + if (!SDL_Init(SDL_INIT_VIDEO)) { std::cout << "SDL could not initialize!\nSDL Error: " << SDL_GetError() << std::endl; success = false; @@ -298,22 +298,21 @@ bool Director::initSDL() else { // Obtiene información sobre la pantalla - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); + auto DM= SDL_GetCurrentDisplayMode(0); // Calcula el máximo factor de zoom que se puede aplicar a la pantalla - options.video.window.max_zoom = std::min(DM.w / param.game.width, DM.h / param.game.height); + options.video.window.max_zoom = std::min(DM->w / param.game.width, DM->h / param.game.height); options.video.window.zoom = std::min(options.video.window.zoom, options.video.window.max_zoom); // Muestra información sobre el tamaño de la pantalla y de la ventana de juego - std::cout << "\nCurrent display mode: " << DM.w << "x" << DM.h << " @ " << DM.refresh_rate << "Hz" << std::endl; + std::cout << "\nCurrent display mode: " << DM->w << "x" << DM->h << " @ " << DM->refresh_rate << "Hz" << std::endl; std::cout << "Window resolution : " << param.game.width << "x" << param.game.height << " x" << options.video.window.zoom << std::endl; // Establece el filtro de la textura - if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast(options.video.filter)).c_str())) + /*if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, std::to_string(static_cast(options.video.filter)).c_str())) { std::cout << "Warning: texture filtering not enabled!\n"; - } + }*/ if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl")) { @@ -321,7 +320,7 @@ bool Director::initSDL() } // Crea la ventana - window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_HIDDEN); + window_ = SDL_CreateWindow(WINDOW_CAPTION, param.game.width * options.video.window.zoom, param.game.height * options.video.window.zoom, SDL_WINDOW_OPENGL); if (!window_) { std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl; @@ -333,13 +332,13 @@ bool Director::initSDL() Uint32 flags = 0; if (options.video.v_sync) { - flags = SDL_RENDERER_PRESENTVSYNC; + //flags = SDL_RENDERER_PRESENTVSYNC; } // La aceleración se activa según el define - flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; + //flags = flags | SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE; - renderer_ = SDL_CreateRenderer(window_, -1, flags); + renderer_ = SDL_CreateRenderer(window_, nullptr); if (!renderer_) { @@ -349,8 +348,7 @@ bool Director::initSDL() else { SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height); - SDL_RenderSetIntegerScale(renderer_, static_cast(options.video.integer_scale)); + SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); SDL_SetWindowFullscreen(window_, static_cast(options.video.mode)); SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND); } diff --git a/source/director.h b/source/director.h index 9913715..da8ff0c 100644 --- a/source/director.h +++ b/source/director.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Renderer -#include // Para SDL_Window +#include // Para SDL_Renderer +#include // Para SDL_Window #include // Para string namespace lang { diff --git a/source/fade.cpp b/source/fade.cpp index 753e1c7..9ec39db 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -1,6 +1,6 @@ #include "fade.h" -#include // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_NONE -#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_NONE +#include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para rand #include // Para min, max #include "param.h" // Para Param, param, ParamGame, ParamFade @@ -56,7 +56,7 @@ void Fade::render() { if (state_ != FadeState::NOT_ENABLED) { - SDL_RenderCopy(renderer_, backbuffer_, nullptr, nullptr); + SDL_RenderTexture(renderer_, backbuffer_, nullptr, nullptr); } } @@ -191,7 +191,7 @@ void Fade::update() for (size_t i = 0; i < square_.size(); ++i) { // A partir del segundo rectangulo se pinta en función del anterior - square_.at(i).h = i == 0 ? h : std::max(square_.at(i - 1).h - 2, 0); + square_.at(i).h = i == 0 ? h : std::max(static_cast(square_.at(i - 1).h) - 2, 0); } int completed = 0; @@ -259,15 +259,15 @@ void Fade::activate() case FadeType::CENTER: { - rect1_ = {0, 0, param.game.width, 0}; - rect2_ = {0, 0, param.game.width, 0}; + rect1_ = {0, 0, static_cast(param.game.width), 0}; + rect2_ = {0, 0, static_cast(param.game.width), 0}; a_ = 64; break; } case FadeType::RANDOM_SQUARE: { - rect1_ = {0, 0, param.game.width / num_squares_width_, param.game.height / num_squares_height_}; + rect1_ = {0, 0, static_cast(param.game.width / num_squares_width_), static_cast(param.game.height / num_squares_height_)}; square_.clear(); // Añade los cuadrados al vector @@ -283,7 +283,7 @@ void Fade::activate() while (num > 1) { auto num_arreu = rand() % num; - SDL_Rect temp = square_[num_arreu]; + SDL_FRect temp = square_[num_arreu]; square_[num_arreu] = square_[num - 1]; square_[num - 1] = temp; num--; @@ -310,10 +310,10 @@ void Fade::activate() // Añade los cuadrados al vector square_.clear(); - rect1_ = {0, 0, param.game.width, 0}; - const int max = param.game.height / param.fade.venetian_size; + rect1_ = {0, 0, static_cast(param.game.width), 0}; + const int MAX = param.game.height / param.fade.venetian_size; - for (int i = 0; i < max; ++i) + for (int i = 0; i < MAX; ++i) { rect1_.y = i * param.fade.venetian_size; square_.push_back(rect1_); diff --git a/source/fade.h b/source/fade.h index ab4888f..2bbfe2f 100644 --- a/source/fade.h +++ b/source/fade.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint8, Uint16 +#include // Para SDL_Rect +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint8, Uint16 #include // Para vector // Tipos de fundido @@ -45,11 +45,11 @@ private: FadeState state_ = FadeState::NOT_ENABLED; // Estado actual del objeto Uint16 counter_; // Contador interno Uint8 r_, g_, b_, a_; // Colores para el fade - SDL_Rect rect1_; // Rectangulo usado para crear los efectos de transición - SDL_Rect rect2_; // Rectangulo usado para crear los efectos de transición + SDL_FRect rect1_; // Rectangulo usado para crear los efectos de transición + SDL_FRect rect2_; // Rectangulo usado para crear los efectos de transición int num_squares_width_; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE int num_squares_height_; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE - std::vector square_; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE + std::vector square_; // Vector con los indices de los cuadrados para el FadeType::RANDOM_SQUARE int fade_random_squares_delay_; // Duración entre cada pintado de cuadrados int fade_random_squares_mult_; // Cantidad de cuadrados que se pintaran cada vez int post_duration_ = 0; // Duración posterior del fade tras finalizar diff --git a/source/game.cpp b/source/game.cpp index 8ab89be..e1096fb 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -1,10 +1,10 @@ #include "game.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_Event, SDL_PollEvent, SDL_KEYDOWN -#include // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4 -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks -#include // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_... +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_Event, SDL_PollEvent, SDL_KEYDOWN +#include // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4 +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks +#include // Para SDL_WINDOWEVENT_FOCUS_GAINED, SDL_... #include // Para rand, size_t #include // Para find_if, clamp, min #include // Para function @@ -1066,7 +1066,7 @@ void Game::render() screen_->start(); // Copia la textura con la zona de juego a la pantalla - SDL_RenderCopy(renderer_, canvas_, nullptr, ¶m.game.play_area.rect); + SDL_RenderTexture(renderer_, canvas_, nullptr, ¶m.game.play_area.rect); // Dibuja el marcador scoreboard_->render(); diff --git a/source/game.h b/source/game.h index de1358b..8c7b1a6 100644 --- a/source/game.h +++ b/source/game.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32, Uint8 -#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint32, Uint8 +#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector diff --git a/source/game_logo.cpp b/source/game_logo.cpp index 1f986a4..0793266 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -1,5 +1,5 @@ #include "game_logo.h" -#include // Para SDL_FLIP_HORIZONTAL +#include // Para SDL_FLIP_HORIZONTAL #include // Para max #include "animated_sprite.h" // Para AnimatedSprite #include "jail_audio.h" // Para JA_PlaySound diff --git a/source/global_events.cpp b/source/global_events.cpp index ed99ae2..564a25d 100644 --- a/source/global_events.cpp +++ b/source/global_events.cpp @@ -1,5 +1,5 @@ #include "global_events.h" -#include // Para SDL_WINDOWEVENT_SIZE_CHANGED +#include // Para SDL_WINDOWEVENT_SIZE_CHANGED #include // Para char_traits, basic_ostream, operator<< #include "mouse.h" // Para handleEvent #include "section.h" // Para Name, Options, name, options diff --git a/source/global_events.h b/source/global_events.h index 8e0751f..c3add83 100644 --- a/source/global_events.h +++ b/source/global_events.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace globalEvents { diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index c6b15a3..e976905 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -1,6 +1,6 @@ #include "global_inputs.h" -#include // Para SDL_RenderSetIntegerScale -#include // Para SDL_FALSE, SDL_TRUE +#include // Para SDL_RenderSetIntegerScale +#include // Para SDL_FALSE, SDL_TRUE #include // Para operator+, string, to_string, basic_string #include // Para vector #include "asset.h" // Para Asset diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 51ceae7..a0072a7 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -1,8 +1,8 @@ #include "hiscore_table.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PollEvent, SDL_Event -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks #include // Para rand, size_t #include // Para max #include // Para function @@ -125,7 +125,7 @@ void HiScoreTable::render() view_area_.y = std::max(0, param.game.height - counter_ + 100); // Copia el backbuffer al renderizador - SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_area_); + SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_); // Renderiza el fade fade_->render(); diff --git a/source/hiscore_table.h b/source/hiscore_table.h index 46d8dac..de30de7 100644 --- a/source/hiscore_table.h +++ b/source/hiscore_table.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint16, Uint32, Uint8 +#include // Para SDL_Rect +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint16, Uint32, Uint8 #include // Para unique_ptr, shared_ptr #include // Para string #include // Para vector diff --git a/source/input.cpp b/source/input.cpp index d3cd523..89ad070 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -1,8 +1,8 @@ #include "input.h" -#include // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS... -#include // Para SDL_GetError -#include // Para SDL_ENABLE -#include // Para SDL_GetKeyboardState +#include // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS... +#include // Para SDL_GetError +#include // Para SDL_ENABLE +#include // Para SDL_GetKeyboardState #include // Para find #include // Para basic_ostream, operator<<, cout, endl #include // Para distance diff --git a/source/input.h b/source/input.h index 15a5f23..3a8e2bd 100644 --- a/source/input.h +++ b/source/input.h @@ -1,9 +1,9 @@ #pragma once -#include // Para SDL_GameControllerButton, SDL_G... -#include // Para SDL_Joystick -#include // Para SDL_Scancode -#include // Para Uint8 +#include // Para SDL_GamepadButton, SDL_G... +#include // Para SDL_Joystick +#include // Para SDL_Scancode +#include // Para Uint8 #include // Para string, basic_string #include // Para vector @@ -80,17 +80,17 @@ private: struct ControllerBindings { - SDL_GameControllerButton button; // GameControllerButton asociado + SDL_GamepadButton button; // GameControllerButton asociado bool active; // Indica si está activo bool axis_active; // Estado del eje // Constructor - explicit ControllerBindings(SDL_GameControllerButton btn = SDL_CONTROLLER_BUTTON_INVALID, bool act = false, bool axis_act = false) + explicit ControllerBindings(SDL_GamepadButton btn = SDL_GAMEPAD_BUTTON_INVALID, bool act = false, bool axis_act = false) : button(btn), active(act), axis_active(axis_act) {} }; // Variables - std::vector connected_controllers_; // Vector con todos los mandos conectados + std::vector connected_controllers_; // Vector con todos los mandos conectados std::vector joysticks_; // Vector con todos los joysticks conectados std::vector key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos std::vector> controller_bindings_; // Vector con los botones asociadas a los inputs predefinidos para cada mando @@ -123,7 +123,7 @@ public: void bindKey(InputAction input, SDL_Scancode code); // Asigna inputs a botones del mando - void bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button); + void bindGameControllerButton(int controller_index, InputAction input, SDL_GamepadButton button); void bindGameControllerButton(int controller_index, InputAction inputTarget, InputAction inputSource); // Comprueba si un input esta activo @@ -153,8 +153,8 @@ public: // Muestra por consola los controles asignados void printBindings(InputDeviceToUse device = InputDeviceToUse::KEYBOARD, int controller_index = 0) const; - // Obtiene el SDL_GameControllerButton asignado a un input - SDL_GameControllerButton getControllerBinding(int controller_index, InputAction input) const; + // Obtiene el SDL_GamepadButton asignado a un input + SDL_GamepadButton getControllerBinding(int controller_index, InputAction input) const; // Convierte un InputAction a std::string std::string to_string(InputAction input) const; diff --git a/source/instructions.cpp b/source/instructions.cpp index 14ecc66..af14cbf 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -1,8 +1,8 @@ #include "instructions.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PollEvent, SDL_Event -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks #include // Para max #include // Para move #include // Para vector @@ -186,7 +186,7 @@ void Instructions::fillBackbuffer() SDL_RenderClear(renderer_); // Coloca el texto de fondo - SDL_RenderCopy(renderer_, texture_, nullptr, nullptr); + SDL_RenderTexture(renderer_, texture_, nullptr, nullptr); // Dibuja los sprites for (auto &sprite : sprites_) @@ -251,7 +251,7 @@ void Instructions::render() if (view_.y == 0) renderLines(renderer_, backbuffer_, lines_); else - SDL_RenderCopy(renderer_, backbuffer_, nullptr, &view_); + SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_); fade_->render(); @@ -340,7 +340,7 @@ void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, con { SDL_Rect srcRect = {0, line.y, 320, 1}; SDL_Rect dstRect = {static_cast(line.x), line.y, 320, 1}; - SDL_RenderCopy(renderer, texture, &srcRect, &dstRect); + SDL_RenderTexture(renderer, texture, &srcRect, &dstRect); } } diff --git a/source/instructions.h b/source/instructions.h index 4c6a2f4..3ac4bfc 100644 --- a/source/instructions.h +++ b/source/instructions.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Point, SDL_Rect -#include // Para SDL_Texture, SDL_Renderer -#include // Para Uint32 +#include // Para SDL_Point, SDL_Rect +#include // Para SDL_Texture, SDL_Renderer +#include // Para Uint32 #include // Para unique_ptr, shared_ptr #include // Para vector class Fade; // lines 8-8 diff --git a/source/intro.cpp b/source/intro.cpp index f8312d2..8627b5e 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -1,10 +1,10 @@ #include "intro.h" -#include // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD -#include // Para SDL_PollEvent, SDL_Event -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_Rect -#include // Para SDL_SetTextureBlendMode, SDL_GetRend... -#include // Para SDL_GetTicks +#include // Para SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_Rect +#include // Para SDL_SetTextureBlendMode, SDL_GetRend... +#include // Para SDL_GetTicks #include // Para array #include // Para function #include // Para basic_string, string @@ -354,10 +354,10 @@ void Intro::initSprites() SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0xFF, 0x00, 0x00, 0xFF); SDL_RenderClear(Screen::get()->getRenderer()); - SDL_Rect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT}; + SDL_FRect rect = {BORDER / 2, BORDER / 2, SPRITE_WIDTH, SPRITE_HEIGHT}; auto inner_texture = Resource::get()->getTexture(TEXTURE_LIST.at(i))->getSDLTexture(); SDL_SetTextureBlendMode(inner_texture, SDL_BLENDMODE_MOD); - SDL_RenderCopy(Screen::get()->getRenderer(), inner_texture, nullptr, &rect); + SDL_RenderTexture(Screen::get()->getRenderer(), inner_texture, nullptr, &rect); SDL_SetTextureBlendMode(inner_texture, SDL_BLENDMODE_NONE); SDL_SetRenderTarget(Screen::get()->getRenderer(), temp); diff --git a/source/intro.h b/source/intro.h index 4b1c132..26b1d60 100644 --- a/source/intro.h +++ b/source/intro.h @@ -1,6 +1,6 @@ #pragma once -#include // Para Uint32, Uint8 +#include // Para Uint32, Uint8 #include // Para unique_ptr #include // Para vector #include "path_sprite.h" // Para PathSprite diff --git a/source/item.h b/source/item.h index 66397e3..28d5f90 100644 --- a/source/item.h +++ b/source/item.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para Uint16 +#include // Para SDL_Rect +#include // Para Uint16 #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index 5449a42..5042432 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -1,7 +1,7 @@ #ifndef JA_USESDLMIXER #include "jail_audio.h" -#include // Para SDL_RWFromMem -#include // Para SDL_GetTicks +#include // Para SDL_RWFromMem +#include // Para SDL_GetTicks #include // Para uint8_t, uint32_t #include // Para NULL, fseek, fclose, fopen, fread, ftell #include // Para free, malloc diff --git a/source/jail_audio.h b/source/jail_audio.h index 597d875..3bd1591 100644 --- a/source/jail_audio.h +++ b/source/jail_audio.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_AudioFormat -#include // Para Uint32, Uint8 +#include // Para SDL_AudioFormat +#include // Para Uint32, Uint8 struct JA_Music_t; // lines 4-4 struct JA_Sound_t; // lines 5-5 diff --git a/source/jail_shader.cpp b/source/jail_shader.cpp index b7b832f..52165bf 100644 --- a/source/jail_shader.cpp +++ b/source/jail_shader.cpp @@ -1,6 +1,6 @@ #include "jail_shader.h" -#include // Para SDL_Point -#include // Para SDL_bool +#include // Para SDL_Point +#include // Para SDL_bool #include // Para strncmp #include // Para basic_ostream, operator<<, endl, cout #include // Para runtime_error @@ -15,7 +15,7 @@ #include // Para OpenGL (compatibilidad) en macOS #endif // ESSENTIAL_GL_PRACTICES_SUPPORT_GL3 #else // SI NO ES __APPLE__ -#include // Para GLuint, glTexCoord2f, glVertex2f, GLfloat +#include // Para GLuint, glTexCoord2f, glVertex2f, GLfloat #endif // __APPLE__ namespace shader @@ -287,7 +287,7 @@ namespace shader } else { - SDL_RenderCopy(renderer, backBuffer, nullptr, nullptr); + SDL_RenderTexture(renderer, backBuffer, nullptr, nullptr); SDL_RenderPresent(renderer); } } diff --git a/source/jail_shader.h b/source/jail_shader.h index eaf7558..8182f42 100644 --- a/source/jail_shader.h +++ b/source/jail_shader.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Texture -#include // Para SDL_Window +#include // Para SDL_Texture +#include // Para SDL_Window #include namespace shader diff --git a/source/logo.cpp b/source/logo.cpp index 3625841..69e4d3d 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -1,6 +1,6 @@ #include "logo.h" -#include // Para SDL_PollEvent, SDL_Event -#include // Para SDL_GetTicks +#include // Para SDL_PollEvent, SDL_Event +#include // Para SDL_GetTicks #include // Para move #include "global_events.h" // Para check #include "global_inputs.h" // Para check, update diff --git a/source/logo.h b/source/logo.h index bd7cb3f..0bb4d95 100644 --- a/source/logo.h +++ b/source/logo.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Point -#include // Para Uint32 +#include // Para SDL_Point +#include // Para Uint32 #include // Para shared_ptr, unique_ptr #include // Para vector class Sprite; // lines 8-8 diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 01c26c9..bdd521f 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -1,6 +1,6 @@ #include "manage_hiscore_table.h" -#include // Para SDL_GetError -#include // Para SDL_RWread, SDL_RWwrite, SDL_RWFromFile +#include // Para SDL_GetError +#include // Para SDL_RWread, SDL_RWwrite, SDL_RWFromFile #include // Para find_if, sort #include // Para basic_ostream, operator<<, cout, endl #include // Para distance diff --git a/source/mouse.cpp b/source/mouse.cpp index e412ac6..ea4709f 100644 --- a/source/mouse.cpp +++ b/source/mouse.cpp @@ -1,6 +1,6 @@ #include "mouse.h" -#include // Para SDL_ShowCursor -#include // Para SDL_GetTicks +#include // Para SDL_ShowCursor +#include // Para SDL_GetTicks namespace Mouse { diff --git a/source/mouse.h b/source/mouse.h index d99ea3c..db34a34 100644 --- a/source/mouse.h +++ b/source/mouse.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Event -#include // Para Uint32 +#include // Para SDL_Event +#include // Para Uint32 namespace Mouse { diff --git a/source/moving_sprite.h b/source/moving_sprite.h index c55c2c1..d23856a 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_RendererFlip +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_RendererFlip #include // Para shared_ptr #include #include "sprite.h" // Para Sprite diff --git a/source/notifier.cpp b/source/notifier.cpp index 079ff1f..5c906df 100644 --- a/source/notifier.cpp +++ b/source/notifier.cpp @@ -1,6 +1,6 @@ #include "notifier.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para string #include #include diff --git a/source/notifier.h b/source/notifier.h index 47995be..5b694e4 100644 --- a/source/notifier.h +++ b/source/notifier.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer +#include // Para SDL_Rect +#include // Para SDL_Renderer #include // Para shared_ptr #include // Para string, basic_string #include // Para vector diff --git a/source/on_screen_help.cpp b/source/on_screen_help.cpp index 2f82d2f..7e02b44 100644 --- a/source/on_screen_help.cpp +++ b/source/on_screen_help.cpp @@ -1,6 +1,6 @@ #include "on_screen_help.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para make_unique, unique_ptr #include "lang.h" // Para getText #include "param.h" // Para Param, ParamGame, param @@ -82,7 +82,7 @@ void OnScreenHelp::render() { if (state != OnScreenHelpStatus::hidden) { - SDL_RenderCopy(Screen::get()->getRenderer(), texture, nullptr, &dest); + SDL_RenderTexture(Screen::get()->getRenderer(), texture, nullptr, &dest); } } diff --git a/source/on_screen_help.h b/source/on_screen_help.h index f4cd01d..1f953f3 100644 --- a/source/on_screen_help.h +++ b/source/on_screen_help.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Texture +#include // Para SDL_Rect +#include // Para SDL_Texture #include // Para vector class Sprite; class Text; diff --git a/source/options.cpp b/source/options.cpp index 30ae5bd..b163de0 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -1,5 +1,5 @@ #include "options.h" -#include // Para SDL_GameControllerButton +#include // Para SDL_GameControllerButton #include // Para clamp #include // Para basic_ostream, operator<<, basi... #include // Para cout diff --git a/source/options.h b/source/options.h index 9976dc0..96ad84e 100644 --- a/source/options.h +++ b/source/options.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_CONTROLLER_BUTTON_B, SDL_CO... -#include // Para Uint32 +#include // Para SDL_CONTROLLER_BUTTON_B, SDL_CO... +#include // Para Uint32 #include // Para string #include // Para vector #include "input.h" // Para InputAction, InputDeviceToUse diff --git a/source/param.h b/source/param.h index 8438193..b56fd1b 100644 --- a/source/param.h +++ b/source/param.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para Uint32 +#include // Para SDL_Rect +#include // Para Uint32 #include // Para string #include // Para vector #include "utils.h" // Para Color, Zone diff --git a/source/path_sprite.h b/source/path_sprite.h index 404bec4..93c5613 100644 --- a/source/path_sprite.h +++ b/source/path_sprite.h @@ -1,6 +1,6 @@ #pragma once -#include // Para SDL_Point +#include // Para SDL_Point #include // Para function #include // Para shared_ptr #include // Para vector diff --git a/source/player.cpp b/source/player.cpp index a7a8346..7fd025f 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,6 +1,6 @@ #include "player.h" -#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL... -#include // Para SDL_GetTicks +#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL... +#include // Para SDL_GetTicks #include // Para rand #include // Para clamp, max, min #include "animated_sprite.h" // Para AnimatedSprite diff --git a/source/player.h b/source/player.h index e83eeb1..68bb10d 100644 --- a/source/player.h +++ b/source/player.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para Uint32 +#include // Para SDL_Rect +#include // Para Uint32 #include // Para unique_ptr, shared_ptr #include // Para string #include // Para vector diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index d9c3ec0..9386973 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -1,7 +1,7 @@ #include "scoreboard.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks #include // Para roundf #include // Para operator<<, setfill, setw #include // Para basic_ostream, basic_ostringstream @@ -120,7 +120,7 @@ void Scoreboard::update() // Pinta el marcador void Scoreboard::render() { - SDL_RenderCopy(renderer_, background_, nullptr, &rect_); + SDL_RenderTexture(renderer_, background_, nullptr, &rect_); } // Establece el valor de la variable @@ -296,7 +296,7 @@ void Scoreboard::fillPanelTextures() // NAME text_scoreboard_->writeCentered(slot4_3_.x, slot4_3_.y, lang::getText(106)); /* TEXTO CENTRADO */ - //text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[i], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5)); + // text_scoreboard_->writeDX(TEXT_CENTER | TEXT_COLOR, slot4_4_.x, slot4_4_.y, record_name_[i], 1, getColorLikeKnightRider(name_colors_, loop_counter_ / 5)); /* TEXTO A LA IZQUIERDA */ text_scoreboard_->writeColored(enter_name_pos_.x, enter_name_pos_.y, record_name_[i], getColorLikeKnightRider(name_colors_, loop_counter_ / 5)); @@ -340,7 +340,7 @@ void Scoreboard::fillBackgroundTexture() // Copia las texturas de los paneles for (int i = 0; i < SCOREBOARD_MAX_PANELS; ++i) { - SDL_RenderCopy(renderer_, panel_texture_[i], nullptr, &panel_[i].pos); + SDL_RenderTexture(renderer_, panel_texture_[i], nullptr, &panel_[i].pos); } // Dibuja la linea que separa la zona de juego del marcador diff --git a/source/scoreboard.h b/source/scoreboard.h index 22d834e..d7ec4f4 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -1,9 +1,9 @@ #pragma once -#include // Para SDL_Point, SDL_Rect -#include // Para SDL_Texture, SDL_Renderer -#include // Para Uint32 -#include // Para SDL_GetTicks +#include // Para SDL_Point, SDL_Rect +#include // Para SDL_Texture, SDL_Renderer +#include // Para Uint32 +#include // Para SDL_GetTicks #include // Para size_t #include // Para unique_ptr, shared_ptr #include // Para string diff --git a/source/screen.cpp b/source/screen.cpp index 9623676..fba3570 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -1,6 +1,6 @@ #include "screen.h" -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_GetTicks +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_GetTicks #include // Para max, min #include // Para basic_ifstream, ifstream #include // Para istreambuf_iterator, operator== @@ -32,13 +32,12 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) : window_(window), renderer_(renderer), game_canvas_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), - src_rect_({0, 0, param.game.width, param.game.height}), - dst_rect_({0, 0, param.game.width, param.game.height}) + src_rect_(SDL_FRect{0, 0, static_cast(param.game.width), static_cast(param.game.height)}), + dst_rect_(SDL_FRect{0, 0, static_cast(param.game.width), static_cast(param.game.height)}) { // Inicializa variables - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); - info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ"; + auto DM = SDL_GetCurrentDisplayMode(0); + info_resolution_ = std::to_string(DM->w) + " X " + std::to_string(DM->h) + " AT " + std::to_string(DM->refresh_rate) + " HZ"; adjustRenderLogicalSize(); // Muestra la ventana @@ -85,7 +84,7 @@ void Screen::renderScreen() } else { - SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr); + SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr); SDL_RenderPresent(renderer_); } } @@ -100,7 +99,7 @@ void Screen::setVideoMode(ScreenVideoMode mode) Uint32 flags = SDL_GetWindowFlags(window_); if (flags != static_cast(options.video.mode)) { - SDL_SetWindowFullscreen(window_, static_cast(options.video.mode)); + SDL_SetWindowFullscreen(window_, static_cast(options.video.mode)); } initShaders(); @@ -192,11 +191,11 @@ void Screen::renderShake() // Vuelca game_canvas_ a la textura temporal SDL_SetRenderTarget(renderer_, temp_texture); - SDL_RenderCopy(renderer_, game_canvas_, nullptr, nullptr); + SDL_RenderTexture(renderer_, game_canvas_, nullptr, nullptr); // Vuelca textura temporal a game_canvas_ SDL_SetRenderTarget(renderer_, game_canvas_); - SDL_RenderCopy(renderer_, temp_texture, &src_rect_, &dst_rect_); + SDL_RenderTexture(renderer_, temp_texture, &src_rect_, &dst_rect_); // Elimina la textura temporal SDL_DestroyTexture(temp_texture); @@ -261,7 +260,7 @@ void Screen::adjustWindowSize() const int NEW_POS_Y = old_pos_y + (old_height - HEIGHT) / 2; SDL_Rect viewport = {0, 0, WIDTH, HEIGHT}; - SDL_RenderSetViewport(renderer_, &viewport); + SDL_SetRenderViewport(renderer_, &viewport); SDL_SetWindowPosition(window_, std::max(NEW_POS_X, WINDOWS_DECORATIONS_), std::max(NEW_POS_Y, 0)); SDL_SetWindowSize(window_, WIDTH, HEIGHT); @@ -274,11 +273,10 @@ void Screen::adjustWindowSize() int Screen::getMaxZoom() { // Obtiene información sobre la pantalla - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); + auto DM = SDL_GetCurrentDisplayMode(0); // Calcula el máximo factor de zoom que se puede aplicar a la pantalla - const int MAX_ZOOM = std::min(DM.w / param.game.width, (DM.h - WINDOWS_DECORATIONS_) / param.game.height); + const int MAX_ZOOM = std::min(DM->w / param.game.width, (DM->h - WINDOWS_DECORATIONS_) / param.game.height); // Normaliza los valores de zoom options.video.window.zoom = std::min(options.video.window.zoom, MAX_ZOOM); diff --git a/source/screen.h b/source/screen.h index d301cc7..aff1fd8 100644 --- a/source/screen.h +++ b/source/screen.h @@ -1,10 +1,10 @@ #pragma once -#include // Para SDL_BlendMode -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Renderer, SDL_Texture -#include // Para Uint32 -#include // Para SDL_Window +#include // Para SDL_BlendMode +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_Renderer, SDL_Texture +#include // Para Uint32 +#include // Para SDL_Window #include // Para string #include "param.h" // Para Param, ParamGame, param #include "utils.h" // Para Color @@ -16,10 +16,10 @@ enum class ScreenFilter : int LINEAL = 1, }; -enum class ScreenVideoMode : Uint32 +enum class ScreenVideoMode : bool { - WINDOW = 0, - FULLSCREEN = SDL_WINDOW_FULLSCREEN_DESKTOP, + WINDOW = false, + FULLSCREEN = true, }; class Screen @@ -92,7 +92,7 @@ private: : desp(dp), delay(dl), counter(cnt), lenght(len), remaining(rem), original_pos(origPos), original_width(origWidth), enabled(en) {} // Método para habilitar el efecto - void enable(SDL_Rect &src_rect, SDL_Rect &dst_rect) + void enable(SDL_FRect &src_rect, SDL_FRect &dst_rect) { if (!enabled) { @@ -112,7 +112,7 @@ private: } // Método para actualizar el efecto de movimiento/agitación - void update(SDL_Rect &src_rect, SDL_Rect &dst_rect) + void update(SDL_FRect &src_rect, SDL_FRect &dst_rect) { if (enabled) { @@ -162,8 +162,8 @@ private: SDL_Texture *game_canvas_; // Textura donde se dibuja todo antes de volcarse al renderizador // Variables - SDL_Rect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla - SDL_Rect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana + SDL_FRect src_rect_; // Coordenadas de donde va a pillar la textura del juego para dibujarla + SDL_FRect dst_rect_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana FPS fps_; // Variable para gestionar los frames por segundo std::string info_resolution_; // Texto con la informacion de la pantalla std::string shader_source_; // Almacena el contenido del archivo GLSL @@ -199,7 +199,7 @@ private: void adjustWindowSize(); // Ajusta el tamaño lógico del renderizador - void adjustRenderLogicalSize() { SDL_RenderSetLogicalSize(renderer_, param.game.width, param.game.height); } + void adjustRenderLogicalSize() { SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE); } // Obtiene el tamaño máximo de zoom posible para la ventana int getMaxZoom(); diff --git a/source/sprite.h b/source/sprite.h index a8657e0..5f45c08 100644 --- a/source/sprite.h +++ b/source/sprite.h @@ -1,6 +1,6 @@ #pragma once -#include // Para SDL_Rect, SDL_Point +#include // Para SDL_Rect, SDL_Point #include // Para shared_ptr class Texture; diff --git a/source/tabe.cpp b/source/tabe.cpp index 2ff762d..005f00f 100644 --- a/source/tabe.cpp +++ b/source/tabe.cpp @@ -1,6 +1,6 @@ // IWYU pragma: no_include #include "tabe.h" -#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE +#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE #include // Para rand, abs #include // Para max #include "jail_audio.h" // Para JA_PlaySound diff --git a/source/tabe.h b/source/tabe.h index 7b9679f..c1d9a82 100644 --- a/source/tabe.h +++ b/source/tabe.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Rect -#include // Para Uint32 -#include // Para SDL_GetTicks +#include // Para SDL_Rect +#include // Para Uint32 +#include // Para SDL_GetTicks #include // Para rand #include // Para unique_ptr #include "animated_sprite.h" // Para AnimatedSprite diff --git a/source/text.cpp b/source/text.cpp index d51e621..69e583c 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -1,8 +1,8 @@ #include "text.h" -#include // Para SDL_BLENDMODE_BLEND -#include // Para SDL_PIXELFORMAT_RGBA8888 -#include // Para SDL_Rect -#include // Para SDL_TEXTUREACCESS_TARGET +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_Rect +#include // Para SDL_TEXTUREACCESS_TARGET #include // Para size_t #include // Para basic_ifstream, basic_istream, basic... #include // Para cerr diff --git a/source/text.h b/source/text.h index d66af00..23e570c 100644 --- a/source/text.h +++ b/source/text.h @@ -1,6 +1,6 @@ #pragma once -#include // Para Uint8 +#include // Para Uint8 #include // Para unique_ptr, shared_ptr #include // Para string #include "sprite.h" // Para Sprite diff --git a/source/texture.cpp b/source/texture.cpp index 04ae838..7959028 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -1,6 +1,6 @@ #include "texture.h" -#include // Para SDL_GetError -#include // Para SDL_CreateRGBSurfaceWithFormatFrom +#include // Para SDL_GetError +#include // Para SDL_CreateRGBSurfaceWithFormatFrom #include // Para uint32_t #include // Para memcpy, size_t #include // Para basic_ostream, operator<<, basic_ifstream diff --git a/source/texture.h b/source/texture.h index 16cc4e6..d187cfb 100644 --- a/source/texture.h +++ b/source/texture.h @@ -1,10 +1,10 @@ #pragma once -#include // Para SDL_BlendMode -#include // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... -#include // Para SDL_Point, SDL_Rect -#include // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... -#include // Para Uint8, Uint16, Uint32 +#include // Para SDL_BlendMode +#include // Para SDL_PIXELFORMAT_RGBA8888, SDL_PixelF... +#include // Para SDL_Point, SDL_Rect +#include // Para SDL_Renderer, SDL_FLIP_NONE, SDL_TEX... +#include // Para Uint8, Uint16, Uint32 #include // Para shared_ptr #include // Para string #include // Para vector diff --git a/source/tiled_bg.cpp b/source/tiled_bg.cpp index b367789..a730ceb 100644 --- a/source/tiled_bg.cpp +++ b/source/tiled_bg.cpp @@ -1,5 +1,5 @@ #include "tiled_bg.h" -#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_PIXELFORMAT_RGBA8888 #include // Para rand #include // Para sin #include // Para unique_ptr, make_unique @@ -81,7 +81,7 @@ void TiledBG::fillTexture() // Pinta la clase en pantalla void TiledBG::render() { - SDL_RenderCopy(renderer_, canvas_, &window_, &pos_); + SDL_RenderTexture(renderer_, canvas_, &window_, &pos_); } // Actualiza la lógica de la clase diff --git a/source/tiled_bg.h b/source/tiled_bg.h index 9508dde..d18218c 100644 --- a/source/tiled_bg.h +++ b/source/tiled_bg.h @@ -1,7 +1,7 @@ #pragma once -#include // Para SDL_Rect -#include // Para SDL_Renderer, SDL_Texture +#include // Para SDL_Rect +#include // Para SDL_Renderer, SDL_Texture #include "utils.h" // Modos de funcionamiento para el tileado de fondo diff --git a/source/title.cpp b/source/title.cpp index 3c48474..7c14399 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1,7 +1,7 @@ #include "title.h" -#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN -#include // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5 -#include // Para SDL_GetTicks +#include // Para SDL_PollEvent, SDL_Event, SDL_KEYDOWN +#include // Para SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5 +#include // Para SDL_GetTicks #include // Para size_t #include // Para char_traits, operator+, basic_string #include // Para vector diff --git a/source/title.h b/source/title.h index cee2ec4..a873a76 100644 --- a/source/title.h +++ b/source/title.h @@ -1,6 +1,6 @@ #pragma once -#include // Para Uint32 +#include // Para Uint32 #include // Para unique_ptr, shared_ptr #include "section.h" // Para Options class DefineButtons; // lines 5-5 diff --git a/source/utils.cpp b/source/utils.cpp index d8d5cc2..2852519 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -1,5 +1,5 @@ #include "utils.h" -#include // Para SDL_RWFromFile, SDL_RWclose, SDL_RWread +#include // Para SDL_RWFromFile, SDL_RWclose, SDL_RWread #include // Para size_t #include // Para min, clamp, find_if_not, find, transform #include // Para tolower, isspace diff --git a/source/utils.h b/source/utils.h index 4973f6d..8fc824c 100644 --- a/source/utils.h +++ b/source/utils.h @@ -1,8 +1,8 @@ #pragma once -#include // Para SDL_Rect, SDL_Point -#include // Para SDL_Renderer -#include // Para Uint8 +#include // Para SDL_Rect, SDL_Point +#include // Para SDL_Renderer +#include // Para Uint8 #include // Para int32_t #include // Para max, min #include // Para string @@ -116,7 +116,7 @@ struct Demo // Posiciones dentro de un rectangulo struct Zone { - SDL_Rect rect; // Rectangulo que define la zona + SDL_FRect rect; // Rectangulo que define la zona int center_x; // Anclaje al 50% del eje X int first_quarter_x; // Anclaje al 25% del eje X int third_quarter_x; // Anclaje al 75% del eje X