Radium Engine  1.5.20
Loading...
Searching...
No Matches
ComponentMessenger.cpp
1#include <Engine/Scene/ComponentMessenger.hpp>
2
3#include <functional>
4
5namespace Ra {
6namespace Engine {
7namespace Scene {
8
9RA_SINGLETON_IMPLEMENTATION( ComponentMessenger );
10
12 for ( auto& entityList : std::array<std::reference_wrapper<EntityMap>, 3> {
13 { m_entitySetLists, m_entityGetLists, m_entityRwLists } } ) {
14
15 auto listItr = entityList.get().find( entity );
16 if ( listItr != entityList.get().end() ) {
17 CallbackMap& list = listItr->second;
18
19 // erase_if implementation for map's, should be replaced by std::erase_if(list, pred)
20 // when RadiumEngine's c++ version will be c++20
21 // see https://en.cppreference.com/w/cpp/container/unordered_map/erase_if
22 auto pred = [comp]( const Key& k ) -> bool { return k.first == comp->getName(); };
23 for ( auto it = list.begin(); it != list.end(); ) {
24 if ( pred( it->first ) )
25 it = list.erase( it );
26 else
27 ++it;
28 }
29 }
30 }
31}
32
33} // namespace Scene
34} // namespace Engine
35} // namespace Ra
T begin(T... args)
void unregisterAll(const Entity *entity, Component *component)
unregister all callbacks attached to entity's component
A component is an element that can be updated by a system. It is also linked to some other components...
Definition Component.hpp:31
virtual const std::string & getName() const
Return the component's name.
Definition Component.hpp:56
An entity is an scene element. It ties together components with a transform.
Definition Entity.hpp:23
T end(T... args)
T erase(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3