pub fn run_until_closed<G: Game>(mut graphics: Graphics, mut game: G){
    let mut last = Instant::now();
    let mut mousepos = (0., 0.);
    let mut down_keys = HashSet::new();

    'game: loop{
        let mut keys = Vec::new();
        // mice?
        let mut mouses = Vec::new();
        let mut misc_events = Vec::new();

        let mut resized = None;

        for ev in graphics.poll_events() {
            match ev {
                Event::Closed => break 'game,
                Event::KeyboardInput(es, _, Some(vkc)) => match es{
                    ElementState::Pressed  => {
                        down_keys.insert( vkc);
                        keys.push((true , vkc));
                    },
                    ElementState::Released => {
                        down_keys.remove(&vkc);
                        keys.push((false, vkc));
                    }
                },
                Event::MouseMoved(x, y) => {
                    let (w, h) = graphics.get_h_size();

                    mousepos = (x as f32 - w, h - y as f32);
                },
                // This is only neccessary because `graphics` gets immutably borrowed for this for-loop
                Event::Resized(w, h) => resized = Some((w, h)),
                Event::MouseInput(state, button) => mouses.push((state == ElementState::Pressed, button)),
                // Put any other event in the misc_events vector in case the game needs them.
                misc_event => misc_events.push(misc_event)
            }
        }

        if let Some((w, h)) = resized{
            resize(&mut graphics, w, h);
        }

        let dur = last.elapsed();
        let delta = dur.as_secs() as f32 + dur.subsec_nanos() as f32 / 1e9;
        last = Instant::now();

        let update = FrameInfo{
            delta    : delta,
            key_events: keys,
            mouse_events: mouses,
            misc_events: misc_events,
            down_keys: &down_keys,
            mousepos : mousepos
        };

        let update = game.frame(&update, &mut Drawer::new(&graphics)).into();

        if let GameUpdate::Close = update {
            break
        }
    }
}
/// Runs the game until the window is closed
Runs the game until the window is closed
Runs the game until the window is closed
pub fn run_until_closed<G: Game>(mut graphics: Graphics, mut game: G){
    let mut last = Instant::now();
    let mut mousepos = (0., 0.);
    let mut down_keys = HashSet::new();
    'game: loop{
        let mut keys = Vec::new();
        // mice?
        let mut mouses = Vec::new();
        let mut misc_events = Vec::new();
        let mut resized = None;
        for ev in graphics.poll_events() {
            match ev {
                Event::Closed => break 'game,
                Event::KeyboardInput(es, _, Some(vkc)) => match es{
                    ElementState::Pressed  => {
                        down_keys.insert( vkc);
                        keys.push((true , vkc));
                    },
                    ElementState::Released => {
                        down_keys.remove(&vkc);
                        keys.push((false, vkc));
                    }
                },
                Event::MouseMoved(x, y) => {
                    let (w, h) = graphics.get_h_size();
                    mousepos = (x as f32 - w, h - y as f32);
                },
                // This is only neccessary because `graphics` gets immutably borrowed for this for-loop
                Event::Resized(w, h) => resized = Some((w, h)),
                Event::MouseInput(state, button) => mouses.push((state == ElementState::Pressed, button)),
                // Put any other event in the misc_events vector in case the game needs them.
                misc_event => misc_events.push(misc_event)
            }
        }
        if let Some((w, h)) = resized{
            resize(&mut graphics, w, h);
        }
        let dur = last.elapsed();
        let delta = dur.as_secs() as f32 + dur.subsec_nanos() as f32 / 1e9;
        last = Instant::now();
        let update = FrameInfo{
            delta    : delta,
            key_events: keys,
            mouse_events: mouses,
            misc_events: misc_events,
            down_keys: &down_keys,
            mousepos : mousepos
        };
        let update = game.frame(&update, &mut Drawer::new(&graphics)).into();
        if let GameUpdate::Close = update {
            break
        }
    }
}
pub fn run_until_closed < G : Game > ( mut graphics : Graphics , mut game : G ) { let mut last = Instant :: now ( ) ; let mut mousepos = ( 0. , 0. ) ; let mut down_keys = HashSet :: new ( ) ; ' game : loop { let mut keys = Vec :: new ( ) ; // mice? let mut mouses = Vec :: new ( ) ; let mut misc_events = Vec :: new ( ) ; let mut resized = None ; for ev in graphics . poll_events ( ) { match ev { Event :: Closed => break ' game , Event :: KeyboardInput ( es , _ , Some ( vkc ) ) => match es { ElementState :: Pressed => { down_keys . insert ( vkc ) ; keys . push ( ( true , vkc ) ) ; } , ElementState :: Released => { down_keys . remove ( & vkc ) ; keys . push ( ( false , vkc ) ) ; } } , Event :: MouseMoved ( x , y ) => { let ( w , h ) = graphics . get_h_size ( ) ; mousepos = ( x as f32 - w , h - y as f32 ) ; } , // This is only neccessary because `graphics` gets immutably borrowed for this for-loop Event :: Resized ( w , h ) => resized = Some ( ( w , h ) ) , Event :: MouseInput ( state , button ) => mouses . push ( ( state == ElementState :: Pressed , button ) ) , // Put any other event in the misc_events vector in case the game needs them. misc_event => misc_events . push ( misc_event ) } } if let Some ( ( w , h ) ) = resized { resize ( & mut graphics , w , h ) ; } let dur = last . elapsed ( ) ; let delta = dur . as_secs ( ) as f32 + dur . subsec_nanos ( ) as f32 / 1e9 ; last = Instant :: now ( ) ; let update = FrameInfo { delta : delta , key_events : keys , mouse_events : mouses , misc_events : misc_events , down_keys : & down_keys , mousepos : mousepos } ; let update = game . frame ( & update , & mut Drawer :: new ( & graphics ) ) . into ( ) ; if let GameUpdate :: Close = update { break } } }
Runs the game until the window is closed
Runs the game until the window is closed
graphics
Graphics
game
G
graphics
Graphics
game
G