CmGameObjectRTTI.h 1.2 KB

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