1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Game loop utilities for timing and state management (planned feature).
//!
//! This module provides utilities for managing game timing, frame rates, and the
//! separation of update and render logic. It helps create smooth, consistent
//! game experiences regardless of hardware performance.
//!
//! ## Planned Features
//!
//! - **Fixed Timestep**: Consistent physics updates independent of frame rate
//! - **Delta Time**: Frame-independent movement and animation
//! - **Frame Rate Control**: Target FPS management and limiting
//! - **State Management**: Game state transitions and management
//! - **Performance Monitoring**: FPS counting and performance metrics
//!
//! ## Future API Design
//!
//! ```rust,ignore
//! use minui::game::game_loop::{GameLoop, FixedTimestep, DeltaTime};
//! use std::time::Duration;
//!
//! // Fixed timestep game loop (good for deterministic games)
//! let mut game_loop = GameLoop::new()
//! .with_fixed_timestep(Duration::from_millis(16)) // 60 FPS
//! .with_max_catchup_frames(5); // Prevent spiral of death
//!
//! game_loop.run(|timestep, input| {
//! match timestep {
//! FixedTimestep::Update => {
//! // Fixed-rate game logic updates
//! update_physics();
//! update_ai();
//! handle_collisions();
//! }
//! FixedTimestep::Render => {
//! // Variable-rate rendering
//! render_game(window)?;
//! }
//! }
//! Ok(())
//! })?;
//!
//! // Delta time game loop (good for smooth animation)
//! let mut smooth_loop = GameLoop::new()
//! .with_target_fps(60.0)
//! .with_delta_time(true);
//!
//! smooth_loop.run(|delta: DeltaTime, input| {
//! // Update with delta time for smooth movement
//! player.position.x += player.velocity.x * delta.as_secs_f32();
//! player.position.y += player.velocity.y * delta.as_secs_f32();
//!
//! render_game(window)?;
//! Ok(())
//! })?;
//! ```
//!
//! ## Game State Management
//!
//! ```rust,ignore
//! use minui::game::game_loop::{StateManager, GameState};
//!
//! enum MyGameState {
//! MainMenu,
//! Playing,
//! Paused,
//! GameOver,
//! }
//!
//! let mut state_manager = StateManager::new(MyGameState::MainMenu);
//!
//! // State transitions
//! state_manager.transition_to(MyGameState::Playing);
//!
//! // State-specific updates
//! match state_manager.current() {
//! MyGameState::Playing => {
//! update_gameplay(delta_time);
//! if player.health <= 0 {
//! state_manager.transition_to(MyGameState::GameOver);
//! }
//! }
//! MyGameState::Paused => {
//! // Don't update game logic, just render pause screen
//! }
//! _ => {}
//! }
//! ```
//!
//! ## Performance Monitoring
//!
//! ```rust,ignore
//! use minui::game::game_loop::PerformanceMonitor;
//!
//! let mut monitor = PerformanceMonitor::new();
//!
//! // In game loop
//! monitor.frame_start();
//!
//! // Game logic here
//! update_game();
//! render_game();
//!
//! monitor.frame_end();
//!
//! // Check performance
//! if monitor.current_fps() < 30.0 {
//! println!("Warning: Low FPS detected: {:.1}", monitor.current_fps());
//! }
//! ```
// TODO: Implement game loop utilities
// This will include fixed timestep, delta time, state management, and performance monitoring