1#include <Engine/Rendering/RenderObjectManager.hpp>
3#include <Engine/RadiumEngine.hpp>
5#include <Engine/Scene/Component.hpp>
6#include <Engine/Scene/Entity.hpp>
8#include <Engine/Data/Mesh.hpp>
9#include <Engine/Rendering/RenderObject.hpp>
11#include <Engine/Scene/SignalManager.hpp>
19RenderObjectManager::RenderObjectManager() =
default;
21RenderObjectManager::~RenderObjectManager() =
default;
23bool RenderObjectManager::exists(
const Core::Utils::Index& index )
const {
24 return ( index.isValid() && m_renderObjects.contains( index ) );
27Core::Utils::Index RenderObjectManager::addRenderObject( Rendering::RenderObject* renderObject ) {
32 Core::Utils::Index index = m_renderObjects.insert( newRenderObject );
34 newRenderObject->setIndex( index );
36 auto type = renderObject->getType();
38 m_renderObjectByType[(int)type].insert( index );
40 Engine::RadiumEngine::getInstance()->getSignalManager()->fireRenderObjectAdded(
42 renderObject->getComponent()->getEntity(), renderObject->getComponent(), index ) );
46void RenderObjectManager::removeRenderObject(
const Core::Utils::Index& index ) {
47 CORE_ASSERT( exists( index ),
"Trying to access a render object which doesn't exist" );
52 Engine::RadiumEngine::getInstance()->getSignalManager()->fireRenderObjectRemoved(
54 renderObject->getComponent()->getEntity(), renderObject->getComponent(), index ) );
58 m_renderObjects.remove( index );
60 auto type = renderObject->getType();
61 m_renderObjectByType[(int)type].erase( index );
65size_t RenderObjectManager::getRenderObjectsCount() {
66 return m_renderObjects.size();
70RenderObjectManager::getRenderObject(
const Core::Utils::Index& index ) {
71 CORE_ASSERT( exists( index ),
"Trying to access a render object which doesn't exist" );
72 return m_renderObjects.at( index );
75const Core::Utils::IndexMap<std::shared_ptr<Rendering::RenderObject>>&
76RenderObjectManager::getRenderObjects()
const {
77 return m_renderObjects;
80void RenderObjectManager::getRenderObjectsByType(
88 m_renderObjectByType[(
int)type].begin(),
89 m_renderObjectByType[(
int)type].end(),
91 [
this](
const Core::Utils::Index& i ) {
return this->m_renderObjects.at( i ); } );
94void RenderObjectManager::renderObjectExpired(
const Core::Utils::Index& idx ) {
97 auto ro = m_renderObjects.at( idx );
98 m_renderObjects.remove( idx );
100 auto type = ro->getType();
102 m_renderObjectByType[size_t( type )].erase( idx );
109size_t RenderObjectManager::getNumFaces()
const {
112 m_renderObjects.begin(),
113 m_renderObjects.end(),
116 if ( ro->isVisible() && ro->getType() == Rendering::RenderObjectType::Geometry ) {
117 return a + ro->getMesh()->getNumFaces();
124size_t RenderObjectManager::getNumVertices()
const {
127 m_renderObjects.begin(),
128 m_renderObjects.end(),
131 if ( ro->isVisible() && ro->getType() == Rendering::RenderObjectType::Geometry ) {
132 return a + ro->getMesh()->getNumVertices();
T back_inserter(T... args)
hepler function to manage enum as underlying types in VariableSet