mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-05 00:38:00 +01:00
Clean up global speed handling and add GetGameSpeed API function
This commit is contained in:
parent
9a2f26c609
commit
0981175a78
5 changed files with 17 additions and 15 deletions
|
@ -103,7 +103,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
|
|||
game->_priv.bsod_cond = al_create_cond();
|
||||
game->_priv.bsod_mutex = al_create_mutex();
|
||||
|
||||
game->_priv.speed = ALLEGRO_BPS_TO_SECS(60.0);
|
||||
game->_priv.speed = 1.0;
|
||||
|
||||
game->_priv.transforms = NULL;
|
||||
game->_priv.transforms_no = 0;
|
||||
|
|
|
@ -216,7 +216,7 @@ struct Game {
|
|||
ALLEGRO_EVENT_QUEUE* event_queue; /*!< Main event queue. */
|
||||
bool show_timeline;
|
||||
|
||||
double speed; /*!< Speed of the game in FPS. 60 == 1x */
|
||||
double speed; /*!< Speed of the game */
|
||||
|
||||
struct {
|
||||
double old_time, fps, time;
|
||||
|
|
|
@ -184,25 +184,21 @@ static inline void HandleDebugEvent(struct Game* game, ALLEGRO_EVENT* ev) {
|
|||
}
|
||||
break;
|
||||
case ALLEGRO_KEY_F9:
|
||||
game->_priv.speed = ALLEGRO_BPS_TO_SECS(60.0);
|
||||
game->_priv.speed = 1.0;
|
||||
game->show_console = true;
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: 1.00x");
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: %.2fx", game->_priv.speed);
|
||||
break;
|
||||
case ALLEGRO_KEY_F10: {
|
||||
double speed = ALLEGRO_BPS_TO_SECS(game->_priv.speed); // inverting
|
||||
speed -= 10;
|
||||
if (speed < 10) { speed = 10; }
|
||||
game->_priv.speed = ALLEGRO_BPS_TO_SECS(speed);
|
||||
game->_priv.speed -= 1.0 / 6.0;
|
||||
if (game->_priv.speed < 0.1666) { game->_priv.speed = 0.1666; }
|
||||
game->show_console = true;
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: %.2fx", speed / 60.0);
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: %.2fx", game->_priv.speed);
|
||||
} break;
|
||||
case ALLEGRO_KEY_F11: {
|
||||
double speed = ALLEGRO_BPS_TO_SECS(game->_priv.speed); // inverting
|
||||
speed += 10;
|
||||
if (speed > 600) { speed = 600; }
|
||||
game->_priv.speed = ALLEGRO_BPS_TO_SECS(speed);
|
||||
game->_priv.speed += 1.0 / 6.0;
|
||||
if (game->_priv.speed > 10.0) { game->_priv.speed = 10.0; }
|
||||
game->show_console = true;
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: %.2fx", speed / 60.0);
|
||||
PrintConsole(game, "DEBUG: Gameplay speed: %.2fx", game->_priv.speed);
|
||||
} break;
|
||||
}
|
||||
|
||||
|
@ -498,7 +494,7 @@ static inline bool MainloopTick(struct Game* game) {
|
|||
|
||||
double delta = al_get_time() - game->_priv.timestamp;
|
||||
game->_priv.timestamp += delta;
|
||||
delta *= ALLEGRO_BPS_TO_SECS(game->_priv.speed / (1 / 60.0));
|
||||
delta *= game->_priv.speed;
|
||||
|
||||
#ifdef LIBSUPERDERPY_IMGUI
|
||||
ImGui_ImplAllegro5_NewFrame();
|
||||
|
|
|
@ -716,3 +716,7 @@ SYMBOL_EXPORT bool ToggleMute(struct Game* game) {
|
|||
PrintConsole(game, "Mute: %d", game->config.mute);
|
||||
return game->config.mute;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double GetGameSpeed(struct Game* game) {
|
||||
return game->_priv.speed;
|
||||
}
|
||||
|
|
|
@ -99,4 +99,6 @@ void QuitGame(struct Game* game, bool allow_pausing);
|
|||
bool ToggleFullscreen(struct Game* game);
|
||||
bool ToggleMute(struct Game* game);
|
||||
|
||||
double GetGameSpeed(struct Game* game);
|
||||
|
||||
#endif /* LIBSUPERDERPY_UTILS_H */
|
||||
|
|
Loading…
Reference in a new issue