Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PathManager Class Reference

#include <navpath.h>

Public Types

enum  UpdateType { ALL, CURRENT, TARGET }
 

Public Member Functions

void addPath ()
 
bool removePath (NavPath *path)
 
void showAll ()
 
void showNone ()
 
bool updateSpecificPath (NavPath *path)
 
void updatePaths (UpdateType type=ALL)
 
void updateDependants (NavPath *parent)
 
 PathManager ()
 
 ~PathManager ()
 

Protected Member Functions

void DFS ()
 
void dfsVisit (NavPath *path)
 

Protected Attributes

std::vector< NavPath * > paths
 
std::list< NavPath * > topoOrder
 
unsigned topoTime
 

Friends

class NavPath
 
class NavComputer
 

Detailed Description

Definition at line 131 of file navpath.h.

Member Enumeration Documentation

Enumerator
ALL 
CURRENT 
TARGET 

Definition at line 139 of file navpath.h.

139 {ALL, CURRENT, TARGET};

Constructor & Destructor Documentation

PathManager::PathManager ( )

Definition at line 646 of file navpath.cpp.

646 {}
PathManager::~PathManager ( )

Definition at line 648 of file navpath.cpp.

References i, and paths.

649 {
650  for (std::vector< NavPath* >::iterator i = paths.begin(); i < paths.end(); ++i) {
651  delete (*i);
652  (*i) = NULL;
653  }
654 }

Member Function Documentation

void PathManager::addPath ( )

Definition at line 546 of file navpath.cpp.

References NavPath, paths, and NavPath::setSourceNode().

Referenced by NavComputer::actionAdd().

547 {
548  NavPath *path = new NavPath();
549  path->setSourceNode( new CurrentPathNode() );
550  paths.push_back( path );
551 }
void PathManager::DFS ( )
protected

Definition at line 620 of file navpath.cpp.

References dfsVisit(), paths, TOPO_WHITE, topoOrder, and topoTime.

Referenced by updatePaths().

621 {
622  topoOrder.clear();
623  std::vector< NavPath* >::iterator u;
624  for (u = paths.begin(); u < paths.end(); ++u)
625  (*u)->topoColor = TOPO_WHITE;
626  topoTime = 0;
627  for (u = paths.begin(); u < paths.end(); ++u)
628  if ( (*u)->topoColor == TOPO_WHITE )
629  dfsVisit( *u );
630 }
void PathManager::dfsVisit ( NavPath path)
protected

Definition at line 632 of file navpath.cpp.

References NavPath::getDependants(), TOPO_BLACK, TOPO_GRAY, TOPO_WHITE, NavPath::topoColor, topoOrder, NavPath::topoTime, topoTime, and v.

Referenced by DFS().

633 {
634  path->topoColor = TOPO_GRAY;
635 
636  std::set< NavPath* > *dependants = path->getDependants();
637  for (std::set< NavPath* >::iterator v = dependants->begin(); v != dependants->end(); ++v)
638  if ( (*v)->topoColor == TOPO_WHITE )
639  dfsVisit( *v );
640  path->topoColor = TOPO_BLACK;
641  ++topoTime;
642  path->topoTime = topoTime;
643  topoOrder.push_front( path );
644 }
bool PathManager::removePath ( NavPath path)

Definition at line 553 of file navpath.cpp.

References i, and paths.

Referenced by NavComputer::actionRemove().

554 {
555  bool ret = false;
556  for (std::vector< NavPath* >::iterator i = paths.begin(); i < paths.end(); ++i)
557  if ( (*i) == path ) {
558  delete (*i);
559  ret = true;
560  paths.erase( i );
561  }
562  return ret;
563 }
void PathManager::showAll ( )

Definition at line 565 of file navpath.cpp.

References i, and paths.

Referenced by NavComputer::actionShowAll().

566 {
567  for (std::vector< NavPath* >::iterator i = paths.begin(); i < paths.end(); ++i)
568  (*i)->setVisible( true );
569 }
void PathManager::showNone ( )

Definition at line 571 of file navpath.cpp.

References i, and paths.

Referenced by NavComputer::actionShowNone().

572 {
573  for (std::vector< NavPath* >::iterator i = paths.begin(); i < paths.end(); ++i)
574  (*i)->setVisible( false );
575 }
void PathManager::updateDependants ( NavPath parent)

Definition at line 613 of file navpath.cpp.

References NavPath::getDependants(), i, and updateSpecificPath().

Referenced by updateSpecificPath().

614 {
615  set< NavPath* > *dependants = parent->getDependants();
616  for (std::set< NavPath* >::iterator i = dependants->begin(); i != dependants->end(); ++i)
617  updateSpecificPath( *i );
618 }
void PathManager::updatePaths ( UpdateType  type = ALL)

Definition at line 585 of file navpath.cpp.

References ALL, CURRENT, DFS(), i, j, paths, topoOrder, and updateSpecificPath().

Referenced by NavComputer::toggleVisibility(), and GameCockpit::visitSystem().

586 {
587  std::list< NavPath* >::iterator i;
588  DFS();
589  if (type == ALL) {
590  for (std::vector< NavPath* >::iterator j = paths.begin(); j < paths.end(); ++j) {
591  std::cerr<<"Updating path: "<<(*j)->getName()<<endl;
592  (*j)->update();
593  }
594  } else if (type == CURRENT) {
595  for (i = topoOrder.begin(); i != topoOrder.end(); ++i)
596  (*i)->updated = false;
597  for (i = topoOrder.begin(); i != topoOrder.end(); ++i)
598  if ( (*i)->updated == false && (*i)->isCurrentDependant() ) {
599  std::cerr<<"Updating path: "<<(*i)->getName()<<endl;
600  updateSpecificPath( *i );
601  }
602  } else {
603  for (i = topoOrder.begin(); i != topoOrder.end(); ++i)
604  (*i)->updated = false;
605  for (i = topoOrder.begin(); i != topoOrder.end(); ++i)
606  if ( (*i)->updated == false && (*i)->isTargetDependant() ) {
607  std::cerr<<"Updating path: "<<(*i)->getName()<<endl;
608  updateSpecificPath( *i );
609  }
610  }
611 }
bool PathManager::updateSpecificPath ( NavPath path)

Definition at line 577 of file navpath.cpp.

References NavPath::update(), NavPath::updated, and updateDependants().

Referenced by NavPath::setDestinationNode(), NavPath::setSourceNode(), updateDependants(), and updatePaths().

578 {
579  path->updated = true;
580  path->update();
581  updateDependants( path );
582  return path->updated;
583 }

Friends And Related Function Documentation

friend class NavComputer
friend

Definition at line 149 of file navpath.h.

friend class NavPath
friend

Definition at line 148 of file navpath.h.

Referenced by addPath().

Member Data Documentation

std::vector< NavPath* > PathManager::paths
protected
std::list< NavPath* > PathManager::topoOrder
protected

Definition at line 152 of file navpath.h.

Referenced by DFS(), dfsVisit(), and updatePaths().

unsigned PathManager::topoTime
protected

Definition at line 156 of file navpath.h.

Referenced by DFS(), and dfsVisit().


The documentation for this class was generated from the following files: