Nui Engine
A game engine framework
Loading...
Searching...
No Matches
TestECSStructures.h
1#pragma once
2#include "CppUnitTest.h"
3#include <Core/Engine/ECS/ECS.h>
4
5using namespace Microsoft::VisualStudio::CppUnitTestFramework;
6
8{
9 // Defualt values is '-1 for testing
10 Nui::I32 X = -1;
11 Nui::I32 Y = -1;
12};
13
15{
16 Nui::I32 ID;
17};
18
20 public Nui::ECS::EventSubscriber<Nui::ECS::Events::OnEntityCreate>,
21 public Nui::ECS::EventSubscriber<Nui::ECS::Events::OnEntityDestroy>,
22 public Nui::ECS::EventSubscriber<Nui::ECS::Events::OnComponentAdd<TestComponent>>,
23 public Nui::ECS::EventSubscriber<Nui::ECS::Events::OnComponentRemove<TestComponent>>,
24 public Nui::ECS::EventSubscriber<TestEvent>
25{
26public:
27 virtual ~TestSystem() {}
28
39
40 virtual void OnUpdate(Nui::ECS::Context* ctx, const Nui::F64 dt)
41 {
42 // Change all entities with test component values to 1
43 ctx->Each<TestComponent>(
45 {
46 comp->X = 1;
47 comp->Y = 1;
48 });
49 }
50
51 virtual void OnShutdown(Nui::ECS::Context* ctx)
52 {
53 ctx->UnsubscribeAll(this);
54 }
55
56 virtual void OnEvent(class Nui::ECS::Context* ctx, const Nui::ECS::Events::OnEntityCreate& event) override
57 {
58 }
59
60 virtual void OnEvent(class Nui::ECS::Context* ctx, const Nui::ECS::Events::OnEntityDestroy& event) override
61 {
62 }
63
64 virtual void OnEvent(class Nui::ECS::Context* ctx, const Nui::ECS::Events::OnComponentAdd<TestComponent>& event) override
65 {
66 m_testComponentCount++;
67 }
68
70 {
71 m_testComponentCount--;
72 }
73
74 virtual void OnEvent(class Nui::ECS::Context* ctx, const TestEvent& event) override
75 {
76 m_eventVal = event.ID;
77 }
78
79public:
80 bool m_initialized{ false };
81 Nui::I32 m_testComponentCount{ 0 };
82 Nui::I32 m_eventVal{ 0 };
83};
This class provides a handle to a component.
Definition Component.h:52
The ECS context class manages entities, systems, and events in the ECS framework.
Definition Context.h:17
Internal::EntityComponentView< Types... > Each(bool includePendingDestroy=false)
Iterates over all entities in the ECS context (used in ranged loops)
Definition ECS.h:551
void SubscribeEvent(EventSubscriber< T > *subscriber)
Subscribes to an event in the ECS context.
Definition ECS.h:460
void UnsubscribeAll(void *subscriber)
Un-subscribes from all events in the ECS context (usually called in the system destructor)
Definition ECS.h:501
Class to represent an entity in an ECS Context.
Definition Entity.h:10
Base class for all event subscribers.
Definition Event.h:27
Base class for all ECS systems.
Definition System.h:10
Definition TestECSStructures.h:25
virtual void OnEvent(class Nui::ECS::Context *ctx, const Nui::ECS::Events::OnEntityDestroy &event) override
Pure virtual function for handling event callback.
Definition TestECSStructures.h:60
virtual void OnEvent(class Nui::ECS::Context *ctx, const Nui::ECS::Events::OnEntityCreate &event) override
Pure virtual function for handling event callback.
Definition TestECSStructures.h:56
virtual void OnShutdown(Nui::ECS::Context *ctx)
Called when the system is shutdown.
Definition TestECSStructures.h:51
virtual void OnEvent(class Nui::ECS::Context *ctx, const TestEvent &event) override
Pure virtual function for handling event callback.
Definition TestECSStructures.h:74
virtual void OnInit(Nui::ECS::Context *ctx)
Called when the system is initialized.
Definition TestECSStructures.h:29
virtual void OnEvent(class Nui::ECS::Context *ctx, const Nui::ECS::Events::OnComponentRemove< TestComponent > &event) override
Pure virtual function for handling event callback.
Definition TestECSStructures.h:69
virtual void OnEvent(class Nui::ECS::Context *ctx, const Nui::ECS::Events::OnComponentAdd< TestComponent > &event) override
Pure virtual function for handling event callback.
Definition TestECSStructures.h:64
virtual void OnUpdate(Nui::ECS::Context *ctx, const Nui::F64 dt)
Called when the system is updated (every frame)
Definition TestECSStructures.h:40
Event for when component is added.
Definition Event.h:75
Event for when component is removed.
Definition Event.h:93
Event for entity creation.
Definition Event.h:51
Event for entity destruction.
Definition Event.h:62
Definition TestECSStructures.h:8
Definition TestECSStructures.h:15