diff --git a/common/src/comp/body.rs b/common/src/comp/body.rs index ff0117f9e6..dcff04d592 100644 --- a/common/src/comp/body.rs +++ b/common/src/comp/body.rs @@ -695,8 +695,7 @@ impl Body { object::Body::HaniwaSentry => 60, object::Body::SeaLantern => 100, object::Body::GnarlingTotemGreen => 25, - object::Body::GnarlingTotemRed - | object::Body::GnarlingTotemWhite => 35, + object::Body::GnarlingTotemRed | object::Body::GnarlingTotemWhite => 35, _ => 1000, }, Body::Golem(golem) => match golem.species { diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index f71e38652c..ac771bbdab 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -24,7 +24,10 @@ use common_base::span; use hashbrown::HashMap; use rand::prelude::*; use specs::{Join, WorldExt}; -use std::{f32::consts::PI, time::Duration}; +use std::{ + f32::consts::{PI, TAU}, + time::Duration, +}; use vek::*; pub struct ParticleMgr { @@ -978,7 +981,7 @@ impl ParticleMgr { kind: buff::BuffKind::Burning, .. } => { - let num_particles = aura.radius.powi(2) * dt / inline_tweak::tweak!(250.0); + let num_particles = aura.radius.powi(2) * dt / 250.0; let num_particles = num_particles.floor() as usize + if rng.gen_bool(f64::from(num_particles % 1.0)) { 1 @@ -988,13 +991,11 @@ impl ParticleMgr { self.particles .resize_with(self.particles.len() + num_particles, || { let rand_pos = { - let mut x = (rng.gen::() - 0.5) * 2.0; - let mut y = (rng.gen::() - 0.5) * 2.0; - while (x.powi(2) + y.powi(2)) > 1.0 { - x = (rng.gen::() - 0.5) * 2.0; - y = (rng.gen::() - 0.5) * 2.0; - } - Vec2::new(x, y) * aura.radius + pos.0.xy() + let theta = rng.gen::() * TAU; + let radius = aura.radius * rng.gen::().sqrt(); + let x = radius * theta.sin(); + let y = radius * theta.cos(); + Vec2::new(x, y) + pos.0.xy() }; let max_dur = Duration::from_secs(1); Particle::new_directed( @@ -1313,12 +1314,12 @@ impl ParticleMgr { let position = pos.0 + distance * Vec3::new(arc_position.cos(), arc_position.sin(), 0.0); - let ray_length = 10.0; + let half_ray_length = 10.0; let mut last_air = false; let _ = terrain .ray( - position + Vec3::unit_z() * ray_length, - position - Vec3::unit_z() * ray_length, + position + Vec3::unit_z() * half_ray_length, + position - Vec3::unit_z() * half_ray_length, ) .for_each(|block: &Block, pos: Vec3| { if block.is_solid() && block.get_sprite().is_none() { diff --git a/world/src/site2/gen.rs b/world/src/site2/gen.rs index c668473ea3..d7a9e17345 100644 --- a/world/src/site2/gen.rs +++ b/world/src/site2/gen.rs @@ -318,12 +318,17 @@ impl Fill { }, Primitive::Repeat(prim, offset, count) => { let aabb = self.get_bounds(tree, *prim); - let diff = pos - aabb.min; + let aabb_corner = { + let min_red = aabb.min.map2(*offset, |a, b| if b < 0 { 0 } else { a }); + let max_red = aabb.max.map2(*offset, |a, b| if b < 0 { a } else { 0 }); + min_red + max_red + }; + let diff = pos - aabb_corner; let min = diff .map2(*offset, |a, b| if b == 0 { i32::MAX } else { a / b }) .reduce_min() .min(*count); - let pos = aabb.min + diff - offset * min; + let pos = pos - offset * min; self.contains_at(tree, *prim, pos) }, } diff --git a/world/src/site2/mod.rs b/world/src/site2/mod.rs index dc5d17ae6f..7bec90181f 100644 --- a/world/src/site2/mod.rs +++ b/world/src/site2/mod.rs @@ -3,10 +3,11 @@ pub mod plot; mod tile; pub mod util; -use self::tile::{HazardKind, KeepKind, Ori, RoofKind, Tile, TileGrid, TileKind, TILE_SIZE}; +use self::tile::{HazardKind, KeepKind, RoofKind, Tile, TileGrid, TileKind, TILE_SIZE}; pub use self::{ gen::{aabr_with_z, Fill, Painter, Primitive, Structure}, plot::{Plot, PlotKind}, + util::Dir, }; use crate::{ site::{namegen::NameGen, SpawnRules}, @@ -608,13 +609,13 @@ impl Site { }); let wall_north = Tile { - kind: TileKind::Wall(Ori::North), + kind: TileKind::Wall(Dir::Y), plot: Some(plot), hard_alt: Some(castle_alt), }; let wall_east = Tile { - kind: TileKind::Wall(Ori::East), + kind: TileKind::Wall(Dir::X), plot: Some(plot), hard_alt: Some(castle_alt), }; @@ -697,7 +698,7 @@ impl Site { max: aabr.center() + 3, }, Tile { - kind: TileKind::Wall(Ori::North), + kind: TileKind::Wall(Dir::Y), plot: Some(plot), hard_alt: Some(castle_alt), }, diff --git a/world/src/site2/plot/castle.rs b/world/src/site2/plot/castle.rs index dca21d2916..05afc40bcd 100644 --- a/world/src/site2/plot/castle.rs +++ b/world/src/site2/plot/castle.rs @@ -76,7 +76,7 @@ impl Structure for Castle { let wpos = site.tile_wpos(tile_pos); match site.tiles.get(tile_pos).kind.clone() { TileKind::Wall(ori) => { - let dir = ori.dir(); + let dir = ori.to_vec2(); let wall = painter.prim(Primitive::Aabb(Aabb { min: wpos.with_z(self.alt - 20), max: (wpos + ts).with_z(self.alt + wall_height), diff --git a/world/src/site2/plot/gnarling.rs b/world/src/site2/plot/gnarling.rs index 4cdbdf67cc..d52a3de95b 100644 --- a/world/src/site2/plot/gnarling.rs +++ b/world/src/site2/plot/gnarling.rs @@ -25,7 +25,7 @@ pub struct GnarlingFortification { wall_towers: Vec>, // Structure indicates the kind of structure it is, vec2 is relative position of a hut compared // to origin, ori tells which way structure should face - structure_locations: Vec<(GnarlingStructure, Vec3, Ori)>, + structure_locations: Vec<(GnarlingStructure, Vec3, Dir)>, tunnels: Tunnels, } @@ -171,7 +171,7 @@ impl GnarlingFortification { ]; let desired_structures = wall_radius.pow(2) / 100; - let mut structure_locations = Vec::<(GnarlingStructure, Vec3, Ori)>::new(); + let mut structure_locations = Vec::<(GnarlingStructure, Vec3, Dir)>::new(); for _ in 0..desired_structures { if let Some((hut_loc, kind)) = attempt(50, || { // Choose structure kind @@ -238,12 +238,12 @@ impl GnarlingFortification { )) } }) { - let dir_to_center = Ori::from_vec2(hut_loc.xy()).opposite(); + let dir_to_center = Dir::from_vector(hut_loc.xy()).opposite(); let door_rng: u32 = rng.gen_range(0..9); let door_dir = match door_rng { 0..=3 => dir_to_center, - 4..=5 => dir_to_center.cw(), - 6..=7 => dir_to_center.ccw(), + 4..=5 => dir_to_center.rotated_cw(), + 6..=7 => dir_to_center.rotated_ccw(), // Should only be 8 _ => dir_to_center.opposite(), }; @@ -263,7 +263,7 @@ impl GnarlingFortification { let chieftain_hut_loc = ((inner_tower_locs[0] + inner_tower_locs[1]) + 2 * outer_wall_corners[chieftain_indices[1]]) / 4; - let chieftain_hut_ori = Ori::from_vec2(chieftain_hut_loc).opposite(); + let chieftain_hut_ori = Dir::from_vector(chieftain_hut_loc).opposite(); structure_locations.push(( GnarlingStructure::ChieftainHut, chieftain_hut_loc.with_z(rpos_height(chieftain_hut_loc)), @@ -284,7 +284,7 @@ impl GnarlingFortification { structure_locations.push(( GnarlingStructure::WatchTower, loc.with_z(rpos_height(*loc)), - Ori::North, + Dir::Y, )); }); @@ -755,7 +755,7 @@ impl Structure for GnarlingFortification { painter: &Painter, wpos: Vec2, alt: i32, - door_dir: Ori, + door_dir: Dir, hut_radius: f32, hut_wall_height: f32, door_height: i32, @@ -799,16 +799,16 @@ impl Structure for GnarlingFortification { // Door let aabb_min = |dir| { match dir { - Ori::North | Ori::East => wpos - Vec2::one(), - Ori::South | Ori::West => wpos + randx / 5 + 1, + Dir::X | Dir::Y => wpos - Vec2::one(), + Dir::NegX | Dir::NegY => wpos + randx / 5 + 1, } .with_z(alt + 1) }; let aabb_max = |dir| { (match dir { - Ori::North | Ori::East => wpos + randx / 5 + 1, - Ori::South | Ori::West => wpos - Vec2::one(), - } + dir.dir() * hut_radius as i32) + Dir::X | Dir::Y => wpos + randx / 5 + 1, + Dir::NegX | Dir::NegY => wpos - Vec2::one(), + } + dir.to_vec2() * hut_radius as i32) .with_z(alt + 1 + door_height) }; @@ -881,30 +881,26 @@ impl Structure for GnarlingFortification { painter.fill(platform, darkwood.clone()); - let support_1 = painter.line( - (wpos - 19).with_z(alt - 3), - (wpos - 19).with_z(alt + raise), - 2.0, - ); - let support_inner_1 = painter.aabb(Aabb { - min: (wpos - 19).with_z(alt - 10), - max: (wpos - 15).with_z(alt + raise), - }); - let support_2 = support_1.translate(Vec3::new(0, 37, 0)); - let support_3 = support_1.translate(Vec3::new(37, 0, 0)); - let support_4 = support_1.translate(Vec3::new(37, 37, 0)); - let support_inner_1 = support_inner_1.translate(Vec3::new(0, 17, 0)); - let support_inner_2 = support_inner_1.translate(Vec3::new(34, 0, 0)); - let support_inner_3 = support_inner_1.translate(Vec3::new(17, 17, 0)); - let support_inner_4 = support_inner_1.translate(Vec3::new(17, -17, 0)); - let supports = support_1 - .union(support_2) - .union(support_3) - .union(support_4) - .union(support_inner_1) - .union(support_inner_2) - .union(support_inner_3) - .union(support_inner_4); + let supports = painter + .line( + (wpos - 19).with_z(alt - 3), + (wpos - 19).with_z(alt + raise), + 2.0, + ) + .repeat(Vec3::new(37, 0, 0), 1) + .repeat(Vec3::new(0, 37, 0), 1); + + let supports_inner = painter + .aabb(Aabb { + min: (wpos - 19).with_z(alt - 10) + Vec3::unit_y() * 17, + max: (wpos - 15).with_z(alt + raise) + Vec3::unit_y() * 17, + }) + .repeat(Vec3::new(17, 17, 0), 1) + .repeat(Vec3::new(17, -17, 0), 1); + // let support_inner_2 = support_inner_1.translate(Vec3::new(34, 0, 0)); + // let support_inner_3 = support_inner_1.translate(Vec3::new(17, 17, 0)); + // let support_inner_4 = support_inner_1.translate(Vec3::new(17, -17, 0)); + let supports = supports.union(supports_inner); painter.fill(supports, darkwood.clone()); let height_1 = 10.0; diff --git a/world/src/site2/tile.rs b/world/src/site2/tile.rs index bb43e09724..4f82952b6f 100644 --- a/world/src/site2/tile.rs +++ b/world/src/site2/tile.rs @@ -183,7 +183,7 @@ pub enum TileKind { Road { a: u16, b: u16, w: u16 }, Building, Castle, - Wall(Ori), + Wall(Dir), Tower(RoofKind), Keep(KeepKind), Gate, @@ -243,7 +243,7 @@ pub enum HazardKind { pub enum KeepKind { Middle, Corner, - Wall(Ori), + Wall(Dir), } #[derive(Copy, Clone, PartialEq)] @@ -251,52 +251,3 @@ pub enum RoofKind { Parapet, Pyramid, } - -#[repr(u8)] -#[derive(Copy, Clone, PartialEq)] -pub enum Ori { - North = 0, - East = 1, - South = 2, - West = 3, -} - -impl Ori { - pub fn dir(self) -> Vec2 { CARDINALS[self as u8 as usize] } - - pub fn cw(self) -> Self { - match self { - Ori::North => Ori::East, - Ori::East => Ori::South, - Ori::South => Ori::West, - Ori::West => Ori::North, - } - } - - pub fn ccw(self) -> Self { - match self { - Ori::North => Ori::West, - Ori::East => Ori::North, - Ori::South => Ori::East, - Ori::West => Ori::South, - } - } - - pub fn opposite(self) -> Self { - match self { - Ori::North => Ori::South, - Ori::East => Ori::West, - Ori::South => Ori::North, - Ori::West => Ori::East, - } - } - - pub fn from_vec2(vec: Vec2) -> Self { - match vec { - vec if vec.x.abs() > vec.y.abs() && vec.x > 0 => Ori::East, - vec if vec.x.abs() > vec.y.abs() => Ori::West, - vec if vec.y > 0 => Ori::North, - _ => Ori::South, - } - } -} diff --git a/world/src/site2/util/mod.rs b/world/src/site2/util/mod.rs index 09624a08e6..99eb36abef 100644 --- a/world/src/site2/util/mod.rs +++ b/world/src/site2/util/mod.rs @@ -44,7 +44,7 @@ impl Dir { /// Rotate the direction anti clock wise #[must_use] - pub fn rotate_left(self) -> Dir { + pub fn rotated_ccw(self) -> Dir { match self { Dir::X => Dir::Y, Dir::NegX => Dir::NegY, @@ -55,7 +55,7 @@ impl Dir { /// Rotate the direction clock wise #[must_use] - pub fn rotate_right(self) -> Dir { + pub fn rotated_cw(self) -> Dir { match self { Dir::X => Dir::NegY, Dir::NegX => Dir::Y, @@ -121,8 +121,8 @@ impl Dir { match other { Dir::X => self, Dir::NegX => self.opposite(), - Dir::Y => self.rotate_right(), - Dir::NegY => self.rotate_left(), + Dir::Y => self.rotated_cw(), + Dir::NegY => self.rotated_ccw(), } }