-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
How to port existing code from Game
to GameIterator
#521
Labels
Comments
Porting code is easy because you can implement the methods directly on the structure. Considering the following example: impl<W: GameWindow> Game<W> for App {
fn load(&mut self, _window: &mut W) {
let asset_store = AssetStore::from_folder("../bin/assets");
let image = asset_store.path("rust-logo.png").unwrap();
self.image = Some(Texture::from_path(&image).unwrap());
}
fn render(&mut self, _window: &mut W, args: &RenderArgs) {
let ref mut gl = self.gl;
gl.viewport(0, 0, args.width as i32, args.height as i32);
let ref c = Context::abs(args.width as f64, args.height as f64);
c.rgb(1.0, 1.0, 1.0).draw(gl);
// Draw image.
c.image(self.image.as_ref().unwrap()).draw(gl);
}
} This can be changed to: impl App {
fn load<W: GameWindow>(&mut self, _window: &mut W) {
let asset_store = AssetStore::from_folder("../bin/assets");
let image = asset_store.path("rust-logo.png").unwrap();
self.image = Some(Texture::from_path(&image).unwrap());
}
fn render<W: GameWindow>(&mut self, _window: &mut W, args: &RenderArgs) {
let ref mut gl = self.gl;
gl.viewport(0, 0, args.width as i32, args.height as i32);
let ref c = Context::abs(args.width as f64, args.height as f64);
c.rgb(1.0, 1.0, 1.0).draw(gl);
// Draw image.
c.image(self.image.as_ref().unwrap()).draw(gl);
}
} |
bvssvni
added a commit
to bvssvni/piston
that referenced
this issue
Aug 18, 2014
Closes PistonDevelopers#555 For fixing existing code, see PistonDevelopers#521
Game
traitGame
to GameIterator
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
GameIterator
is strictly better than theGame
trait and it scales much better. I think we should markGame
as deprecated and port all code over toGameIterator
.For example, if you are writing a game consisting of higher level building blocks, then it is very nice to redirect
e
from the iterator to a single method:If you are using the
Game
trait you need to deal with each event specifically and call the methods. When Piston adds a new type of event, for example gamepad input, the higher level building blocks will not receive those events. All the parents blocks need to update their code. This adds a linear complexity on the number of blocks.The text was updated successfully, but these errors were encountered: