CmComponent.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  10. * @brief Returns the GameObject this Component is assigned to.
  11. */
  12. GameObjectPtr gameObject() const { return mParent.lock(); }
  13. /**
  14. * @brief Same as gameObject(), just a shorter name.
  15. */
  16. GameObjectPtr GO() const { return gameObject(); }
  17. /**
  18. * @brief Called once per frame on all components.
  19. */
  20. virtual void update() = 0;
  21. virtual ~Component();
  22. protected:
  23. friend class GameObject;
  24. Component(GameObjectPtr parent);
  25. /**
  26. * @brief Destroys the Component and makes it unusable, without actually deleting it.
  27. *
  28. * This is an internal method that should only get called by GameObject.
  29. */
  30. void destroy();
  31. std::weak_ptr<GameObject> mParent;
  32. bool mIsDestroyed;
  33. /************************************************************************/
  34. /* RTTI */
  35. /************************************************************************/
  36. public:
  37. friend class ComponentRTTI;
  38. static RTTITypeBase* getRTTIStatic();
  39. virtual RTTITypeBase* getRTTI() const;
  40. protected:
  41. Component() {} // Serialization only
  42. };
  43. }