decline-cookies / anvil-unity-dots

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

Adapt EntitySpawner to be ACV compatible #220

Closed mbaker3 closed 1 year ago

mbaker3 commented 1 year ago

The entity spawning feature has been adapted to conform to the ISharedWriteAccessControlledValue interface. This makes for easy inclusion in TaskDriver jobs that require entity spawning.

What is the current behaviour?

In a TaskDriver, to gain access to an EntitySpawnWriter the developer must manually acquire and pass the writer into their job through a custom the scheduling delegate. This is painful.

What is the new behaviour?

Developers can now include EntitySpawnWriters in their TaskDriver jobs with a convenient RequireGenericDataForWrite(EntitySpawner) call.

As part of this work EntitySpawner is now a public type. Since developers may hold reference to the spawner rather than calling GetSpawner<T> every frame the mechanism for marking a spawner for update needed to be updated. EntitySpawner now emits an event indicating that it has pending work to schedule instead of having EntitySpawnSystem track that dirty state.

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?

Migration

EntitySpawnSystem.AcquireEntitySpawnWriterAsync<DefinitionType>(out var value) -> EntitySpawnSystem.GetSpawner<DefinitionType>.AcquireSharedWriteAsync(out var value)

EntitySpawnSystem.ReleaseEntitySpawnWriterAsync(JobHandle) -> EntitySpawnSystem.GetSpawner<DefinitionType>.ReleaseAsync(JobHandle)

mbaker3 commented 1 year ago

Comments addressed. Ready for re-review