D:/simple_rts/src/TeamUpdater.cpp

Go to the documentation of this file.
00001 #include "TeamUpdater.h"
00002 
00003 #include "Team.h"
00004 #include "TeamUnits.h"
00005 #include "TeamBuildings.h"
00006 
00007 #include "FogOfWar.h"
00008 #include "Unit.h"
00009 #include "TeamUnits.h"
00010 
00011 #include "OgreMaterialManager.h"
00012 #include "OgreMaterial.h"
00013 #include "OgreEntity.h"
00014 #include "OgreSubEntity.h"
00015 using namespace Ogre;
00016 
00017 #include "OgreVector3.h"
00018 using Ogre::Vector3;
00019 
00020 
00021 namespace ASR
00022 {
00023         // ----------------------------------------------------------------------------
00024         TeamUpdater::TeamUpdater ( Team* team )
00025                 : mTeam ( team )
00026         {
00027                 mFadeTime = 0.0f;
00028         }
00029 
00030 
00031         // ----------------------------------------------------------------------------
00032         TeamUpdater::~TeamUpdater(void)
00033         {
00034         }
00035 
00036 
00037         // ----------------------------------------------------------------------------
00038         bool TeamUpdater::updateBeforeFrame ( const Ogre::FrameEvent& e, const Ogre::InputReader* inputDevice )
00039         {
00040                 mTeam->mUnits->animateUnits( e.timeSinceLastFrame );
00041                 mTeam->mUnits->moveUnits ( e.timeSinceLastFrame );
00042 
00043                 mTeam->mUnits->updateSpatialGrid ();
00044 
00045                 // TODO
00046                 //              Make some constants for the timeToFadeOneUnit
00047                 // Update the fog of war
00048                 mFadeTime += e.timeSinceLastFrame;
00049                 if ( mFadeTime >= 0.05f )
00050                 {
00051                         mTeam->mFogOfWar->fadeOut ();
00052                         mFadeTime -= 0.05f;
00053                 }
00054 
00055                 TeamUnits::UnitIterator iter = mTeam->getUnitIterator ();
00056                 while ( iter.hasMoreElements () )
00057                 {
00058                         Unit* unit = iter.getNext ();
00059                         if ( !unit->isDead () )
00060                                 mTeam->mFogOfWar->setVisible ( unit->getPosition().x, unit->getPosition().z, unit->getSightRadius () );
00061                 }
00062                 mTeam->mFogOfWar->updateTexture ();
00063 
00064                 return true;
00065         }
00066 
00067 
00068         // ----------------------------------------------------------------------------
00069         bool TeamUpdater::updateAfterFrame ( const Ogre::FrameEvent& e, const Ogre::InputReader* inputDevice )
00070         {
00071                 // Only find the targets after the frame has passed so that each unit
00072                 // from each team is now in their final positions
00073                 mTeam->mUnits->findTargets ();
00074                 mTeam->mUnits->performAttacks ();
00075 
00076                 // HACK
00077                 //              Fade units out
00078                 static float alpha = 1.0f;
00079                 alpha -= ( 1.0f / 5.0f ) * e.timeSinceLastFrame;
00080                 if ( alpha < 0.0f )
00081                         alpha = 1.0f;
00082 
00083                 Unit* unit = mTeam->mUnits->getUnit ( 0 );
00084                 MaterialPtr mat = unit->getEntity ()->getSubEntity (0)->getMaterial ();
00085                 //mat->getSupportedTechnique (0)->getPass(0)->setSceneBlending ( Ogre::SBT_ADD );
00086                 //mat->getSupportedTechnique (0)->getPass(0)->setDiffuse ( alpha, alpha, alpha, alpha );
00087                 //mat->getSupportedTechnique (0)->getPass(0)->setAmbient ( alpha, alpha, alpha );
00088 
00089 
00090                 
00091                 /*
00092                 unsigned short i = 0, j;
00093                 ColourValue sc, dc; // Source colur, destination colour
00094                 Material::TechniqueIterator techniqueIt = mat->getTechniqueIterator ();
00095                 while (techniqueIt.hasMoreElements ())
00096                 {
00097                         Technique *t = techniqueIt.getNext ();
00098                         Technique::PassIterator passIt = t->getPassIterator ();
00099                         j = 0;
00100                         while (passIt.hasMoreElements ())
00101                         {
00102                                 sc = mat->getTechnique (i)->getPass (j)->getDiffuse ();
00103 
00104                                 Ogre::SceneBlendType mSBT = SBT_TRANSPARENT_ALPHA;
00105 
00106                                 switch (mSBT)
00107                                 {
00108                                 case SBT_ADD:
00109                                         dc = sc;
00110                                         dc.r -= sc.r * alpha;
00111                                         dc.g -= sc.g * alpha;
00112                                         dc.b -= sc.b * alpha;
00113                                         passIt.peekNext ()->setAmbient (ColourValue::Black);
00114                                         break;
00115                                 case SBT_TRANSPARENT_ALPHA:
00116                                 default:
00117                                         dc = sc;
00118                                         dc.a = sc.a * (1.0f - alpha);
00119                                         passIt.peekNext ()->setAmbient (mat->getTechnique (i)->getPass (j)->getAmbient ());
00120                                         break;
00121                                 }
00122                                 passIt.peekNext ()->setDiffuse (dc);
00123                                 passIt.moveNext ();
00124 
00125                                 ++j;
00126                         }
00127 
00128                         ++i;
00129                 }
00130                 */
00131                 
00132 
00133                 return true;
00134         }
00135 }

Generated on Sun Jun 25 19:23:43 2006 for Valors End by  doxygen 1.4.7