00001 #include "ClientUpdater.h" 00002 00003 #include "Level.h" 00004 #include "Team.h" 00005 #include "Client.h" 00006 #include "FogOfWar.h" 00007 #include "Unit.h" 00008 00009 #include "OgreEntity.h" 00010 #include "OgreMovableObject.h" 00011 using Ogre::Entity; 00012 using Ogre::MovableObject; 00013 00014 namespace ASR 00015 { 00016 // ---------------------------------------------------------------------------- 00017 ClientUpdater::ClientUpdater ( Client* parentClient ) 00018 : mClient ( parentClient ) 00019 { 00020 } 00021 00022 00023 // ---------------------------------------------------------------------------- 00024 ClientUpdater::~ClientUpdater () 00025 { 00026 00027 } 00028 00029 00030 // ---------------------------------------------------------------------------- 00031 bool ClientUpdater::updateBeforeFrame ( const FrameEvent& e, const InputReader* inputDevice ) 00032 { 00033 _findVisibleObjects (); 00034 00035 return true; 00036 } 00037 00038 00039 // ---------------------------------------------------------------------------- 00040 bool ClientUpdater::updateAfterFrame ( const FrameEvent& e, const InputReader* inputDevice ) 00041 { 00042 return true; 00043 } 00044 00045 00046 // ---------------------------------------------------------------------------- 00047 void ClientUpdater::_findVisibleObjects () const 00048 { 00049 FogOfWar* fog = mClient->mTeam->getFogOfWar (); 00050 00051 Level::TeamList enemyList = Level::getSingleton ().getEnemyTeams ( mClient->mTeam ); 00052 Level::TeamIterator iter ( enemyList.begin(), enemyList.end() ); 00053 00054 while ( iter.hasMoreElements () ) 00055 { 00056 Team* enemyTeam = iter.getNext (); 00057 TeamUnits::UnitIterator unitIter = enemyTeam->getUnitIterator (); 00058 while ( unitIter.hasMoreElements () ) 00059 { 00060 Unit* enemyUnit = unitIter.getNext (); 00061 00062 // HACK 00063 // Dead units should still be visible as long as they are dying 00064 if ( !enemyUnit->isDead() && fog->isUnitVisible ( enemyUnit ) ) 00065 { 00066 _showUnit ( enemyUnit ); 00067 } 00068 else 00069 { 00070 _hideUnit ( enemyUnit ); 00071 } 00072 } 00073 } 00074 } 00075 00076 00077 // ---------------------------------------------------------------------------- 00078 void ClientUpdater::_showUnit ( Unit* unit ) const 00079 { 00080 unit->getEntity ()->getParentSceneNode ()->setVisible ( true ); 00081 Entity::ChildObjectListIterator iter = unit->getEntity ()->getAttachedObjectIterator (); 00082 while ( iter.hasMoreElements () ) 00083 { 00084 MovableObject* obj = iter.getNext (); 00085 obj->setVisible ( true ); 00086 } 00087 } 00088 00089 00090 // ---------------------------------------------------------------------------- 00091 void ClientUpdater::_hideUnit ( Unit* unit ) const 00092 { 00093 unit->getEntity ()->getParentSceneNode ()->setVisible ( false ); 00094 Entity::ChildObjectListIterator iter = unit->getEntity ()->getAttachedObjectIterator (); 00095 while ( iter.hasMoreElements () ) 00096 { 00097 MovableObject* obj = iter.getNext (); 00098 obj->setVisible ( false ); 00099 } 00100 } 00101 }