1#include <catch2/catch_test_macros.hpp>
3#include <Engine/RadiumEngine.hpp>
4#include <Engine/Scene/Component.hpp>
5#include <Engine/Scene/Entity.hpp>
6#include <Engine/Scene/EntityManager.hpp>
7#include <Engine/Scene/SignalManager.hpp>
14 Ra::Core::Utils::Index i { 0 };
22 explicit Bar( Foo& f ) : m_f { f } {};
23 void operator()(
const ItemEntry& entity ) { m_f.incr( entity ); }
33 void initialize()
override {};
36TEST_CASE(
"Engine/Scene/SignalManager/ON",
37 "[unittests][Engine][Engine/Scene][SignalManager][ON]" ) {
39 auto engine = Ra::Engine::RadiumEngine::createInstance();
43 signalmanager.
setOn(
true );
50 auto entity = engine->getEntityManager()->createEntity(
"test entity" );
52 SECTION(
"Entities signals" ) {
55 auto& delNotifier = signalmanager.getEntityDestroyedNotifier();
57 Bar bar { entitytest };
59 int ia = addNotifier.
attach( bar );
60 int id = delNotifier.attachMember( &entitytest, &Foo::decr );
62 REQUIRE( entitytest.i == 0 );
65 REQUIRE( entitytest.i == 1 );
66 REQUIRE( componenttest.i == 0 );
67 REQUIRE( renderobjecttest.i == 0 );
68 REQUIRE( eoftest.i == 0 );
71 REQUIRE( entitytest.i == 0 );
72 REQUIRE( componenttest.i == 0 );
73 REQUIRE( renderobjecttest.i == 0 );
74 REQUIRE( eoftest.i == 0 );
76 addNotifier.detach( ia );
78 REQUIRE( entitytest.i == 0 );
79 REQUIRE( componenttest.i == 0 );
80 REQUIRE( renderobjecttest.i == 0 );
81 REQUIRE( eoftest.i == 0 );
83 delNotifier.detach(
id );
85 REQUIRE( entitytest.i == 0 );
86 REQUIRE( componenttest.i == 0 );
87 REQUIRE( renderobjecttest.i == 0 );
88 REQUIRE( eoftest.i == 0 );
91 SECTION(
"Components signals" ) {
93 auto component =
new FooBarComponent(
"test component", entity );
96 auto& addNotifier = signalmanager.getComponentCreatedNotifier();
97 auto& delNotifier = signalmanager.getComponentDestroyedNotifier();
99 auto bar = [&componenttest](
const ItemEntry& e ) { componenttest.incr( e ); };
101 int ia = addNotifier.attach( bar );
102 int id = delNotifier.attachMember( &componenttest, &Foo::decr );
104 REQUIRE( componenttest.i == 0 );
107 REQUIRE( componenttest.i == 1 );
108 REQUIRE( entitytest.i == 0 );
109 REQUIRE( renderobjecttest.i == 0 );
110 REQUIRE( eoftest.i == 0 );
113 REQUIRE( componenttest.i == 0 );
114 REQUIRE( entitytest.i == 0 );
115 REQUIRE( renderobjecttest.i == 0 );
116 REQUIRE( eoftest.i == 0 );
118 addNotifier.detach( ia );
120 REQUIRE( componenttest.i == 0 );
121 REQUIRE( entitytest.i == 0 );
122 REQUIRE( renderobjecttest.i == 0 );
123 REQUIRE( eoftest.i == 0 );
125 delNotifier.detach(
id );
127 REQUIRE( componenttest.i == 0 );
128 REQUIRE( entitytest.i == 0 );
129 REQUIRE( renderobjecttest.i == 0 );
130 REQUIRE( eoftest.i == 0 );
132 SECTION(
"RenderObjects signals" ) {
134 auto component =
new FooBarComponent(
"test component", entity );
137 auto& addNotifier = signalmanager.getRenderObjectCreatedNotifier();
138 auto& delNotifier = signalmanager.getRenderObjectDestroyedNotifier();
140 int ia = addNotifier.attach(
141 [&renderobjecttest](
const ItemEntry& e ) { renderobjecttest.incr( e ); } );
142 int id = delNotifier.attachMember( &renderobjecttest, &Foo::decr );
144 REQUIRE( renderobjecttest.i == 0 );
147 REQUIRE( renderobjecttest.i == 1 );
148 REQUIRE( componenttest.i == 0 );
149 REQUIRE( entitytest.i == 0 );
150 REQUIRE( eoftest.i == 0 );
153 REQUIRE( renderobjecttest.i == 0 );
154 REQUIRE( componenttest.i == 0 );
155 REQUIRE( entitytest.i == 0 );
156 REQUIRE( eoftest.i == 0 );
158 addNotifier.detach( ia );
160 REQUIRE( renderobjecttest.i == 0 );
161 REQUIRE( componenttest.i == 0 );
162 REQUIRE( entitytest.i == 0 );
163 REQUIRE( eoftest.i == 0 );
165 delNotifier.detach(
id );
167 REQUIRE( renderobjecttest.i == 0 );
168 REQUIRE( componenttest.i == 0 );
169 REQUIRE( entitytest.i == 0 );
170 REQUIRE( eoftest.i == 0 );
173 SECTION(
"End of Frame signal" ) {
175 auto component =
new FooBarComponent(
"test component", entity );
178 auto& eofNotifier = signalmanager.getEndFrameNotifier();
182 int ia = eofNotifier.attach( [&eoftest, item]() { eoftest.incr( item ); } );
184 REQUIRE( eoftest.i == 0 );
187 REQUIRE( eoftest.i == 1 );
189 REQUIRE( eoftest.i == 2 );
191 eofNotifier.detach( ia );
193 REQUIRE( eoftest.i == 2 );
196 Ra::Engine::RadiumEngine::destroyInstance();
199TEST_CASE(
"Engine/Scene/SignalManager/OFF/",
200 "[unittests][Engine][Engine/Scene][SignalManager][OFF]" ) {
202 auto engine = Ra::Engine::RadiumEngine::createInstance();
203 engine->initialize();
206 signalmanager.
setOn(
false );
208 auto entity = engine->getEntityManager()->createEntity(
"test entity" );
212 Foo renderobjecttest;
215 SECTION(
"Entities signals" ) {
218 auto& delNotifier = signalmanager.getEntityDestroyedNotifier();
220 Bar bar { entitytest };
222 addNotifier.
attach( bar );
223 delNotifier.attachMember( &entitytest, &Foo::decr );
225 REQUIRE( entitytest.i == 0 );
228 REQUIRE( entitytest.i == 0 );
229 REQUIRE( componenttest.i == 0 );
230 REQUIRE( renderobjecttest.i == 0 );
231 REQUIRE( eoftest.i == 0 );
234 REQUIRE( entitytest.i == 0 );
235 REQUIRE( componenttest.i == 0 );
236 REQUIRE( renderobjecttest.i == 0 );
237 REQUIRE( eoftest.i == 0 );
240 SECTION(
"Components signals" ) {
241 auto component =
new FooBarComponent(
"test component", entity );
244 auto& addNotifier = signalmanager.getComponentCreatedNotifier();
245 auto& delNotifier = signalmanager.getComponentDestroyedNotifier();
247 auto bar = [&componenttest](
const ItemEntry& e ) { componenttest.incr( e ); };
249 addNotifier.
attach( bar );
250 delNotifier.attachMember( &componenttest, &Foo::decr );
252 REQUIRE( componenttest.i == 0 );
255 REQUIRE( componenttest.i == 0 );
256 REQUIRE( entitytest.i == 0 );
257 REQUIRE( renderobjecttest.i == 0 );
258 REQUIRE( eoftest.i == 0 );
261 REQUIRE( componenttest.i == 0 );
262 REQUIRE( entitytest.i == 0 );
263 REQUIRE( renderobjecttest.i == 0 );
264 REQUIRE( eoftest.i == 0 );
267 SECTION(
"RenderObjects signals" ) {
269 auto component =
new FooBarComponent(
"test component", entity );
272 auto& addNotifier = signalmanager.getRenderObjectCreatedNotifier();
273 auto& delNotifier = signalmanager.getRenderObjectDestroyedNotifier();
276 [&renderobjecttest](
const ItemEntry& e ) { renderobjecttest.incr( e ); } );
277 delNotifier.attachMember( &renderobjecttest, &Foo::decr );
279 REQUIRE( renderobjecttest.i == 0 );
282 REQUIRE( renderobjecttest.i == 0 );
283 REQUIRE( componenttest.i == 0 );
284 REQUIRE( entitytest.i == 0 );
285 REQUIRE( eoftest.i == 0 );
288 REQUIRE( renderobjecttest.i == 0 );
289 REQUIRE( componenttest.i == 0 );
290 REQUIRE( entitytest.i == 0 );
291 REQUIRE( eoftest.i == 0 );
294 SECTION(
"End of Frame signal" ) {
295 auto component =
new FooBarComponent(
"test component", entity );
298 auto& eofNotifier = signalmanager.getEndFrameNotifier();
302 eofNotifier.attach( [&eoftest, item]() { eoftest.incr( item ); } );
304 REQUIRE( eoftest.i == 0 );
307 REQUIRE( eoftest.i == 0 );
310 Ra::Engine::RadiumEngine::destroyInstance();
int attach(Observer observer)
A component is an element that can be updated by a system. It is also linked to some other components...
Component(const std::string &name, Entity *entity)
CONSTRUCTOR.
void fireEntityDestroyed(const ItemEntry &entity) const
Notifies all observers of an entity removal.
ItemObservable & getEntityCreatedNotifier()
void fireRenderObjectRemoved(const ItemEntry &ro) const
Notifies all observers of a render object removal.
void fireComponentAdded(const ItemEntry &component) const
Notifies all observers of a component creation.
void setOn(bool on)
Enable/disable the notification of observers.
void fireEntityCreated(const ItemEntry &entity) const
Notifies all observers of an entity creation.
void fireComponentRemoved(const ItemEntry &component) const
Notifies all observers of a component removal.
void fireRenderObjectAdded(const ItemEntry &ro) const
Notifies all observers of a render object creation.
void fireFrameEnded() const
Notifies all observers of a end of frame event.
Scene and how to communicate.