diff --git a/assets/voxygen/shaders/fluid-vert.glsl b/assets/voxygen/shaders/fluid-vert.glsl index cb7effea26..52907b1ef6 100644 --- a/assets/voxygen/shaders/fluid-vert.glsl +++ b/assets/voxygen/shaders/fluid-vert.glsl @@ -27,7 +27,7 @@ void main() { // Small waves f_pos.xy += 0.01; // Avoid z-fighting - f_pos.z -= 0.1 * (sin(tick.x * 2.0 + f_pos.x * 2.0 + f_pos.y * 2.0) + 1.0) * 0.5 - 0.1; + f_pos.z -= 0.1 + 0.1 * (sin(tick.x * 2.0 + f_pos.x * 2.0 + f_pos.y * 2.0) + 1.0) * 0.5; f_col = vec3( float((v_col_light >> 8) & 0xFFu), @@ -39,8 +39,6 @@ void main() { f_pos_norm = v_pos_norm; - f_pos.z -= 0.2; - gl_Position = all_mat * vec4(f_pos, 1); diff --git a/assets/voxygen/shaders/terrain-frag.glsl b/assets/voxygen/shaders/terrain-frag.glsl index 020edd0156..a1d526bd95 100644 --- a/assets/voxygen/shaders/terrain-frag.glsl +++ b/assets/voxygen/shaders/terrain-frag.glsl @@ -45,7 +45,7 @@ void main() { diffuse_light *= f_light * ao; diffuse_light += point_light * ao; - vec3 col = f_col + hash(vec4(floor(f_chunk_pos * 3.0), 0)) * 0.02; // Small-scale noise + vec3 col = f_col + hash(vec4(floor(f_chunk_pos * 3.0 + 0.5), 0)) * 0.02; // Small-scale noise vec3 surf_color = illuminate(srgb_to_linear(col), light, diffuse_light, ambient_light); float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x); diff --git a/assets/voxygen/shaders/terrain-vert.glsl b/assets/voxygen/shaders/terrain-vert.glsl index eb81ee8bef..0b4664b24d 100644 --- a/assets/voxygen/shaders/terrain-vert.glsl +++ b/assets/voxygen/shaders/terrain-vert.glsl @@ -19,10 +19,10 @@ out vec3 f_col; out float f_light; out float f_ao; -const float EXTRA_NEG_Z = 65536.0; +const int EXTRA_NEG_Z = 65536; void main() { - f_chunk_pos = vec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0x1FFFFu)) - vec3(0, 0, EXTRA_NEG_Z); + f_chunk_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 6, 12)) & uvec3(0x3Fu, 0x3Fu, 0x1FFFFu)) - ivec3(0, 0, EXTRA_NEG_Z)); f_pos = f_chunk_pos + model_offs; f_pos.z -= 250.0 * (1.0 - min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0)); diff --git a/common/src/generation.rs b/common/src/generation.rs index f33583d243..22cf420021 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -101,7 +101,7 @@ impl ChunkSupplement { pub fn add_entity(&mut self, entity: EntityInfo) { self.entities.push(entity); } } -fn get_npc_name< +pub fn get_npc_name< 'a, Species, SpeciesData: for<'b> core::ops::Index<&'b Species, Output = npc::SpeciesNames>, diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index af72e1b215..092777e205 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -114,6 +114,10 @@ impl<'a> System<'a> for Sys { const MIN_ATTACK_DIST: f32 = 3.25; let scale = scales.get(entity).map(|s| s.0).unwrap_or(1.0); + + // This controls how picky NPCs are about their pathfinding. Giants are larger and so + // can afford to be less precise when trying to move around the world (especially since + // they would otherwise get stuck on obstacles that smaller entities would not). let traversal_tolerance = scale; let mut do_idle = false; diff --git a/server/src/cmd.rs b/server/src/cmd.rs index b9a107d4d8..7bc96dde8f 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -216,7 +216,7 @@ lazy_static! { "waypoint", "{}", "/waypoint : Set your waypoint to your current position", - false, + true, handle_waypoint, ), ChatCommand::new( diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index d268daa5f0..b76d06ccec 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -5,9 +5,10 @@ use common::{ comp::{self, item, CharacterAbility, Item, ItemConfig, Player, Pos}, event::{EventBus, ServerEvent}, msg::ServerMsg, - npc::{self, NPC_NAMES}, + npc::NPC_NAMES, state::TerrainChanges, terrain::TerrainGrid, + generation::get_npc_name, }; use rand::Rng; use specs::{Join, Read, ReadStorage, System, Write, WriteExpect, WriteStorage}; @@ -105,89 +106,6 @@ impl<'a> System<'a> for Sys { continue; } - fn get_npc_name< - 'a, - Species, - SpeciesData: for<'b> core::ops::Index<&'b Species, Output = npc::SpeciesNames>, - >( - body_data: &'a comp::BodyData, - species: Species, - ) -> &'a str { - &body_data.species[&species].generic - } - - /* - const SPAWN_NPCS: &'static [fn() -> ( - String, - comp::Body, - Option, - comp::Alignment, - )] = &[ - (|| { - let body = comp::humanoid::Body::random(); - ( - format!("{} Traveler", get_npc_name(&NPC_NAMES.humanoid, body.race)), - comp::Body::Humanoid(body), - Some(assets::load_expect_cloned( - "common.items.weapons.starter_axe", - )), - comp::Alignment::Npc, - ) - }) as _, - (|| { - let body = comp::humanoid::Body::random(); - ( - format!("{} Bandit", get_npc_name(&NPC_NAMES.humanoid, body.race)), - comp::Body::Humanoid(body), - Some(assets::load_expect_cloned( - "common.items.weapons.short_sword_0", - )), - comp::Alignment::Enemy, - ) - }) as _, - (|| { - let body = comp::quadruped_medium::Body::random(); - ( - get_npc_name(&NPC_NAMES.quadruped_medium, body.species).into(), - comp::Body::QuadrupedMedium(body), - None, - comp::Alignment::Enemy, - ) - }) as _, - (|| { - let body = comp::bird_medium::Body::random(); - ( - get_npc_name(&NPC_NAMES.bird_medium, body.species).into(), - comp::Body::BirdMedium(body), - None, - comp::Alignment::Wild, - ) - }) as _, - (|| { - let body = comp::critter::Body::random(); - ( - get_npc_name(&NPC_NAMES.critter, body.species).into(), - comp::Body::Critter(body), - None, - comp::Alignment::Wild, - ) - }) as _, - (|| { - let body = comp::quadruped_small::Body::random(); - ( - get_npc_name(&NPC_NAMES.quadruped_small, body.species).into(), - comp::Body::QuadrupedSmall(body), - None, - comp::Alignment::Wild, - ) - }), - ]; - let (name, mut body, main, alignment) = SPAWN_NPCS - .choose(&mut rand::thread_rng()) - .expect("SPAWN_NPCS is nonempty")( - ); - */ - let mut body = entity.body; let name = entity.name.unwrap_or("Unnamed".to_string()); let alignment = entity.alignment; diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index b49e3a4799..962a6ed93e 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -44,15 +44,11 @@ impl Meshable for Segment { for x in 0..3 { for y in 0..3 { for z in 0..3 { - ls[z][y][x] = if self + ls[z][y][x] = self .get(pos + Vec3::new(x as i32, y as i32, z as i32) - 1) .map(|v| v.is_empty()) .unwrap_or(true) - { - Some(1.0) - } else { - None - }; + .then_some(1.0); } } } @@ -97,15 +93,11 @@ impl Meshable for Segment { for x in 0..3 { for y in 0..3 { for z in 0..3 { - ls[z][y][x] = if self + ls[z][y][x] = self .get(pos + Vec3::new(x as i32, y as i32, z as i32) - 1) .map(|v| v.is_empty()) .unwrap_or(true) - { - Some(1.0) - } else { - None - }; + .then_some(1.0); } } } diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index 59e9be7aef..402b442ed3 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -28,7 +28,7 @@ impl Blendable for BlockKind { fn calc_light + ReadVol + Debug>( bounds: Aabb, vol: &VolGrid2d, -) -> impl FnMut(Vec3) -> Option + '_ { +) -> impl FnMut(Vec3) -> f32 + '_ { const UNKNOWN: u8 = 255; const OPAQUE: u8 = 254; const SUNLIGHT: u8 = 24; @@ -189,22 +189,12 @@ fn calc_light + ReadVol + Debug>( } move |wpos| { - if vol_cached - .get(wpos) - .map(|block| block.is_opaque()) - .unwrap_or(false) - { - None - } else { - let pos = wpos - outer.min; - Some( - light_map - .get(lm_idx(pos.x, pos.y, pos.z)) - .filter(|l| **l != OPAQUE && **l != UNKNOWN) - .map(|l| *l as f32 / SUNLIGHT as f32) - .unwrap_or(0.0), - ) - } + let pos = wpos - outer.min; + light_map + .get(lm_idx(pos.x, pos.y, pos.z)) + .filter(|l| **l != OPAQUE && **l != UNKNOWN) + .map(|l| *l as f32 / SUNLIGHT as f32) + .unwrap_or(0.0) } } @@ -307,15 +297,32 @@ impl + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable + ReadVol + Debug> Meshable| { let pos = (pos + 1).map(|e| e as usize); - unsafe { - darknesses - .get_unchecked(pos.z) - .get_unchecked(pos.y) - .get_unchecked(pos.x) - .is_none() - } + darknesses[pos.z][pos.y][pos.x].is_none() }; let (s1, s2) = ( @@ -45,12 +39,11 @@ fn get_ao_quad( for x in 0..2 { for y in 0..2 { let dark_pos = shift + offs[0] * x + offs[1] * y + 1; - if let Some(dark) = unsafe { - darknesses - .get_unchecked(dark_pos.z as usize) - .get_unchecked(dark_pos.y as usize) - .get_unchecked(dark_pos.x as usize) - } { + if let Some(dark) = darknesses + [dark_pos.z as usize] + [dark_pos.y as usize] + [dark_pos.x as usize] + { darkness += dark; total += 1.0; } diff --git a/voxygen/src/render/mesh.rs b/voxygen/src/render/mesh.rs index 2b708f1fde..d0c48275c6 100644 --- a/voxygen/src/render/mesh.rs +++ b/voxygen/src/render/mesh.rs @@ -66,8 +66,6 @@ impl Mesh

{ } } - pub fn verts(&self) -> &[P::Vertex] { &self.verts } - pub fn iter(&self) -> std::slice::Iter { self.verts.iter() } } diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index 103e9b7d14..901e09523e 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -54,7 +54,7 @@ impl Civs { for _ in 0..INITIAL_CIV_COUNT { log::info!("Creating civilisation..."); - if let None = this.birth_civ(&mut ctx.reseed()) { + if this.birth_civ(&mut ctx.reseed()).is_none() { log::warn!("Failed to find starting site for civilisation."); } } @@ -481,8 +481,9 @@ fn find_path( .and_then(|path| astar.get_cheapest_cost().map(|cost| (path, cost))) } -/// Return true if travel between a location and a chunk next to it is permitted -/// (TODO: by whom?) +/// Return Some if travel between a location and a chunk next to it is permitted +/// If permitted, the approximate relative const of traversal is given +// (TODO: by whom?) fn walk_in_dir(sim: &WorldSim, a: Vec2, dir: Vec2) -> Option { if loc_suitable_for_walking(sim, a) && loc_suitable_for_walking(sim, a + dir) { let a_chunk = sim.get(a)?; diff --git a/world/src/sim/map.rs b/world/src/sim/map.rs index 4dd96c3700..d37e5641a5 100644 --- a/world/src/sim/map.rs +++ b/world/src/sim/map.rs @@ -298,7 +298,7 @@ impl MapConfig { }; let rgba = if is_path { - (0x20, 0x19, 0x13, 255) + (0x20, 0x19, 0x13, 0xFF) } else { rgba }; diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 459ad921ef..56a0d2b67e 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -44,19 +44,6 @@ pub fn intersect(a: [Vec2; 2], b: [Vec2; 2]) -> Option> { } } -pub fn dist_to_line(line: [Vec2; 2], p: Vec2) -> f32 { - let lsq = line[0].distance_squared(line[1]); - - if lsq == 0.0 { - line[0].distance(p) - } else { - let t = ((p - line[0]).dot(line[1] - line[0]) / lsq) - .max(0.0) - .min(1.0); - p.distance(line[0] + (line[1] - line[0]) * t) - } -} - pub fn center_of(p: [Vec2; 3]) -> Vec2 { let ma = -1.0 / gradient([p[0], p[1]]); let mb = -1.0 / gradient([p[1], p[2]]);