main_game_loop

Crates.iomain_game_loop
lib.rsmain_game_loop
version0.6.1
created_at2022-04-20 10:54:11.64242+00
updated_at2022-11-27 23:17:35.415596+00
descriptionA tool collection for building a winit game loop
homepage
repositoryhttps://github.com/Overpeek/main_game_loop
max_upload_size
id570914
size79,395
xor-bits (xor-bits)

documentation

https://docs.rs/main_game_loop

README

main_game_loop

dependency status build status crates.io docs.rs

Example usage with some random Engine

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

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
    );
}
Commit count: 57

cargo fmt