From 5bb2b5e7c4f0fa434396c2f5495dcd4c40a16a1b Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 28 Feb 2025 14:00:59 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20les=20notificacions=20ja=20no=20embruten?= =?UTF-8?q?=20la=20pantalla=20de=20c=C3=A0rrega?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/loading_screen.cpp | 46 +++++++++++++++++++++++++++++++++++++-- source/loading_screen.h | 29 ++++++++++++++---------- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/source/loading_screen.cpp b/source/loading_screen.cpp index cd32f39..334d2eb 100644 --- a/source/loading_screen.cpp +++ b/source/loading_screen.cpp @@ -14,6 +14,7 @@ #include "sprite.h" // for Sprite #include "texture.h" // for Texture #include "utils.h" // for Color, stringToColor, Palette +#include // Constructor LoadingScreen::LoadingScreen() @@ -40,6 +41,16 @@ LoadingScreen::LoadingScreen() loading_sound2_ = resource_->getMusic("loading_sound2.ogg"); loading_sound3_ = resource_->getMusic("loading_sound3.ogg"); + texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width, options.game.height); + if (texture_ == nullptr) + { + if (options.console) + { + std::cout << "LoadingScreen::texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl; + } + } + clearTexture(); + // Inicializa variables options.section.section = Section::LOADING_SCREEN; options.section.subsection = Subsection::NONE; @@ -71,6 +82,7 @@ LoadingScreen::LoadingScreen() LoadingScreen::~LoadingScreen() { JA_StopMusic(); + SDL_DestroyTexture(texture_); } // Comprueba el manejador de eventos @@ -193,6 +205,7 @@ void LoadingScreen::update() checkInput(); updateCounter(); updateLoad(); + fillTexture(); screen_->update(); } } @@ -212,8 +225,8 @@ void LoadingScreen::render() // Prepara para empezar a dibujar en la textura de juego screen_->start(); - // Dibuja la pantalla de carga - renderLoad(); + // Copila la textura a la pantalla + SDL_RenderCopy(renderer_, texture_, nullptr, nullptr); // Vuelca el contenido del renderizador en pantalla screen_->render(); @@ -278,4 +291,33 @@ void LoadingScreen::recreateLoadingScreen() // Vuelca el contenido del renderizador en pantalla screen_->render(); +} + +// Dibuja sobre la textura +void LoadingScreen::fillTexture() +{ + // Empieza a dibujar en la textura + auto temp = SDL_GetRenderTarget(renderer_); + SDL_SetRenderTarget(renderer_, texture_); + + // Dibuja la pantalla de carga + renderLoad(); + + // Deja el renderizador como estaba + SDL_SetRenderTarget(renderer_, temp); +} + +// Limpia la textura +void LoadingScreen::clearTexture() +{ + // Empieza a dibujar en la textura + auto temp = SDL_GetRenderTarget(renderer_); + SDL_SetRenderTarget(renderer_, texture_); + + // Limpia + SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF); + SDL_RenderClear(renderer_); + + // Deja el renderizador como estaba + SDL_SetRenderTarget(renderer_, temp); } \ No newline at end of file diff --git a/source/loading_screen.h b/source/loading_screen.h index 2741fb0..36099fc 100644 --- a/source/loading_screen.h +++ b/source/loading_screen.h @@ -1,16 +1,16 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Renderer -#include // for Uint32 -#include // for shared_ptr -class Asset; // lines 8-8 -class Input; // lines 9-9 -class Resource; // lines 10-10 -class Screen; // lines 11-11 -class Sprite; // lines 12-12 -class Texture; // lines 13-13 -struct JA_Music_t; // lines 14-14 +#include // for SDL_Rect +#include // for SDL_Renderer +#include // for Uint32 +#include // for shared_ptr +class Asset; // lines 8-8 +class Input; // lines 9-9 +class Resource; // lines 10-10 +class Screen; // lines 11-11 +class Sprite; // lines 12-12 +class Texture; // lines 13-13 +struct JA_Music_t; // lines 14-14 class LoadingScreen { @@ -37,6 +37,7 @@ private: JA_Music_t *loading_sound3_; // Sonidos para imitar la carga tipo spectrum int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga + SDL_Texture *texture_; // Textura para dibujar la pantalla de carga // Actualiza las variables void update(); @@ -65,6 +66,12 @@ private: // Reconstruye la pantalla de carga void recreateLoadingScreen(); + // Dibuja sobre la textura + void fillTexture(); + + // Limpia la textura + void clearTexture(); + public: // Constructor LoadingScreen();