pub struct Game<W: Write, S = ()> { /* private fields */ }Expand description
The driving type of a game.
A Game consists of a number of components that are executed in a loop and act on some shared state.
§Example
use teng::{install_panic_handler, terminal_cleanup, terminal_setup, Game};
terminal_setup().unwrap();
install_panic_handler();
let mut game: Game<_, ()> = Game::new_with_custom_buf_writer();
game.install_recommended_components();
game.run().unwrap();
terminal_cleanup().unwrap();Implementations§
Source§impl<S: Default + 'static> Game<CustomBufWriter, S>
impl<S: Default + 'static> Game<CustomBufWriter, S>
Sourcepub fn new_with_custom_buf_writer() -> Self
pub fn new_with_custom_buf_writer() -> Self
Creates a new game with a sink that only flushes once every frame. This is the recommended sink.
Examples found in repository?
examples/simple.rs (line 29)
25fn main() -> io::Result<()> {
26 terminal_setup()?;
27 install_panic_handler();
28
29 let mut game = Game::new_with_custom_buf_writer();
30 // If you don't install the recommended components, you will need to have your own
31 // component that exits the process, since Ctrl-C does not work in raw mode.
32 game.install_recommended_components();
33 game.add_component(Box::new(MyComponent));
34 game.run()?;
35
36 terminal_cleanup()?;
37
38 Ok(())
39}Source§impl<W: Write, S: Default + 'static> Game<W, S>
impl<W: Write, S: Default + 'static> Game<W, S>
Sourcepub fn new(sink: W) -> Self
pub fn new(sink: W) -> Self
Examples found in repository?
More examples
examples/boundschecker.rs (line 18)
14fn main() -> io::Result<()> {
15 terminal_setup()?;
16 install_panic_handler();
17
18 let mut game = Game::new(stdout());
19 game.install_recommended_components();
20 game.add_component(Box::new(BoundsCheckerComponent::new()));
21 game.run()?;
22
23 terminal_cleanup()?;
24
25 Ok(())
26}examples/falling-sand/main.rs (line 16)
12fn main() -> std::io::Result<()> {
13 terminal_setup()?;
14 install_panic_handler();
15
16 let mut game = Game::new(stdout());
17 game.install_recommended_components();
18 game.add_component(Box::new(FallingSimulationComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/exponentialgrowingboundschecker.rs (line 20)
16fn main() -> io::Result<()> {
17 terminal_setup()?;
18 install_panic_handler();
19
20 let mut game = Game::new(stdout());
21 game.install_recommended_components();
22 game.add_component(Box::new(ExponentialBoundsCheckerComponent::new()));
23 game.run()?;
24
25 terminal_cleanup()?;
26
27 Ok(())
28}examples/fpschecker.rs (line 15)
11fn main() -> io::Result<()> {
12 terminal_setup()?;
13 install_panic_handler();
14
15 let mut game = Game::new(stdout());
16 game.install_recommended_components();
17 // game.add_component(Box::new(FpsCheckerComponent::new()));
18 game.add_component(Box::new(FpsCheckerFrameCountComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/ecs/main.rs (line 75)
71fn main() -> io::Result<()> {
72 teng::terminal_setup()?;
73 teng::install_panic_handler();
74
75 let mut game = Game::new(stdout());
76 game.install_recommended_components();
77 game.add_component(Box::new(EcsComponent::default()));
78 game.add_component(Box::new(DrawSystem));
79 game.add_component(Box::new(PhysicsSystem));
80 game.run()?;
81
82 teng::terminal_cleanup()?;
83 Ok(())
84}Sourcepub fn add_component(&mut self, component: Box<dyn Component<S>>)
pub fn add_component(&mut self, component: Box<dyn Component<S>>)
Examples found in repository?
examples/boundschecker.rs (line 20)
14fn main() -> io::Result<()> {
15 terminal_setup()?;
16 install_panic_handler();
17
18 let mut game = Game::new(stdout());
19 game.install_recommended_components();
20 game.add_component(Box::new(BoundsCheckerComponent::new()));
21 game.run()?;
22
23 terminal_cleanup()?;
24
25 Ok(())
26}More examples
examples/falling-sand/main.rs (line 18)
12fn main() -> std::io::Result<()> {
13 terminal_setup()?;
14 install_panic_handler();
15
16 let mut game = Game::new(stdout());
17 game.install_recommended_components();
18 game.add_component(Box::new(FallingSimulationComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/exponentialgrowingboundschecker.rs (line 22)
16fn main() -> io::Result<()> {
17 terminal_setup()?;
18 install_panic_handler();
19
20 let mut game = Game::new(stdout());
21 game.install_recommended_components();
22 game.add_component(Box::new(ExponentialBoundsCheckerComponent::new()));
23 game.run()?;
24
25 terminal_cleanup()?;
26
27 Ok(())
28}examples/fpschecker.rs (line 18)
11fn main() -> io::Result<()> {
12 terminal_setup()?;
13 install_panic_handler();
14
15 let mut game = Game::new(stdout());
16 game.install_recommended_components();
17 // game.add_component(Box::new(FpsCheckerComponent::new()));
18 game.add_component(Box::new(FpsCheckerFrameCountComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/ecs/main.rs (line 77)
71fn main() -> io::Result<()> {
72 teng::terminal_setup()?;
73 teng::install_panic_handler();
74
75 let mut game = Game::new(stdout());
76 game.install_recommended_components();
77 game.add_component(Box::new(EcsComponent::default()));
78 game.add_component(Box::new(DrawSystem));
79 game.add_component(Box::new(PhysicsSystem));
80 game.run()?;
81
82 teng::terminal_cleanup()?;
83 Ok(())
84}examples/simple.rs (line 33)
25fn main() -> io::Result<()> {
26 terminal_setup()?;
27 install_panic_handler();
28
29 let mut game = Game::new_with_custom_buf_writer();
30 // If you don't install the recommended components, you will need to have your own
31 // component that exits the process, since Ctrl-C does not work in raw mode.
32 game.install_recommended_components();
33 game.add_component(Box::new(MyComponent));
34 game.run()?;
35
36 terminal_cleanup()?;
37
38 Ok(())
39}pub fn add_component_with( &mut self, init_fn: impl FnOnce(usize, usize) -> Box<dyn Component<S>>, )
Sourcepub fn run(&mut self) -> Result<()>
pub fn run(&mut self) -> Result<()>
Examples found in repository?
More examples
examples/boundschecker.rs (line 21)
14fn main() -> io::Result<()> {
15 terminal_setup()?;
16 install_panic_handler();
17
18 let mut game = Game::new(stdout());
19 game.install_recommended_components();
20 game.add_component(Box::new(BoundsCheckerComponent::new()));
21 game.run()?;
22
23 terminal_cleanup()?;
24
25 Ok(())
26}examples/falling-sand/main.rs (line 19)
12fn main() -> std::io::Result<()> {
13 terminal_setup()?;
14 install_panic_handler();
15
16 let mut game = Game::new(stdout());
17 game.install_recommended_components();
18 game.add_component(Box::new(FallingSimulationComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/exponentialgrowingboundschecker.rs (line 23)
16fn main() -> io::Result<()> {
17 terminal_setup()?;
18 install_panic_handler();
19
20 let mut game = Game::new(stdout());
21 game.install_recommended_components();
22 game.add_component(Box::new(ExponentialBoundsCheckerComponent::new()));
23 game.run()?;
24
25 terminal_cleanup()?;
26
27 Ok(())
28}examples/fpschecker.rs (line 19)
11fn main() -> io::Result<()> {
12 terminal_setup()?;
13 install_panic_handler();
14
15 let mut game = Game::new(stdout());
16 game.install_recommended_components();
17 // game.add_component(Box::new(FpsCheckerComponent::new()));
18 game.add_component(Box::new(FpsCheckerFrameCountComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/ecs/main.rs (line 80)
71fn main() -> io::Result<()> {
72 teng::terminal_setup()?;
73 teng::install_panic_handler();
74
75 let mut game = Game::new(stdout());
76 game.install_recommended_components();
77 game.add_component(Box::new(EcsComponent::default()));
78 game.add_component(Box::new(DrawSystem));
79 game.add_component(Box::new(PhysicsSystem));
80 game.run()?;
81
82 teng::terminal_cleanup()?;
83 Ok(())
84}Additional examples can be found in:
Sourcepub fn install_recommended_components(&mut self)
pub fn install_recommended_components(&mut self)
Examples found in repository?
examples/boundschecker.rs (line 19)
14fn main() -> io::Result<()> {
15 terminal_setup()?;
16 install_panic_handler();
17
18 let mut game = Game::new(stdout());
19 game.install_recommended_components();
20 game.add_component(Box::new(BoundsCheckerComponent::new()));
21 game.run()?;
22
23 terminal_cleanup()?;
24
25 Ok(())
26}More examples
examples/falling-sand/main.rs (line 17)
12fn main() -> std::io::Result<()> {
13 terminal_setup()?;
14 install_panic_handler();
15
16 let mut game = Game::new(stdout());
17 game.install_recommended_components();
18 game.add_component(Box::new(FallingSimulationComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/exponentialgrowingboundschecker.rs (line 21)
16fn main() -> io::Result<()> {
17 terminal_setup()?;
18 install_panic_handler();
19
20 let mut game = Game::new(stdout());
21 game.install_recommended_components();
22 game.add_component(Box::new(ExponentialBoundsCheckerComponent::new()));
23 game.run()?;
24
25 terminal_cleanup()?;
26
27 Ok(())
28}examples/fpschecker.rs (line 16)
11fn main() -> io::Result<()> {
12 terminal_setup()?;
13 install_panic_handler();
14
15 let mut game = Game::new(stdout());
16 game.install_recommended_components();
17 // game.add_component(Box::new(FpsCheckerComponent::new()));
18 game.add_component(Box::new(FpsCheckerFrameCountComponent::new()));
19 game.run()?;
20
21 terminal_cleanup()?;
22
23 Ok(())
24}examples/ecs/main.rs (line 76)
71fn main() -> io::Result<()> {
72 teng::terminal_setup()?;
73 teng::install_panic_handler();
74
75 let mut game = Game::new(stdout());
76 game.install_recommended_components();
77 game.add_component(Box::new(EcsComponent::default()));
78 game.add_component(Box::new(DrawSystem));
79 game.add_component(Box::new(PhysicsSystem));
80 game.run()?;
81
82 teng::terminal_cleanup()?;
83 Ok(())
84}examples/simple.rs (line 32)
25fn main() -> io::Result<()> {
26 terminal_setup()?;
27 install_panic_handler();
28
29 let mut game = Game::new_with_custom_buf_writer();
30 // If you don't install the recommended components, you will need to have your own
31 // component that exits the process, since Ctrl-C does not work in raw mode.
32 game.install_recommended_components();
33 game.add_component(Box::new(MyComponent));
34 game.run()?;
35
36 terminal_cleanup()?;
37
38 Ok(())
39}Auto Trait Implementations§
impl<W, S> Freeze for Game<W, S>
impl<W, S = ()> !RefUnwindSafe for Game<W, S>
impl<W, S = ()> !Send for Game<W, S>
impl<W, S = ()> !Sync for Game<W, S>
impl<W, S> Unpin for Game<W, S>
impl<W, S = ()> !UnwindSafe for Game<W, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more