From aec3ff1f631139fd43fcd0138d6bf9129a543c29 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 6 Mar 2013 15:02:17 +0000 Subject: [PATCH] - bugfix for restoring explorations on loading a saved game --- source/glest_game/game/game.cpp | 2 + source/glest_game/type_instances/unit.cpp | 46 +++++------------------ source/glest_game/type_instances/unit.h | 1 + source/glest_game/world/world.cpp | 15 ++++++++ source/glest_game/world/world.h | 1 + 5 files changed, 28 insertions(+), 37 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index cbd739c9..fc065e49 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -5496,6 +5496,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches Faction *faction = world.getFaction(i); faction->clearCaches(); } + world.refreshAllUnitExplorations(); } setupPopupMenus(false); @@ -5521,6 +5522,7 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches Faction *faction = world.getFaction(i); faction->clearCaches(); } + world.refreshAllUnitExplorations(); } pauseRequestSent=false; } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 9d045574..5349a32e 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1116,51 +1116,23 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) { this->lastPos= this->pos; this->pos= pos; -// // This code is initial code to make the camera 'follow' a unit -// //if(this->getId() == 5) { -// if(cameraFollowUnit == true) { -// //printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng()); -// -// //game->getGameCameraPtr()->setClampDisabled(true); -// -// //game->getGameCameraPtr()->setFov(45); -// if(oldLastPos.x > pos.x) { -// game->getGameCameraPtr()->setHAng(270); -// game->getGameCameraPtr()->setVAng(-7.6); -// } -// else if(oldLastPos.x < pos.x) { -// game->getGameCameraPtr()->setHAng(90); -// game->getGameCameraPtr()->setVAng(1.4); -// } -// else if(oldLastPos.y > pos.y) { -// game->getGameCameraPtr()->setHAng(180); -// game->getGameCameraPtr()->setVAng(4.2); -// } -// else { -// game->getGameCameraPtr()->setHAng(-2.4); -// game->getGameCameraPtr()->setVAng(-1.4); -// } -// -// game->getGameCameraPtr()->setPos(getCurrVector()); -// game->getGameCameraPtr()->stop(); -// -// //printf("B fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng()); -// } - map->clampPos(this->pos); this->meetingPos= pos - Vec2i(1); map->clampPos(this->meetingPos); safeMutex.ReleaseLock(); - // Attempt to improve performance - this->exploreCells(); - - calculateFogOfWarRadius(); + refreshPos(); logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__); } +void Unit::refreshPos() { + // Attempt to improve performance + this->exploreCells(); + calculateFogOfWarRadius(); +} + FowAlphaCellsLookupItem Unit::getFogOfWarRadius(bool useCache) const { if(useCache == true && Config::getInstance().getBool("EnableFowCache","true") == true) { return cachedFow; @@ -4539,8 +4511,8 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * result->pathFindRefreshCellCount = unitNode->getAttribute("pathFindRefreshCellCount")->getIntValue(); } - result->exploreCells(); - result->calculateFogOfWarRadius(); + //result->exploreCells(); + //result->calculateFogOfWarRadius(); return result; } diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 86190ac0..49690e70 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -592,6 +592,7 @@ public: inline void setLoadType(const ResourceType *loadType) {this->loadType= loadType;} inline void setProgress2(int progress2) {this->progress2= progress2;} void setPos(const Vec2i &pos,bool clearPathFinder=false); + void refreshPos(); void setTargetPos(const Vec2i &targetPos); void setTarget(const Unit *unit); void setTargetVec(const Vec3f &targetVec); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 609140c3..0b49641e 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -2073,6 +2073,10 @@ void World::initUnits() { f->limitResourcesToStore(); } } + else { + printf("Load game setting unit pos\n"); + refreshAllUnitExplorations(); + } } catch(const megaglest_runtime_error &ex) { gotError = true; @@ -2104,6 +2108,17 @@ void World::initUnits() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void World::refreshAllUnitExplorations() { + for(unsigned int i = 0; i < getFactionCount(); ++i) { + Faction *faction = factions[i]; + + for(unsigned int j = 0; j < faction->getUnitCount(); ++j) { + Unit *unit = faction->getUnit(j); + unit->refreshPos(); + } + } +} + void World::initMap() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); map.init(&tileset); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index d3af5fb3..6ed4c898 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -319,6 +319,7 @@ public: void loadGame(const XmlNode *rootNode); void clearCaches(); + void refreshAllUnitExplorations(); private: