#SystemAPI.Query code with different EntityManager

1 messages · Page 1 of 1 (latest)

mighty wing
#

I'm iterating over another world's data and this requires me to replicate the behavior of SystemAPI.Query manually. I'm not too shocked by that, however there is a performance benefit to SystemAPI.Query since it can iterate over chunks directly, whereas without it I have to use ToArchetypeChunkArray first.

When browsing the generated code, I did see EntityQueryEnumerator, which could be a good start, but it's documented with "exists only for use by code-gen".

Are there other ways to go about this?

bitter lichen
#

when you use query normally

#

and see how it's code

#

codegen is nothing but a boilerplate generator in this case

#

ToArchetypeChunkArray this is array of actual chunks though

#

direct access to entity data

#

not copy

mighty wing
mighty wing
bitter lichen
#

why not just have system iterate over world own data?

mighty wing
#

i have a simulation world that updates independently from the main loop; the data transfer of course needs to be in the main loop because I'm using the transferred data right after

as for not recommended, I think copying data between worlds falls perfectly in the ECS use case; netcode for entities must be doing exactly that, maybe i should take a closer look at that too

bitter lichen
mighty wing
#

jobs that are in progress

bitter lichen
#

when you need to sync

#

in fact

#

you don't care about it

#

if world updates are synced

#

you can just write to 2 containers

#

frame 0 you write to container 0
frame 1 you write to container 1
frame 2 you write to container 0

#

if 1 frame delay is tolerable you'll be able to read data without a sync point

mighty wing
#

sure, yeah, but wait a minute, we are digressing

I already have all the synchronization and chunk copies working, the point was just about accessing the chunk data and avoiding the array allocation

#

the data copy is properly parallelized using IJobChunk and all that

bitter lichen
#

if you already have chunks - simply use type handles

#

to get native arrays of component data

mighty wing
#

I'll be more specific; to iterate over the chunks on the main thread, I need to access them, and that can be done in two ways for my use case:

  • EntityQuery.ToArchetypeChunkArray() -> requires iterating over chunks and allocating the array
  • EntityQueryEnumerator -> "exists only for use by code-gen", but im happy to use it if there's no problem with it
bitter lichen
#

I thought you meant you already have chunks

#

why not just run a job?

#

you can't use enumerator, it's a dummy

#

not real code

mighty wing
#

EntityQueryEnumerator is not code-generated, it exists to be used by code-gen; you made me doubt but after testing I can assure you it works 😛

bitter lichen
#

well yeah, all backend of it does work

calm badge
#

Just a word of caution. Those types are only intended for use by our source-generators. They likely will change in the future.

That said, Rider should show you generated code for all of the generated features we have if you F12 on the system type that contains them. This is probably a great way to see how we are doing things under the hood (and let us know if we are doing anything crazy).

mighty wing
mighty wing
bitter lichen
#

should be less boilerplate overall

mighty wing
#

that will just make it slower, I need to do structural changes right after anyway

there's a reason SystemAPI uses that instead of ToArchetypeChunkArray

bitter lichen
#

but SystemAPI.Query does not let structural changes either

mighty wing
#

yeah but im doing structural changes in another world than the one im iterating on

bitter lichen
#

I'm curious if job forbids from it 🤔