migrat Notifier a time based
This commit is contained in:
@@ -199,10 +199,17 @@ void Screen::toggleShaders() {
|
||||
initShaders();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
// Actualiza la lógica de la clase (versión antigua para escenas no migradas)
|
||||
void Screen::update() {
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
Notifier::get()->update();
|
||||
Notifier::get()->update(0.016f); // Asume ~60 FPS (16ms por frame)
|
||||
Mouse::updateCursorVisibility();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase (versión nueva con delta_time para escenas migradas)
|
||||
void Screen::update(float delta_time) {
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
Notifier::get()->update(delta_time);
|
||||
Mouse::updateCursorVisibility();
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,8 @@ class Screen {
|
||||
void render();
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void update();
|
||||
void update(); // Para escenas no migradas (sin delta_time)
|
||||
void update(float delta_time); // Para escenas migradas (con delta_time)
|
||||
|
||||
// Establece el modo de video
|
||||
void setVideoMode(bool mode);
|
||||
|
||||
@@ -62,7 +62,7 @@ void GameOver::update() {
|
||||
tv_sprite_->update(delta);
|
||||
|
||||
// Actualiza el objeto Screen
|
||||
Screen::get()->update();
|
||||
Screen::get()->update(delta);
|
||||
}
|
||||
|
||||
// Dibuja el final en pantalla
|
||||
|
||||
@@ -180,11 +180,11 @@ void Logo::update() {
|
||||
// Obtener delta time desde el último frame
|
||||
const float DELTA_TIME = delta_timer_->tick();
|
||||
|
||||
checkInput(); // Comprueba las entradas
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
updateJAILGAMES(DELTA_TIME); // Gestiona el logo de JAILGAME
|
||||
updateTextureColors(); // Gestiona el color de las texturas
|
||||
Screen::get()->update(); // Actualiza el objeto Screen
|
||||
checkInput(); // Comprueba las entradas
|
||||
updateState(DELTA_TIME); // Actualiza el estado y gestiona transiciones
|
||||
updateJAILGAMES(DELTA_TIME); // Gestiona el logo de JAILGAME
|
||||
updateTextureColors(); // Gestiona el color de las texturas
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
}
|
||||
|
||||
// Dibuja en pantalla
|
||||
|
||||
@@ -176,7 +176,7 @@ void Title::update() {
|
||||
checkInput();
|
||||
|
||||
// Actualiza la pantalla
|
||||
Screen::get()->update();
|
||||
Screen::get()->update(current_delta_);
|
||||
|
||||
// Actualiza el estado actual
|
||||
updateState(current_delta_);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
#include "external/jail_audio.h" // Para JA_PlaySound
|
||||
#include "game/options.hpp" // Para Options, options, NotificationPosition
|
||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||
#include "utils/utils.hpp" // Para PaletteColor
|
||||
|
||||
// [SINGLETON]
|
||||
@@ -39,6 +40,7 @@ auto Notifier::get() -> Notifier* {
|
||||
Notifier::Notifier(const std::string& icon_file, const std::string& text)
|
||||
: icon_surface_(!icon_file.empty() ? Resource::get()->getSurface(icon_file) : nullptr),
|
||||
text_(Resource::get()->getText(text)),
|
||||
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||
bg_color_(Options::notifications.color),
|
||||
stack_(false),
|
||||
has_icons_(!icon_file.empty()) {}
|
||||
@@ -51,7 +53,7 @@ void Notifier::render() {
|
||||
}
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void Notifier::update() {
|
||||
void Notifier::update(float delta_time) {
|
||||
for (auto& notification : notifications_) {
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (!notifications_.empty() && ¬ification != ¬ifications_.front()) {
|
||||
@@ -63,10 +65,11 @@ void Notifier::update() {
|
||||
|
||||
switch (notification.state) {
|
||||
case Status::RISING: {
|
||||
const int DIRECTION = 1;
|
||||
notification.rect.y += DIRECTION;
|
||||
const float DISPLACEMENT = SLIDE_SPEED * delta_time;
|
||||
notification.rect.y += DISPLACEMENT;
|
||||
|
||||
if (notification.rect.y == notification.y) {
|
||||
if (notification.rect.y >= notification.y) {
|
||||
notification.rect.y = notification.y;
|
||||
notification.state = Status::STAY;
|
||||
notification.start_time = SDL_GetTicks();
|
||||
}
|
||||
@@ -81,10 +84,12 @@ void Notifier::update() {
|
||||
}
|
||||
|
||||
case Status::VANISHING: {
|
||||
const int DIRECTION = -1;
|
||||
notification.rect.y += DIRECTION;
|
||||
const float DISPLACEMENT = SLIDE_SPEED * delta_time;
|
||||
notification.rect.y -= DISPLACEMENT;
|
||||
|
||||
if (notification.rect.y == notification.y - notification.travel_dist) {
|
||||
const float TARGET_Y = notification.y - notification.travel_dist;
|
||||
if (notification.rect.y <= TARGET_Y) {
|
||||
notification.rect.y = TARGET_Y;
|
||||
notification.state = Status::FINISHED;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
class SurfaceSprite; // lines 8-8
|
||||
class Surface; // lines 10-10
|
||||
class Text; // lines 9-9
|
||||
class DeltaTimer; // lines 11-11
|
||||
|
||||
// Constantes
|
||||
constexpr Uint32 DEFAULT_NOTIFICATION_DURATION = 2000;
|
||||
@@ -24,6 +25,7 @@ class Notifier {
|
||||
// Constantes
|
||||
static constexpr float ICON_SIZE = 16.0F;
|
||||
static constexpr float PADDING_OUT = 0.0F;
|
||||
static constexpr float SLIDE_SPEED = 120.0F; // Pixels per second for slide animations
|
||||
|
||||
// [SINGLETON] Objeto notifier
|
||||
static Notifier* notifier;
|
||||
@@ -60,8 +62,9 @@ class Notifier {
|
||||
explicit Notification() = default;
|
||||
};
|
||||
|
||||
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
|
||||
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
||||
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
|
||||
std::shared_ptr<Text> text_; // Objeto para dibujar texto
|
||||
std::unique_ptr<DeltaTimer> delta_timer_; // Timer for frame-independent animations
|
||||
|
||||
// Variables
|
||||
Uint8 bg_color_; // Color de fondo de las notificaciones
|
||||
@@ -97,7 +100,7 @@ class Notifier {
|
||||
void render();
|
||||
|
||||
// Actualiza el estado de las notificaiones
|
||||
void update();
|
||||
void update(float delta_time);
|
||||
|
||||
// Muestra una notificación de texto por pantalla
|
||||
void show(std::vector<std::string> texts, NotificationText text_is = NotificationText::LEFT, Uint32 display_duration = DEFAULT_NOTIFICATION_DURATION, int icon = -1, bool can_be_removed = true, const std::string& code = std::string());
|
||||
|
||||
Reference in New Issue
Block a user