diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index 1d59de63b1..4bde150427 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -13,14 +13,6 @@ use crate::{ // Local use self::cell::Cell; -/// A type representing a single figure bone (e.g: the limb of a character). -#[derive(Copy, Clone)] -pub struct Bone { - origin: Vec3, - offset: Vec3, - ori: Vec3, -} - /// A type representing a volume that may be part of an animated figure. /// /// Figures are used to represent things like characters, NPCs, mobs, etc. diff --git a/common/src/util/mod.rs b/common/src/util/mod.rs index 05f0169051..8b13789179 100644 --- a/common/src/util/mod.rs +++ b/common/src/util/mod.rs @@ -1 +1 @@ -pub mod worker_pool; + diff --git a/common/src/util/worker_pool.rs b/common/src/util/worker_pool.rs deleted file mode 100644 index a5be780a44..0000000000 --- a/common/src/util/worker_pool.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Library -use threadpool::ThreadPool; - -pub struct WorkerPool { - thread_pool: ThreadPool, -} - -impl WorkerPool { - -} diff --git a/common/src/volumes/chunk.rs b/common/src/volumes/chunk.rs index 97fbdc7368..abdea07997 100644 --- a/common/src/volumes/chunk.rs +++ b/common/src/volumes/chunk.rs @@ -14,6 +14,7 @@ use crate::vol::{ VolSize, }; +#[derive(Debug)] pub enum ChunkErr { OutOfBounds, } diff --git a/common/src/volumes/dyna.rs b/common/src/volumes/dyna.rs index ee51bcbb25..f706e53c4f 100644 --- a/common/src/volumes/dyna.rs +++ b/common/src/volumes/dyna.rs @@ -10,6 +10,7 @@ use crate::vol::{ WriteVol, }; +#[derive(Debug)] pub enum DynaErr { OutOfBounds, } diff --git a/common/src/volumes/vol_map.rs b/common/src/volumes/vol_map.rs index 1c62710608..954ac5cc16 100644 --- a/common/src/volumes/vol_map.rs +++ b/common/src/volumes/vol_map.rs @@ -21,6 +21,7 @@ use crate::{ }, }; +#[derive(Debug)] pub enum VolMapErr { NoSuchChunk, ChunkErr(ChunkErr), diff --git a/voxygen/src/main.rs b/voxygen/src/main.rs index a39914db29..3143258e71 100644 --- a/voxygen/src/main.rs +++ b/voxygen/src/main.rs @@ -34,7 +34,7 @@ impl GlobalState { /// Called after a change in play state has occured (usually used to reverse any temporary /// effects a state may have made). pub fn on_play_state_changed(&mut self) { - self.window.untrap_cursor(); + self.window.grab_cursor(false); } } diff --git a/voxygen/src/mesh/mod.rs b/voxygen/src/mesh/mod.rs index 0b898a4c94..1f938ff930 100644 --- a/voxygen/src/mesh/mod.rs +++ b/voxygen/src/mesh/mod.rs @@ -1,9 +1,6 @@ pub mod segment; pub mod terrain; -// Library -use vek::*; - // Crate use crate::render::{ self, diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index e167f8eba6..d04e764e6d 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -9,7 +9,7 @@ use common::{ ReadVol, }, volumes::dyna::Dyna, - terrain::{Block, TerrainChunk}, + terrain::Block, }; // Crate diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 7b6af5be4c..2c33d61d00 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -12,10 +12,7 @@ use vek::*; use client::Client; use common::{ terrain::TerrainMap, - volumes::vol_map::{ - VolMap, - VolMapErr, - }, + volumes::vol_map::VolMapErr, vol::SampleVol, }; @@ -179,7 +176,7 @@ impl Terrain { } pub fn render(&self, renderer: &mut Renderer, globals: &Consts) { - for (pos, chunk) in &self.chunks { + for (_, chunk) in &self.chunks { renderer.render_terrain_chunk( &chunk.model, globals, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 9dbb2ce8eb..6fc7491fa6 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -17,7 +17,7 @@ use crate::{ PlayState, PlayStateResult, GlobalState, - window::Event, + window::{Event, Key}, render::Renderer, scene::Scene, }; @@ -75,14 +75,14 @@ impl SessionState { impl PlayState for SessionState { fn play(&mut self, global_state: &mut GlobalState) -> PlayStateResult { // Trap the cursor - global_state.window.trap_cursor(); + global_state.window.grab_cursor(true); // Set up an fps clock let mut clock = Clock::new(); // Load a few chunks TODO: Remove this - for x in -2..3 { - for y in -2..3 { + for x in -4..5 { + for y in -4..5 { for z in -1..2 { self.client.load_chunk(Vec3::new(x, y, z)); } @@ -97,8 +97,12 @@ impl PlayState for SessionState { Event::Close => return PlayStateResult::Shutdown, // When 'q' is pressed, exit the session Event::Char('q') => return PlayStateResult::Pop, + // Toggle cursor grabbing + Event::KeyDown(Key::ToggleCursor) => { + global_state.window.grab_cursor(!global_state.window.is_cursor_grabbed()); + }, // Pass all other events to the scene - event => self.scene.handle_input_event(event), + event => { self.scene.handle_input_event(event); }, }; // TODO: Do something if the event wasn't handled? } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index d2a88be1b5..b81c9842f8 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -15,8 +15,9 @@ use crate::{ pub struct Window { events_loop: glutin::EventsLoop, - window: glutin::GlWindow, renderer: Renderer, + window: glutin::GlWindow, + cursor_grabbed: bool, } @@ -47,13 +48,14 @@ impl Window { let tmp = Ok(Self { events_loop, - window, renderer: Renderer::new( device, factory, tgt_color_view, tgt_depth_view, )?, + window, + cursor_grabbed: false, }); tmp } @@ -62,15 +64,27 @@ impl Window { pub fn renderer_mut(&mut self) -> &mut Renderer { &mut self.renderer } pub fn fetch_events(&mut self) -> Vec { + // Copy data that is needed by the events closure to avoid lifetime errors + // TODO: Remove this if/when the compiler permits it + let cursor_grabbed = self.cursor_grabbed; + let mut events = vec![]; self.events_loop.poll_events(|event| match event { glutin::Event::WindowEvent { event, .. } => match event { glutin::WindowEvent::CloseRequested => events.push(Event::Close), glutin::WindowEvent::ReceivedCharacter(c) => events.push(Event::Char(c)), + glutin::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode { + Some(glutin::VirtualKeyCode::Escape) => events.push(if input.state == glutin::ElementState::Pressed { + Event::KeyDown(Key::ToggleCursor) + } else { + Event::KeyUp(Key::ToggleCursor) + }), + _ => {}, + }, _ => {}, }, glutin::Event::DeviceEvent { event, .. } => match event { - glutin::DeviceEvent::MouseMotion { delta: (dx, dy), .. } => + glutin::DeviceEvent::MouseMotion { delta: (dx, dy), .. } if cursor_grabbed => events.push(Event::CursorPan(Vec2::new(dx as f32, dy as f32))), _ => {}, }, @@ -84,25 +98,33 @@ impl Window { .map_err(|err| Error::BackendError(Box::new(err))) } - pub fn trap_cursor(&mut self) { - self.window.hide_cursor(true); - self.window.grab_cursor(true) - .expect("Failed to grab cursor"); + pub fn is_cursor_grabbed(&self) -> bool { + self.cursor_grabbed } - pub fn untrap_cursor(&mut self) { - self.window.hide_cursor(false); - self.window.grab_cursor(false) - .expect("Failed to ungrab cursor"); + pub fn grab_cursor(&mut self, grab: bool) { + self.cursor_grabbed = grab; + self.window.hide_cursor(grab); + self.window.grab_cursor(grab) + .expect("Failed to grab/ungrab cursor"); } } +/// Represents a key that the game recognises after keyboard mapping +pub enum Key { + ToggleCursor, +} + /// Represents an incoming event from the window pub enum Event { /// The window has been requested to close. Close, /// A key has been typed that corresponds to a specific character. Char(char), - /// The cursor has been panned across the screen while trapped. + /// The cursor has been panned across the screen while grabbed. CursorPan(Vec2), + /// A key that the game recognises has been pressed down + KeyDown(Key), + /// A key that the game recognises has been released down + KeyUp(Key), } diff --git a/world/src/lib.rs b/world/src/lib.rs index 98c8bbfa5f..aa5407b9da 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -25,6 +25,8 @@ impl World { } pub fn generate_chunk(&self, chunk_pos: Vec3) -> TerrainChunk { + // TODO: This is all test code, remove/improve this later + let mut chunk = TerrainChunk::filled(Block::empty(), TerrainChunkMeta::void()); let air = Block::empty(); @@ -50,7 +52,7 @@ impl World { } } else { air - }); + }).unwrap(); } chunk