Arch icon indicating copy to clipboard operation
Arch copied to clipboard

CommandBuffer Pending Entity

Open martindevans opened this issue 1 year ago • 3 comments

As briefly discussed in Discord, this modifies the CommandBuffer to not return fake Entity objects. Instead it returns a PendingEntity. This makes the API less confusing and prevents all the mistakes you could make.

Added a new test ("CommandBufferEntityErrors") which demonstrates all the possible errors this fixes:

  • Using the returned Entity with the world (fails type checking)
  • Creating an entity with one buffer, using it with another buffer (throws)
  • Creating an entity, calling playback, then trying to use the entity with this buffer (throws).

Breaking Change

Note that this is a breaking change: The Create() -> Entity method has become Create() -> PendingEntity.

Most code that is broken by this should either be extremely easy to fix (just change the type) or was already subtly broken and this more explicit break is a good thing.

martindevans avatar Oct 27 '23 23:10 martindevans

To be honest I don't really like the name PendingEntity, but couldn't think of anything better.

martindevans avatar Oct 27 '23 23:10 martindevans

Thanks! Im gonna look at that one later ^^ Just wonder if there any drawbacks to this. E.g. having an PendingEntity might be a bit restrictive in certain scenarios. Im gonna check that

genaray avatar Oct 30 '23 15:10 genaray

I don't think there's anything that is valid to do with the "Entity" returned by the CommandBuffer that the PendingEntity doesn't allow. If you do identify something a use-case I've missed I'll add something to support it.

martindevans avatar Oct 30 '23 15:10 martindevans