Let us discuss how we want to handle multithreading in the entityComponentSystem
My idea is to Let each Component and the EntityManager have Its own mutex, that has to be locked when interacting with it.
The question is, should component Pointer be given out?
Idea 1: The simple approach
Component pointers are given out only if the Mutex is locked. ( get(id) asserts mutex for entityManager is locked )
benefits
downsides
- someone might accidently use entityPointers after they have unlocked the entityManager (not fool proof)
example:
healthComponent.mutex.lock();
const component:*HealthComponent = healthComponent.get(id); //assert lock
component.health = 15;
healthComponent.mutex.unlock();
//Illegal / not fool proof when:
component.health=17;
idea 2: The more complex approach
have get/set functions
component.set(id,.attribute,newvalue),
component.get(id,.attribute),
example:
healthComponent.mutex.lock();
healthComponent.set(id,.health,15); //assert lock
healthComponent.mutex.unlock();
healthComponent.set(id,.health,17); //assert lock, fails successfully! more fool proof.
which internally asserts the locks for the component, and set/gets an attribute for the component
At no point is an component pointer even given out.
benefit
- more fool proof. (100% fool proof is not reasonably possible, like for attributes of components that are pointers)
- We could integrate it with the network in the future: when component.set(..) then component gets retransmitted to all users automatically, without having to explicity write it every time.
downside:
Idea 3:
insert your idea here
Let us discuss how we want to handle multithreading in the entityComponentSystem
My idea is to Let each Component and the EntityManager have Its own mutex, that has to be locked when interacting with it.
The question is, should component Pointer be given out?
Idea 1: The simple approach
Component pointers are given out only if the Mutex is locked. ( get(id) asserts mutex for entityManager is locked )
benefits
downsides
example:
idea 2: The more complex approach
have get/set functions
example:
which internally asserts the locks for the component, and set/gets an attribute for the component
At no point is an component pointer even given out.
benefit
downside:
Idea 3:
insert your idea here