Skip to content

Commit

Permalink
Fixing up compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratysz committed Jun 4, 2018
1 parent ee85087 commit 670efaa
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
use std::io;
use toml;
use winit;

use GameResult;
use GameError;

/// Possible fullscreen modes.
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
Expand Down
6 changes: 2 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use winit;

use std::fmt;
use std::io::Read;

use GameError;
use GameResult;
use audio;
use conf;
use event::{self, winit_event};
use event::winit_event;
use filesystem::Filesystem;
use graphics::{self, Point2};
use keyboard;
Expand Down Expand Up @@ -171,7 +169,7 @@ impl Context {
}
}
winit_event::Event::DeviceEvent { event: winit_event::DeviceEvent::MouseMotion { delta: (x, y) }, .. } => {
self.mouse_context.set_last_position(
self.mouse_context.set_last_delta(
Point2::new(*x as f32, *y as f32),
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,9 @@ impl From<glutin::CreationError> for GameError {
GameError::WindowError(s)
}
}

impl From<glutin::ContextError> for GameError {
fn from(s: glutin::ContextError) -> GameError {
GameError::RenderError(format!("OpenGL context error: {}", s))
}
}
5 changes: 3 additions & 2 deletions src/graphics/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ where
pub(crate) color_format: gfx::format::Format,
pub(crate) depth_format: gfx::format::Format,

// TODO: is this needed?
pub(crate) backend_spec: B,
pub(crate) window: glutin::GlWindow,
pub(crate) multisample_samples: u8,
Expand Down Expand Up @@ -259,8 +260,8 @@ impl GraphicsContext {
modelview_stack: vec![initial_transform],
white_image,
screen_rect: Rect::new(left, top, right - left, bottom - top),
color_format: color_format,
depth_format: depth_format,
color_format,
depth_format,

backend_spec: backend,
window,
Expand Down
7 changes: 4 additions & 3 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,17 @@ pub fn draw_ex(ctx: &mut Context, drawable: &Drawable, params: DrawParam) -> Gam
/// Call this at the end of your `EventHandler`'s `draw()` method.
///
/// Unsets any active canvas.
pub fn present(ctx: &mut Context) {
pub fn present(ctx: &mut Context) -> GameResult<()> {
let gfx = &mut ctx.gfx_context;
gfx.data.out = gfx.screen_render_target.clone();
// We might want to give the user more control over when the
// encoder gets flushed eventually, if we want them to be able
// to do their own gfx drawing. HOWEVER, the whole pipeline type
// thing is a bigger hurdle, so this is fine for now.
gfx.encoder.flush(&mut *gfx.device);
gfx.window.swap_buffers();
gfx.window.swap_buffers()?;
gfx.device.cleanup();
Ok(())
}

/// Take a screenshot by outputting the current render surface
Expand Down Expand Up @@ -361,7 +362,7 @@ pub fn screenshot(ctx: &mut Context) -> GameResult<Image> {
blend_mode: None,
width: u32::from(w),
height: u32::from(h),
debug_id: debug_id,
debug_id,
};

Ok(image)
Expand Down
2 changes: 0 additions & 2 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Keyboard utility functions.
use context::Context;
use error::GameResult;
use event::Keycode;
use graphics;

/// Tracks last key pressed, to distinguish if the system
/// is sending repeat events when a key is held down.
Expand Down
12 changes: 8 additions & 4 deletions src/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use context::Context;
use graphics;
use graphics::Point2;
use GameResult;
pub use winit::{CursorState, MouseCursor};

/// Stores state information for the mouse,
Expand Down Expand Up @@ -57,9 +58,9 @@ pub fn get_cursor_state(ctx: &Context) -> CursorState {
}

/// Set whether or not the mouse is grabbed (confined to the window) or hidden (invisible).
pub fn set_cursor_state(ctx: &mut Context, state: CursorState) {
pub fn set_cursor_state(ctx: &mut Context, state: CursorState) -> GameResult<()> {
ctx.mouse_context.cursor_state = state;
graphics::get_window(ctx).set_cursor_state(state);
graphics::get_window(ctx).set_cursor_state(state).map_err(|e| e.into())
}

/// Get the current position of the mouse cursor, in pixels.
Expand All @@ -76,7 +77,10 @@ pub fn get_delta(ctx: &Context) -> Point2 {

/// Set the current position of the mouse cursor, in pixels.
/// Uses strictly window-only coordinates.
pub fn set_position(ctx: &mut Context, point: Point2) {
pub fn set_position(ctx: &mut Context, point: Point2) -> GameResult<()> {
ctx.mouse_context.last_position = point;
graphics::get_window(ctx).set_cursor_position(point.x as i32, point.y as i32);
if graphics::get_window(ctx).set_cursor_position(point.x as i32, point.y as i32).is_err() {
return Err("Couldn't set mouse cursor position!".to_owned().into());
}
Ok(())
}

0 comments on commit 670efaa

Please sign in to comment.