ABC-Engine / ABC_lumenpyx

The official implementation of lumenpyx for ABC-Game-Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

winit loop appears to block winput

NoodlesOfWrath opened this issue · comments

The most dumbed down code you can make to produce inputs in abc-engine would be as follows:

struct InputTestSystem;

impl System for InputTestSystem {
    fn run(&mut self, entities_and_components: &mut EntitiesAndComponents) {
        let input = entities_and_components.get_resource::<Input>().unwrap();

        if input.is_key_pressed(Vk::Escape) {
            println!("exiting...");
            std::process::exit(0);
        }
    }
}

fn main() {
    let mut scene = Scene::new();

    {
        let entities_and_components = &mut scene.world.entities_and_components;

        // make a camera, to specify the position we would like to view everything from
        entities_and_components.add_entity_with((
            Camera::new([0.0, 0.0, 0.0]),
            ABC_Game_Engine::Transform::default(),
        ));
    }

    scene.world.add_system(InputTestSystem);

    loop {
        scene.world.run();
    }
}

However, the equivalent code using ABC_Lumenpyx doesn't work.

struct InputTestSystem;

impl System for InputTestSystem {
    fn run(&mut self, entities_and_components: &mut EntitiesAndComponents) {
        let input = entities_and_components.get_resource::<Input>().unwrap();

        if input.is_key_pressed(Vk::Escape) {
            println!("exiting...");
            std::process::exit(0);
        }
    }
}

fn main() {
    let mut scene = Scene::new();

    let (mut lumen_program, event_loop) =
        LumenpyxProgram::new([(128.0 * (16.0 / 9.0)) as u32, 128], "name of your program");

    {
        let entities_and_components = &mut scene.world.entities_and_components;

        // make a camera, to specify the position we would like to view everything from
        entities_and_components.add_entity_with((
            Camera::new([0.0, 0.0, 0.0]),
            ABC_Game_Engine::Transform::default(),
        ));
    }

    scene.world.add_system(InputTestSystem);

    // this is to run the program for forever or until returned
    lumen_program.run(event_loop, |program| {
        scene.world.run();
        render(&mut scene.world.entities_and_components, program);
    });
}

Maybe this is because Winit is "capturing" the input and it doesn't get to winput? A little more investigation must be done into this. I would prefer not to but, if needed we could use the Winit input system to add and remove from the ABC game engine input resource.