Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Fix motherfucking deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubelotix committed Jan 4, 2024
1 parent 3fb0e1a commit 3cfac8f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions minecraft-server/src/world/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ use tokio::sync::RwLock;
pub struct Entities {
eid_counter: std::sync::atomic::AtomicU32,
uuid_counter: std::sync::atomic::AtomicU64,
pub entities: RwLock<HashMap<Eid, AnyEntity>>,
pub tasks: RwLock<HashMap<Eid, EntityTask>>,
tasks: RwLock<HashMap<Eid, EntityTask>>,
entities: RwLock<HashMap<Eid, AnyEntity>>,

/// A hashmap of chunk positions to get a list of entities in a chunk
pub chunks: RwLock<HashMap<ChunkColumnPosition, HashSet<Eid>>>,
pub uuids: RwLock<HashMap<UUID, Eid>>,
chunks: RwLock<HashMap<ChunkColumnPosition, HashSet<Eid>>>,
uuids: RwLock<HashMap<UUID, Eid>>,
}

impl Entities {
pub fn new() -> Entities {
Entities {
eid_counter: std::sync::atomic::AtomicU32::new(0),
uuid_counter: std::sync::atomic::AtomicU64::new(0),
entities: RwLock::new(HashMap::new()),
tasks: RwLock::new(HashMap::new()),
entities: RwLock::new(HashMap::new()),
chunks: RwLock::new(HashMap::new()),
uuids: RwLock::new(HashMap::new()),
}
Expand Down Expand Up @@ -77,8 +77,8 @@ impl Entities {
let task = entity.init_task().await;
let eid = self.eid_counter.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
let uuid = self.uuid_counter.fetch_add(1, std::sync::atomic::Ordering::SeqCst) as u128;
let mut entities = self.entities.write().await;
let mut tasks = self.tasks.write().await;
let mut entities = self.entities.write().await;
let mut chunks = self.chunks.write().await;
let mut uuids = self.uuids.write().await;
chunks.entry(entity.as_entity().position.chunk_column()).or_insert(HashSet::new()).insert(eid);
Expand Down

0 comments on commit 3cfac8f

Please sign in to comment.