from variant to component-type variant? #865
-
Greetings, I whish to change the system so that each shape is a different component type, and each entity with collision also has an aabb component. This way I can first make a view for each different shape+aabb, which updates the aabb of all the entities (no variant needed, easily done, no branching, better cache friendliness), then make a view for each aabb with the n^2 loop, (with the same advantages). However if the aabb-aabb collision is true, now I have an issue: how do I know which collider type to get from the two entities to do the final shape-shape check? I was thinking i could have a variant of pointers to the collider shapes, which would give me all i need, except pointer invalidation creeps in. Would be nice if I could store an "entt type key", and then have something like std::visit that lets me do The only alternative way to do this I have right now is to make an enum value for each collider type, add the enum as component, and write a massive switch for entity "a" of the collision check, with on each case another massive switch for the entity "b", and each inner case gets the correct shape components from entities a and b, to finally perform the actual check... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Before answering, let me ask you a question: are the colliders derived from a base class? You could enable pointer stability for the shape types in this case, put a pointer to the base class on the aabb component or any other known component, then rely on the double dispatching to resolve the call. That or any variation of the problem too. For example, an erased function and a |
Beta Was this translation helpful? Give feedback.
Before answering, let me ask you a question: are the colliders derived from a base class? You could enable pointer stability for the shape types in this case, put a pointer to the base class on the aabb component or any other known component, then rely on the double dispatching to resolve the call. That or any variation of the problem too. For example, an erased function and a
void*
to the shape component.