mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Refactor, addresses more comments
This commit is contained in:
parent
477bdfdfe7
commit
6ac52daeae
@ -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)
|
- Poise system (not currently accessible to players for balancing reasons)
|
||||||
- Snow particles
|
- Snow particles
|
||||||
- Basic NPC interaction
|
- Basic NPC interaction
|
||||||
|
- Lights in dungeons
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -1117,16 +1117,13 @@ impl Floor {
|
|||||||
.min_by_key(|nearest| rpos.distance_squared(*nearest))
|
.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<i32>, pos2: Vec2<i32>) -> u8 {
|
fn relative_ori(pos1: Vec2<i32>, pos2: Vec2<i32>) -> u8 {
|
||||||
if pos1.x == pos2.x && pos1.y < pos2.y {
|
if (pos1.x - pos2.x).abs() < (pos1.y - pos2.y).abs() {
|
||||||
4
|
if pos1.y > pos2.y { 4 } else { 8 }
|
||||||
} else if pos1.x > pos2.x && pos1.y == pos2.y {
|
|
||||||
6
|
|
||||||
} else if pos1.x == pos2.x && pos1.y > pos2.y {
|
|
||||||
8
|
|
||||||
} else {
|
} 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 tunnel_height = if self.final_level { 16.0 } else { 8.0 };
|
||||||
|
let pillar_thickness: i32 = 4;
|
||||||
|
|
||||||
move |z| match self.tiles.get(tile_pos) {
|
move |z| match self.tiles.get(tile_pos) {
|
||||||
Some(Tile::Solid) => BlockMask::nothing(),
|
Some(Tile::Solid) => BlockMask::nothing(),
|
||||||
Some(Tile::Tunnel) => {
|
Some(Tile::Tunnel) => {
|
||||||
let light_offset: i32 = 7;
|
let light_offset: i32 = 7;
|
||||||
if (dist_to_wall - wall_thickness) as i32 == 1
|
if (dist_to_wall - wall_thickness) as i32 == 1
|
||||||
&& rtile_pos
|
&& rtile_pos.map(|e| e % light_offset == 0).reduce_bitxor()
|
||||||
.map(|e| e % light_offset == 0)
|
|
||||||
.reduce(|x, y| x ^ y)
|
|
||||||
&& z == 1
|
&& z == 1
|
||||||
{
|
{
|
||||||
let ori =
|
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;
|
let furniture = SpriteKind::WallSconce;
|
||||||
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
||||||
} else if dist_to_wall >= wall_thickness
|
} else if dist_to_wall >= wall_thickness
|
||||||
@ -1241,19 +1237,18 @@ impl Floor {
|
|||||||
tile_pos
|
tile_pos
|
||||||
.map(|e| e.rem_euclid(pillar_space) == 0)
|
.map(|e| e.rem_euclid(pillar_space) == 0)
|
||||||
.reduce_and()
|
.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) =>
|
.unwrap_or(false) =>
|
||||||
{
|
{
|
||||||
if z == 1 && rtile_pos.map(|e| e as f32).magnitude_squared() > 3.0f32.powi(2) {
|
if z == 1 && rtile_pos.product() == 0 && rtile_pos.sum().abs() == pillar_thickness {
|
||||||
let ori = Floor::relative_ori(
|
let ori = Floor::relative_ori(rtile_pos, Vec2::zero());
|
||||||
self.nearest_wall(rtile_pos).unwrap_or_default(),
|
|
||||||
rtile_pos,
|
|
||||||
);
|
|
||||||
let furniture = SpriteKind::WallSconce;
|
let furniture = SpriteKind::WallSconce;
|
||||||
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
||||||
} else if z < self.rooms[*room].height
|
} 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
|
vacant
|
||||||
} else {
|
} else {
|
||||||
@ -1262,18 +1257,16 @@ impl Floor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Some(Tile::Room(_)) => {
|
Some(Tile::Room(_)) => {
|
||||||
let light_offset: i32 = 7;
|
let light_offset = 7;
|
||||||
if z == 0 {
|
if z == 0 {
|
||||||
floor_sprite
|
floor_sprite
|
||||||
} else if (dist_to_wall - 4.0).abs() < f32::EPSILON
|
} else if dist_to_wall as i32 == 4
|
||||||
&& rtile_pos
|
&& rtile_pos.map(|e| e % light_offset == 0).reduce_bitxor()
|
||||||
.map(|e| e % light_offset == 0)
|
|
||||||
.reduce(|x, y| x ^ y)
|
|
||||||
&& z == 1
|
&& z == 1
|
||||||
{
|
{
|
||||||
let ori = Floor::relative_ori(
|
let ori = Floor::relative_ori(
|
||||||
self.nearest_wall(rpos).unwrap_or_else(Vec2::zero),
|
|
||||||
rpos,
|
rpos,
|
||||||
|
self.nearest_wall(rpos).unwrap_or_else(Vec2::zero),
|
||||||
);
|
);
|
||||||
let furniture = SpriteKind::WallSconce;
|
let furniture = SpriteKind::WallSconce;
|
||||||
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
||||||
@ -1287,31 +1280,28 @@ impl Floor {
|
|||||||
},
|
},
|
||||||
Some(Tile::UpStair(room)) => {
|
Some(Tile::UpStair(room)) => {
|
||||||
let inner_radius: f32 = 0.5;
|
let inner_radius: f32 = 0.5;
|
||||||
let stretch: f32 = 9.0;
|
let stretch = 9;
|
||||||
let block = make_staircase(
|
let block = make_staircase(
|
||||||
Vec3::new(rtile_pos.x, rtile_pos.y, z),
|
Vec3::new(rtile_pos.x, rtile_pos.y, z),
|
||||||
TILE_SIZE as f32 / 2.0,
|
TILE_SIZE as f32 / 2.0,
|
||||||
inner_radius,
|
inner_radius,
|
||||||
stretch,
|
stretch as f32,
|
||||||
);
|
);
|
||||||
let furniture = SpriteKind::WallLampSmall;
|
let furniture = SpriteKind::WallSconce;
|
||||||
let ori = Floor::relative_ori(
|
let ori = Floor::relative_ori(
|
||||||
self.nearest_wall(rtile_pos).unwrap_or_else(Vec2::zero),
|
|
||||||
rpos,
|
rpos,
|
||||||
|
self.nearest_wall(rtile_pos).unwrap_or_else(Vec2::zero),
|
||||||
);
|
);
|
||||||
if z < self.rooms[*room].height {
|
if z < self.rooms[*room].height {
|
||||||
block.resolve_with(vacant)
|
block.resolve_with(vacant)
|
||||||
} else if z as f32 % stretch == 0.0
|
} else if z % stretch == 0 && rtile_pos.x == -TILE_SIZE / 2 && rtile_pos.y == 0 {
|
||||||
&& rtile_pos.x == -TILE_SIZE / 2
|
|
||||||
&& rtile_pos.y == 0
|
|
||||||
{
|
|
||||||
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
BlockMask::new(Block::air(furniture).with_ori(ori).unwrap(), 1)
|
||||||
} else {
|
} else {
|
||||||
make_staircase(
|
make_staircase(
|
||||||
Vec3::new(rtile_pos.x, rtile_pos.y, z),
|
Vec3::new(rtile_pos.x, rtile_pos.y, z),
|
||||||
TILE_SIZE as f32 / 2.0,
|
TILE_SIZE as f32 / 2.0,
|
||||||
inner_radius,
|
inner_radius,
|
||||||
stretch,
|
stretch as f32,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user