In order to create a game engine inspired on Unity3d, I would like to expand this question about how Unity's GetComponent works to how Unity's FindObjectsOfType<T>()
works.
It is expected to return all pointers to objects derived from <T>
present in the scene.
I know Unity implement it in C++, but how? Objects could be anything in Unity and the Unity's solution is tolerant to inheritance.
The Unity Description says it is slow, but why? I can imagine it might be array searching using dynamic cast. I am thinking in implementing this functionality using unordered_multimap
, but it will make the use case of finding for a base class harder.
It doesn't feels right to me making the developer call macros on its implementations. Users must be free to code frictionless.
Another problem is: Who is the owner of the smart pointer taking this into account:
- Object must return find operations as described.
GameObject
has its own implementation ofGetComponents<T>()
where Component is an Object too.