Finality Engine
Loading...
Searching...
No Matches
ScriptableComponent.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <memory>
14#include <vector>
15#include <functional>
16#include <entt.hpp>
17#include <Core/Core.h>
18#include <string>
19#include <map>
20#include <variant>
21#include <glm/glm.hpp>
23
24#ifdef FINALITY_REFLECTION_SCAN
25#define FISerializeField friend struct ::FINALITY::ScriptFieldAccess; [[clang::annotate("finality.serialize")]]
26#else
27#define FISerializeField friend struct ::FINALITY::ScriptFieldAccess;
28#endif
29
30namespace FINALITY
31{
32 struct ScriptFieldAccess;
33 class Entity;
34 class Scene;
35
45 class ScriptableComponent;
46
53
55 using ScriptValue = std::variant<bool, int, float, std::string, glm::vec3, ScriptAssetReference>;
56
59 {
62 {
63 std::shared_ptr<void> ModuleLease;
64 std::shared_ptr<ScriptableComponent> Instance;
65 bool Started = false;
66 bool Awakened = false;
67 bool Active = false;
68 bool Enabled = true;
69 std::string TypeName;
70 std::map<std::string, ScriptValue> Properties;
71 std::function<std::unique_ptr<ScriptableComponent>()> Factory;
72
73 FAPI ScriptInstance(std::unique_ptr<ScriptableComponent> instance, bool started,
74 std::function<std::unique_ptr<ScriptableComponent>()> factory = {}, std::shared_ptr<void> moduleLease = {});
75
76 ScriptInstance(ScriptInstance&&) noexcept = default;
77 FAPI ScriptInstance& operator=(ScriptInstance&& other) noexcept;
78
80 ScriptInstance& operator=(const ScriptInstance&) = delete;
81 };
82
84
85 ScriptStorage() = default;
86
87 ScriptStorage(ScriptStorage&&) noexcept = default;
88 ScriptStorage& operator=(ScriptStorage&&) noexcept = default;
89
90 ScriptStorage(const ScriptStorage&) = delete;
91 ScriptStorage& operator=(const ScriptStorage&) = delete;
92 };
93
96 {
97 public:
98 virtual ~ScriptableComponent() = default;
99
101 const Entity GetEntity() const;
102
103 protected:
104 template<typename T>
105 bool HasComponent() const;
106
107 template<typename T>
109
110 protected:
111 entt::entity m_EntityHandle{ entt::null };
113 std::weak_ptr<void> m_Lifetime;
114
115 private:
116 virtual void Awake() {}
117 virtual void Start() {}
118 virtual void OnEnable() {}
119 virtual void OnDisable() {}
120 virtual void FixedUpdate(float dt) {}
121 virtual void Update(float dt) {}
122 virtual void LateUpdate(float dt) {}
123 virtual void OnDestroy() {}
124
125 friend class Scene;
126 friend class Entity;
127 friend class ScriptRegistry;
128 };
129}
130
131#include "ScriptableComponent.inl"
Tracks project assets, metadata and reference resolution.
#define FAPI
Definition Core.h:22
virtual ~ScriptableComponent()=default
const Entity GetEntity() const
std::variant< bool, int, float, std::string, glm::vec3, ScriptAssetReference > ScriptValue
ProjectAssetType
Asset categories used by registry discovery and editor inspection.
Definition UUID.h:29
Typed Inspector asset reference stored as a registry reference or path.
Script instance state and its module lease; keeps native code alive while the instance exists.
std::function< std::unique_ptr< ScriptableComponent >()> Factory
ScriptInstance(std::unique_ptr< ScriptableComponent > instance, bool started, std::function< std::unique_ptr< ScriptableComponent >()> factory={}, std::shared_ptr< void > moduleLease={})
ScriptInstance(ScriptInstance &&) noexcept=default
std::map< std::string, ScriptValue > Properties
std::shared_ptr< ScriptableComponent > Instance
std::vector< ScriptInstance > Scripts