From 02f446fe4b5e514f1eb85bbce67f72cd57853f56 Mon Sep 17 00:00:00 2001 From: Snowram Date: Sun, 7 Feb 2021 01:45:30 +0100 Subject: [PATCH 1/3] Adds lights to dungeons --- assets/voxygen/voxel/sprite_manifest.ron | 15 ++++-- common/src/terrain/block.rs | 1 + common/src/terrain/sprite.rs | 2 + world/src/site/dungeon/mod.rs | 64 +++++++++++++++++++++--- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/assets/voxygen/voxel/sprite_manifest.ron b/assets/voxygen/voxel/sprite_manifest.ron index 6f5d74d391..454163267f 100644 --- a/assets/voxygen/voxel/sprite_manifest.ron +++ b/assets/voxygen/voxel/sprite_manifest.ron @@ -1773,13 +1773,20 @@ HangingSign: Some(( WallLamp: Some(( variations: [ ( - model: "voxygen.voxel.sprite.furniture.lamp_wall-0", - offset: (-6.5, -3.5, 0.0), + model: "voxygen.voxel.sprite.furniture.lamp_wall-1", + offset: (-10.5, -12.5, 0.0), lod_axes: (1.0, 1.0, 1.0), ), + ], + wind_sway: 0.0, +)), + +// WallLampSmall +WallLampSmall: Some(( + variations: [ ( - model: "voxygen.voxel.sprite.furniture.lamp_wall-1", - offset: (-10.5, -9.0, 0.0), + model: "voxygen.voxel.sprite.furniture.lamp_wall-0", + offset: (-5.5, 0.5, 0.0), lod_axes: (1.0, 1.0, 1.0), ), ], diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 5b2fd5e78d..52abcebda6 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -172,6 +172,7 @@ impl Block { SpriteKind::StreetLamp | SpriteKind::StreetLampTall => Some(24), SpriteKind::Ember => Some(20), SpriteKind::WallLamp => Some(16), + SpriteKind::WallLampSmall => Some(16), SpriteKind::FireBowlGround => Some(16), SpriteKind::Velorite | SpriteKind::VeloriteFrag => Some(6), SpriteKind::CaveMushroom => Some(12), diff --git a/common/src/terrain/sprite.rs b/common/src/terrain/sprite.rs index 9fccea234a..884c0e4be5 100644 --- a/common/src/terrain/sprite.rs +++ b/common/src/terrain/sprite.rs @@ -126,6 +126,7 @@ make_case_elim!( RubySmall = 0x63, EmeraldSmall = 0x64, SapphireSmall = 0x65, + WallLampSmall = 0x66, } ); @@ -252,6 +253,7 @@ impl SpriteKind { | SpriteKind::HangingBasket | SpriteKind::HangingSign | SpriteKind::WallLamp + | SpriteKind::WallLampSmall | SpriteKind::Planter | SpriteKind::Shelf | SpriteKind::TableSide diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index 19f5263128..d7c0baf622 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -1117,6 +1117,19 @@ impl Floor { .min_by_key(|nearest| rpos.distance_squared(*nearest)) } + // Find relative orientation of a position relative to another position + fn relative_ori(pos1: Vec2, pos2: Vec2) -> u8 { + if pos1.x == pos2.x && pos1.y < pos2.y { + 4 + } else if pos1.x > pos2.x && pos1.y == pos2.y { + 6 + } else if pos1.x == pos2.x && pos1.y > pos2.y { + 8 + } else { + 2 + } + } + #[allow(clippy::unnested_or_patterns)] // TODO: Pending review in #587 fn col_sampler<'a>( &'a self, @@ -1194,7 +1207,19 @@ impl Floor { move |z| match self.tiles.get(tile_pos) { Some(Tile::Solid) => BlockMask::nothing(), Some(Tile::Tunnel) => { - if dist_to_wall >= wall_thickness + let light_offset: i32 = 7; + if (dist_to_wall - 4.0).abs() < f32::EPSILON + && rtile_pos + .map(|e| e % light_offset == 0) + .reduce(|x, y| x ^ y) + && z == 1 + { + let ori = + Floor::relative_ori(self.nearest_wall(rpos).unwrap_or_default(), rpos); + // NOTE: Used only for dynamic elements like chests and entities! + let furniture = SpriteKind::WallLamp; + BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) + } else if dist_to_wall >= wall_thickness && (z as f32) < tunnel_height * (1.0 - tunnel_dist.powi(4)) { if z == 0 { floor_sprite } else { vacant } @@ -1219,8 +1244,19 @@ impl Floor { BlockMask::nothing() }, Some(Tile::Room(_)) => { + let light_offset: i32 = 7; if z == 0 { floor_sprite + } else if (dist_to_wall - 4.0).abs() < f32::EPSILON + && rtile_pos + .map(|e| e % light_offset == 0) + .reduce(|x, y| x ^ y) + && z == 1 + { + let ori = + Floor::relative_ori(self.nearest_wall(rpos).unwrap_or_default(), rpos); + let furniture = SpriteKind::WallLamp; + BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else { vacant } @@ -1230,16 +1266,32 @@ impl Floor { .resolve_with(vacant) }, Some(Tile::UpStair(room)) => { - let mut block = make_staircase( + let inner_radius: f32 = 0.5; + let stretch: f32 = 9.0; + let block = make_staircase( Vec3::new(rtile_pos.x, rtile_pos.y, z), TILE_SIZE as f32 / 2.0, - 0.5, - 9.0, + inner_radius, + stretch, ); + let furniture = SpriteKind::WallLampSmall; + let ori = + Floor::relative_ori(self.nearest_wall(rtile_pos).unwrap_or_default(), rpos); if z < self.rooms[*room].height { - block = block.resolve_with(vacant); + block.resolve_with(vacant) + } else if z as f32 % stretch == 0.0 + && rtile_pos.x == -TILE_SIZE / 2 + && rtile_pos.y == 0 + { + BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) + } else { + make_staircase( + Vec3::new(rtile_pos.x, rtile_pos.y, z), + TILE_SIZE as f32 / 2.0, + inner_radius, + stretch, + ) } - block }, None => BlockMask::nothing(), } From 477bdfdfe7af0350d22342284d40de20c0636085 Mon Sep 17 00:00:00 2001 From: Snowram Date: Mon, 8 Feb 2021 00:04:10 +0100 Subject: [PATCH 2/3] Adresses some comments, various visual tweaks --- .../voxel/sprite/furniture/sconce_wall-0.vox | 3 + assets/voxygen/voxel/sprite_manifest.ron | 12 ++++ common/src/terrain/block.rs | 1 + common/src/terrain/sprite.rs | 2 + voxygen/src/scene/terrain/watcher.rs | 1 + world/src/site/dungeon/mod.rs | 58 +++++++++++++------ 6 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 assets/voxygen/voxel/sprite/furniture/sconce_wall-0.vox diff --git a/assets/voxygen/voxel/sprite/furniture/sconce_wall-0.vox b/assets/voxygen/voxel/sprite/furniture/sconce_wall-0.vox new file mode 100644 index 0000000000..79c62f0ddd --- /dev/null +++ b/assets/voxygen/voxel/sprite/furniture/sconce_wall-0.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7dae9af55f76f7f9c39c1cd2ac2ea0dd10c90b8d0343e698337f0f38af8b89f8 +size 1608 diff --git a/assets/voxygen/voxel/sprite_manifest.ron b/assets/voxygen/voxel/sprite_manifest.ron index 454163267f..2de54b1163 100644 --- a/assets/voxygen/voxel/sprite_manifest.ron +++ b/assets/voxygen/voxel/sprite_manifest.ron @@ -1793,6 +1793,18 @@ WallLampSmall: Some(( wind_sway: 0.0, )), +// WallSconce +WallSconce: Some(( + variations: [ + ( + model: "voxygen.voxel.sprite.furniture.sconce_wall-0", + offset: (-2.5, -1.5, 0.0), + lod_axes: (1.0, 1.0, 1.0), + ), + ], + wind_sway: 0.0, +)), + // Planter Planter: Some(( variations: [ diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 52abcebda6..5da34b509f 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -173,6 +173,7 @@ impl Block { SpriteKind::Ember => Some(20), SpriteKind::WallLamp => Some(16), SpriteKind::WallLampSmall => Some(16), + SpriteKind::WallSconce => Some(16), SpriteKind::FireBowlGround => Some(16), SpriteKind::Velorite | SpriteKind::VeloriteFrag => Some(6), SpriteKind::CaveMushroom => Some(12), diff --git a/common/src/terrain/sprite.rs b/common/src/terrain/sprite.rs index 884c0e4be5..8756584c33 100644 --- a/common/src/terrain/sprite.rs +++ b/common/src/terrain/sprite.rs @@ -127,6 +127,7 @@ make_case_elim!( EmeraldSmall = 0x64, SapphireSmall = 0x65, WallLampSmall = 0x66, + WallSconce = 0x67, } ); @@ -254,6 +255,7 @@ impl SpriteKind { | SpriteKind::HangingSign | SpriteKind::WallLamp | SpriteKind::WallLampSmall + | SpriteKind::WallSconce | SpriteKind::Planter | SpriteKind::Shelf | SpriteKind::TableSide diff --git a/voxygen/src/scene/terrain/watcher.rs b/voxygen/src/scene/terrain/watcher.rs index 02cfdbb087..50f42d1668 100644 --- a/voxygen/src/scene/terrain/watcher.rs +++ b/voxygen/src/scene/terrain/watcher.rs @@ -71,6 +71,7 @@ impl BlocksOfInterest { Some(SpriteKind::StreetLampTall) => { fire_bowls.push(pos + Vec3::unit_z() * 4) }, + Some(SpriteKind::WallSconce) => fire_bowls.push(pos + Vec3::unit_z()), Some(SpriteKind::Beehive) => beehives.push(pos), Some(SpriteKind::Reed) => reeds.push(pos), Some(SpriteKind::PinkFlower) => flowers.push(pos), diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index d7c0baf622..425f092069 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -1208,7 +1208,7 @@ impl Floor { Some(Tile::Solid) => BlockMask::nothing(), Some(Tile::Tunnel) => { let light_offset: i32 = 7; - if (dist_to_wall - 4.0).abs() < f32::EPSILON + if (dist_to_wall - wall_thickness) as i32 == 1 && rtile_pos .map(|e| e % light_offset == 0) .reduce(|x, y| x ^ y) @@ -1216,8 +1216,7 @@ impl Floor { { let ori = Floor::relative_ori(self.nearest_wall(rpos).unwrap_or_default(), rpos); - // NOTE: Used only for dynamic elements like chests and entities! - let furniture = SpriteKind::WallLamp; + let furniture = SpriteKind::WallSconce; BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else if dist_to_wall >= wall_thickness && (z as f32) < tunnel_height * (1.0 - tunnel_dist.powi(4)) @@ -1230,19 +1229,38 @@ impl Floor { Some(Tile::Room(room)) | Some(Tile::DownStair(room)) if dist_to_wall < wall_thickness || z as f32 - >= self.rooms[*room].height as f32 * (1.0 - tunnel_dist.powi(4)) - || self.rooms[*room] - .pillars - .map(|pillar_space| { - tile_pos - .map(|e| e.rem_euclid(pillar_space) == 0) - .reduce_and() - && rtile_pos.map(|e| e as f32).magnitude_squared() < 3.5f32.powi(2) - }) - .unwrap_or(false) => + >= self.rooms[*room].height as f32 * (1.0 - tunnel_dist.powi(4)) => { BlockMask::nothing() }, + + Some(Tile::Room(room)) | Some(Tile::DownStair(room)) + if self.rooms[*room] + .pillars + .map(|pillar_space| { + tile_pos + .map(|e| e.rem_euclid(pillar_space) == 0) + .reduce_and() + && rtile_pos.map(|e| e as f32).magnitude_squared() < 3.5f32.powi(2) + }) + .unwrap_or(false) => + { + if z == 1 && rtile_pos.map(|e| e as f32).magnitude_squared() > 3.0f32.powi(2) { + let ori = Floor::relative_ori( + self.nearest_wall(rtile_pos).unwrap_or_default(), + rtile_pos, + ); + let furniture = SpriteKind::WallSconce; + BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) + } else if z < self.rooms[*room].height + && rtile_pos.map(|e| e as f32).magnitude_squared() > 3.0f32.powi(2) + { + vacant + } else { + BlockMask::nothing() + } + } + Some(Tile::Room(_)) => { let light_offset: i32 = 7; if z == 0 { @@ -1253,9 +1271,11 @@ impl Floor { .reduce(|x, y| x ^ y) && z == 1 { - let ori = - Floor::relative_ori(self.nearest_wall(rpos).unwrap_or_default(), rpos); - let furniture = SpriteKind::WallLamp; + let ori = Floor::relative_ori( + self.nearest_wall(rpos).unwrap_or_else(Vec2::zero), + rpos, + ); + let furniture = SpriteKind::WallSconce; BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else { vacant @@ -1275,8 +1295,10 @@ impl Floor { stretch, ); let furniture = SpriteKind::WallLampSmall; - let ori = - Floor::relative_ori(self.nearest_wall(rtile_pos).unwrap_or_default(), rpos); + let ori = Floor::relative_ori( + self.nearest_wall(rtile_pos).unwrap_or_else(Vec2::zero), + rpos, + ); if z < self.rooms[*room].height { block.resolve_with(vacant) } else if z as f32 % stretch == 0.0 From 6ac52daeaed58a5677c22e28df5162344ab8a949 Mon Sep 17 00:00:00 2001 From: Snowram Date: Wed, 10 Feb 2021 00:30:16 +0100 Subject: [PATCH 3/3] Refactor, addresses more comments --- CHANGELOG.md | 1 + world/src/site/dungeon/mod.rs | 58 +++++++++++++++-------------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2afc16d3e..ae610fb41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Poise system (not currently accessible to players for balancing reasons) - Snow particles - Basic NPC interaction +- Lights in dungeons ### Changed diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index 425f092069..fc5b6c4ba4 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -1117,16 +1117,13 @@ impl Floor { .min_by_key(|nearest| rpos.distance_squared(*nearest)) } - // Find relative orientation of a position relative to another position + // Find orientation of a position relative to another position + #[allow(clippy::collapsible_if)] fn relative_ori(pos1: Vec2, pos2: Vec2) -> u8 { - if pos1.x == pos2.x && pos1.y < pos2.y { - 4 - } else if pos1.x > pos2.x && pos1.y == pos2.y { - 6 - } else if pos1.x == pos2.x && pos1.y > pos2.y { - 8 + if (pos1.x - pos2.x).abs() < (pos1.y - pos2.y).abs() { + if pos1.y > pos2.y { 4 } else { 8 } } else { - 2 + if pos1.x > pos2.x { 2 } else { 6 } } } @@ -1203,19 +1200,18 @@ impl Floor { }; let tunnel_height = if self.final_level { 16.0 } else { 8.0 }; + let pillar_thickness: i32 = 4; move |z| match self.tiles.get(tile_pos) { Some(Tile::Solid) => BlockMask::nothing(), Some(Tile::Tunnel) => { let light_offset: i32 = 7; if (dist_to_wall - wall_thickness) as i32 == 1 - && rtile_pos - .map(|e| e % light_offset == 0) - .reduce(|x, y| x ^ y) + && rtile_pos.map(|e| e % light_offset == 0).reduce_bitxor() && z == 1 { let ori = - Floor::relative_ori(self.nearest_wall(rpos).unwrap_or_default(), rpos); + Floor::relative_ori(rpos, self.nearest_wall(rpos).unwrap_or_default()); let furniture = SpriteKind::WallSconce; BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else if dist_to_wall >= wall_thickness @@ -1241,19 +1237,18 @@ impl Floor { tile_pos .map(|e| e.rem_euclid(pillar_space) == 0) .reduce_and() - && rtile_pos.map(|e| e as f32).magnitude_squared() < 3.5f32.powi(2) + && rtile_pos.map(|e| e as f32).magnitude_squared() + < (pillar_thickness as f32 + 0.5).powi(2) }) .unwrap_or(false) => { - if z == 1 && rtile_pos.map(|e| e as f32).magnitude_squared() > 3.0f32.powi(2) { - let ori = Floor::relative_ori( - self.nearest_wall(rtile_pos).unwrap_or_default(), - rtile_pos, - ); + if z == 1 && rtile_pos.product() == 0 && rtile_pos.sum().abs() == pillar_thickness { + let ori = Floor::relative_ori(rtile_pos, Vec2::zero()); let furniture = SpriteKind::WallSconce; BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else if z < self.rooms[*room].height - && rtile_pos.map(|e| e as f32).magnitude_squared() > 3.0f32.powi(2) + && rtile_pos.map(|e| e as f32).magnitude_squared() + > (pillar_thickness as f32 - 0.5).powi(2) { vacant } else { @@ -1262,18 +1257,16 @@ impl Floor { } Some(Tile::Room(_)) => { - let light_offset: i32 = 7; + let light_offset = 7; if z == 0 { floor_sprite - } else if (dist_to_wall - 4.0).abs() < f32::EPSILON - && rtile_pos - .map(|e| e % light_offset == 0) - .reduce(|x, y| x ^ y) + } else if dist_to_wall as i32 == 4 + && rtile_pos.map(|e| e % light_offset == 0).reduce_bitxor() && z == 1 { let ori = Floor::relative_ori( - self.nearest_wall(rpos).unwrap_or_else(Vec2::zero), rpos, + self.nearest_wall(rpos).unwrap_or_else(Vec2::zero), ); let furniture = SpriteKind::WallSconce; BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) @@ -1287,31 +1280,28 @@ impl Floor { }, Some(Tile::UpStair(room)) => { let inner_radius: f32 = 0.5; - let stretch: f32 = 9.0; + let stretch = 9; let block = make_staircase( Vec3::new(rtile_pos.x, rtile_pos.y, z), TILE_SIZE as f32 / 2.0, inner_radius, - stretch, + stretch as f32, ); - let furniture = SpriteKind::WallLampSmall; + let furniture = SpriteKind::WallSconce; let ori = Floor::relative_ori( - self.nearest_wall(rtile_pos).unwrap_or_else(Vec2::zero), rpos, + self.nearest_wall(rtile_pos).unwrap_or_else(Vec2::zero), ); if z < self.rooms[*room].height { block.resolve_with(vacant) - } else if z as f32 % stretch == 0.0 - && rtile_pos.x == -TILE_SIZE / 2 - && rtile_pos.y == 0 - { + } else if z % stretch == 0 && rtile_pos.x == -TILE_SIZE / 2 && rtile_pos.y == 0 { BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1) } else { make_staircase( Vec3::new(rtile_pos.x, rtile_pos.y, z), TILE_SIZE as f32 / 2.0, inner_radius, - stretch, + stretch as f32, ) } },