diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 43f1e943..56dbefea 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -483,13 +483,13 @@ void Commander::tryDisconnectNetworkPlayer(const Faction* faction, int playerInd pushNetworkCommand(&command); } -void Commander::tryPauseGame() const { - NetworkCommand command(this->world,nctPauseResume, 1); +void Commander::tryPauseGame(bool clearCaches) const { + NetworkCommand command(this->world,nctPauseResume, 1, (clearCaches == true ? 1 : 0)); pushNetworkCommand(&command); } -void Commander::tryResumeGame() const { - NetworkCommand command(this->world,nctPauseResume, 0); +void Commander::tryResumeGame(bool clearCaches) const { + NetworkCommand command(this->world,nctPauseResume, 0, (clearCaches == true ? 1 : 0)); pushNetworkCommand(&command); } @@ -613,6 +613,7 @@ void Commander::updateNetwork(Game *game) { GameSettings *gameSettings = game->getGameSettings(); if( networkManager.isNetworkGame() == false || (world->getFrameCount() % gameSettings->getNetworkFramePeriod()) == 0) { + //printf("Commander world->getFrameCount() = %d gameSettings->getNetworkFramePeriod() = %d\n",world->getFrameCount(),gameSettings->getNetworkFramePeriod()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] networkManager.isNetworkGame() = %d,world->getFrameCount() = %d, gameSettings->getNetworkFramePeriod() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkManager.isNetworkGame(),world->getFrameCount(),gameSettings->getNetworkFramePeriod()); @@ -870,11 +871,12 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const { commandWasHandled = true; - bool pauseGame = networkCommand->getUnitId() != 0; + bool pauseGame = networkCommand->getUnitId() != 0; + bool clearCaches = networkCommand->getCommandTypeId(); Game *game = this->world->getGame(); //printf("nctPauseResume pauseGame = %d\n",pauseGame); - game->setPaused(pauseGame,true); + game->setPaused(pauseGame,true,clearCaches); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctPauseResume\n",__FILE__,__FUNCTION__,__LINE__); } diff --git a/source/glest_game/game/commander.h b/source/glest_game/game/commander.h index ae449bf5..73dbc061 100644 --- a/source/glest_game/game/commander.h +++ b/source/glest_game/game/commander.h @@ -114,8 +114,8 @@ public: void trySwitchTeam(const Faction* faction, int teamIndex) const; void trySwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) const; void tryDisconnectNetworkPlayer(const Faction* faction, int playerIndex) const; - void tryPauseGame() const; - void tryResumeGame() const; + void tryPauseGame(bool clearCaches) const; + void tryResumeGame(bool clearCaches) const; void tryNetworkPlayerDisconnected(int factionIndex) const; Command* buildCommand(const NetworkCommand* networkCommand) const; diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index e4aa7a7f..fb0ed913 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1416,10 +1416,6 @@ void Game::init(bool initForPreviewOnly) { void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) { Lang &lang= Lang::getInstance(); - //Logger &logger= Logger::getInstance(); - //CoreData &coreData= CoreData::getInstance(); - //Renderer &renderer= Renderer::getInstance(); - //Map *map= world.getMap(); NetworkManager &networkManager= NetworkManager::getInstance(); NetworkRole role = networkManager.getNetworkRole(); ClientInterface *clientInterface = NULL; @@ -1442,6 +1438,14 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) { (clientInterface != NULL && (gameSettings.getMasterserver_admin() != clientInterface->getSessionKey() && clientInterface->isMasterServerAdminOverride() == true))) { + exitGamePopupMenuIndex = -1; + joinTeamPopupMenuIndex = -1; + pauseGamePopupMenuIndex = -1; + saveGamePopupMenuIndex = -1; + loadGamePopupMenuIndex = -1; + keyboardSetupPopupMenuIndex = -1; + disconnectPlayerPopupMenuIndex = -1; + if(checkClientAdminOverrideOnly == true) { gameSettings.setMasterserver_admin(clientInterface->getSessionKey()); gameSettings.setMasterserver_admin_faction_index(clientInterface->getPlayerIndex()); @@ -1474,6 +1478,11 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) { // loadGamePopupMenuIndex= menuItems.size() - 1; } + //printf("Checking disconnect menu: %d\n",gameSettings.isNetworkGame()); + //for(int idx = 0; idx < GameConstants::maxPlayers; ++idx) { + // printf("Faction Index: %d, control: %d\n",idx,gameSettings.getFactionControl(idx)); + //} + if(gameSettings.isNetworkGame() == true){ menuItems.push_back(lang.get("DisconnectNetorkPlayer")); disconnectPlayerPopupMenuIndex= menuItems.size() - 1; @@ -1588,107 +1597,6 @@ void Game::update() { perfList.push_back(perfBuf); } - if(role == nrServer) { - ServerInterface *server = NetworkManager::getInstance().getServerInterface(); - if(server->getPauseForInGameConnection() == true && paused == false) { - - //printf("================= Switching player pausing game\n"); - - for(int i = 0; i < world.getFactionCount(); ++i) { - Faction *faction = world.getFaction(i); - - //printf("Switching player check %d from: %d connected: %d, startindex = %d, connected #2: %d\n",i,faction->getControlType(),server->isClientConnected(faction->getStartLocationIndex()),faction->getStartLocationIndex(),server->isClientConnected(i)); - //printf("Slot: %d faction name: %s\n",i,faction->getType()->getName().c_str()); - - if( faction->getControlType() != ctNetwork && - faction->getControlType() != ctHuman && - server->isClientConnected(faction->getStartLocationIndex()) == true) { - - //printf("Switching player %d from: %d to %d\n",i,faction->getControlType(),ctNetwork); - //printf("Slot: %d faction name: %s GS faction: %s\n",i,faction->getType()->getName().c_str(),server->gameSettings.getFactionTypeName(i).c_str()); - - server->gameSettings.setFactionControl(i,ctNetwork); - ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); - server->gameSettings.setNetworkPlayerName(i,slot->getName()); - - this->gameSettings.setFactionControl(i,ctNetwork); - this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i)); - } - } - //printf("#1 Data synch: lmap %u ltile: %d ltech: %u\n",gameSettings.getMapCRC(),gameSettings.getTilesetCRC(),gameSettings.getTechCRC()); - //printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC()); - server->broadcastGameSetup(&server->gameSettings,true); - - server->setPauseForInGameConnection(false); - } - else if(server->getStartInGameConnectionLaunch() == true) { - //printf("^^^ getStartInGameConnectionLaunch triggered!\n"); - - server->setStartInGameConnectionLaunch(false); - - Lang &lang= Lang::getInstance(); - bool pauseAndSaveGameForNewClient = false; - for(int i = 0; i < world.getFactionCount(); ++i) { - Faction *faction = world.getFaction(i); - ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); - if(slot != NULL && slot->getJoinGameInProgress() == true) { - //printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex()); - - this->gameSettings.setFactionControl(i,ctNetwork); - this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i)); - - //printf("START Purging AI player for index: %d\n",i); - masterController.clearSlaves(true); - delete aiInterfaces[i]; - aiInterfaces[i] = NULL; - //printf("END Purging AI player for index: %d\n",i); - - Faction *faction = world.getFaction(i); - faction->setControlType(ctNetwork); - - pauseAndSaveGameForNewClient = true; - } - else if((slot == NULL || slot->isConnected() == false) && - this->gameSettings.getFactionControl(i) == ctNetwork && - aiInterfaces[i] == NULL) { - faction->setFactionDisconnectHandled(false); - //this->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1)); - //server->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1)); - } - } - - if(pauseAndSaveGameForNewClient == true) { - commander.tryPauseGame(); - } - } - else if(server->getUnPauseForInGameConnection() == true && paused == true) { - //printf("^^^ getUnPauseForInGameConnection triggered!\n"); - - server->setUnPauseForInGameConnection(false); - commander.tryResumeGame(); - } - else { - // handle setting changes from clients - Map *map= world.getMap(); - //printf("switchSetupRequests != NULL\n"); - - bool switchRequested = switchSetupForSlots(server, 0, map->getMaxPlayers(), false); - switchRequested = switchRequested || switchSetupForSlots(server, map->getMaxPlayers(), GameConstants::maxPlayers, true); - - if(switchRequested == true) { - //printf("Send new game setup from switch: %d\n",switchRequested); - - //for(int i= 0; i < gameSettings.getFactionCount(); ++i) { - //printf("#1 Faction Index: %d control: %d startlocation: %d\n",i,gameSettings.getFactionControl(i),gameSettings.getStartLocationIndex(i)); - - //printf("#2 Faction Index: %d control: %d startlocation: %d\n",i,server->gameSettings.getFactionControl(i),server->gameSettings.getStartLocationIndex(i)); - //} - - server->broadcastGameSetup(&server->gameSettings,true); - } - } - } - // Check to see if we are playing a network game and if any players // have disconnected? ReplaceDisconnectedNetworkPlayersWithAI(isNetworkGame, role); @@ -1712,6 +1620,7 @@ void Game::update() { if(replayTotal > 0) { chronoReplay.start(); } + do { if(replayTotal > 0) { replayCommandsPlayed = (replayTotal - commander.getReplayCommandListForFrameCount()); @@ -2006,6 +1915,111 @@ void Game::update() { perfList.push_back(perfBuf); } + // START - Handle joining in progress games + if(role == nrServer) { + ServerInterface *server = NetworkManager::getInstance().getServerInterface(); + if(server->getPauseForInGameConnection() == true && paused == false) { + + //printf("================= Switching player pausing game\n"); + + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + + //printf("Switching player check %d from: %d connected: %d, startindex = %d, connected #2: %d\n",i,faction->getControlType(),server->isClientConnected(faction->getStartLocationIndex()),faction->getStartLocationIndex(),server->isClientConnected(i)); + //printf("Slot: %d faction name: %s\n",i,faction->getType()->getName().c_str()); + + if( faction->getControlType() != ctNetwork && + faction->getControlType() != ctHuman && + server->isClientConnected(faction->getStartLocationIndex()) == true) { + + //printf("Switching player %d from: %d to %d\n",i,faction->getControlType(),ctNetwork); + //printf("Slot: %d faction name: %s GS faction: %s\n",i,faction->getType()->getName().c_str(),server->gameSettings.getFactionTypeName(i).c_str()); + + server->gameSettings.setFactionControl(i,ctNetwork); + ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + server->gameSettings.setNetworkPlayerName(i,slot->getName()); + + this->gameSettings.setFactionControl(i,ctNetwork); + this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i)); + } + } + //printf("#1 Data synch: lmap %u ltile: %d ltech: %u\n",gameSettings.getMapCRC(),gameSettings.getTilesetCRC(),gameSettings.getTechCRC()); + //printf("#2 Data synch: lmap %u ltile: %d ltech: %u\n",server->gameSettings.getMapCRC(),server->gameSettings.getTilesetCRC(),server->gameSettings.getTechCRC()); + server->broadcastGameSetup(&server->gameSettings,true); + + server->setPauseForInGameConnection(false); + } + else if(server->getStartInGameConnectionLaunch() == true) { + //printf("^^^ getStartInGameConnectionLaunch triggered!\n"); + + server->setStartInGameConnectionLaunch(false); + + Lang &lang= Lang::getInstance(); + bool pauseAndSaveGameForNewClient = false; + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex()); + if(slot != NULL && slot->getJoinGameInProgress() == true) { + //printf("$$$ signalling client to start game [deleting AI player] factionIndex: %d slot: %d startlocation: %d!\n",i,slot->getPlayerIndex(),faction->getStartLocationIndex()); + + this->gameSettings.setFactionControl(i,ctNetwork); + this->gameSettings.setNetworkPlayerName(i,server->gameSettings.getNetworkPlayerName(i)); + + //printf("START Purging AI player for index: %d\n",i); + masterController.clearSlaves(true); + delete aiInterfaces[i]; + aiInterfaces[i] = NULL; + //printf("END Purging AI player for index: %d\n",i); + + Faction *faction = world.getFaction(i); + faction->setControlType(ctNetwork); + + pauseAndSaveGameForNewClient = true; + } + else if((slot == NULL || slot->isConnected() == false) && + this->gameSettings.getFactionControl(i) == ctNetwork && + aiInterfaces[i] == NULL) { + faction->setFactionDisconnectHandled(false); + //this->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1)); + //server->gameSettings.setNetworkPlayerName(i,lang.get("AI") + intToStr(i+1)); + } + } + + if(pauseAndSaveGameForNewClient == true) { + commander.tryPauseGame(true); + //return; + } + } + else if(server->getUnPauseForInGameConnection() == true && paused == true) { + //printf("^^^ getUnPauseForInGameConnection triggered!\n"); + + server->setUnPauseForInGameConnection(false); + commander.tryResumeGame(false); + //return; + } + else { + // handle setting changes from clients + Map *map= world.getMap(); + //printf("switchSetupRequests != NULL\n"); + + bool switchRequested = switchSetupForSlots(server, 0, map->getMaxPlayers(), false); + switchRequested = switchRequested || switchSetupForSlots(server, map->getMaxPlayers(), GameConstants::maxPlayers, true); + + if(switchRequested == true) { + //printf("Send new game setup from switch: %d\n",switchRequested); + + //for(int i= 0; i < gameSettings.getFactionCount(); ++i) { + //printf("#1 Faction Index: %d control: %d startlocation: %d\n",i,gameSettings.getFactionControl(i),gameSettings.getStartLocationIndex(i)); + + //printf("#2 Faction Index: %d control: %d startlocation: %d\n",i,server->gameSettings.getFactionControl(i),server->gameSettings.getStartLocationIndex(i)); + //} + + server->broadcastGameSetup(&server->gameSettings,true); + } + } + } + // END - Handle joining in progress games + //update auto test if(Config::getInstance().getBool("AutoTest")){ AutoTest::getInstance().updateGame(this); @@ -2869,14 +2883,14 @@ void Game::tryPauseToggle(bool pauseValue) { if(allowAdminMenuItems) { if(pauseValue == true) { - commander.tryPauseGame(); + commander.tryPauseGame(false); } else { if(isNetworkGame == false) { setPaused(pauseValue, true); } else { - commander.tryResumeGame(); + commander.tryResumeGame(false); } } } @@ -3049,6 +3063,8 @@ void Game::mouseDownLeft(int x, int y) { std::pair result = popupMenu.mouseClickedMenuItem(x, y); //printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first); + //printf("popupMenu.mouseClick == true result.first = %d disconnectPlayerPopupMenuIndex = %d\n",result.first,disconnectPlayerPopupMenuIndex); + popupMenu.setEnabled(false); popupMenu.setVisible(false); @@ -3168,10 +3184,10 @@ void Game::mouseDownLeft(int x, int y) { if(allowAdminMenuItems) { if(getPaused() == false) { - commander.tryPauseGame(); + commander.tryPauseGame(false); } else { - commander.tryResumeGame(); + commander.tryResumeGame(false); } } } @@ -4078,10 +4094,10 @@ void Game::keyDown(SDL_KeyboardEvent key) { if(allowAdminMenuItems) { if(getPaused() == false) { - commander.tryPauseGame(); + commander.tryPauseGame(false); } else { - commander.tryResumeGame(); + commander.tryResumeGame(false); } } } @@ -5166,7 +5182,7 @@ void Game::decSpeed() { } } -void Game::setPaused(bool value,bool forceAllowPauseStateChange) { +void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches) { bool speedChangesAllowed= !NetworkManager::getInstance().isNetworkGame(); //printf("Toggle pause value = %d, speedChangesAllowed = %d, forceAllowPauseStateChange = %d\n",value,speedChangesAllowed,forceAllowPauseStateChange); @@ -5177,6 +5193,15 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange) { if(value == false) { console.addLine(lang.get("GameResumed")); paused= false; + + if(clearCaches == true) { + world.clearCaches(); + for(int i = 0; i < world.getFactionCount(); ++i) { + Faction *faction = world.getFaction(i); + faction->clearCaches(); + } + } + setupPopupMenus(false); } else { console.addLine(lang.get("GamePaused")); diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 5cdb133c..b98a773c 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -239,7 +239,7 @@ public: Uint64 getTickCount() {return tickCount;} bool getPaused(); - void setPaused(bool value, bool forceAllowPauseStateChange=false); + void setPaused(bool value, bool forceAllowPauseStateChange=false,bool clearCaches=false); void tryPauseToggle(bool pause); void setupRenderForVideo(); void saveGame(); diff --git a/source/glest_game/network/client_interface.cpp b/source/glest_game/network/client_interface.cpp index 529f7e2c..ce969a8c 100644 --- a/source/glest_game/network/client_interface.cpp +++ b/source/glest_game/network/client_interface.cpp @@ -634,13 +634,14 @@ void ClientInterface::updateLobby() { break; case nmtReady: - { + { NetworkMessageReady networkMessageReady; if(receiveMessage(&networkMessageReady)) { this->readyForInGameJoin = true; } - break; - } + } + break; + case nmtCommandList: { @@ -1332,17 +1333,19 @@ void ClientInterface::waitUntilReady(Checksum* checksum) { return; } + joinGameInProgress = false; + //printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame); if(signalServerWhenReadyToStartJoinedGame == true) { NetworkMessageReady networkMessageReady; sendMessage(&networkMessageReady); } - - joinGameInProgress = false; - // delay the start a bit, so clients have more room to get messages - // This is to ensure clients don't start ahead of the server and thus - // constantly freeze because they are waiting for the server to catch up - sleep(120); + else { + // delay the start a bit, so clients have more room to get messages + // This is to ensure clients don't start ahead of the server and thus + // constantly freeze because they are waiting for the server to catch up + sleep(120); + } // This triggers LAG update packets to begin as required lastNetworkCommandListSendTime = time(NULL); diff --git a/source/glest_game/type_instances/faction.cpp b/source/glest_game/type_instances/faction.cpp index 7d0981bb..2a0201eb 100644 --- a/source/glest_game/type_instances/faction.cpp +++ b/source/glest_game/type_instances/faction.cpp @@ -1842,6 +1842,20 @@ bool Faction::canCreateUnit(const UnitType *ut, bool checkBuild, bool checkProdu return foundUnit; } +void Faction::clearCaches() { + cacheResourceTargetList.clear(); + cachedCloseResourceTargetLookupList.clear(); + mapSharedPathFinderCache.clear(); + + unsigned int unitCount = this->getUnitCount(); + for(unsigned int i = 0; i < unitCount; ++i) { + Unit *unit = this->getUnit(i); + if(unit != NULL) { + unit->clearCaches(); + } + } +} + uint64 Faction::getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size) { uint64 cache1Count = 0; uint64 cache2Count = 0; diff --git a/source/glest_game/type_instances/faction.h b/source/glest_game/type_instances/faction.h index 0dd87e8c..8632e96d 100644 --- a/source/glest_game/type_instances/faction.h +++ b/source/glest_game/type_instances/faction.h @@ -344,6 +344,8 @@ public: void saveGame(XmlNode *rootNode); void loadGame(const XmlNode *rootNode, int factionIndex,GameSettings *settings,World *world); + void clearCaches(); + private: void init(); void resetResourceAmount(const ResourceType *rt); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index f24b50d5..7d78f7eb 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -84,6 +84,12 @@ void UnitPathBasic::dumpMemoryList() { } #endif +void UnitPathBasic::clearCaches() { + this->blockCount = 0; + this->pathQueue.clear(); + this->lastPathCacheQueue.clear(); +} + bool UnitPathBasic::isEmpty() const { return pathQueue.empty(); } @@ -178,6 +184,30 @@ void UnitPathBasic::saveGame(XmlNode *rootNode) { } } +void UnitPathBasic::loadGame(const XmlNode *rootNode) { + const XmlNode *unitPathBasicNode = rootNode->getChild("UnitPathBasic"); + + blockCount = unitPathBasicNode->getAttribute("blockCount")->getIntValue(); + + pathQueue.clear(); + vector pathqueueNodeList = unitPathBasicNode->getChildList("pathQueue"); + for(unsigned int i = 0; i < pathqueueNodeList.size(); ++i) { + XmlNode *node = pathqueueNodeList[i]; + + Vec2i vec = Vec2i::strToVec2(node->getAttribute("vec")->getValue()); + pathQueue.push_back(vec); + } + + lastPathCacheQueue.clear(); + vector lastpathqueueNodeList = unitPathBasicNode->getChildList("lastPathCacheQueue"); + for(unsigned int i = 0; i < lastpathqueueNodeList.size(); ++i) { + XmlNode *node = lastpathqueueNodeList[i]; + + Vec2i vec = Vec2i::strToVec2(node->getAttribute("vec")->getValue()); + lastPathCacheQueue.push_back(vec); + } +} + // ===================================================== // class UnitPath // ===================================================== @@ -1508,13 +1538,6 @@ std::pair Unit::giveCommand(Command *command, bool tryQueu //empty command queue if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); -// bool willChangedActiveCommand = (commands.size() > 0); -// if(willChangedActiveCommand && getCurrCommand()->getCommandType()->getClass() == command->getCommandType()->getClass()) { -// willChangedActiveCommand = false; -// } -// clearCommands(); -// changedActiveCommand = willChangedActiveCommand; - bool willChangedActiveCommand= (commands.empty() == false); if(willChangedActiveCommand){ CommandClass currCommandClass=getCurrCommand()->getCommandType()->getClass(); @@ -3677,6 +3700,16 @@ Vec2i Unit::getPos() { return result; } +void Unit::clearCaches() { + cachedFow.alphaList.clear(); + cachedFow.surfPosList.clear(); + cachedFowPos = Vec2i(0,0); + + //unitPath->clearCaches(); + + lastHarvestedResourcePos = Vec2i(0,0); +} + std::string Unit::toString() const { std::string result = ""; @@ -4091,6 +4124,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * throw megaglest_runtime_error("detected unsupported pathfinder type!"); } + newpath->loadGame(unitNode); //Unit *result = new Unit(getNextUnitId(f), newpath, Vec2i(0), ut, f, &map, CardinalDir::NORTH); //Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing); Unit *result = new Unit(newUnitId, newpath, newUnitPos, ut, faction, world->getMapPtr(), newModelFacing); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index cd37f8c5..9660ffb5 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -161,6 +161,9 @@ public: virtual Map * getMap() = 0; virtual void saveGame(XmlNode *rootNode) = 0; + virtual void loadGame(const XmlNode *rootNode) = 0; + + virtual void clearCaches() = 0; }; class UnitPathBasic : public UnitPathInterface { @@ -209,6 +212,8 @@ public: virtual std::string toString() const; virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); + virtual void clearCaches(); }; // ===================================================== @@ -227,6 +232,7 @@ private: public: UnitPath() : UnitPathInterface(), blockCount(0), map(NULL) {} /**< Construct path object */ + virtual bool isBlocked() const {return blockCount >= maxBlockCount;} /**< is this path blocked */ virtual bool isEmpty() const {return list::empty();} /**< is path empty */ virtual bool isStuck() const {return false; } @@ -267,6 +273,8 @@ public: virtual std::string toString() const; virtual void saveGame(XmlNode *rootNode) {}; + virtual void loadGame(const XmlNode *rootNode) {}; + virtual void clearCaches() {}; }; class WaypointPath : public list { @@ -739,6 +747,8 @@ public: void saveGame(XmlNode *rootNode); static Unit * loadGame(const XmlNode *rootNode,GameSettings *settings,Faction *faction, World *world); + void clearCaches(); + private: float computeHeight(const Vec2i &pos) const; void calculateXZRotation(); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 6491594c..00fd4f11 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -1424,6 +1424,12 @@ void World::moveToUnit(int unitId, int destUnitId) { } } +void World::clearCaches() { + ExploredCellsLookupItemCache.clear(); + ExploredCellsLookupItemCacheTimer.clear(); + ExploredCellsLookupItemCacheTimerCount = 0; +} + void World::togglePauseGame(bool pauseStatus,bool forceAllowPauseStateChange) { game->setPaused(pauseStatus, forceAllowPauseStateChange); } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 69aa76ad..d3af5fb3 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -318,6 +318,8 @@ public: void saveGame(XmlNode *rootNode); void loadGame(const XmlNode *rootNode); + void clearCaches(); + private: void initCells(bool fogOfWar);