Radium Engine  1.5.0
ComponentMessenger.cpp
1 #include <Engine/Scene/ComponentMessenger.hpp>
2 
3 #include <functional>
4 
5 namespace Ra {
6 namespace Engine {
7 namespace Scene {
8 
9 RA_SINGLETON_IMPLEMENTATION( ComponentMessenger );
10 
11 void ComponentMessenger::unregisterAll( const Entity* entity, Component* comp ) {
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
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
Definition: Cage.cpp:3