Skip to content
Permalink
Browse files

Move `ggez::quit()` to `ggez::event::quit()`.

There are ZERO other functions in the root `ggez` module, and
putting it in `event` makes it symmetrical with `event::run()`.
  • Loading branch information...
icefoxen committed Jul 11, 2019
1 parent 7991b38 commit 66f21b3d03aea482001d60d23032354d7876446b
Showing with 19 additions and 18 deletions.
  1. +2 −2 examples/05_astroblasto.rs
  2. +5 −4 examples/eventloop.rs
  3. +1 −1 examples/logging.rs
  4. +1 −1 examples/sounds.rs
  5. +0 −7 src/context.rs
  6. +9 −2 src/event.rs
  7. +1 −1 src/lib.rs
@@ -473,7 +473,7 @@ impl EventHandler for MainState {
// but for now we just quit.
if self.player.life <= 0.0 {
println!("Game over!");
let _ = ggez::quit(ctx);
let _ = event::quit(ctx);
}
}

@@ -553,7 +553,7 @@ impl EventHandler for MainState {
img.encode(ctx, graphics::ImageFormat::Png, "/screenshot.png")
.expect("Could not save screenshot");
}
KeyCode::Escape => ggez::quit(ctx),
KeyCode::Escape => event::quit(ctx),
_ => (), // Do nothing
}
}
@@ -11,17 +11,18 @@
use cgmath;
use ggez;

use ggez::event;
use ggez::event::winit_event::{Event, KeyboardInput, WindowEvent};
use ggez::graphics::{self, DrawMode};
use ggez::{event, GameResult};
use ggez::GameResult;

pub fn main() -> GameResult {
let cb = ggez::ContextBuilder::new("eventloop", "ggez");
let (ctx, events_loop) = &mut cb.build()?;

let mut position: f32 = 1.0;

// This is also used in the loop inside `::run()` - it can be flipped off with `ggez::quit()`
// This is also used in the loop inside `::run()` - it can be flipped off with `event::quit()`
while ctx.continuing {
// Tell the timer stuff a frame has happened.
// Without this the FPS timer functions and such won't work.
@@ -33,7 +34,7 @@ pub fn main() -> GameResult {
ctx.process_event(&event);
match event {
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => ggez::quit(ctx),
WindowEvent::CloseRequested => event::quit(ctx),
WindowEvent::KeyboardInput {
input:
KeyboardInput {
@@ -42,7 +43,7 @@ pub fn main() -> GameResult {
},
..
} => match keycode {
event::KeyCode::Escape => ggez::quit(ctx),
event::KeyCode::Escape => event::quit(ctx),

_ => (),
},
@@ -114,7 +114,7 @@ impl EventHandler for App {
);
if keycode == KeyCode::Escape {
// Escape key closes the app.
ggez::quit(ctx);
ggez::event::quit(ctx);
}
}

@@ -101,7 +101,7 @@ impl event::EventHandler for MainState {
input::keyboard::KeyCode::Key4 => self.play_highpitch(ctx),
input::keyboard::KeyCode::Key5 => self.play_lowpitch(ctx),
input::keyboard::KeyCode::Key6 => self.play_stats(ctx),
input::keyboard::KeyCode::Escape => ggez::quit(ctx),
input::keyboard::KeyCode::Escape => event::quit(ctx),
_ => (),
}
}
@@ -297,13 +297,6 @@ impl ContextBuilder {
}
}

/// Terminates the [`ggez::run()`](fn.run.html) loop by setting
/// [`Context.continuing`](struct.Context.html#structfield.continuing)
/// to `false`.
pub fn quit(ctx: &mut Context) {
ctx.continuing = false;
}

#[cfg(debug_assertions)]
use std::sync::atomic::{AtomicUsize, Ordering};
#[cfg(debug_assertions)]
@@ -102,7 +102,7 @@ pub trait EventHandler {
_repeat: bool,
) {
if keycode == KeyCode::Escape {
super::quit(ctx);
quit(ctx);
}
}

@@ -144,6 +144,13 @@ pub trait EventHandler {
fn resize_event(&mut self, _ctx: &mut Context, _width: f32, _height: f32) {}
}

/// Terminates the [`ggez::event::run()`](fn.run.html) loop by setting
/// [`Context.continuing`](struct.Context.html#structfield.continuing)
/// to `false`.
pub fn quit(ctx: &mut Context) {
ctx.continuing = false;
}

/// Runs the game's main loop, calling event callbacks on the given state
/// object as events occur.
///
@@ -175,7 +182,7 @@ where
}
WindowEvent::CloseRequested => {
if !state.quit_event(ctx) {
super::quit(ctx);
quit(ctx);
}
}
WindowEvent::Focused(gained) => {
@@ -117,5 +117,5 @@ mod vfs;
#[cfg(test)]
pub mod tests;

pub use crate::context::{quit, Context, ContextBuilder};
pub use crate::context::{Context, ContextBuilder};
pub use crate::error::*;

0 comments on commit 66f21b3

Please sign in to comment.
You can’t perform that action at this time.