Advertisement
Guest User

Untitled

a guest
May 7th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include <algorithm>
  2.  
  3. #include "renderGraph.hpp"
  4.  
  5. void RenderGraph::SetEntities( const std::vector< Entity* >& a_entities ) {
  6.     for ( unsigned int i = 0; i < a_entities.size(); ++i ) {
  7.         nodes_.push_back( Node( a_entities[ i ] ) );
  8.     };
  9. };
  10.  
  11. void RenderGraph::CalculateDependencies() {
  12.     for ( unsigned int j = 0; j < nodes_.size(); ++j ) {
  13.         AABB::MinMax a = nodes_[ j ].entity_->GetMinMax();
  14.  
  15.         for ( unsigned int k = 0; k < nodes_.size(); ++k ) {
  16.             if ( j != k ) {
  17.                 AABB::MinMax b = nodes_[ k ].entity_->GetMinMax();
  18.                 if ( b.min.x < a.max.x && b.min.y < a.max.y && b.min.z < a.max.z ) {
  19.                     nodes_[ j ].dependencies_.push_back( &nodes_[ k ] );
  20.                 };
  21.             };
  22.         };
  23.     };
  24. };
  25.  
  26. void RenderGraph::Sort( std::vector< Entity* >& a_output ) {
  27.     int sortDepth = 0;
  28.  
  29.     for ( unsigned int i = 0; i < nodes_.size(); ++i ) {
  30.         VisitNode( sortDepth, &nodes_[ i ] );
  31.     };
  32.  
  33.     std::sort( nodes_.begin(), nodes_.end(), Comparator() );
  34.  
  35.     a_output.clear();
  36.     for ( unsigned int i = 0; i < nodes_.size(); ++i ) {
  37.         a_output.push_back( nodes_[ i ].entity_ );
  38.     };
  39. };
  40.  
  41. void RenderGraph::VisitNode( int& sortDepth, Node* a_node ) {
  42.     if ( a_node->isoDepth_ < 0 ) {
  43.         for ( unsigned int i = 0; i < a_node->dependencies_.size(); ++i ) {
  44.             if ( a_node->dependencies_[ i ] == nullptr ) {
  45.                 break;
  46.             } else {
  47.                 VisitNode( sortDepth, a_node->dependencies_[ i ] );
  48.                 a_node->dependencies_[ i ] = nullptr;
  49.             };
  50.         };
  51.  
  52.         a_node->isoDepth_ = sortDepth++;
  53.     };
  54. };
  55.  
  56. bool RenderGraph::Comparator::operator()( const Node& a_lhs, const Node& a_rhs ) const {
  57.     return a_lhs.isoDepth_ < a_rhs.isoDepth_;
  58. };
  59.  
  60. RenderGraph::Node::Node( Entity* a_entity ) {
  61.     entity_ = a_entity;
  62.     isoDepth_ = -1;
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement