Finality Engine
Toggle main menu visibility
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>
22
#include <
Assets/AssetRegistry.h
>
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
30
namespace
FINALITY
31
{
32
struct
ScriptFieldAccess;
33
class
Entity;
34
class
Scene;
35
45
class
ScriptableComponent;
46
48
struct
ScriptAssetReference
49
{
50
ProjectAssetType
Type
=
ProjectAssetType::Unknown
;
51
std::string
Reference
;
52
};
53
55
using
ScriptValue
= std::variant<bool, int, float, std::string, glm::vec3, ScriptAssetReference>;
56
58
struct
ScriptStorage
59
{
61
struct
ScriptInstance
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
79
ScriptInstance
(const
ScriptInstance
&) = delete;
80
ScriptInstance
& operator=(const
ScriptInstance
&) = delete;
81
};
82
83
std
::vector<
ScriptInstance
>
Scripts
;
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
95
class
FAPI
ScriptableComponent
96
{
97
public
:
98
virtual
~ScriptableComponent
() =
default
;
99
100
Entity
GetEntity
();
101
const
Entity
GetEntity
()
const
;
102
103
protected
:
104
template
<
typename
T>
105
bool
HasComponent
()
const
;
106
107
template
<
typename
T>
108
T&
GetComponent
();
109
110
protected
:
111
entt::entity
m_EntityHandle
{ entt::null };
112
Scene
*
m_CurrentScene
=
nullptr
;
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"
AssetRegistry.h
Tracks project assets, metadata and reference resolution.
Core.h
FAPI
#define FAPI
Definition
Core.h:22
FINALITY::ScriptableComponent
Definition
ScriptableComponent.h:96
FINALITY::ScriptableComponent::Scene
friend class Scene
Definition
ScriptableComponent.h:125
FINALITY::ScriptableComponent::ScriptRegistry
friend class ScriptRegistry
Definition
ScriptableComponent.h:127
FINALITY::ScriptableComponent::m_Lifetime
std::weak_ptr< void > m_Lifetime
Definition
ScriptableComponent.h:113
FINALITY::ScriptableComponent::GetEntity
Entity GetEntity()
FINALITY::ScriptableComponent::GetComponent
T & GetComponent()
FINALITY::ScriptableComponent::~ScriptableComponent
virtual ~ScriptableComponent()=default
FINALITY::ScriptableComponent::Entity
friend class Entity
Definition
ScriptableComponent.h:126
FINALITY::ScriptableComponent::GetEntity
const Entity GetEntity() const
FINALITY::ScriptableComponent::m_EntityHandle
entt::entity m_EntityHandle
Definition
ScriptableComponent.h:111
FINALITY::ScriptableComponent::m_CurrentScene
Scene * m_CurrentScene
Definition
ScriptableComponent.h:112
FINALITY::ScriptableComponent::HasComponent
bool HasComponent() const
FINALITY
Definition
Asset.h:12
FINALITY::ScriptValue
std::variant< bool, int, float, std::string, glm::vec3, ScriptAssetReference > ScriptValue
Definition
ScriptableComponent.h:55
FINALITY::ProjectAssetType
ProjectAssetType
Asset categories used by registry discovery and editor inspection.
Definition
AssetRegistry.h:23
FINALITY::ProjectAssetType::Unknown
@ Unknown
Definition
AssetRegistry.h:23
std
Definition
UUID.h:29
FINALITY::ScriptAssetReference
Typed Inspector asset reference stored as a registry reference or path.
Definition
ScriptableComponent.h:49
FINALITY::ScriptAssetReference::Type
ProjectAssetType Type
Definition
ScriptableComponent.h:50
FINALITY::ScriptAssetReference::Reference
std::string Reference
Definition
ScriptableComponent.h:51
FINALITY::ScriptStorage::ScriptInstance
Script instance state and its module lease; keeps native code alive while the instance exists.
Definition
ScriptableComponent.h:62
FINALITY::ScriptStorage::ScriptInstance::Awakened
bool Awakened
Definition
ScriptableComponent.h:66
FINALITY::ScriptStorage::ScriptInstance::Enabled
bool Enabled
Definition
ScriptableComponent.h:68
FINALITY::ScriptStorage::ScriptInstance::Factory
std::function< std::unique_ptr< ScriptableComponent >()> Factory
Definition
ScriptableComponent.h:71
FINALITY::ScriptStorage::ScriptInstance::ModuleLease
std::shared_ptr< void > ModuleLease
Definition
ScriptableComponent.h:63
FINALITY::ScriptStorage::ScriptInstance::ScriptInstance
ScriptInstance(std::unique_ptr< ScriptableComponent > instance, bool started, std::function< std::unique_ptr< ScriptableComponent >()> factory={}, std::shared_ptr< void > moduleLease={})
FINALITY::ScriptStorage::ScriptInstance::ScriptInstance
ScriptInstance(ScriptInstance &&) noexcept=default
FINALITY::ScriptStorage::ScriptInstance::Properties
std::map< std::string, ScriptValue > Properties
Definition
ScriptableComponent.h:70
FINALITY::ScriptStorage::ScriptInstance::TypeName
std::string TypeName
Definition
ScriptableComponent.h:69
FINALITY::ScriptStorage::ScriptInstance::Active
bool Active
Definition
ScriptableComponent.h:67
FINALITY::ScriptStorage::ScriptInstance::Started
bool Started
Definition
ScriptableComponent.h:65
FINALITY::ScriptStorage::ScriptInstance::Instance
std::shared_ptr< ScriptableComponent > Instance
Definition
ScriptableComponent.h:64
FINALITY::ScriptStorage::Scripts
std::vector< ScriptInstance > Scripts
Definition
ScriptableComponent.h:83
FINALITY::ScriptStorage::ScriptStorage
ScriptStorage()=default
FinalityEngine
src
Scene
ScriptableComponent.h
Generated by
1.18.0