mirror of
https://github.com/lucaspalomodevelop/binbreak.git
synced 2026-03-13 00:07:28 +00:00
feat: advance game state before rendering to update stats
This commit is contained in:
parent
918dc45226
commit
26b8b6fde5
18
src/app.rs
18
src/app.rs
@ -165,6 +165,15 @@ pub fn run_app(terminal: &mut ratatui::DefaultTerminal) -> color_eyre::Result<()
|
||||
let dt = now - last_frame_time;
|
||||
last_frame_time = now;
|
||||
|
||||
// Advance game BEFORE drawing so stats are updated
|
||||
if let AppState::Playing(game) = &mut app_state {
|
||||
game.run(dt.as_secs_f64());
|
||||
if game.is_exit_intended() {
|
||||
app_state = AppState::Start(StartMenuState::new());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
terminal.draw(|f| match &mut app_state {
|
||||
AppState::Start(menu) => render_start_screen(menu, f.area(), f.buffer_mut()),
|
||||
AppState::Playing(game) => f.render_widget(&mut *game, f.area()),
|
||||
@ -176,15 +185,6 @@ pub fn run_app(terminal: &mut ratatui::DefaultTerminal) -> color_eyre::Result<()
|
||||
game.clear_needs_render();
|
||||
}
|
||||
|
||||
// Advance game if playing
|
||||
if let AppState::Playing(game) = &mut app_state {
|
||||
game.run(dt.as_secs_f64());
|
||||
if game.is_exit_intended() {
|
||||
app_state = AppState::Start(StartMenuState::new());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// handle input
|
||||
if let AppState::Playing(game) = &app_state {
|
||||
let fps_mode = get_fps_mode(game);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user