Skip to content

Discussion: Multithreading in ECS #2800

@tillpp

Description

@tillpp

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

  • doesn't confuse your IDE

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:

  • confuses Intellisense

Idea 3:

insert your idea here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions