BsComponentRTTI.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsRTTIType.h"
  6. #include "BsComponent.h"
  7. #include "BsGameObjectRTTI.h"
  8. namespace BansheeEngine
  9. {
  10. /** @cond RTTI */
  11. /** @addtogroup RTTI-Impl-Core
  12. * @{
  13. */
  14. class BS_CORE_EXPORT ComponentRTTI : public RTTIType<Component, GameObject, ComponentRTTI>
  15. {
  16. public:
  17. ComponentRTTI()
  18. { }
  19. void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
  20. {
  21. Component* comp = static_cast<Component*>(obj);
  22. // It's possible we're just accessing the game object fields, in which case the process below is not needed
  23. // (it's only required for new components).
  24. if (comp->mRTTIData.empty())
  25. return;
  26. GODeserializationData& deserializationData = any_cast_ref<GODeserializationData>(comp->mRTTIData);
  27. // This shouldn't be null during normal deserialization but could be during some other operations, like applying
  28. // a binary diff.
  29. if (deserializationData.ptr != nullptr)
  30. {
  31. // Register the newly created SO with the GameObjectManager and provide it with the original ID so that
  32. // deserialized handles pointing to this object can be resolved.
  33. SPtr<Component> compPtr = std::static_pointer_cast<Component>(deserializationData.ptr);
  34. GameObjectManager::instance().registerObject(compPtr, deserializationData.originalId);
  35. }
  36. comp->mRTTIData = nullptr;
  37. }
  38. const String& getRTTIName() override
  39. {
  40. static String name = "Component";
  41. return name;
  42. }
  43. UINT32 getRTTIId() override
  44. {
  45. return TID_Component;
  46. }
  47. SPtr<IReflectable> newRTTIObject() override
  48. {
  49. BS_EXCEPT(InternalErrorException, "Cannot instantiate an abstract class.");
  50. return nullptr;
  51. }
  52. };
  53. /** @} */
  54. /** @endcond */
  55. }