light/modules/ecs/public/components/scriptable_entity.hpp

47 lines
575 B
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#pragma once
2025-07-11 01:16:52 +03:30
#include <ecs/entity.hpp>
2022-03-08 21:19:19 +03:30
2025-07-11 00:05:48 +03:30
namespace lt {
2022-03-08 21:19:19 +03:30
class NativeScript
{
2025-07-05 16:07:51 +03:30
public:
2022-03-08 21:19:19 +03:30
friend class Scene;
2025-07-05 13:28:41 +03:30
NativeScript() = default;
2025-07-05 16:07:51 +03:30
2022-03-08 21:19:19 +03:30
virtual ~NativeScript() = default;
2025-07-06 16:52:50 +03:30
[[nodiscard]] auto get_uid() const -> unsigned int
2025-07-05 13:28:41 +03:30
{
return m_unique_identifier;
2025-07-05 13:28:41 +03:30
}
2022-03-08 21:19:19 +03:30
template<typename t>
2025-07-06 14:02:50 +03:30
auto GetComponent() -> t &
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
return m_entity.get_component<t>();
2022-03-08 21:19:19 +03:30
}
protected:
virtual void on_create()
2025-07-05 13:28:41 +03:30
{
}
2025-07-05 16:07:51 +03:30
virtual void on_destroy()
2025-07-05 13:28:41 +03:30
{
}
2025-07-05 16:07:51 +03:30
virtual void on_update(float ts)
2025-07-05 13:28:41 +03:30
{
}
2025-07-05 16:07:51 +03:30
private:
Entity m_entity;
unsigned int m_unique_identifier = 0; // :#todo
2022-03-08 21:19:19 +03:30
};
2025-07-11 00:05:48 +03:30
} // namespace lt