Skip to content

Commit

Permalink
Added default () type to GameResult and updated examples
Browse files Browse the repository at this point in the history
Starts to resolve ggez#384
  • Loading branch information
icefoxen committed Jun 8, 2018
1 parent 46e2c95 commit b51fcac
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion examples/astroblasto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl EventHandler for MainState {
/// `ggez::event::run()` with our `EventHandler` type.
/// **********************************************************************
pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let mut cb = ContextBuilder::new("astroblasto", "ggez")
.window_setup(conf::WindowSetup::default().title("Astroblasto!"))
.window_mode(conf::WindowMode::default().dimensions(640, 480));
Expand Down
8 changes: 4 additions & 4 deletions examples/canvas_subframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl MainState {
}

impl MainState {
fn draw_spritebatch(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw_spritebatch(&mut self, ctx: &mut Context) -> GameResult {
graphics::set_canvas(ctx, Some(&self.canvas));
graphics::set_background_color(ctx, graphics::WHITE);
graphics::clear(ctx);
Expand Down Expand Up @@ -90,7 +90,7 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
if timer::get_ticks(ctx) % 100 == 0 {
println!("Delta frame time: {:?} ", timer::get_delta(ctx));
println!("Average FPS: {}", timer::get_fps(ctx));
Expand All @@ -112,7 +112,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::set_background_color(ctx, [0.1, 0.2, 0.3, 1.0].into());
graphics::clear(ctx);
self.draw_spritebatch(ctx)?;
Expand All @@ -137,7 +137,7 @@ impl event::EventHandler for MainState {
// Creating a context depends on loading a config file.
// Loading a config file depends on having FS (or we can just fake our way around it
// by creating an FS and then throwing it away; the costs are not huge.)
pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
println!("Starting with default config: {:#?}", c);
let ctx = &mut Context::load_from_conf("spritebatch", "ggez", c)?;
Expand Down
6 changes: 3 additions & 3 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ void main() {
}

impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
self.rotation += 0.01;
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
// Do gfx-rs drawing
{
let (_factory, device, encoder, _depthview, _colorview) =
Expand Down Expand Up @@ -252,7 +252,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("cube", "ggez", c)?;

Expand Down
8 changes: 4 additions & 4 deletions examples/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn build_mesh(ctx: &mut Context) -> GameResult<graphics::Mesh> {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
const DESIRED_FPS: u32 = 60;

while timer::check_update_time(ctx, DESIRED_FPS) {
Expand All @@ -65,7 +65,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx);
graphics::set_color(ctx, graphics::WHITE)?;
// let src = graphics::Rect::new(0.25, 0.25, 0.5, 0.5);
Expand Down Expand Up @@ -120,9 +120,9 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("drawing", "ggez", c);
let ctx = &mut Context::load_from_conf("drawing", "ggez", c)?;

// We add the CARGO_MANIFEST_DIR/resources do the filesystems paths so
// we we look in the cargo project for files.
Expand Down
2 changes: 1 addition & 1 deletion examples/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ggez::event;
use ggez::graphics::{self, DrawMode, Point2};
use ggez::{conf, Context, GameResult};

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("eventloop", "ggez", c)?;
let mut events = event::Events::new(ctx)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::io::{Read, Write};
use std::path;
use std::str;

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let mut cb = ContextBuilder::new("ggez_files_example", "ggez");

// We add the CARGO_MANIFEST_DIR/resources to the filesystems paths so
Expand Down
6 changes: 3 additions & 3 deletions examples/graphics_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
const DESIRED_FPS: u32 = 60;
while timer::check_update_time(ctx, DESIRED_FPS) {
self.angle += 0.01;
Expand All @@ -78,7 +78,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::set_background_color(ctx, graphics::BLACK);
graphics::clear(ctx);
let rotation = timer::get_ticks(ctx) % 1000;
Expand Down Expand Up @@ -204,7 +204,7 @@ fn print_help() {
println!(" ");
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let matches = App::new("ggez graphics settings example")
.arg(
Arg::with_name("msaa")
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let dest_point = graphics::Point2::new(10.0, 10.0);

if self.draw_with_canvas {
Expand Down Expand Up @@ -114,7 +114,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf {
window_setup: conf::WindowSetup {
samples: conf::NumSamples::Two,
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl MainState {
// The `EventHandler` trait also contains callbacks for event handling
// that you can override if you wish, but the defaults are fine.
impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx);

// Drawables are drawn from their top-left corner.
Expand All @@ -62,7 +62,7 @@ impl event::EventHandler for MainState {
// * Second, create a `ggez::game::Game` object which will
// do the work of creating our MainState and running our game.
// * Then, just call `game.run()` which runs the `Game` mainloop.
pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf {
window_setup: conf::WindowSetup {
samples: conf::NumSamples::Eight,
Expand Down
8 changes: 4 additions & 4 deletions examples/imageview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct MainState {
}

impl MainState {
fn draw_crazy_lines(&self, ctx: &mut Context) -> GameResult<()> {
fn draw_crazy_lines(&self, ctx: &mut Context) -> GameResult {
let num_lines = 100;
let mut colors = Vec::new();
for _ in 0..num_lines {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
const DESIRED_FPS: u32 = 60;
while timer::check_update_time(ctx, DESIRED_FPS) {
self.a += self.direction;
Expand All @@ -99,7 +99,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let c = self.a as u8;
graphics::set_color(ctx, Color::from((c, c, c, 255)))?;
graphics::clear(ctx);
Expand Down Expand Up @@ -132,7 +132,7 @@ impl event::EventHandler for MainState {
// Creating a context depends on loading a config file.
// Loading a config file depends on having FS (or we can just fake our way around it
// by creating an FS and then throwing it away; the costs are not huge.)
pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
println!("Starting with default config: {:#?}", c);
let ctx = &mut Context::load_from_conf("imageview", "ggez", c)?;
Expand Down
6 changes: 3 additions & 3 deletions examples/input_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx);
graphics::circle(
ctx,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("input_test", "ggez", c)?;

Expand Down
8 changes: 4 additions & 4 deletions examples/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl FileLogger {
/// Reads pending messages from the channel and writes them to the file.
/// Intended to be called in `EventHandler::update()`, to avoid using threads.
/// (which you totally shouldn't actively avoid, Rust is perfect for concurrency)
fn update(&mut self) -> GameResult<()> {
fn update(&mut self) -> GameResult {
// try_recv() doesn't block, it returns Err if there's no message to pop.
while let Ok(msg) = self.receiver.try_recv() {
// std::io::Write::write_all() takes a byte array.
Expand Down Expand Up @@ -81,7 +81,7 @@ impl App {
/// Where the app meets the `ggez`.
impl EventHandler for App {
/// This is where the logic should happen.
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
const DESIRED_FPS: u32 = 60;
// This tries to throttle updates to desired value.
while timer::check_update_time(ctx, DESIRED_FPS) {
Expand All @@ -92,7 +92,7 @@ impl EventHandler for App {
}

/// Draws the screen. We don't really have anything to draw.
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx);
graphics::present(ctx);
timer::yield_now();
Expand Down Expand Up @@ -126,7 +126,7 @@ impl EventHandler for App {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
// This creates a channel that can be used to asynchronously pass things between parts of the
// app. There's some overhead, so using it somewhere that doesn't need async (read: threads)
// is suboptimal. But, `fern`'s arbitrary logging requires a channel.
Expand Down
6 changes: 3 additions & 3 deletions examples/render_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, _ctx: &mut Context) -> GameResult {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
// first lets render to our canvas
graphics::set_canvas(ctx, Some(&self.canvas));
graphics::set_background_color(ctx, Color::new(0.1, 0.2, 0.3, 1.0));
Expand Down Expand Up @@ -73,7 +73,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let mut c = conf::Conf::new();
c.window_setup.resizable = true;
let ctx = &mut Context::load_from_conf("super_simple", "ggez", c)?;
Expand Down
6 changes: 3 additions & 3 deletions examples/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
self.dim.rate = 0.5 + (((timer::get_ticks(ctx) as f32) / 100.0).cos() / 2.0);
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx);

graphics::circle(ctx, DrawMode::Fill, Point2::new(100.0, 300.0), 100.0, 2.0)?;
Expand All @@ -62,7 +62,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("shader", "ggez", c)?;

Expand Down
8 changes: 4 additions & 4 deletions examples/shadows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl MainState {
light: Light,
origin: DrawParam,
canvas_origin: DrawParam,
) -> GameResult<()> {
) -> GameResult {
let size = graphics::get_size(ctx);
// Now we want to run the occlusions shader to calculate our 1D shadow
// distances into the `occlusions` canvas.
Expand Down Expand Up @@ -318,7 +318,7 @@ impl MainState {
}

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
fn update(&mut self, ctx: &mut Context) -> GameResult {
if timer::get_ticks(ctx) % 100 == 0 {
println!("Average FPS: {}", timer::get_fps(ctx));
}
Expand All @@ -330,7 +330,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let size = graphics::get_size(ctx);
let origin = DrawParam {
dest: Point2::new(0.0, 0.0),
Expand Down Expand Up @@ -433,7 +433,7 @@ impl event::EventHandler for MainState {
}
}

pub fn main() -> GameResult<()> {
pub fn main() -> GameResult {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("shadows", "ggez", c)?;

Expand Down
Loading

0 comments on commit b51fcac

Please sign in to comment.