Sign in to follow this  
AxeGuywithanAxe

Multithreaded entities

Recommended Posts

Hey, so I'm currently working in building the foundation of my entity component system and I wanted to see how others handle updating entities. I was contemplating going though either a task dependency graph...or using an actor model with deferred updates, fairly sure that's what Frostbite does. I've never implemented the latter model, but I can see the benefits of deferring the actual updating until later in the frame, the issues I see are added memory usage, and maintaining determinism.

Share this post


Link to post
Share on other sites

You might not need a dependency graph, depending on what you at doing. I'm in the process of making threaded actor updates myself with Lua.

 

What made this so difficult was how you handle data, and the fact that Luas documentation is ridiculously vague. But I got it to work without relying on a lua environment per entity.

 

The way I am handling this is by a deferred modification. Actors can pass messages to make changes to data, but they can read immediately. When an actor triggers an event, the event is passed off to Lua immediately and handled there.

 

For the most part Lua behaves single threaded. But each event is actually a coroutine. If an event makes a C call that takes a long time, the call is passed to a task thread and the routine is yielded to allow the next to event to run. Each yield has a flag that tells the scheduler how to continue it. Wait for next frame. Wait till job is done. Or if the routine should be polled for completion.

 

Actor data is updated at the end.

Edited by Tangletail

Share this post


Link to post
Share on other sites

Thank you both for your replies, sorry for the late one, a lot of traveling. What I meant by entity component is more a long the lines of Unreal/Unity, where components are used for certain actions and contain functions and data, such as a MovementComponent, RenderComponent, etc... And yeah Tangletail, that's what I was thinking about doing, but how do you handle the proper order of  events?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this