From 206170bc7657d8b9095f60d564c6744727fdc5bd Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 14 Jul 2010 06:59:55 +0000 Subject: [PATCH] - attempted some speed improvements for unit lookup as well as exploreCells --- source/glest_game/world/unit_updater.cpp | 6 +-- source/glest_game/world/world.cpp | 51 +++++++++++++++++++++++- source/glest_game/world/world.h | 13 ++++++ 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 96b65bd8..598c708d 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -60,7 +60,6 @@ void UnitUpdater::init(Game *game){ //skill dependent actions void UnitUpdater::updateUnit(Unit *unit){ - SoundRenderer &soundRenderer= SoundRenderer::getInstance(); //play skill sound @@ -121,8 +120,7 @@ void UnitUpdater::updateUnit(Unit *unit){ //VERY IMPORTANT: compute next state depending on the first order of the list void UnitUpdater::updateUnitCommand(Unit *unit){ - - //if unis has command process it + //if unit has command process it if(unit->anyCommand()) { unit->getCurrCommand()->getCommandType()->update(this, unit); } @@ -132,7 +130,7 @@ void UnitUpdater::updateUnitCommand(Unit *unit){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->setCurrSkill(scStop); if(unit->getType()->hasCommandClass(ccStop)){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(unit->getType()->getFirstCtOfClass(ccStop))); } } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 97a5839b..c8dc20cc 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -247,6 +247,9 @@ void World::update(){ //tick if(frameCount%GameConstants::updateFps==0){ computeFow(); + + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + tick(); } if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); @@ -296,7 +299,11 @@ void World::tick(){ Unit* World::findUnitById(int id){ for(int i= 0; ifindUnit(id); + if(unit != NULL) { + return unit; + } +/* for(int j= 0; jgetUnitCount(); ++j){ Unit* unit= faction->getUnit(j); @@ -304,6 +311,7 @@ Unit* World::findUnitById(int id){ return unit; } } +*/ } return NULL; } @@ -727,6 +735,28 @@ void World::initMap(){ // ==================== exploration ==================== void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ + // Experimental cache lookup of previously calculated cells + sight range + for(int idx = 0; idx < ExploredCellsLookupItemCache.size(); ++idx) { + ExploredCellsLookupItem &item = ExploredCellsLookupItemCache[idx]; + if(item.pos == newPos && item.sightRange == sightRange && item.teamIndex == teamIndex) { + std::vector &cellList = item.exploredCellList; + for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { + SurfaceCell *sc = cellList[idx2]; + sc->setExplored(teamIndex, true); + } + cellList = item.visibleCellList; + for(int idx2 = 0; idx2 < cellList.size(); ++idx2) { + SurfaceCell *sc = cellList[idx2]; + sc->setVisible(teamIndex, true); + } + + break; + } + } + ExploredCellsLookupItem item; + item.pos = newPos; + item.sightRange = sightRange; + item.teamIndex = teamIndex; Vec2i newSurfPos= Map::toSurfCoords(newPos); int surfSightRange= sightRange/Map::cellScale+1; @@ -743,23 +773,34 @@ void World::exploreCells(const Vec2i &newPos, int sightRange, int teamIndex){ //explore if(Vec2i(0).dist(currRelPos) < surfSightRange+indirectSightRange+1){ sc->setExplored(teamIndex, true); + + item.exploredCellList.push_back(sc); } //visible if(Vec2i(0).dist(currRelPos) < surfSightRange){ sc->setVisible(teamIndex, true); + item.visibleCellList.push_back(sc); } } } } + + if(item.exploredCellList.size() > 0 || item.visibleCellList.size() > 0) { + ExploredCellsLookupItemCache.push_back(item); + } } //computes the fog of war texture, contained in the minimap void World::computeFow(){ + Chrono chrono; + chrono.start(); //reset texture minimap.resetFowTex(); + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //reset cells for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //compute cells for(int i=0; igetUnitCount(); ++j){ @@ -783,6 +826,8 @@ void World::computeFow(){ } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //fire for(int i=0; igetUnitCount(); ++j){ @@ -796,6 +841,8 @@ void World::computeFow(){ } } + if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); + //compute texture for(int i=0; i 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); } // WARNING! This id is critical! MAke sure it fits inside the network packet diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 03bc8fa8..5b9fced9 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -52,10 +52,23 @@ class RoutePlanner; /// The game world: Map + Tileset + TechTree // ===================================================== +class ExploredCellsLookupItem { +public: + + Vec2i pos; + int sightRange; + int teamIndex; + + std::vector exploredCellList; + std::vector visibleCellList; +}; + class World{ private: typedef vector Factions; + std::vector ExploredCellsLookupItemCache; + public: static const int generationArea= 100; static const float airHeight;