netejat codi mort en screen.cpp

This commit is contained in:
2025-10-16 13:29:25 +02:00
parent 7fe2523221
commit 9db902c024
3 changed files with 1 additions and 47 deletions

View File

@@ -46,7 +46,6 @@ void Resource::clear() {
// Carga todos los recursos // Carga todos los recursos
void Resource::load() { void Resource::load() {
calculateTotal(); calculateTotal();
Screen::get()->show();
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
std::cout << "** LOADING RESOURCES" << std::endl; std::cout << "** LOADING RESOURCES" << std::endl;
loadSounds(); loadSounds();

View File

@@ -44,7 +44,7 @@ Screen::Screen()
// Ajusta los tamaños // Ajusta los tamaños
game_surface_dstrect_ = {options.video.border.width, options.video.border.height, options.game.width, options.game.height}; game_surface_dstrect_ = {options.video.border.width, options.video.border.height, options.game.width, options.game.height};
adjustWindowSize(); //adjustWindowSize();
current_palette_ = findPalette(options.video.palette); current_palette_ = findPalette(options.video.palette);
// Define el color del borde para el modo de pantalla completa // Define el color del borde para el modo de pantalla completa
@@ -70,18 +70,6 @@ Screen::Screen()
} }
SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST); SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST);
// Crea la textura para los shaders
const int EXTRA_WIDTH = options.video.border.enabled ? options.video.border.width * 2 : 0;
const int EXTRA_HEIGHT = options.video.border.enabled ? options.video.border.height * 2 : 0;
shaders_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width + EXTRA_WIDTH, options.game.height + EXTRA_HEIGHT);
if (!shaders_texture_) {
// Registrar el error si está habilitado
if (options.console) {
std::cerr << "Error: shaders_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
SDL_SetTextureScaleMode(shaders_texture_, SDL_SCALEMODE_NEAREST);
// Crea la surface donde se dibujan los graficos del juego // Crea la surface donde se dibujan los graficos del juego
game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height); game_surface_ = std::make_shared<Surface>(options.game.width, options.game.height);
game_surface_->setPalette(readPalFile(palettes_.at(current_palette_))); game_surface_->setPalette(readPalFile(palettes_.at(current_palette_)));
@@ -95,9 +83,6 @@ Screen::Screen()
// Establece la surface que actuará como renderer para recibir las llamadas a render() // Establece la surface que actuará como renderer para recibir las llamadas a render()
renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_); renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
// Muestra la ventana
show();
// Extrae el nombre de las paletas desde su ruta // Extrae el nombre de las paletas desde su ruta
processPaletteList(); processPaletteList();
@@ -114,7 +99,6 @@ Screen::Screen()
Screen::~Screen() { Screen::~Screen() {
SDL_DestroyTexture(game_texture_); SDL_DestroyTexture(game_texture_);
SDL_DestroyTexture(border_texture_); SDL_DestroyTexture(border_texture_);
SDL_DestroyTexture(shaders_texture_);
} }
// Limpia el renderer // Limpia el renderer
@@ -199,7 +183,6 @@ void Screen::setBorderColor(Uint8 color) {
void Screen::toggleBorder() { void Screen::toggleBorder() {
options.video.border.enabled = !options.video.border.enabled; options.video.border.enabled = !options.video.border.enabled;
setVideoMode(options.video.fullscreen); setVideoMode(options.video.fullscreen);
//createShadersTexture();
initShaders(); initShaders();
} }
@@ -314,9 +297,6 @@ void Screen::textureToRenderer() {
SDL_Texture* texture_to_render = options.video.border.enabled ? border_texture_ : game_texture_; SDL_Texture* texture_to_render = options.video.border.enabled ? border_texture_ : game_texture_;
if (options.video.shaders && shader_backend_) { if (options.video.shaders && shader_backend_) {
SDL_SetRenderTarget(renderer_, shaders_texture_);
SDL_RenderTexture(renderer_, texture_to_render, nullptr, nullptr);
SDL_SetRenderTarget(renderer_, nullptr);
shader_backend_->render(); shader_backend_->render();
} else { } else {
SDL_SetRenderTarget(renderer_, nullptr); SDL_SetRenderTarget(renderer_, nullptr);
@@ -345,24 +325,6 @@ size_t Screen::findPalette(const std::string& name) {
return static_cast<size_t>(0); return static_cast<size_t>(0);
} }
// Recrea la textura para los shaders
void Screen::createShadersTexture() {
if (shaders_texture_) {
SDL_DestroyTexture(shaders_texture_);
}
// Crea la textura donde se dibuja el borde que rodea el area de juego
const int EXTRA_WIDTH = options.video.border.enabled ? options.video.border.width * 2 : 0;
const int EXTRA_HEIGHT = options.video.border.enabled ? options.video.border.height * 2 : 0;
shaders_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, options.game.width + EXTRA_WIDTH, options.game.height + EXTRA_HEIGHT);
if (!shaders_texture_) {
// Registrar el error si está habilitado
if (options.console) {
std::cerr << "Error: shaders_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
}
}
}
// Muestra información por pantalla // Muestra información por pantalla
void Screen::renderInfo() { void Screen::renderInfo() {
if (show_debug_info_ && Resource::get()) { if (show_debug_info_ && Resource::get()) {

View File

@@ -67,7 +67,6 @@ class Screen {
SDL_Renderer* renderer_; // El renderizador de la ventana SDL_Renderer* renderer_; // El renderizador de la ventana
SDL_Texture* game_texture_; // Textura donde se dibuja el juego SDL_Texture* game_texture_; // Textura donde se dibuja el juego
SDL_Texture* border_texture_; // Textura donde se dibuja el borde del juego SDL_Texture* border_texture_; // Textura donde se dibuja el borde del juego
SDL_Texture* shaders_texture_; // Textura para aplicar los shaders
std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_ std::shared_ptr<Surface> game_surface_; // Surface principal para manejar game_surface_data_
std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla std::shared_ptr<Surface> border_surface_; // Surface para pintar el el borde de la pantalla
std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua std::shared_ptr<std::shared_ptr<Surface>> renderer_surface_; // Puntero a la Surface que actua
@@ -117,9 +116,6 @@ class Screen {
// Localiza la paleta dentro del vector de paletas // Localiza la paleta dentro del vector de paletas
size_t findPalette(const std::string& name); size_t findPalette(const std::string& name);
// Recrea la textura para los shaders
void createShadersTexture();
void initShaders(); // Inicializa los shaders void initShaders(); // Inicializa los shaders
void loadShaders(); // Carga el contenido del archivo GLSL void loadShaders(); // Carga el contenido del archivo GLSL
void renderInfo(); // Muestra información por pantalla void renderInfo(); // Muestra información por pantalla
@@ -196,9 +192,6 @@ class Screen {
// Oculta la ventana // Oculta la ventana
void hide(); void hide();
// Obtiene el tamaño máximo de zoom posible para la ventana
int getMaxZoom();
// Establece el renderizador para las surfaces // Establece el renderizador para las surfaces
void setRendererSurface(std::shared_ptr<Surface> surface = nullptr); void setRendererSurface(std::shared_ptr<Surface> surface = nullptr);