Radium Engine  1.5.0
ItemEntry.cpp
1 
2 #include <Engine/Scene/ItemEntry.hpp>
3 
4 #include <Engine/RadiumEngine.hpp>
5 
6 #include <Engine/Scene/EntityManager.hpp>
7 #include <Engine/Scene/SystemDisplay.hpp>
8 
9 #include <Engine/Rendering/RenderObject.hpp>
10 #include <Engine/Rendering/RenderObjectManager.hpp>
11 
12 namespace Ra {
13 namespace Engine {
14 namespace Scene {
15 
16 std::string getEntryName( const Engine::RadiumEngine* engine, const ItemEntry& ent ) {
17  if ( ent.isValid() ) {
18  if ( ent.isRoNode() ) {
19  return engine->getRenderObjectManager()->getRenderObject( ent.m_roIndex )->getName();
20  }
21  else if ( ent.isComponentNode() ) { return ent.m_component->getName(); }
22  else if ( ent.isEntityNode() ) { return ent.m_entity->getName(); }
23  }
24  return "Invalid Entry";
25 }
26 
27 std::vector<Ra::Core::Utils::Index> getItemROs( const Engine::RadiumEngine* /*engine*/,
28  const ItemEntry& ent ) {
29  std::vector<Ra::Core::Utils::Index> result;
30  if ( ent.isValid() ) {
31  if ( ent.isRoNode() ) { result.push_back( ent.m_roIndex ); }
32  else if ( ent.isComponentNode() ) { result = ent.m_component->m_renderObjects; }
33  else if ( ent.isEntityNode() ) {
34  for ( const auto& c : ent.m_entity->getComponents() ) {
35  result.insert( result.end(), c->m_renderObjects.begin(), c->m_renderObjects.end() );
36  }
37  }
38  }
39  return result;
40 }
41 
42 bool ItemEntry::isValid() const {
43  ON_DEBUG( checkConsistency() );
44  Engine::RadiumEngine* engine = Engine::RadiumEngine::getInstance();
45  return m_entity != nullptr // It has an entity
46  && engine->getEntityManager() // Is entityManager up ?
47  && engine->getEntityManager()->entityExists( m_entity->getName() ) // The entity exists
48  && ( ( !isRoNode() ||
49  engine->getRenderObjectManager()->exists( m_roIndex ) ) ); // The RO exists
50 }
51 
53  Engine::RadiumEngine* engine = Engine::RadiumEngine::getInstance();
54 
55  if ( m_entity->getIndex() == SystemEntity::getInstance()->getIndex() ) { return false; }
56 
57  if ( isRoNode() ) {
58  const bool isUI =
59  engine->getRenderObjectManager()->getRenderObject( m_roIndex )->getType() ==
60  Rendering::RenderObjectType::UI;
61  const bool isDebug =
62  engine->getRenderObjectManager()->getRenderObject( m_roIndex )->getType() ==
63  Rendering::RenderObjectType::Debug;
64  return ( !( isUI || isDebug ) );
65  }
66 
67  return true;
68 }
69 
70 } // namespace Scene
71 } // namespace Engine
72 } // namespace Ra
Scene::EntityManager * getEntityManager() const
Rendering::RenderObjectManager * getRenderObjectManager() const
Manager getters.
Definition: Cage.cpp:3
Ra::Core::Utils::Index m_roIndex
RO index of the represented object.
Definition: ItemEntry.hpp:67
bool isValid() const
Returns true if the item represents any valid object.
Definition: ItemEntry.cpp:42
bool isSelectable() const
Returns true if the item can be selected.
Definition: ItemEntry.cpp:52
void checkConsistency() const
Debug checks.
Definition: ItemEntry.hpp:95
Entity * m_entity
The entity represented by the item, or owning the object represented.
Definition: ItemEntry.hpp:60
bool isRoNode() const
Returns true if the item represents a render object.
Definition: ItemEntry.hpp:90