New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-Implement the event loop to be able to be used in a while let loop #130

Merged
merged 5 commits into from Apr 19, 2016

Conversation

Projects
None yet
2 participants
@TheNeikos
Copy link
Contributor

TheNeikos commented Apr 18, 2016

Ready for review!

This targets #123


I'm mainly already submitting this to get some feedback. Please do check out the example if the interface changes are warranted, or if I could do it better? (For now the only change, except from losing the iterator, is that you have to pass the event into the draw functions.)

TheNeikos added some commits Apr 18, 2016

@TheNeikos TheNeikos changed the title [WIP] Re-Implement the event loop to be able to be used in a while let loop Re-Implement the event loop to be able to be used in a while let loop Apr 18, 2016

@bvssvni

This comment has been minimized.

Copy link
Member

bvssvni commented Apr 18, 2016

@TheNeikos You are awesome!

@@ -3,21 +3,22 @@ extern crate piston_window;
use piston_window::*;

fn main() {
let window: PistonWindow = WindowSettings::new("Hello Piston!", [640, 480])
let mut events: WindowEvents = WindowEvents::new();

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

Could be let mut events = window.events();

src/lib.rs Outdated
@@ -246,135 +217,38 @@ impl<T, W> PistonWindow<T, W>
/// Changes application structure.
#[inline(always)]
pub fn app_by_value<U>(self, app: U) -> PistonWindow<U, W> {

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

Can remove app_by_value.

src/lib.rs Outdated
}

/// Renders 2D graphics.
pub fn draw_2d<F>(&self, f: F) where
pub fn draw_2d<F>(&mut self, e: &Event, f: F) where

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

Use e: &E where E: GenericEvent

src/lib.rs Outdated
}
}

/// Renders 3D graphics.
pub fn draw_3d<F>(&self, f: F) where
pub fn draw_3d<F>(&mut self, e: &Event, f: F) where

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

Use e: &E where E: GenericEvent

src/lib.rs Outdated
/// Creates a new empty application.
pub fn empty_app() -> Rc<RefCell<()>> { Rc::new(RefCell::new(())) }
pub fn empty_app() -> () { () }

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

Can remove empty_app and just use ().

@bvssvni

This comment has been minimized.

Copy link
Member

bvssvni commented Apr 18, 2016

Can also use W instead of Rc<RefCell<W>>.

PistonWindow::new should take mut window: W.

Remove these unused imports:

use std::cell::RefCell;
use std::rc::Rc;
use std::any::Any;
.exit_on_esc(true)
.build()
.unwrap_or_else(|e| { panic!("Failed to build PistonWindow: {}", e) });
println!("Press any button to enter inner loop");
for e in window {
e.draw_2d(|_c, g| {
while let Some(e) = events.next(&mut window) {

This comment has been minimized.

@bvssvni

bvssvni Apr 18, 2016

Member

There is an extra space here.

TheNeikos added some commits Apr 18, 2016

@TheNeikos TheNeikos force-pushed the TheNeikos:move-piston_window_from_iterator_to_while_let branch from 7828a57 to 5219edc Apr 18, 2016

@TheNeikos

This comment has been minimized.

Copy link
Contributor

TheNeikos commented Apr 18, 2016

I also made the documentation build (but not run) as it was on ignore before.

@bvssvni

This comment has been minimized.

Copy link
Member

bvssvni commented Apr 19, 2016

Looks good! There are some minor things left, but I'll merge and fix them myself.

@bvssvni bvssvni merged commit 0f3abc2 into PistonDevelopers:master Apr 19, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@TheNeikos TheNeikos deleted the TheNeikos:move-piston_window_from_iterator_to_while_let branch Apr 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment