Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include "renderGraph.hpp"
- void RenderGraph::SetEntities( const std::vector< Entity* >& a_entities ) {
- for ( unsigned int i = 0; i < a_entities.size(); ++i ) {
- nodes_.push_back( Node( a_entities[ i ] ) );
- };
- };
- void RenderGraph::CalculateDependencies() {
- for ( unsigned int j = 0; j < nodes_.size(); ++j ) {
- AABB::MinMax a = nodes_[ j ].entity_->GetMinMax();
- for ( unsigned int k = 0; k < nodes_.size(); ++k ) {
- if ( j != k ) {
- AABB::MinMax b = nodes_[ k ].entity_->GetMinMax();
- if ( b.min.x < a.max.x && b.min.y < a.max.y && b.min.z < a.max.z ) {
- nodes_[ j ].dependencies_.push_back( &nodes_[ k ] );
- };
- };
- };
- };
- };
- void RenderGraph::Sort( std::vector< Entity* >& a_output ) {
- int sortDepth = 0;
- for ( unsigned int i = 0; i < nodes_.size(); ++i ) {
- VisitNode( sortDepth, &nodes_[ i ] );
- };
- std::sort( nodes_.begin(), nodes_.end(), Comparator() );
- a_output.clear();
- for ( unsigned int i = 0; i < nodes_.size(); ++i ) {
- a_output.push_back( nodes_[ i ].entity_ );
- };
- };
- void RenderGraph::VisitNode( int& sortDepth, Node* a_node ) {
- if ( !a_node->visited_ ) {
- a_node->visited_ = true;
- for ( unsigned int i = 0; i < a_node->dependencies_.size(); ++i ) {
- if ( a_node->dependencies_[ i ] == nullptr ) {
- break;
- } else {
- VisitNode( sortDepth, a_node->dependencies_[ i ] );
- a_node->dependencies_[ i ] = nullptr;
- };
- };
- a_node->isoDepth_ = sortDepth++;
- };
- };
- bool RenderGraph::Comparator::operator()( const Node& a_lhs, const Node& a_rhs ) const {
- return a_lhs.isoDepth_ < a_rhs.isoDepth_;
- };
- RenderGraph::Node::Node( Entity* a_entity ) {
- entity_ = a_entity;
- isoDepth_ = -1;
- visited_ = false;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement