CmGameObjectRTTI.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmRTTIType.h"
  4. #include "CmGameObject.h"
  5. #include "CmSceneObject.h"
  6. #include "CmGameObjectManager.h"
  7. namespace CamelotFramework
  8. {
  9. class CM_EXPORT GameObjectRTTI : public RTTIType<GameObject, IReflectable, GameObjectRTTI>
  10. {
  11. private:
  12. UINT64& getInstanceID(GameObject* obj) { return obj->mInstanceData->mInstanceId; }
  13. void setInstanceID(GameObject* obj, UINT64& instanceId)
  14. {
  15. // The system will have already assigned the instance ID, but since other objects might be referencing
  16. // the old (serialized) ID we store it in the GameObjectSerializationManager so we can map from old to new id.
  17. GameObjectManager::instance().registerDeserializedId(instanceId, obj->getInstanceId());
  18. }
  19. public:
  20. template <typename T>
  21. static std::shared_ptr<T> createGameObject()
  22. {
  23. return SceneObject::createEmptyComponent<T>();
  24. }
  25. public:
  26. GameObjectRTTI()
  27. {
  28. addPlainField("mInstanceID", 0, &GameObjectRTTI::getInstanceID, &GameObjectRTTI::setInstanceID);
  29. }
  30. virtual const String& getRTTIName()
  31. {
  32. static String name = "GameObject";
  33. return name;
  34. }
  35. virtual UINT32 getRTTIId()
  36. {
  37. return TID_GameObject;
  38. }
  39. virtual std::shared_ptr<IReflectable> newRTTIObject()
  40. {
  41. CM_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  42. }
  43. };
  44. }