decline-cookies / anvil-unity-dots

Unity DOTS and ECS specific additions and extensions to Anvil
MIT License
4 stars 1 forks source link

ComponentTypeDependencyExtension - Add #226

Closed mbaker3 closed 1 year ago

mbaker3 commented 1 year ago

Provides ability to get the job dependency on an arbitrary component or set of components.

@jkeon This may provide the opportunity to decouple task drivers from systems (if we want that)

Question: Does making these extension methods of ComponentSystemBase and EntityManager make sense? Alternatively (or additionally) we can have the extension methods work off of the ComponentType<T> instances themselves. Examples:

EntityManager and ComponentSystemBase are the providers for the pointer to the underlying ComponentDependencyManager instance. That's why the current extension methods are setup as they are.

What is the current behaviour?

Currently, the only way to get the scheduling dependency of a collection of components is through an EntityQuery.

What is the new behaviour?

With a reference to EntityManager or ComponentSystemBase instance developers can calculate the scheduling dependency on an arbitrary collection of components.

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?

jkeon commented 1 year ago

Ah... sorry. I just saw this in action here: https://github.com/decline-cookies/station-x/pull/430/

I think we should remove the ComponentSystemBase extensions and just have the EntityManager one.

This line: dependsOn = JobHandle.CombineDependencies(dependsOn, this.GetDependency(ComponentType.ReadWrite<IsSelected>()));

Reads to me like we are getting this system's dependency for the component which is a bit confusing since my system may not interact with the component at all.

dependsOn = JobHandle.CombineDependencies(dependsOn, EntityManager.GetDependency(ComponentType.ReadWrite<IsSelected>()));

This reads better that we are trying to get whatever this component's global access dependency is.

This would also read well:

dependsOn = JobHandle.CombineDependencies(dependsOn, ComponentType.ReadWrite<IsSelected>().GetDepencency(ref EntityManager));

mbaker3 commented 1 year ago

Updated based on PR feedback.

My only question is how does the other side of this work?

I have a TaskDriver job that operates out of band and requires access to MyComponent : IComponentData.

So TaskDriver gets the dependency for me so I know when I can use it which is great.

How do I let Unity know to update it's dependency for MyComponent to wait on my TaskDriver job?

At the moment, you don't. I'll fast follow with this functionality in a new PR.