Fixed minor issues with walls, better particles

This commit is contained in:
Joshua Barretto 2023-05-19 14:25:49 +01:00
parent b0556588b8
commit c73848b932
5 changed files with 110 additions and 48 deletions

View File

@ -680,14 +680,14 @@ void main() {
break;
case PORTAL_FIZZ:
attr = Attr(
vec3(0, 0, lower * -0.5) + vec3(
sin(lifetime * 0.5 + rand0 * 10) + sin(lifetime * 0.3 + rand3 * 10),
sin(lifetime * 0.9 + rand1 * 10) + sin(lifetime * 0.4 + rand4 * 10),
sin(lifetime * 2 + rand2) * 0.2
) * 0.25,
vec3(pow(1.0 - abs(percent() - 0.5) * 2.0, 0.5)),
vec4(vec3(0.3, 3.0 + rand6, 2.5), 1),
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 1)
inst_dir * pow(percent(), 2) + vec3(0, 0, lower * -0.5) + vec3(
sin(lifetime * 1.25 + rand0 * 10) + sin(lifetime * 1.3 + rand3 * 10),
sin(lifetime * 1.2 + rand1 * 10) + sin(lifetime * 1.4 + rand4 * 10),
sin(lifetime * 5 + rand2)
) * 0.1,
vec3(pow(1.0 - abs(percent() - 0.5) * 2.0, 0.2)),
vec4(vec3(1.8, 0.4, 5.0 + rand6), 1),
spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 5)
);
break;
default:

View File

