Skip to content

Commit

Permalink
rustfmt, and messed with the logging example format 'cause I'm OCD
Browse files Browse the repository at this point in the history
  • Loading branch information
icefoxen committed Apr 27, 2018
1 parent f925cdf commit 0b484c1
Show file tree
Hide file tree
Showing 32 changed files with 263 additions and 582 deletions.
9 changes: 2 additions & 7 deletions examples/astroblasto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate rand;
use ggez::{Context, ContextBuilder, GameResult};
use ggez::audio;
use ggez::conf;
use ggez::event::{self, Keycode, Mod, EventHandler};
use ggez::event::{self, EventHandler, Keycode, Mod};
use ggez::graphics;
use ggez::timer;
use ggez::graphics::{Point2, Vector2};
Expand Down Expand Up @@ -420,12 +420,7 @@ fn print_instructions() {
println!();
}

fn draw_actor(
assets: &mut Assets,
ctx: &mut Context,
actor: &Actor,
world_coords: (u32, u32),
) -> GameResult<()> {
fn draw_actor(assets: &mut Assets, ctx: &mut Context, actor: &Actor, world_coords: (u32, u32)) -> GameResult<()> {
let (screen_w, screen_h) = world_coords;
let pos = world_to_screen_coords(screen_w, screen_h, actor.pos);
let image = assets.actor_image(actor);
Expand Down
10 changes: 3 additions & 7 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ impl MainState {
fn new(ctx: &mut Context) -> Self {
let font = graphics::Font::new(ctx, "/DejaVuSerif.ttf", 18).unwrap();
let text1 = graphics::Text::new(ctx, "You can mix ggez and gfx drawing;", &font).unwrap();
let text2 =
graphics::Text::new(ctx, "it basically draws gfx stuff first, then ggez", &font)
.unwrap();
let text2 = graphics::Text::new(ctx, "it basically draws gfx stuff first, then ggez", &font).unwrap();

let color_view = graphics::get_screen_render_target(ctx);
let depth_view = graphics::get_depth_view(ctx);
Expand Down Expand Up @@ -177,8 +175,7 @@ void main() {
)
.unwrap();

let sinfo =
texture::SamplerInfo::new(texture::FilterMethod::Bilinear, texture::WrapMode::Clamp);
let sinfo = texture::SamplerInfo::new(texture::FilterMethod::Bilinear, texture::WrapMode::Clamp);

// Create pipeline state object
let pso = factory.create_pipeline_simple(vs, fs, pipe::new()).unwrap();
Expand Down Expand Up @@ -218,8 +215,7 @@ impl event::EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
// Do gfx-rs drawing
{
let (_factory, device, encoder, _depthview, _colorview) =
graphics::get_gfx_objects(ctx);
let (_factory, device, encoder, _depthview, _colorview) = graphics::get_gfx_objects(ctx);
encoder.clear(&self.data.out_color, [0.1, 0.1, 0.1, 1.0]);

let rotation = na::Matrix4::from_scaled_axis(na::Vector3::z() * self.rotation);
Expand Down
2 changes: 1 addition & 1 deletion examples/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern crate ggez;

use ggez::{ContextBuilder};
use ggez::ContextBuilder;
use ggez::filesystem;
use ggez::conf;
use std::env;
Expand Down
4 changes: 3 additions & 1 deletion examples/glyph_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl MainState {
Ok(MainState {
frames: 0,
text_base: String::new(),
text_src: "Lorem ipsum dolor sit amet, ferri simul omittantur eam eu, no debet doming dolorem ius.".chars().collect(),
text_src: "Lorem ipsum dolor sit amet, ferri simul omittantur eam eu, no debet doming dolorem ius."
.chars()
.collect(),
glyph_brush,
window_w,
window_h,
Expand Down
38 changes: 9 additions & 29 deletions examples/graphics_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ impl event::EventHandler for MainState {
graphics::clear(ctx);
let rotation = timer::get_ticks(ctx) % 1000;
graphics::set_color(ctx, graphics::WHITE)?;
let circle = graphics::Mesh::new_circle(
ctx,
DrawMode::Line(3.0),
Point2::new(0.0, 0.0),
100.0,
4.0,
)?;
let circle = graphics::Mesh::new_circle(ctx, DrawMode::Line(3.0), Point2::new(0.0, 0.0), 100.0, 4.0)?;
graphics::draw(ctx, &self.image, Point2::new(400.0, 300.0), 0.0)?;
graphics::draw(ctx, &circle, Point2::new(400.0, 300.0), rotation as f32)?;

Expand Down Expand Up @@ -117,13 +111,7 @@ impl event::EventHandler for MainState {
Ok(())
}

fn mouse_button_down_event(
&mut self,
_ctx: &mut Context,
_btn: event::MouseButton,
x: i32,
y: i32,
) {
fn mouse_button_down_event(&mut self, _ctx: &mut Context, _btn: event::MouseButton, x: i32, y: i32) {
println!("Button clicked at: {} {}", x, y);
}

Expand All @@ -137,36 +125,31 @@ impl event::EventHandler for MainState {
Keycode::H => {
self.window_settings.window_size_toggle = true;
self.window_settings.resolution_index += 1;
self.window_settings.resolution_index %=
self.window_settings.num_of_resolutions;
self.window_settings.resolution_index %= self.window_settings.num_of_resolutions;
}
Keycode::G => {
if self.window_settings.resolution_index > 0 {
self.window_settings.window_size_toggle = true;
self.window_settings.resolution_index -= 1;
self.window_settings.resolution_index %=
self.window_settings.num_of_resolutions;
self.window_settings.resolution_index %= self.window_settings.num_of_resolutions;
}
}
Keycode::Up => {
self.zoom += 0.1;
println!("Zoom is now {}", self.zoom);
let (w, h) = graphics::get_size(ctx);
let new_rect =
graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
let new_rect = graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
graphics::set_screen_coordinates(ctx, new_rect).unwrap();
}
Keycode::Down => {
self.zoom -= 0.1;
println!("Zoom is now {}", self.zoom);
let (w, h) = graphics::get_size(ctx);
let new_rect =
graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
let new_rect = graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
graphics::set_screen_coordinates(ctx, new_rect).unwrap();
}
Keycode::Space => {
self.window_settings.resize_projection =
!self.window_settings.resize_projection;
self.window_settings.resize_projection = !self.window_settings.resize_projection;
println!(
"Resizing the projection on window resize is now: {}",
self.window_settings.resize_projection
Expand Down Expand Up @@ -196,9 +179,7 @@ fn print_help() {
println!(" F: toggle fullscreen");
println!(" G/H: Increase/decrease window sizes");
println!(" Up/Down: Zoom in/out");
println!(
" Spacebar: Toggle whether or not to resize the projection when the window is resized"
);
println!(" Spacebar: Toggle whether or not to resize the projection when the window is resized");
println!(" ");
println!(" To see command-line options, run with `cargo run --example graphics_settings -- --help`");
println!(" ");
Expand All @@ -222,8 +203,7 @@ pub fn main() {
.expect("Option msaa needs to be a number!");
let mut c = conf::Conf::new();
c.window_mode.fullscreen_type = conf::FullscreenType::Off;
c.window_setup.samples =
conf::NumSamples::from_u32(msaa).expect("Option msaa needs to be 1, 2, 4, 8 or 16!");
c.window_setup.samples = conf::NumSamples::from_u32(msaa).expect("Option msaa needs to be 1, 2, 4, 8 or 16!");
c.window_setup.resizable = true;
println!("{:?}", c);

Expand Down
5 changes: 1 addition & 4 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ impl MainState {
let font = graphics::Font::new(ctx, "/DejaVuSerif.ttf", 48)?;
let text = graphics::Text::new(ctx, "Hello world!", &font)?;

let s = MainState {
text,
frames: 0,
};
let s = MainState { text, frames: 0 };
Ok(s)
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/imageview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct MainState {
text: graphics::Text,
bmptext: graphics::Text,
// Not actually dead, see BUGGO below
#[allow(dead_code)] sound: audio::Source,
#[allow(dead_code)]
sound: audio::Source,
}

impl MainState {
Expand Down Expand Up @@ -52,8 +53,7 @@ impl MainState {

let font = graphics::Font::new(ctx, "/DejaVuSerif.ttf", 48).unwrap();
let text = graphics::Text::new(ctx, "Hello world!", &font).unwrap();
let bmpfont =
graphics::Font::new_bitmap(ctx, "/arial.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ").unwrap();
let bmpfont = graphics::Font::new_bitmap(ctx, "/arial.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ").unwrap();
let bmptext = graphics::Text::new(ctx, "ZYXWVYTSRQPONMLKJIHGFEDCBA", &bmpfont).unwrap();
let sound = audio::Source::new(ctx, "/sound.ogg").unwrap();

Expand Down
20 changes: 3 additions & 17 deletions examples/input_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate ggez;

use ggez::{Context, GameResult};
use ggez::event::{self, MouseButton, Button, MouseState, Keycode, Mod, Axis};
use ggez::event::{self, Axis, Button, Keycode, Mod, MouseButton, MouseState};
use ggez::graphics::{self, DrawMode, Point2};
use ggez::conf;
use std::env;
Expand Down Expand Up @@ -53,15 +53,7 @@ impl event::EventHandler for MainState {
println!("Mouse button released: {:?}, x: {}, y: {}", button, x, y);
}

fn mouse_motion_event(
&mut self,
_ctx: &mut Context,
_state: MouseState,
x: i32,
y: i32,
xrel: i32,
yrel: i32,
) {
fn mouse_motion_event(&mut self, _ctx: &mut Context, _state: MouseState, x: i32, y: i32, xrel: i32, yrel: i32) {
if self.mouse_down {
self.pos_x = x;
self.pos_y = y;
Expand Down Expand Up @@ -114,13 +106,7 @@ impl event::EventHandler for MainState {
);
}

fn controller_axis_event(
&mut self,
_ctx: &mut Context,
axis: Axis,
value: i16,
instance_id: i32,
) {
fn controller_axis_event(&mut self, _ctx: &mut Context, axis: Axis, value: i16, instance_id: i32) {
println!(
"Axis Event: {:?} Value: {} Controller_Id: {}",
axis, value, instance_id
Expand Down
60 changes: 32 additions & 28 deletions examples/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate log;
use ggez::{Context, ContextBuilder, GameResult};
use ggez::conf::{WindowMode, WindowSetup};
use ggez::event::{EventHandler, Keycode, Mod};
use ggez::filesystem::{File};
use ggez::filesystem::File;
use ggez::graphics;
use ggez::timer;
use std::io::Write;
Expand All @@ -33,14 +33,14 @@ struct FileLogger {

impl FileLogger {
/// Initializes a file writer. Needs an initialized `ggez::Context`, to use it's filesystem.
fn new(
ctx: &mut Context,
path: &str,
receiver: mpsc::Receiver<String>,
) -> GameResult<FileLogger> {
fn new(ctx: &mut Context, path: &str, receiver: mpsc::Receiver<String>) -> GameResult<FileLogger> {
// This (re)creates a file and opens it for appending.
let file = ctx.filesystem.create(path::Path::new(path))?;
debug!("Created log file {:?} in {:?}", path, ctx.filesystem.get_user_config_dir());
debug!(
"Created log file {:?} in {:?}",
path,
ctx.filesystem.get_user_config_dir()
);
Ok(FileLogger { file, receiver })
}

Expand Down Expand Up @@ -68,7 +68,9 @@ struct App {
impl App {
/// Creates an instance, takes ownership of passed FileLogger.
fn new(_ctx: &mut Context, logger: FileLogger) -> GameResult<App> {
Ok(App { file_logger: logger })
Ok(App {
file_logger: logger,
})
}
}

Expand Down Expand Up @@ -96,7 +98,10 @@ impl EventHandler for App {
/// Called when `ggez` catches a keyboard key being pressed.
fn key_down_event(&mut self, ctx: &mut Context, keycode: Keycode, keymod: Mod, repeat: bool) {
// Log the keypress to info channel!
info!("Key down event: {}, modifiers: {:?}, repeat: {}", keycode, keymod, repeat);
info!(
"Key down event: {}, modifiers: {:?}, repeat: {}",
keycode, keymod, repeat
);
if keycode == Keycode::Escape {
// Escape key closes the app.
if let Err(e) = ctx.quit() {
Expand Down Expand Up @@ -128,20 +133,20 @@ pub fn main() {

// This sets up a `fern` logger and initializes `log`.
fern::Dispatch::new()
// Formats logs.
.format(|out, msg, rec| {
// Formats logs
.format(|out, message, record| {
out.finish(format_args!(
"[{}][{}][{}] {}",
chrono::Local::now().format("%H:%M:%S"),
rec.target(),
rec.level(),
msg,
"[{}][{:<5}][{}] {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
record.level().to_string(),
record.target(),
message
))
})
// Sets global log level.
.level(log::LevelFilter::Trace)
// `gfx_device_gl` is very verbose, on info channel too, so let's filter most of that out.
// `gfx_device_gl` is very chatty on info loglevel, so
// filter that a bit more strictly.
.level_for("gfx_device_gl", log::LevelFilter::Warn)
.level(log::LevelFilter::Trace)
// Hooks up console output.
.chain(std::io::stdout())
// Hooks up the channel.
Expand All @@ -152,6 +157,7 @@ pub fn main() {
// Note, even though our file logger hasn't been initialized in any way yet, logs starting
// from here will still appear in the log file.
debug!("I am logged!");
info!("I am too!");

trace!("Creating ggez context.");

Expand All @@ -177,16 +183,14 @@ pub fn main() {
Err(e) => {
error!("Could not initialize: {}", e);
}
Ok(ref mut app) => {
match ggez::event::run(ctx, app) {
Err(e) => {
error!("Error occurred: {}", e);
}
Ok(_) => {
debug!("Exited cleanly.");
}
Ok(ref mut app) => match ggez::event::run(ctx, app) {
Err(e) => {
error!("Error occurred: {}", e);
}
}
Ok(_) => {
debug!("Exited cleanly.");
}
},
}

trace!("Since file logger is dropped with App, this line will cause an error in fern!");
Expand Down
2 changes: 1 addition & 1 deletion examples/render_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extern crate ggez;

use ggez::{Context, GameResult};
use ggez::graphics::{self, DrawParam, Color, Point2};
use ggez::graphics::{self, Color, DrawParam, Point2};
use ggez::conf;
use ggez::event;

Expand Down
Loading

0 comments on commit 0b484c1

Please sign in to comment.