migrat instructions a delta_time pur

This commit is contained in:
2025-10-23 18:59:37 +02:00
parent 245524c021
commit 1acbe1d097
3 changed files with 55 additions and 36 deletions

View File

@@ -25,17 +25,20 @@ class TiledBG;
*/
// --- Estructuras ---
struct Line { // Almacena información de línea animada
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
Uint32 start_time{0}; // Tiempo de inicio del movimiento
struct Line { // Almacena información de línea animada
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
float accumulated_time{0}; // Tiempo acumulado desde que empezó la animación (segundos)
float delay_time{0}; // Tiempo de retraso antes de comenzar la animación (segundos)
bool started{false}; // Indica si la línea ha comenzado a moverse
// Constructor de Line
Line(int y, float x, int direction)
Line(int y, float x, int direction, float delay)
: y(y),
x(x),
direction(direction) {}
direction(direction),
delay_time(delay) {}
};
// Clase Instructions
@@ -53,7 +56,8 @@ class Instructions {
static constexpr float SPRITE_ANIMATION_CYCLE_S = 36.0F / 60.0F; // Ciclo de animación sprites (≈0.6s)
static constexpr float START_DELAY_S = 4.0F; // Retraso antes de mover líneas (4s)
static constexpr float LINE_MOVE_DURATION_S = 1.0F; // Duración movimiento líneas (1s)
static constexpr float LINE_START_DELAY_MS = 5.0F; // Retraso entre líneas (5ms)
static constexpr float LINE_START_DELAY_S = 0.005F; // Retraso entre líneas (5ms = 0.005s)
static constexpr float SCROLL_SPEED_PPS = 60.0F; // Velocidad de scroll (60 pixels por segundo)
// --- Objetos y punteros ---
SDL_Renderer* renderer_; // El renderizador de la ventana
@@ -86,9 +90,9 @@ class Instructions {
void fillBackbuffer(); // Rellena el backbuffer
void iniSprites(); // Inicializa los sprites de los items
void updateSprites(); // Actualiza los sprites
static auto initializeLines(int height) -> std::vector<Line>; // Inicializa las líneas animadas
static auto moveLines(std::vector<Line>& lines, int width, float duration, Uint32 start_delay) -> bool; // Mueve las líneas (ya usa tiempo real)
static void renderLines(SDL_Renderer* renderer, SDL_Texture* texture, const std::vector<Line>& lines); // Renderiza las líneas
static auto initializeLines(int height, float line_delay) -> std::vector<Line>; // Inicializa las líneas animadas
static auto moveLines(std::vector<Line>& lines, int width, float duration, float delta_time) -> bool; // Mueve las líneas usando delta_time puro
static void renderLines(SDL_Renderer* renderer, SDL_Texture* texture, const std::vector<Line>& lines); // Renderiza las líneas
void updateBackbuffer(float delta_time); // Gestiona la textura con los gráficos
auto calculateDeltaTime() -> float; // Calcula el tiempo transcurrido desde el último frame
};