#include <LevelStatusVisualizer.h>
Inheritance diagram for ASR::LevelStatusVisualizer:
Public Member Functions | |
LevelStatusVisualizer (Level *lev) | |
~LevelStatusVisualizer (void) | |
bool | updateBeforeFrame (const FrameEvent &e, const InputReader *inputDevice) |
Called each frame to perform the "update". | |
bool | updateAfterFrame (const FrameEvent &e, const InputReader *inputDevice) |
Private Member Functions | |
void | _rebuild () |
void | _paintBlockedTiles (unsigned char *data, unsigned int rowSkip) |
void | _paintUnitPaths (unsigned char *data, unsigned int rowSkip) |
Private Attributes | |
Level * | mLevel |
TexturePtr | tex |
It is mainly used for debugging as it renders a layer on top of the terrain.
Color coded squares will be rendered over the entire terrain to represent the current state of the occupied cells.
Definition at line 38 of file LevelStatusVisualizer.h.
ASR::LevelStatusVisualizer::LevelStatusVisualizer | ( | Level * | lev | ) |
Definition at line 38 of file LevelStatusVisualizer.cpp.
References _rebuild(), ASR::Level::mCellsHigh, ASR::Level::mCellsWide, mLevel, and tex.
00039 : mLevel ( lev ) 00040 { 00041 // Create a dynamic texture 00042 tex = TextureManager::getSingleton ().createManual ( 00043 "DynamicTexture", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 00044 Ogre::TEX_TYPE_2D, mLevel->mCellsWide, mLevel->mCellsHigh, 0, Ogre::PF_BYTE_BGRA, Ogre::TU_DYNAMIC_WRITE_ONLY ); 00045 00046 00047 // Add another layer onto the terrain to show the occlusion information 00048 MaterialPtr material = MaterialManager::getSingleton ().getByName ( "ASR/Terrain" ); 00049 TextureUnitState* texState = material->getTechnique (0)->getPass (0)->createTextureUnitState ( "DynamicTexture" ); 00050 texState->setColourOperation ( Ogre::LBO_ADD ); 00051 00052 texState->setTextureFiltering ( Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_NONE ); 00053 00054 _rebuild(); 00055 }
ASR::LevelStatusVisualizer::~LevelStatusVisualizer | ( | void | ) |
void ASR::LevelStatusVisualizer::_paintBlockedTiles | ( | unsigned char * | data, | |
unsigned int | rowSkip | |||
) | [private] |
Definition at line 141 of file LevelStatusVisualizer.cpp.
References ASR::Level::mCellsHigh, ASR::Level::mCellsWide, mLevel, and ASR::Level::mOccupied.
Referenced by _rebuild().
00142 { 00143 for ( unsigned int j = 0; j < mLevel->mCellsHigh; j++ ) 00144 { 00145 for ( unsigned int i = 0; i < mLevel->mCellsWide; i++ ) 00146 { 00147 if ( mLevel->mOccupied[ (j * mLevel->mCellsWide) + i ].getTraversalCost () < 0.0f ) 00148 { 00149 data[i*4] = 0; 00150 data[i*4 + 1] = 0; 00151 data[i*4 + 2] = 125; 00152 data[i*4 + 3] = 80; 00153 } 00154 else 00155 { 00156 data[i*4] = 0; 00157 data[i*4 + 1] = 0; 00158 data[i*4 + 2] = 0; 00159 data[i*4 + 3] = 80; 00160 } 00161 } 00162 data += (mLevel->mCellsWide * 4) + (rowSkip * 4); 00163 } 00164 }
void ASR::LevelStatusVisualizer::_paintUnitPaths | ( | unsigned char * | data, | |
unsigned int | rowSkip | |||
) | [private] |
Definition at line 98 of file LevelStatusVisualizer.cpp.
References ASR::Level::getCellLocation(), ASR::Level::getTeamIterator(), ASR::Level::mCellsWide, and mLevel.
Referenced by _rebuild().
00099 { 00100 Level::TeamIterator teamIter = mLevel->getTeamIterator (); 00101 00102 // For each team 00103 while ( teamIter.hasMoreElements () ) 00104 { 00105 Team* curTeam = teamIter.getNext (); 00106 00107 // For each unit on the team 00108 TeamUnits::UnitIterator unitIter = curTeam->getUnitIterator (); 00109 while ( unitIter.hasMoreElements () ) 00110 { 00111 Unit* curUnit = unitIter.getNext (); 00112 if ( curUnit->hasDestination () ) 00113 { 00114 // For each waypoint of each unit on each team 00115 Unit::WaypointIterator wayIter = curUnit->getWaypointIterator (); 00116 while ( wayIter.hasMoreElements () ) 00117 { 00118 Vector3 dest = wayIter.getNext (); 00119 int x; 00120 int z; 00121 00122 mLevel->getCellLocation ( dest, &x, &z ); 00123 00124 int index; 00125 index = z * ( mLevel->mCellsWide * 4 ); 00126 index += z * rowSkip * 4; 00127 index += x * 4; 00128 00129 data[ index + 0] = 255; 00130 data[ index + 1] = 255; 00131 data[ index + 2] = 255; 00132 data[ index + 3] = 155; 00133 } 00134 } 00135 } 00136 } 00137 }
void ASR::LevelStatusVisualizer::_rebuild | ( | ) | [private] |
Definition at line 81 of file LevelStatusVisualizer.cpp.
References _paintBlockedTiles(), _paintUnitPaths(), and tex.
Referenced by LevelStatusVisualizer(), and updateBeforeFrame().
00082 { 00083 HardwarePixelBufferSharedPtr pixBuf = tex->getBuffer (); 00084 pixBuf->lock ( HardwareBuffer::HBL_DISCARD ); 00085 const PixelBox& pixelBox = pixBuf->getCurrentLock (); 00086 00087 unsigned char* pBuf = static_cast<unsigned char*>(pixelBox.data); 00088 unsigned char* data = pBuf; 00089 00090 _paintBlockedTiles ( data, pixelBox.getRowSkip () ); 00091 _paintUnitPaths ( data, pixelBox.getRowSkip () ); 00092 00093 pixBuf->unlock (); 00094 }
bool ASR::LevelStatusVisualizer::updateAfterFrame | ( | const FrameEvent & | e, | |
const InputReader * | inputDevice | |||
) | [virtual] |
bool ASR::LevelStatusVisualizer::updateBeforeFrame | ( | const FrameEvent & | e, | |
const InputReader * | inputDevice | |||
) | [virtual] |
Called each frame to perform the "update".
Return true if rendering should continue, false otherwise.
Implements ASR::Updater.
Definition at line 65 of file LevelStatusVisualizer.cpp.
References _rebuild().
00066 { 00067 _rebuild (); 00068 00069 return true; 00070 }
Level* ASR::LevelStatusVisualizer::mLevel [private] |
Definition at line 43 of file LevelStatusVisualizer.h.
Referenced by _paintBlockedTiles(), _paintUnitPaths(), and LevelStatusVisualizer().
TexturePtr ASR::LevelStatusVisualizer::tex [private] |
Definition at line 44 of file LevelStatusVisualizer.h.
Referenced by _rebuild(), and LevelStatusVisualizer().