NcEngine
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
FrameLogic.h
Go to the documentation of this file.
1
5#pragma once
6
8#include "ncengine/ecs/Ecs.h"
9
10#include <functional>
11
12namespace nc
13{
15using FrameLogicCallable_t = std::move_only_function<void(Entity self, ecs::Ecs world, float dt)>;
16
18template<class Func>
19concept FrameLogicCallable = std::convertible_to<Func, FrameLogicCallable_t>;
20
22class FrameLogic final : public ComponentBase
23{
24 public:
25 template<FrameLogicCallable Func>
26 FrameLogic(Entity entity, Func&& func)
27 : ComponentBase{entity},
28 m_func{std::forward<Func>(func)}
29 {
30 }
31
33 template<FrameLogicCallable Func>
34 void SetFunction(Func&& func)
35 {
36 m_func = std::forward<Func>(func);
37 }
38
39 void Run(ecs::Ecs world, float dt)
40 {
41 if(m_func) m_func(ParentEntity(), world, dt);
42 }
43
44 private:
45 FrameLogicCallable_t m_func;
46};
47} // namespace nc
std::move_only_function< void(Entity self, ecs::Ecs world, float dt)> FrameLogicCallable_t
FrameLogic callable member type.
Definition: FrameLogic.h:15
Optional base class for components.
Definition: Component.h:27
Identifies an object in the registry.
Definition: Entity.h:18
Component that runs a custom callable during each logic phase.
Definition: FrameLogic.h:23
void SetFunction(Func &&func)
Set a new callable.
Definition: FrameLogic.h:34
Interface for higher-level entity and component operations with optional type access restriction.
Definition: Ecs.h:18
FrameLogic callable type requirements.
Definition: FrameLogic.h:19