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
use crate::{Graphics, Input};
/// Represents the data in the Frame
pub struct FrameContext {
pub(crate) gfx: Graphics,
pub(crate) inputs: Input,
pub(crate) dt: f64,
}
impl FrameContext {
pub(crate) fn new(gfx : Graphics, inputs: Input) -> Self {
FrameContext {
gfx,
inputs,
dt: 0.0
}
}
/// Gets a mutable referance to the Graphics. <br>
/// Only use this method if you only need to draw otherwise refer to the [Self::split] .
pub fn graphics(&mut self) -> &mut Graphics{
&mut self.gfx
}
/// Returns the Delta time of the frame. Good if you are creating animations or a game. <br>
/// It's better to call this method before `split` and `graphics` so Rust does not bother you with the Barrow Checker.
pub fn delta_time(&self) -> f64{
self.dt
}
/// Gets a referance to the Input. <br>
/// Only use this method if you only need to read inputs otherwise refer to the [Self::split] .
pub fn input(&self) -> &Input{
&self.inputs
}
/// Splits the Graphics and Input from the Context
pub fn split(&mut self) -> (&mut Graphics, &Input){
return (&mut self.gfx, &self.inputs);
}
}