Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
NativeScriptingComponent.hpp
Go to the documentation of this file.
1#pragma once
2
4
12 std::unique_ptr<Utils::ScriptableEntity> seInstance = nullptr;
13
14 std::function<void(Engine::Entity)> Instantiate;
15 std::function<void()> DestroyInstance;
16
17 std::function<void(Utils::ScriptableEntity *)> OnCreate;
18 std::function<void(Utils::ScriptableEntity *)> OnDestroy;
19 std::function<void(Utils::ScriptableEntity *)> OnUpdate;
20
21 template <typename T> void Bind(Engine::Core &core)
22 {
23 Instantiate = [this, &core](Engine::Entity entity) { seInstance = std::make_unique<T>(entity); };
24 DestroyInstance = [this]() { seInstance.reset(); };
25
26 OnCreate = [&core](Utils::ScriptableEntity *instance) { static_cast<T *>(instance)->OnCreate(core); };
27 OnDestroy = [&core](Utils::ScriptableEntity *instance) { static_cast<T *>(instance)->OnDestroy(core); };
28 OnUpdate = [&core](Utils::ScriptableEntity *instance) { static_cast<T *>(instance)->OnUpdate(core); };
29 }
30};
31} // namespace NativeScripting::Component
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
Wrapper class providing a convenient interface for entity manipulation with the Core....
Definition Entity.hpp:20
Definition ScriptableEntity.hpp:6
Definition NativeScriptingComponent.hpp:5
Definition NativeScriptingComponent.hpp:5
std::function< void(Utils::ScriptableEntity *)> OnUpdate
Definition NativeScriptingComponent.hpp:19
std::function< void(Utils::ScriptableEntity *)> OnDestroy
Definition NativeScriptingComponent.hpp:18
std::function< void(Engine::Entity)> Instantiate
Definition NativeScriptingComponent.hpp:14
void Bind(Engine::Core &core)
Definition NativeScriptingComponent.hpp:21
std::function< void()> DestroyInstance
Definition NativeScriptingComponent.hpp:15
std::unique_ptr< Utils::ScriptableEntity > seInstance
Definition NativeScriptingComponent.hpp:12
std::function< void(Utils::ScriptableEntity *)> OnCreate
Definition NativeScriptingComponent.hpp:17