migració a delta time
This commit is contained in:
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
Section::name = Section::Name::INSTRUCTIONS;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -204,18 +204,15 @@ void Instructions::fillBackbuffer() {
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Instructions::update() {
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed) {
|
||||
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
|
||||
Screen::get()->update(); // Actualiza el objeto screen
|
||||
void Instructions::update(float delta_time) {
|
||||
Screen::get()->update(); // Actualiza el objeto screen
|
||||
|
||||
counter_++; // Incrementa el contador
|
||||
updateSprites(); // Actualiza los sprites
|
||||
updateBackbuffer(); // Gestiona la textura con los graficos
|
||||
tiled_bg_->update(); // Actualiza el mosaico de fondo
|
||||
fade_->update(); // Actualiza el objeto "fade"
|
||||
fillBackbuffer(); // Rellena el backbuffer
|
||||
}
|
||||
counter_++; // Incrementa el contador
|
||||
updateSprites(); // Actualiza los sprites
|
||||
updateBackbuffer(); // Gestiona la textura con los graficos
|
||||
tiled_bg_->update(delta_time); // Actualiza el mosaico de fondo
|
||||
fade_->update(delta_time); // Actualiza el objeto "fade"
|
||||
fillBackbuffer(); // Rellena el backbuffer
|
||||
|
||||
Audio::update();
|
||||
}
|
||||
@@ -255,12 +252,24 @@ void Instructions::checkInput() {
|
||||
GlobalInputs::check();
|
||||
}
|
||||
|
||||
// Calcula el tiempo transcurrido desde el último frame
|
||||
float Instructions::calculateDeltaTime() {
|
||||
const Uint64 current_time = SDL_GetTicks();
|
||||
const float delta_time = static_cast<float>(current_time - last_time_);
|
||||
last_time_ = current_time;
|
||||
return delta_time;
|
||||
}
|
||||
|
||||
// Bucle para la pantalla de instrucciones
|
||||
void Instructions::run() {
|
||||
last_time_ = SDL_GetTicks();
|
||||
Audio::get()->playMusic("title.ogg");
|
||||
|
||||
while (Section::name == Section::Name::INSTRUCTIONS) {
|
||||
const float delta_time = calculateDeltaTime();
|
||||
|
||||
checkInput();
|
||||
update();
|
||||
update(delta_time);
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class Instructions {
|
||||
|
||||
// --- Variables ---
|
||||
int counter_ = 0; // Contador para manejar el progreso en la pantalla de instrucciones
|
||||
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
|
||||
SDL_FRect view_; // Vista del backbuffer que se va a mostrar por pantalla
|
||||
SDL_FPoint sprite_pos_ = {0, 0}; // Posición del primer sprite en la lista
|
||||
float item_space_ = 2.0; // Espacio entre los items en pantalla
|
||||
@@ -73,7 +73,7 @@ class Instructions {
|
||||
bool start_delay_triggered_ = false; // Bandera para determinar si el retraso ha comenzado
|
||||
|
||||
// --- Métodos internos ---
|
||||
void update(); // Actualiza las variables
|
||||
void update(float delta_time); // Actualiza las variables
|
||||
void render(); // Pinta en pantalla
|
||||
static void checkEvents(); // Comprueba los eventos
|
||||
static void checkInput(); // Comprueba las entradas
|
||||
@@ -82,7 +82,8 @@ class Instructions {
|
||||
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
|
||||
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
|
||||
void updateBackbuffer(); // Gestiona la textura con los gráficos
|
||||
float calculateDeltaTime(); // Calcula el tiempo transcurrido desde el último frame
|
||||
};
|
||||
Reference in New Issue
Block a user