https://github.com/xor-bits/main_game_loop
https://github.com/xor-bits/main_game_loop
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/xor-bits/main_game_loop
- Owner: xor-bits
- License: mit
- Created: 2022-04-04T12:07:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-27T23:17:20.000Z (over 3 years ago)
- Last Synced: 2024-03-15T01:03:59.393Z (over 2 years ago)
- Language: Rust
- Size: 190 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# main_game_loop
[](https://deps.rs/repo/github/Overpeek/main_game_loop)
[](https://github.com/Overpeek/main_game_loop/actions)
[](https://crates.io/crates/main_game_loop)
[](https://docs.rs/main_game_loop/)
### Example usage with some random `Engine`
```rust
struct App {
window: Window,
ws: WindowState,
update_loop: UpdateLoop,
}
impl App {
fn init(target: &EventLoopTarget) -> Self {
let window = WindowBuilder::new().build(target).unwrap();
let ws = WindowState::new(&window);
let update_loop = UpdateLoop::new(UpdateRate::PerSecond(60));
Self {
window,
ws,
update_loop,
}
}
fn event(&mut self, event: Event, _: &EventLoopTarget, control: &mut ControlFlow) {
self.ws.event(&event);
if self.ws.should_close {
*control = ControlFlow::Exit;
}
}
fn draw(&mut self) {
self.update_loop.update(|| {
// update();
});
// draw();
}
}
fn main() {
run_app!(App);
}
```
### Example usage with different init, event and draw functions
```rust
use main_game_loop::prelude::*;
struct App {
// ...
}
async fn init(target: &EventLoopTarget) -> App {
// init
App {
// ..
}
}
impl App {
fn draw(&mut self) {
// draw
}
}
#[tokio::main]
async fn main() {
run_app!(
async init,
|_, _, _, _| {
// events
},
App::draw
);
}
```