diff --git a/client/src/lib.rs b/client/src/lib.rs index 11d93cdc3c..f6e2fa5d29 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -76,11 +76,15 @@ impl Client { postbox.send_message(ClientMsg::Ping); + let mut thread_pool = threadpool::Builder::new() + .thread_name("veloren-worker".into()) + .build(); + // We reduce the thread count by 1 to keep rendering smooth + thread_pool.set_num_threads((thread_pool.max_count() - 1).max(1)); + Ok(Self { client_state, - thread_pool: threadpool::Builder::new() - .thread_name("veloren-worker".into()) - .build(), + thread_pool, server_info, postbox, @@ -97,6 +101,12 @@ impl Client { }) } + #[allow(dead_code)] + pub fn with_thread_pool(mut self, thread_pool: ThreadPool) -> Self { + self.thread_pool = thread_pool; + self + } + /// Request a state transition to `ClientState::Registered`. pub fn register(&mut self, player: comp::Player) { self.postbox.send_message(ClientMsg::Register { player }); @@ -434,7 +444,7 @@ impl Client { /// computationally expensive operations that run outside of the main thread (i.e., threads that /// block on I/O operations are exempt). #[allow(dead_code)] - pub fn thread_pool(&self) -> &threadpool::ThreadPool { + pub fn thread_pool(&self) -> &ThreadPool { &self.thread_pool } diff --git a/server/src/lib.rs b/server/src/lib.rs index 9c657c517b..d680fe79a4 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -122,6 +122,12 @@ impl Server { Ok(this) } + #[allow(dead_code)] + pub fn with_thread_pool(mut self, thread_pool: ThreadPool) -> Self { + self.thread_pool = thread_pool; + self + } + /// Get a reference to the server's game state. #[allow(dead_code)] pub fn state(&self) -> &State { diff --git a/voxygen/shaders/postprocess.frag b/voxygen/shaders/postprocess.frag index 304a0de91c..8eda152c57 100644 --- a/voxygen/shaders/postprocess.frag +++ b/voxygen/shaders/postprocess.frag @@ -171,5 +171,5 @@ void main() { //hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0); vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a); - tgt_color = final_color; + tgt_color = vec4(final_color.rgb, 0.5); } diff --git a/voxygen/shaders/terrain.frag b/voxygen/shaders/terrain.frag index 4561529aa3..ac07bd0ef9 100644 --- a/voxygen/shaders/terrain.frag +++ b/voxygen/shaders/terrain.frag @@ -14,6 +14,11 @@ uniform u_locals { out vec4 tgt_color; +float fog() { + float half_vd = 0.95 * view_distance.x / 2.0; + return clamp(distance(f_pos, cam_pos.xyz) / half_vd - 1.0, 0.0, 1.0); +} + void main() { // Calculate normal from packed data vec3 f_norm; @@ -40,5 +45,9 @@ void main() { vec3 light = vec3(static_light); - tgt_color = vec4(f_col * light, 1.0); + vec3 frag_color = f_col * light; + + vec3 fog_color = vec3(0.0, 0.25, 0.55); + + tgt_color = vec4(mix(frag_color, fog_color, fog()), 1.0); } diff --git a/voxygen/src/anim/character/run.rs b/voxygen/src/anim/character/run.rs index 6e1937380a..53845caeec 100644 --- a/voxygen/src/anim/character/run.rs +++ b/voxygen/src/anim/character/run.rs @@ -38,7 +38,7 @@ impl Animation for RunAnimation { next.head.offset = Vec3::new(0.0, 3.0, 12.0 + wave_cos * 1.3); next.head.ori = - Quaternion::rotation_z(head_look.x) * Quaternion::rotation_x(head_look.y + 0.35); + Quaternion::rotation_z(head_look.x + wave * 0.1) * Quaternion::rotation_x(head_look.y + 0.35); next.head.scale = Vec3::one(); next.chest.offset = Vec3::new(0.0, 0.0, 7.0 + wave_cos * 1.1); @@ -53,20 +53,20 @@ impl Animation for RunAnimation { next.shorts.ori = Quaternion::rotation_z(wave * 0.6); next.shorts.scale = Vec3::one(); - next.l_hand.offset = Vec3::new(-8.0, 3.0 + wave_cos * 5.0, 9.0 - wave * 2.0) / 11.0; + next.l_hand.offset = Vec3::new(-9.0, 3.0 + wave_cos * 8.0, 12.0 - wave * 1.0) / 11.0; next.l_hand.ori = Quaternion::rotation_x(wave_cos * 1.1); next.l_hand.scale = Vec3::one() / 11.0; - next.r_hand.offset = Vec3::new(8.0, 3.0 - wave_cos * 5.0, 9.0 + wave * 2.0) / 11.0; + next.r_hand.offset = Vec3::new(9.0, 3.0 - wave_cos * 8.0, 12.0 + wave * 1.0) / 11.0; next.r_hand.ori = Quaternion::rotation_x(wave_cos * -1.1); next.r_hand.scale = Vec3::one() / 11.0; - next.l_foot.offset = Vec3::new(-3.4, 0.0 + wave * 1.0, 6.0); - next.l_foot.ori = Quaternion::rotation_x(-0.0 - wave * 1.5); + next.l_foot.offset = Vec3::new(-3.4, 0.0 + wave_cos * 1.0, 6.0); + next.l_foot.ori = Quaternion::rotation_x(-0.0 - wave_cos * 1.5); next.l_foot.scale = Vec3::one(); - next.r_foot.offset = Vec3::new(3.4, 0.0 - wave * 1.0, 6.0); - next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave * 1.5); + next.r_foot.offset = Vec3::new(3.4, 0.0 - wave_cos * 1.0, 6.0); + next.r_foot.ori = Quaternion::rotation_x(-0.0 + wave_cos * 1.5); next.r_foot.scale = Vec3::one(); next.weapon.offset = Vec3::new(-7.0, -5.0, 15.0); diff --git a/voxygen/src/menu/main/start_singleplayer.rs b/voxygen/src/menu/main/start_singleplayer.rs index a44efca663..9ab08b138a 100644 --- a/voxygen/src/menu/main/start_singleplayer.rs +++ b/voxygen/src/menu/main/start_singleplayer.rs @@ -4,6 +4,7 @@ use crate::{ PlayState, PlayStateResult, }; use common::comp; +use client::Client; use log::warn; use std::net::SocketAddr; @@ -15,7 +16,7 @@ pub struct StartSingleplayerState { impl StartSingleplayerState { /// Create a new `MainMenuState`. pub fn new() -> Self { - let (singleplayer, sock) = Singleplayer::new(); + let (singleplayer, sock) = Singleplayer::new(None); // TODO: Make client and server use the same thread pool Self { singleplayer, sock } } diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index fa7317ae89..794b59ca4b 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -230,9 +230,9 @@ impl Renderer { /// Queue the clearing of the color and depth targets ready for a new frame to be rendered. /// TODO: Make a version of this that doesn't clear the colour target for speed. pub fn clear(&mut self, col: Rgba) { - self.encoder.clear(&self.tgt_color_view, col.into_array()); + //self.encoder.clear(&self.tgt_color_view, col.into_array()); self.encoder.clear_depth(&self.tgt_depth_view, 1.0); - self.encoder.clear(&self.win_color_view, col.into_array()); + //self.encoder.clear(&self.win_color_view, col.into_array()); self.encoder.clear_depth(&self.win_depth_view, 1.0); } diff --git a/voxygen/src/scene/figure.rs b/voxygen/src/scene/figure.rs index 0c17815f6b..8be3ca11b4 100644 --- a/voxygen/src/scene/figure.rs +++ b/voxygen/src/scene/figure.rs @@ -742,7 +742,8 @@ impl FigureState { ) { let mat = Mat4::::identity() * Mat4::translation_3d(pos) - * Mat4::rotation_z(-ori.x.atan2(ori.y)); // + f32::consts::PI / 2.0); + * Mat4::rotation_z(-ori.x.atan2(ori.y)) // + f32::consts::PI / 2.0); + * Mat4::scaling_3d(Vec3::from(0.8)); let locals = FigureLocals::new(mat, col); renderer.update_consts(&mut self.locals, &[locals]).unwrap(); diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index 0f8d33f4ce..f768afa6c6 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -136,7 +136,7 @@ impl Scene { proj_mat, cam_pos, self.camera.get_focus_pos(), - 10.0, + client.view_distance().unwrap_or(0) as f32 * 32.0, // TODO: No magic numbers client.state().get_time_of_day(), client.state().get_time(), renderer.get_resolution(), diff --git a/voxygen/src/singleplayer.rs b/voxygen/src/singleplayer.rs index 4c78a9f550..27bb198596 100644 --- a/voxygen/src/singleplayer.rs +++ b/voxygen/src/singleplayer.rs @@ -1,4 +1,5 @@ use common::clock::Clock; +use client::Client; use log::info; use portpicker::pick_unused_port; use server::{Event, Input, Server}; @@ -23,7 +24,7 @@ pub struct Singleplayer { } impl Singleplayer { - pub fn new() -> (Self, SocketAddr) { + pub fn new(client: Option<&Client>) -> (Self, SocketAddr) { let (sender, receiver) = channel(); let sock = SocketAddr::from(( @@ -32,7 +33,13 @@ impl Singleplayer { )); // Create server - let server = Server::bind(sock.clone()).expect("Failed to create server instance!"); + let server = Server::bind(sock.clone()) + .expect("Failed to create server instance!"); + + let server = match client { + Some(client) => server.with_thread_pool(client.thread_pool().clone()), + None => server, + }; let thread = thread::spawn(move || { run_server(server, receiver); diff --git a/world/src/sim.rs b/world/src/sim.rs index d1bf63b25e..2415bd2389 100644 --- a/world/src/sim.rs +++ b/world/src/sim.rs @@ -57,8 +57,8 @@ impl WorldSim { rock_nz: HybridMulti::new().set_persistence(0.3).set_seed(seed + 7), warp_nz: BasicMulti::new().set_octaves(3).set_seed(seed + 8), tree_nz: BasicMulti::new() - .set_octaves(8) - .set_persistence(0.75) + .set_octaves(12) + .set_persistence(0.9) .set_seed(seed + 9), cave_0_nz: SuperSimplex::new().set_seed(seed + 10), cave_1_nz: SuperSimplex::new().set_seed(seed + 11), @@ -357,8 +357,9 @@ impl<'a> Sampler<'a> { { let tree_pos3d = Vec3::new(tree_pos.x, tree_pos.y, tree_sample.alt as i32); + let rpos = wpos - tree_pos3d; block.or(TREES[*tree_seed as usize % TREES.len()] - .get(wpos - tree_pos3d) + .get((rpos * 160) / 128) // Scaling .map(|b| b.clone()) .unwrap_or(Block::empty())) }