#Adding Dynamic Components

1 messages · Page 1 of 1 (latest)

scarlet osprey
#

I know it's possible to register dynamic components with init_component_with_descriptor, but is it possible to insert components via descriptor or anything?

dense gate
#

Use reflection!

#

IIRC we have the APIs for this on World now

scarlet osprey
#

insert with reflection?

#

mm using ReflectComponent...

#

This could work

#

well that's gonna go through ReflectComponentFn which will leave me with a world, entity, and dynamic reflected component

#

Oh I guess I'm supposed to cast via function pointer or something

#

@dense gate is there anyway to do something like insert_by_id with a pointer to data or something?

#

nvrmnd TypeRegistration may work

#

ehhh actually that won't work either...

dense gate
#

Deferring to @random forge and @silver cargo here 🙂

scarlet osprey
#

For when y'all arrive, I'm trying to do some cursed stuff:
I want to dynamically add components to entities in order to get entities into different archetypes

#

so I could have two (Position, Health, Chunk) entities exist as two separate archetypes with Chunk being a dynamically inserted ComponentId

random forge
#

why do you want to separate them across archetypes?

scarlet osprey
#

Just experimenting

#

I want to see if I can move dynamically move entities closer together in memory essentially

random forge
#

moving things across archetypes like that just moves them apart in memory

scarlet osprey
#

yes

random forge
#

if you want them close then you have to keep them in the same archetype

scarlet osprey
#

uhh so lets say I have 400 entities of the same archetype

#

and I want entities 1 and 400 closer together

#

based on some dynamic property

#

the exact thing I'm trying to do is see if I can create tilemap chunks like this

#

so pretty much every tile is the same archetype, but I want to essentially have sub archetypes based on the chunk the tile is in, which is not type level information

random forge
#

so like... you're trying to strategically add and remove tiles from the archetype to sort them how you want?

scarlet osprey
#

yeah

random forge
#

do you need to use dynamic components then? Can't you just make a Mover ZST that you use to remove, and then remove it to put them back in?

scarlet osprey
#

No since it's going to be an undefined number of chunks

#

so for instance, every 64 by 64 tile entities, I would want to group in their own set of archetypes

random forge
#

ahh

#

so you want more than one destination archetpye

scarlet osprey
#

exactly

random forge
#

that makes more sense

scarlet osprey
#

I basically want something like (Chunk<1, 2, 3>, TilePos) as an entity, but not using const generics because then I can't really do it

random forge
#

tbh I don't know anything about dynamic components and am too sick to think about it very hard rn but dubi steinkek might be more familiar.

scarlet osprey
#

kind of a weird use case but I think it could lead to some cache improvements in tilemap libs

#

Damn, I hope you get better

#

I just got over covid and yeesh that was not a fun two weeks

random forge
#

thankfully doesn't feel like covid but still don't feel great

#

also not too bad either way just kinda gross

scarlet osprey
#

if this isn't something possible yet it would be a fun capability to try and add myself

dense gate
scarlet osprey
#

Sick, any work items or RFCs to look at on this? I've been needing an outside of work project

dense gate
#

And then @exotic moth will likely need help getting the trait query crate to play nice

#

Components-as-entities would also super charge trait queries, but I'm unsure if it's needed

scarlet osprey
#

Components as entities?

#

As in you can use your own component as an indexer instead of entity?

dense gate
#

No, as in "instead of a type registry, registry the component types and their metadata in the ECS" in an isolated partition

#

Which should let us have e.g. ?Sized trait queries

#

At least, that's my intuition. Need to do more experiments to be sure

exotic moth
dense gate
#

For non object safe traits

#

May need to tweak the syntax but that's worth it

#

(a bit feverish so this is a little speculative)

exotic moth
silver cargo