c45e524109
Pase automático de clang-tidy --fix sobre el conjunto de checks que son puro transform de sintaxis y no rompen API. Invocado con --format-style=none para que clang-tidy NO arrastre clang-format sobre las líneas tocadas (evita la regla NamespaceIndentation: All del .clang-format reformateando solo trozos del archivo). Checks aplicados: - modernize-use-trailing-return-type (193 hits): 'int foo()' → 'auto foo() -> int'. Estilo coherente con la convención del proyecto. - modernize-use-default-member-init (36 hits): inicialización de miembros pasa de la lista del constructor a la declaración. Reduce duplicación cuando hay varios constructores con los mismos defaults. - modernize-use-auto (6 hits): tipos largos sustituidos por auto donde el tipo es evidente del contexto (new T, dynamic_cast, etc). - modernize-use-starts-ends-with (2 hits): s.rfind(x) == 0 → s.starts_with(x), aprovechando C++20. - performance-enum-size (10 hits): enums pequeños declaran tipo subyacente (uint8_t / similar) para reducir tamaño y precisar layout. NO aplicado en este pase (riesgo de cambios semánticos o de API): - readability-identifier-naming (renames pueden romper callsites parciales) - readability-convert-member-functions-to-static (cambia firma) - readability-use-anyofallof (reescribe loops, side effects) - readability-function-cognitive-complexity (requiere refactor manual) - bugs reales (bugprone-*, clang-diagnostic-*) → uno a uno Cambios manuales asociados: - SDLManager::clear() ahora devuelve bool: propaga el resultado de beginFrame al caller para que Director::runFrameLoop salte draw+present cuando la swapchain no esté disponible (ventana minimizada). Antes la función ignoraba el [[nodiscard]] del beginFrame y los vértices se acumulaban en el batch sin nadie que los consumiera. - vector_text.cpp: borrada la línea suelta "// Test pre-commit hook" que quedó como cruft. clang-tidy crashea en LLVM 19.1 con performance-noexcept-move-constructor (recursión infinita en ExceptionSpecAnalyzer al procesar std::set); check deshabilitado en .clang-tidy con comentario explicativo. Build limpio, smoke test OK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
72 lines
3.0 KiB
C++
72 lines
3.0 KiB
C++
// sdl_manager.hpp - Gestor de inicialización de SDL3
|
|
// © 2026 JailDesigner
|
|
//
|
|
// Tras la Fase 7 de la migración, el rendering ya no usa SDL_Renderer:
|
|
// SDLManager posee un GpuFrameRenderer (SDL3 GPU) que es el contexto único
|
|
// de dibujo del juego. El resto del código accede vía getRenderer() →
|
|
// Rendering::Renderer* (alias del GpuFrameRenderer).
|
|
|
|
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
|
|
#include "core/rendering/render_context.hpp"
|
|
|
|
class SDLManager {
|
|
public:
|
|
SDLManager(); // Constructor per defecte (usa Defaults::)
|
|
SDLManager(int width, int height, bool fullscreen); // Constructor con configuración
|
|
~SDLManager();
|
|
|
|
// No permetre còpia ni assignació
|
|
SDLManager(const SDLManager&) = delete;
|
|
auto operator=(const SDLManager&) -> SDLManager& = delete;
|
|
|
|
// [NUEVO] Gestió de finestra dinàmica
|
|
void increaseWindowSize(); // F2: +100px
|
|
void decreaseWindowSize(); // F1: -100px
|
|
void toggleFullscreen(); // F3
|
|
void toggleVSync(); // F4
|
|
auto handleWindowEvent(const SDL_Event& event) -> bool; // Per a SDL_EVENT_WINDOW_RESIZED
|
|
|
|
// Funciones principals (renderizado).
|
|
// clear() devuelve false si la swapchain no está disponible (p.ej.
|
|
// ventana minimizada). El caller debe saltarse draw+present ese frame.
|
|
[[nodiscard]] auto clear(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) -> bool;
|
|
void present();
|
|
|
|
// Getters
|
|
auto getRenderer() -> Rendering::Renderer* { return &gpu_renderer_; }
|
|
[[nodiscard]] auto getScaleFactor() const -> float { return zoom_factor_; }
|
|
|
|
// [NUEVO] Actualitzar context de renderizado (factor de scale global)
|
|
void updateRenderingContext() const;
|
|
|
|
private:
|
|
SDL_Window* finestra_;
|
|
Rendering::Renderer gpu_renderer_; // GpuFrameRenderer (SDL3 GPU)
|
|
|
|
// [NUEVO] Estat de la finestra
|
|
int current_width_; // Mida física actual
|
|
int current_height_;
|
|
bool is_fullscreen_;
|
|
int max_width_; // Calculat des del display
|
|
int max_height_;
|
|
|
|
// [ZOOM SYSTEM]
|
|
float zoom_factor_; // Current zoom (0.5x to max_zoom_)
|
|
int windowed_width_; // Saved size before fullscreen
|
|
int windowed_height_; // Saved size before fullscreen
|
|
float max_zoom_; // Maximum zoom (calculated from display)
|
|
|
|
// [NUEVO] Funciones internes
|
|
void calculateMaxWindowSize(); // Llegir resolució del display
|
|
void calculateMaxZoom(); // Calculate max zoom from display
|
|
void applyZoom(float new_zoom); // Apply zoom and resize window
|
|
void applyWindowSize(int width, int height); // Canviar mida + centrar
|
|
void updateViewport(); // Configurar viewport con letterbox
|
|
|
|
};
|