aboutsummaryrefslogtreecommitdiff
path: root/azalea-physics/src/collision
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-12-11 00:15:37 -0600
committermat <github@matdoes.dev>2022-12-11 00:15:37 -0600
commit37b9f10b3bcc74b48df2c6843a5286a7d41e2414 (patch)
tree6a995f7ad3f3309e57c276e10dc7e655dae9c5bb /azalea-physics/src/collision
parent2d6737b247b74e964fd734d5ab4828a3193c296f (diff)
downloadazalea-drasl-37b9f10b3bcc74b48df2c6843a5286a7d41e2414.tar.xz
make entities have a reference to WeakWorlds instead
... and other exciting bug fixes
Diffstat (limited to 'azalea-physics/src/collision')
-rw-r--r--azalea-physics/src/collision/mod.rs10
-rw-r--r--azalea-physics/src/collision/world_collisions.rs14
2 files changed, 12 insertions, 12 deletions
diff --git a/azalea-physics/src/collision/mod.rs b/azalea-physics/src/collision/mod.rs
index c057f8d7..458303c5 100644
--- a/azalea-physics/src/collision/mod.rs
+++ b/azalea-physics/src/collision/mod.rs
@@ -6,11 +6,11 @@ mod world_collisions;
use azalea_core::{Axis, Vec3, AABB, EPSILON};
use azalea_world::entity::{Entity, EntityData};
-use azalea_world::{MoveEntityError, World};
+use azalea_world::{MoveEntityError, WeakWorld};
pub use blocks::BlockWithShape;
pub use discrete_voxel_shape::*;
pub use shape::*;
-use std::ops::DerefMut;
+use std::ops::Deref;
use world_collisions::CollisionGetter;
pub enum MoverType {
@@ -33,7 +33,7 @@ pub trait MovableEntity {
) -> Result<(), MoveEntityError>;
}
-impl HasCollision for World {
+impl<D: Deref<Target = WeakWorld>> HasCollision for D {
// private Vec3 collide(Vec3 var1) {
// AABB var2 = this.getBoundingBox();
// List var3 = this.level.getEntityCollisions(this,
@@ -87,7 +87,7 @@ impl HasCollision for World {
}
}
-impl<D: DerefMut<Target = World>> MovableEntity for Entity<'_, D> {
+impl<D: Deref<Target = WeakWorld>> MovableEntity for Entity<'_, D> {
/// Move an entity by a given delta, checking for collisions.
fn move_colliding(
&mut self,
@@ -206,7 +206,7 @@ fn collide_bounding_box(
entity: Option<&EntityData>,
movement: &Vec3,
entity_bounding_box: &AABB,
- world: &World,
+ world: &WeakWorld,
entity_collisions: Vec<VoxelShape>,
) -> Vec3 {
let mut collision_boxes: Vec<VoxelShape> = Vec::with_capacity(entity_collisions.len() + 1);
diff --git a/azalea-physics/src/collision/world_collisions.rs b/azalea-physics/src/collision/world_collisions.rs
index a28bce14..9e238bf9 100644
--- a/azalea-physics/src/collision/world_collisions.rs
+++ b/azalea-physics/src/collision/world_collisions.rs
@@ -2,8 +2,8 @@ use crate::collision::{BlockWithShape, VoxelShape, AABB};
use azalea_block::BlockState;
use azalea_core::{ChunkPos, ChunkSectionPos, Cursor3d, CursorIterationType, EPSILON};
use azalea_world::entity::EntityData;
-use azalea_world::{Chunk, World};
-use parking_lot::Mutex;
+use azalea_world::{Chunk, WeakWorld};
+use parking_lot::RwLock;
use std::sync::Arc;
use super::Shapes;
@@ -16,7 +16,7 @@ pub trait CollisionGetter {
) -> BlockCollisions<'a>;
}
-impl CollisionGetter for World {
+impl CollisionGetter for WeakWorld {
fn get_block_collisions<'a>(
&'a self,
entity: Option<&EntityData>,
@@ -27,7 +27,7 @@ impl CollisionGetter for World {
}
pub struct BlockCollisions<'a> {
- pub world: &'a World,
+ pub world: &'a WeakWorld,
// context: CollisionContext,
pub aabb: AABB,
pub entity_shape: VoxelShape,
@@ -37,7 +37,7 @@ pub struct BlockCollisions<'a> {
impl<'a> BlockCollisions<'a> {
// TODO: the entity is stored in the context
- pub fn new(world: &'a World, _entity: Option<&EntityData>, aabb: AABB) -> Self {
+ pub fn new(world: &'a WeakWorld, _entity: Option<&EntityData>, aabb: AABB) -> Self {
let origin_x = (aabb.min_x - EPSILON) as i32 - 1;
let origin_y = (aabb.min_y - EPSILON) as i32 - 1;
let origin_z = (aabb.min_z - EPSILON) as i32 - 1;
@@ -57,7 +57,7 @@ impl<'a> BlockCollisions<'a> {
}
}
- fn get_chunk(&self, block_x: i32, block_z: i32) -> Option<Arc<Mutex<Chunk>>> {
+ fn get_chunk(&self, block_x: i32, block_z: i32) -> Option<Arc<RwLock<Chunk>>> {
let chunk_x = ChunkSectionPos::block_to_section_coord(block_x);
let chunk_z = ChunkSectionPos::block_to_section_coord(block_z);
let chunk_pos = ChunkPos::new(chunk_x, chunk_z);
@@ -96,7 +96,7 @@ impl<'a> Iterator for BlockCollisions<'a> {
let pos = item.pos;
let block_state: BlockState = chunk
- .lock()
+ .read()
.get(&(&pos).into(), self.world.min_y())
.unwrap_or(BlockState::Air);