#Operations using lists of components

1 messages · Page 1 of 1 (latest)

prisma zephyr
#

Hey,

It is the second time I run into this kind of thing, where I can not avoid the use of generics.

The last time, I wanted to copy data between worlds without using generics. This is parallelizable, because I know the entities exist only once in each world. I managed to access data from one world using archetype chunk iteration, but I can not anonymously write this to the other world without using generics, because DynamicComponentTypeHandle requires the chunk to access any data (which is not accessible while iterating over another world's entities).

Thus, it's necessary to copy all the data in an intermediate step, and then launching another archetype chunk iteration. This multi-stage data transfer is somewhat difficult to organize in parallel, let alone do so efficiently. I fell back to duplicating some code and writing the data using ComponentTypeHandles ComponentLookups.

In this second case, I want to clear all buffers from a list of buffer types on a specific entity (a list of events). Here, too, there is no way to do this anonymously, but looking at the implementation, this looks like it could be done.

Did anyone have similar "problems", or am I the odd one out? Are there solutions to avoid duplicating code for these kinds of cases (e.g. when adding event types)?

spring pine
#

I'm confused why you could use component type handle but not dynamic type handle?

prisma zephyr
#

Because I can access components with ComponentTypeHandle, without requiring to access their chunks

spring pine
#

They work the same way

#

And ah how? Component type handle is kind of just an indexer to a chunk. I'm confused by how you're using it without a chunk.

prisma zephyr
#

yeah, but I can create the typehandle on the main thread beforehand, it will do everything I need to prepare the data access

#

the dynamic type handle API doesn't allow me to access the data in the same way

#

sorry, I am using the wrong name, I meant ComponentLookup

#

🤦‍♂️

spring pine
#

Oh that's completely different. OK that makes sense 😅

prisma zephyr
#

To give some more context, I'm not looking to plainly move or copy entities, which could be done with MoveEntities and such, I'm only interested in updating changed entities (using chunk last version)

I can't really use change filters, because they only allow checking up to two component types, and I have entities with many component types that I want to copy (and also, anyway, it would just add redundant checks, because I want to know which types changed so I can copy only the changed ones).

Right now I'm doing all of them in one job with an if statement for every component type I care about, so it's very efficient, but it's a little tedious to add and remove types because of the component lookups and handles.

I suppose code generation could help with this kind of thing, but that's a whole other type of problem I'm not ready to tackle yet. 😅

chilly finch
#

what problem are you trying to solve overall?

#

and do you have a ballpark estimate of just how much copying you can save by not just doing e.g. moveentities?