I'm currently looking for an entity system framework that works well with my customized photon server. I looked at your examples and tried implementing it in my server but I had issues with the Contexts being a singleton. Is there any way to have multiple instances of the contexts? I saw details about pool on the old versions of entitas and but it seems no where to found now.
Or maybe I'm just doing all wrong. Photon server plugin for what I know creates one thread per room. I tried changing the singleton to ThreadLocal but I received a bunch of exceptions.
Can anyone shed some light? Or is it time to drop this and move to other ECS?
Thank you
EDIT: Basically, I want to separate all instances of my Contexts (ie. For each photon room they have their own Game and Input instances). Or do you have any good design recommendation?
Hi, you can easily create and manage your own instances of contexts like GameContext or InputContexts and the Contextsclass itself (e.g. new Contexts();). The singleton you are talking about is a result of the ContextsGenerator which generates the Contexts class for convenience. You don't have to use this class or this generator at all. If you have other requirements you can create as many Context or Contexts as you need. Generally, everything in Entitas is very flexible and you can use it the way you need it. What you see in Demo projects are suggestions that I've used over the last few years that proved to be flexible, testable and scalable.
Entitas is not thread safe out of the box, so caution is advised when using the same context across multiple threads.
It's perfectly fine to have multiple contexts for each photon room I think.
Hello! Wow that is a really quick response.
So I just tried not using the sharedInstance and just creating my own object and boom everything works perfectly now. No more weird packets and movement going somewhere.
Wow I really missed that line! I didn't noticed that public Contexts() I thought it was private like in most Singleton. I guess I have too much coding today.
Thank you.
Most helpful comment
Hi, you can easily create and manage your own instances of contexts like GameContext or InputContexts and the
Contextsclass itself (e.g.new Contexts();). The singleton you are talking about is a result of the ContextsGenerator which generates the Contexts class for convenience. You don't have to use this class or this generator at all. If you have other requirements you can create as manyContextorContextsas you need. Generally, everything in Entitas is very flexible and you can use it the way you need it. What you see in Demo projects are suggestions that I've used over the last few years that proved to be flexible, testable and scalable.Entitas is not thread safe out of the box, so caution is advised when using the same context across multiple threads.
It's perfectly fine to have multiple contexts for each photon room I think.