From a702f7258a8b033c21adc20fae9ebd7a02d8e45c Mon Sep 17 00:00:00 2001 From: timokoesters Date: Wed, 3 Jul 2019 21:25:26 +0200 Subject: [PATCH] Fix building --- common/src/volumes/dyna.rs | 2 +- common/src/volumes/vol_map_2d.rs | 2 +- voxygen/src/session.rs | 62 +++++++++++++++++--------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/common/src/volumes/dyna.rs b/common/src/volumes/dyna.rs index 4e7f4982d1..e88ccd3de7 100644 --- a/common/src/volumes/dyna.rs +++ b/common/src/volumes/dyna.rs @@ -2,7 +2,7 @@ use crate::vol::{BaseVol, ReadVol, SizedVol, Vox, WriteVol}; use serde_derive::{Deserialize, Serialize}; use vek::*; -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum DynaErr { OutOfBounds, } diff --git a/common/src/volumes/vol_map_2d.rs b/common/src/volumes/vol_map_2d.rs index c77b98d0ea..28b29fdcbb 100644 --- a/common/src/volumes/vol_map_2d.rs +++ b/common/src/volumes/vol_map_2d.rs @@ -6,7 +6,7 @@ use fxhash::FxHashMap; use std::{collections::hash_map, fmt::Debug, marker::PhantomData, sync::Arc}; use vek::*; -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum VolMap2dErr { NoSuchChunk, ChunkErr(V::Err), diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index b58dc142d4..289d39e30f 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -8,7 +8,9 @@ use crate::{ Direction, Error, GlobalState, PlayState, PlayStateResult, }; use client::{self, Client}; -use common::{terrain::block::Block, ray::Ray, vol::ReadVol, clock::Clock, comp, comp::Pos, msg::ClientState}; +use common::{ + clock::Clock, comp, comp::Pos, msg::ClientState, ray::Ray, terrain::block::Block, vol::ReadVol, +}; use log::{error, warn}; use std::{cell::RefCell, rc::Rc, time::Duration}; use vek::*; @@ -110,30 +112,31 @@ impl PlayState for SessionState { Event::InputUpdate(GameInput::Attack, state) => { // Check the existence of CanBuild component. If it's here, use LMB to // place blocks, if not, use it to attack - match self.client.borrow().state().read_component_cloned::(self.client.borrow().entity()) { - Some(_build_perms) => { - println!("Placing block"); - let (view_mat, _, dist) = self.scene.camera().compute_dependents(&self.client.borrow()); - let cam_pos = self.scene.camera().compute_dependents(&self.client.borrow()).2; - let cam_dir = (view_mat.inverted() * Vec4::unit_z()).normalized(); - match self.client - .borrow() - .state() - .terrain() - .ray(cam_pos, cam_pos + cam_dir * 100.0) - .cast() - { - (d, Ok(Some((_)))) => { - let cam_pos = self.scene.camera().compute_dependents(&self.client.borrow()).2; - let cam_dir = (view_mat.inverted() * Vec4::unit_z()).normalized(); - let pos = (cam_pos + cam_dir * d).map(|e| e.floor() as i32); - self.client.borrow_mut().place_block(pos, Block::new(1, Rgb::broadcast(255)));// TODO: Handle block color with a command - }, - (_, Err(_)) => {}, - (_, Ok(None)) => {}, - }; + let mut client = self.client.borrow_mut(); + match client + .state() + .read_component_cloned::(client.entity()) + { + Some(_build_perms) => { + println!("Placing block"); - }, + let (view_mat, _, cam_pos) = + self.scene.camera().compute_dependents(&client); + let cam_dir = + (self.scene.camera().get_focus_pos() - cam_pos).normalized(); + + let (d, b) = { + let terrain = client.state().terrain(); + let ray = + terrain.ray(cam_pos, cam_pos + cam_dir * 100.0).cast(); + (ray.0, if let Ok(Some(_)) = ray.1 { true } else { false }) + }; + + if b { + let pos = (cam_pos + cam_dir * d).map(|e| e.floor() as i32); + client.place_block(pos, Block::new(1, Rgb::broadcast(255))); // TODO: Handle block color with a command + } + } None => { if state { if let ClientState::Character = current_client_state { @@ -149,10 +152,13 @@ impl PlayState for SessionState { } } Event::InputUpdate(GameInput::SecondAttack, state) => { - match self.client.borrow().state().read_component_cloned::(self.client.borrow().entity()) { - Some(_build_perms) => { - - } + match self + .client + .borrow() + .state() + .read_component_cloned::(self.client.borrow().entity()) + { + Some(_build_perms) => {} None => { // TODO: Handle secondary attack here }