migració a delta time

This commit is contained in:
2025-09-16 10:48:22 +02:00
parent 6c702e7e23
commit 7579594c22
8 changed files with 189 additions and 91 deletions

View File

@@ -24,17 +24,31 @@ enum class PathCentered { // Centrado del recorrido
};
// --- Estructuras ---
struct Path { // Define un recorrido para el sprite
std::vector<SDL_FPoint> spots; // Puntos por los que se desplazará el sprite
int waiting_counter; // Tiempo de espera una vez en el destino
bool on_destination = false; // Indica si ha llegado al destino
bool finished = false; // Indica si ha terminado de esperarse
int counter = 0; // Contador interno
struct Path { // Define un recorrido para el sprite
float start_pos; // Posición inicial
float end_pos; // Posición final
PathType type; // Tipo de movimiento (horizontal/vertical)
float fixed_pos; // Posición fija en el eje contrario
float duration_ms; // Duración de la animación en milisegundos
float waiting_time_ms; // Tiempo de espera una vez en el destino
std::function<double(double)> easing_function; // Función de easing
float elapsed_time = 0.0f; // Tiempo transcurrido
float waiting_elapsed = 0.0f; // Tiempo de espera transcurrido
bool on_destination = false; // Indica si ha llegado al destino
bool finished = false; // Indica si ha terminado de esperarse
// Constructor
Path(const std::vector<SDL_FPoint> &spots_init, int waiting_counter_init)
: spots(spots_init),
waiting_counter(waiting_counter_init) {}
// Constructor para paths generados
Path(float start, float end, PathType path_type, float fixed, float duration, float waiting, std::function<double(double)> easing)
: start_pos(start), end_pos(end), type(path_type), fixed_pos(fixed),
duration_ms(duration), waiting_time_ms(waiting), easing_function(std::move(easing)) {}
// Constructor para paths por puntos (mantenemos compatibilidad)
Path(const std::vector<SDL_FPoint> &spots_init, int waiting_counter_init);
// Variables para paths por puntos
std::vector<SDL_FPoint> spots; // Solo para paths por puntos
int counter = 0; // Solo para paths por puntos
bool is_point_path = false; // Indica si es un path por puntos
};
// --- Funciones ---
@@ -49,7 +63,8 @@ class PathSprite : public Sprite {
~PathSprite() override = default;
// --- Métodos principales ---
void update(); // Actualiza la posición del sprite según el recorrido
void update(); // Actualiza la posición del sprite según el recorrido (compatibilidad)
void update(float delta_time); // Actualiza la posición del sprite según el recorrido
void render() override; // Muestra el sprite por pantalla
// --- Gestión de recorridos ---
@@ -72,6 +87,6 @@ class PathSprite : public Sprite {
std::vector<Path> paths_; // Caminos a recorrer por el sprite
// --- Métodos internos ---
void moveThroughCurrentPath(); // Coloca el sprite en los diferentes puntos del recorrido
void moveThroughCurrentPath(float delta_time); // Coloca el sprite en los diferentes puntos del recorrido
void goToNextPathOrDie(); // Cambia de recorrido o finaliza
};