@ -398,7 +398,8 @@ impl Block {
SpriteKind::Keyhole
| SpriteKind::KeyDoor
| SpriteKind::BoneKeyhole
| SpriteKind::BoneKeyDoor => None,
| SpriteKind::BoneKeyDoor
| SpriteKind::OneWayWall => None,
SpriteKind::Anvil
| SpriteKind::Cauldron
| SpriteKind::CookingPot

View File

@ -1393,6 +1393,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
near_aabb: Aabb<i32>,
radius: f32,
z_range: Range<f32>,
move_dir: Vec3<f32>,
) -> bool {
let player_aabb = player_aabb(pos, radius, z_range);
@ -1407,7 +1408,9 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
min: block_pos.map(|e| e as f32),
max: block_pos.map(|e| e as f32) + Vec3::new(1.0, 1.0, block.solid_height()),
};
if player_aabb.collides_with_aabb(block_aabb) {
if player_aabb.collides_with_aabb(block_aabb)
&& block.valid_collision_dir(player_aabb, block_aabb, move_dir)
{
collision = true;
}
}
@ -1557,6 +1560,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
near_aabb,
radius,
z_range.clone(),
vel.0,
)
}
// ...and there is a collision with a block beneath our current hitbox...
@ -1569,6 +1573,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
near_aabb,
radius,
z_range.clone(),
vel.0,
)
} {
// ...block-hop!
@ -1623,6 +1628,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
near_aabb,
radius,
z_range.clone(),
vel.0,
)
} {
//prof_span!("snap!!");

View File

@ -1456,7 +1456,7 @@ impl ParticleMgr {
struct BlockParticles<'a> {
// The function to select the blocks of interest that we should emit from
blocks: fn(&'a BlocksOfInterest) -> &'a [Vec3<i32>],
blocks: fn(&'a BlocksOfInterest) -> BlockParticleSlice<'a>,
// The range, in chunks, that the particles should be generated in from the player
range: usize,
// The emission rate, per block per second, of the generated particles
@ -1469,9 +1469,23 @@ impl ParticleMgr {
cond: fn(&SceneData) -> bool,
}
enum BlockParticleSlice<'a> {
Pos(&'a [Vec3<i32>]),
PosAndDirs(&'a [(Vec3<i32>, Vec3<f32>)]),
}
impl<'a> BlockParticleSlice<'a> {
fn len(&self) -> usize {
match self {
Self::Pos(blocks) => blocks.len(),
Self::PosAndDirs(blocks) => blocks.len(),
}
}
}
let particles: &[BlockParticles] = &[
BlockParticles {
blocks: |boi| &boi.leaves,
blocks: |boi| BlockParticleSlice::Pos(&boi.leaves),
range: 4,
rate: 0.001,
lifetime: 30.0,
@ -1479,7 +1493,7 @@ impl ParticleMgr {
cond: |_| true,
},
BlockParticles {
blocks: |boi| &boi.drip,
blocks: |boi| BlockParticleSlice::Pos(&boi.drip),
range: 4,
rate: 0.004,
lifetime: 20.0,
@ -1487,7 +1501,7 @@ impl ParticleMgr {
cond: |_| true,
},
BlockParticles {
blocks: |boi| &boi.fires,
blocks: |boi| BlockParticleSlice::Pos(&boi.fires),
range: 2,
rate: 20.0,
lifetime: 0.25,
@ -1495,7 +1509,7 @@ impl ParticleMgr {
cond: |_| true,
},
BlockParticles {
blocks: |boi| &boi.fire_bowls,
blocks: |boi| BlockParticleSlice::Pos(&boi.fire_bowls),
range: 2,
rate: 20.0,
lifetime: 0.25,
@ -1503,7 +1517,7 @@ impl ParticleMgr {
cond: |_| true,
},
BlockParticles {
blocks: |boi| &boi.fireflies,
blocks: |boi| BlockParticleSlice::Pos(&boi.fireflies),
range: 6,
rate: 0.004,
lifetime: 40.0,
@ -1511,7 +1525,7 @@ impl ParticleMgr {
cond: |sd| sd.state.get_day_period().is_dark(),
},
BlockParticles {
blocks: |boi| &boi.flowers,
blocks: |boi| BlockParticleSlice::Pos(&boi.flowers),
range: 5,
rate: 0.002,
lifetime: 40.0,
@ -1519,7 +1533,7 @@ impl ParticleMgr {
cond: |sd| sd.state.get_day_period().is_dark(),
},
BlockParticles {
blocks: |boi| &boi.beehives,
blocks: |boi| BlockParticleSlice::Pos(&boi.beehives),
range: 3,
rate: 0.5,
lifetime: 30.0,
@ -1527,7 +1541,7 @@ impl ParticleMgr {
cond: |sd| sd.state.get_day_period().is_light(),
},
BlockParticles {
blocks: |boi| &boi.snow,
blocks: |boi| BlockParticleSlice::Pos(&boi.snow),
range: 4,
rate: 0.025,
lifetime: 15.0,
@ -1535,10 +1549,10 @@ impl ParticleMgr {
cond: |_| true,
},
BlockParticles {
blocks: |boi| &boi.one_way_walls,
blocks: |boi| BlockParticleSlice::PosAndDirs(&boi.one_way_walls),
range: 2,
rate: 8.0,
lifetime: 3.0,
rate: 12.0,
lifetime: 1.5,
mode: ParticleMode::PortalFizz,
cond: |_| true,
},
@ -1563,16 +1577,35 @@ impl ParticleMgr {
self.particles
.resize_with(self.particles.len() + particle_count, || {
let block_pos =
Vec3::from(chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32))
+ blocks.choose(&mut rng).copied().unwrap(); // Can't fail
Particle::new(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
block_pos.map(|e: i32| e as f32 + rng.gen::<f32>()),
)
match blocks {
BlockParticleSlice::Pos(blocks) => {
let block_pos = Vec3::from(
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
) + blocks.choose(&mut rng).copied().unwrap(); // Can't fail
Particle::new(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
block_pos.map(|e: i32| e as f32 + rng.gen::<f32>()),
)
},
BlockParticleSlice::PosAndDirs(blocks) => {
let (block_offset, particle_dir) =
blocks.choose(&mut rng).copied().unwrap(); // Can't fail
let block_pos = Vec3::from(
chunk_pos * TerrainChunk::RECT_SIZE.map(|e| e as i32),
) + block_offset;
let particle_pos =
block_pos.map(|e: i32| e as f32 + rng.gen::<f32>());
Particle::new_directed(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
particle_pos,
particle_pos + particle_dir,
)
},
}
})
});
}
@ -1600,19 +1633,37 @@ impl ParticleMgr {
self.particles
.resize_with(self.particles.len() + particle_count, || {
let rel_pos = blocks
.choose(&mut rng)
.copied()
.unwrap()
.map(|e: i32| e as f32 + rng.gen::<f32>()); // Can't fail
let wpos = mat.mul_point(rel_pos);
match blocks {
BlockParticleSlice::Pos(blocks) => {
let rel_pos = blocks
.choose(&mut rng)
.copied()
.unwrap()
.map(|e: i32| e as f32 + rng.gen::<f32>()); // Can't fail
let wpos = mat.mul_point(rel_pos);
Particle::new(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
wpos,
)
Particle::new(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
wpos,
)
},
BlockParticleSlice::PosAndDirs(blocks) => {
let (block_offset, particle_dir) =
blocks.choose(&mut rng).copied().unwrap(); // Can't fail
let particle_pos =
block_offset.map(|e: i32| e as f32 + rng.gen::<f32>());
let wpos = mat.mul_point(particle_pos);
Particle::new_directed(
Duration::from_secs_f32(particles.lifetime),
time,
particles.mode,
wpos,
wpos + mat.mul_direction(particle_dir),
)
},
}
})
}
}

View File

@ -48,7 +48,7 @@ pub struct BlocksOfInterest {
pub cricket2: Vec<Vec3<i32>>,
pub cricket3: Vec<Vec3<i32>>,
pub frogs: Vec<Vec3<i32>>,
pub one_way_walls: Vec<Vec3<i32>>, // Vec<(Vec3<i32>, Vec3<f32>)>
pub one_way_walls: Vec<(Vec3<i32>, Vec3<f32>)>,
// Note: these are only needed for chunks within the iteraction range so this is a potential
// area for optimization
pub interactables: Vec<(Vec3<i32>, Interaction)>,
@ -174,10 +174,14 @@ impl BlocksOfInterest {
Some(SpriteKind::RepairBench) => {
interactables.push((pos, Interaction::Craft(CraftingTab::All)))
},
Some(SpriteKind::OneWayWall) => one_way_walls.push(pos),/*one_way_walls.push((
Some(SpriteKind::OneWayWall) => one_way_walls.push((
pos,
Vec3::unit_y().rotated_z(std::f32::consts::PI * 0.25 * block.get_ori().unwrap_or(0) as f32),
)),*/
Vec2::unit_y()
.rotated_z(
std::f32::consts::PI * 0.25 * block.get_ori().unwrap_or(0) as f32,
)
.with_z(0.0),
)),
_ if block.is_mountable() => interactables.push((pos, Interaction::Mount)),
_ => {},
},