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
use crateGame;
/// The lifecycle trait for game logic.
///
/// Implement this trait to hook your application into the engine's event
/// loop. Pass an instance to [`Game::new`] or [`Game::run`] and the engine
/// drives the three lifecycle methods automatically.
///
/// | Method | Called | Purpose |
/// |---|---|---|
/// | [`start`](Runtime::start) | Once, before the first frame | One-time setup |
/// | [`update`](Runtime::update) | Every frame | Input, logic, rendering |
/// | [`end`](Runtime::end) | Once, on shutdown | Cleanup |
///
/// Each method receives `&mut Game`, giving you access to the renderer,
/// camera, window, events, and time.
///
/// # Example
///
/// ```ignore
/// use optic_loop::{Game, Runtime};
///
/// struct FpsCounter {
/// frames: u64,
/// }
///
/// impl Runtime for FpsCounter {
/// fn start(&mut self, _game: &mut Game) {
/// println!("Starting...");
/// }
///
/// fn update(&mut self, game: &mut Game) {
/// self.frames += 1;
/// if self.frames % 60 == 0 {
/// let fps = game.time.fps();
/// println!("FPS: {:.1}", fps);
/// }
/// game.renderer.clear();
/// // ... draw scene ...
/// }
///
/// fn end(&mut self, _game: &mut Game) {
/// println!("Rendered {} frames total", self.frames);
/// }
/// }
///
/// Game::run(FpsCounter { frames: 0 });
/// ```
///
/// # Why three methods?
///
/// Separating `start` from `update` avoids re-initialising assets every
/// frame. Separating `end` from `drop` gives you a predictable point to
/// save state before the engine tears down subsystems.