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>
103 lines
3.4 KiB
C++
103 lines
3.4 KiB
C++
// ship_animator.hpp - Sistema de animación de naves para l'escena de título
|
|
// © 2026 JailDesigner
|
|
|
|
#pragma once
|
|
|
|
#include "core/rendering/render_context.hpp"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
|
|
#include "core/graphics/shape.hpp"
|
|
#include "core/types.hpp"
|
|
|
|
namespace Title {
|
|
|
|
// Estats de l'animación de la ship
|
|
enum class ShipState {
|
|
ENTERING, // Entrant desde fuera de pantalla
|
|
FLOATING, // Flotante en posición estàtica
|
|
EXITING // Volant hacia el point de fuga
|
|
};
|
|
|
|
// Dades de una ship individual al título.
|
|
// Todos los miembros tienen inicializador por defecto: ShipAnimator::ships_
|
|
// es un std::array<TitleShip, 2> y sin estos defaults los campos primitivos
|
|
// quedarían indeterminados al instanciar el animador.
|
|
struct TitleShip {
|
|
// Identificació
|
|
int player_id{0}; // 1 o 2
|
|
|
|
// Estat
|
|
ShipState state{ShipState::ENTERING};
|
|
float state_time{0.0F}; // Temps acumulat en l'state actual
|
|
|
|
// Posicions
|
|
Vec2 initial_position{}; // Posición de start (fuera de pantalla per ENTERING)
|
|
Vec2 target_position{}; // Posición objetivo (rellotge 8 o 4)
|
|
Vec2 current_position{}; // Posición interpolada actual
|
|
|
|
// Escales (simulació eix Z)
|
|
float initial_scale{1.0F}; // Escala de start (més grande = més a prop)
|
|
float target_scale{1.0F}; // Escala objetivo (mida flotació)
|
|
float current_scale{1.0F}; // Escala interpolada actual
|
|
|
|
// Flotació
|
|
float oscillation_phase{0.0F}; // Acumulador de fase per movement sinusoïdal
|
|
|
|
// Parámetros de entrada
|
|
float entry_delay{0.0F}; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
|
|
|
// Parámetros de oscil·lació per ship
|
|
float amplitude_x{0.0F};
|
|
float amplitude_y{0.0F};
|
|
float frequency_x{0.0F};
|
|
float frequency_y{0.0F};
|
|
|
|
// Forma
|
|
std::shared_ptr<Graphics::Shape> shape;
|
|
|
|
// Visibilitat
|
|
bool visible{false};
|
|
};
|
|
|
|
// Gestor de animación de naves para l'escena de título
|
|
class ShipAnimator {
|
|
public:
|
|
explicit ShipAnimator(Rendering::Renderer* renderer);
|
|
|
|
// Cicle de vida
|
|
void init();
|
|
void update(float delta_time);
|
|
void draw() const;
|
|
|
|
// Control de state (cridat per TitleScene)
|
|
void start_entry_animation();
|
|
void trigger_exit_animation(); // Anima todas las naves
|
|
void trigger_exit_animation_for_player(int player_id); // Anima solo una ship (P1=1, P2=2)
|
|
void skip_to_floating_state(); // Salta directament a FLOATING sin animación
|
|
|
|
// Control de visibilitat
|
|
void set_visible(bool visible);
|
|
[[nodiscard]] auto is_animation_complete() const -> bool;
|
|
[[nodiscard]] auto is_visible() const -> bool; // Comprova si alguna ship es visible
|
|
|
|
private:
|
|
Rendering::Renderer* renderer_;
|
|
std::array<TitleShip, 2> ships_; // Naves P1 i P2
|
|
|
|
// Métodos de animación
|
|
void actualitzar_entering(TitleShip& ship, float delta_time);
|
|
void actualitzar_floating(TitleShip& ship, float delta_time);
|
|
void actualitzar_exiting(TitleShip& ship, float delta_time);
|
|
|
|
// Configuración
|
|
void configurar_nau_p1(TitleShip& ship);
|
|
void configurar_nau_p2(TitleShip& ship);
|
|
[[nodiscard]] auto calcular_posicio_fora_pantalla(float angle_rellotge) const -> Vec2;
|
|
};
|
|
|
|
} // namespace Title
|