BsGameObjectRTTI.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsRTTIType.h"
  7. #include "BsGameObject.h"
  8. #include "BsSceneObject.h"
  9. #include "BsGameObjectManager.h"
  10. namespace BansheeEngine
  11. {
  12. class BS_CORE_EXPORT GameObjectRTTI : public RTTIType<GameObject, IReflectable, GameObjectRTTI>
  13. {
  14. private:
  15. String& getName(GameObject* obj) { return obj->mName; }
  16. void setName(GameObject* obj, String& name) { obj->mName = name; }
  17. UINT64& getInstanceID(GameObject* obj) { return obj->mInstanceData->mInstanceId; }
  18. void setInstanceID(GameObject* obj, UINT64& instanceId)
  19. {
  20. // The system will have already assigned the instance ID, but since other objects might be referencing
  21. // the old (serialized) ID we store it in the GameObjectSerializationManager so we can map from old to new id.
  22. GameObjectManager::instance().registerDeserializedId(instanceId, obj->getInstanceId());
  23. }
  24. public:
  25. template <typename T>
  26. static std::shared_ptr<T> createGameObject()
  27. {
  28. return SceneObject::createEmptyComponent<T>();
  29. }
  30. public:
  31. GameObjectRTTI()
  32. {
  33. addPlainField("mInstanceID", 0, &GameObjectRTTI::getInstanceID, &GameObjectRTTI::setInstanceID);
  34. addPlainField("mName", 1, &GameObjectRTTI::getName, &GameObjectRTTI::setName);
  35. }
  36. virtual const String& getRTTIName()
  37. {
  38. static String name = "GameObject";
  39. return name;
  40. }
  41. virtual UINT32 getRTTIId()
  42. {
  43. return TID_GameObject;
  44. }
  45. virtual std::shared_ptr<IReflectable> newRTTIObject()
  46. {
  47. BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  48. }
  49. };
  50. }