CmComponent.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmIReflectable.h"
  4. namespace CamelotEngine
  5. {
  6. class CM_EXPORT Component : public IReflectable
  7. {
  8. public:
  9. GameObjectPtr getGameObject() const { return mParent.lock(); }
  10. // TODO - This shouldn't really be public since only GameObject should be allowed to add components.
  11. // But then I have a problem that all derived classes need to have GameObject as a friend class.
  12. Component(GameObjectPtr parent);
  13. virtual ~Component();
  14. protected:
  15. friend class GameObject;
  16. /**
  17. * @brief Destroys the Component and makes it unusable, without actually deleting it.
  18. *
  19. * This is an internal method that should only get called by GameObject.
  20. */
  21. void destroy();
  22. std::weak_ptr<GameObject> mParent;
  23. bool mIsDestroyed;
  24. /************************************************************************/
  25. /* RTTI */
  26. /************************************************************************/
  27. public:
  28. friend class ComponentRTTI;
  29. static RTTITypeBase* getRTTIStatic();
  30. virtual RTTITypeBase* getRTTI() const;
  31. protected:
  32. Component() {} // Serialization only
  33. };
  34. }