attempt to fix out of synch of join in progress game

This commit is contained in:
Mark Vejvoda 2013-05-27 08:26:01 +00:00
parent f4a29d98b8
commit 93caf14362
5 changed files with 83 additions and 5 deletions

View File

@ -1556,7 +1556,11 @@ void Game::init(bool initForPreviewOnly) {
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ==== START GAME ==== getCurrentPixelByteCount() = %llu\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(long long unsigned int)renderer.getCurrentPixelByteCount());
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"=============================================\n");
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"==== START GAME ====\n");
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"=============================================\n");
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"Starting framecount: %d\n",world.getFrameCount());
if(showPerfStats && chronoPerf.getMillis() >= 50) {
for(unsigned int x = 0; x < perfList.size(); ++x) {
@ -1756,7 +1760,7 @@ void Game::update() {
// Temp speed boost when player first joins an in progress game
//if(this->initialResumeSpeedLoops == true && updateLoops == 1) {
if(this->initialResumeSpeedLoops == true) {
printf("Resume #1\n");
printf("Resume In Progress Game: %d\n",__LINE__);
this->initialResumeSpeedLoops = false;
//updateLoops = 80;
@ -2345,7 +2349,8 @@ void Game::update() {
}
//printf("Resuming game for join in progress game resumeRequestSent: %d...\n",resumeRequestSent);
commander.tryResumeGame(true,false);
//commander.tryResumeGame(true,false);
commander.tryResumeGame(true,true);
resumeRequestSent = true;
// server->setAllowInGameConnections(false);
@ -5634,6 +5639,9 @@ 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);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"game.cpp line: %d setPaused value: %d clearCaches: %d forceAllowPauseStateChange: %d speedChangesAllowed: %d pausedForJoinGame: %d joinNetworkGame: %d\n",__LINE__,value,clearCaches,forceAllowPauseStateChange,speedChangesAllowed,pausedForJoinGame,joinNetworkGame);
//printf("Line: %d setPaused value: %d clearCaches: %d forceAllowPauseStateChange: %d speedChangesAllowed: %d pausedForJoinGame: %d joinNetworkGame: %d\n",__LINE__,value,clearCaches,forceAllowPauseStateChange,speedChangesAllowed,pausedForJoinGame,joinNetworkGame);
if(forceAllowPauseStateChange == true || speedChangesAllowed == true) {
//printf("setPaused paused = %d, value = %d\n",paused,value);
@ -5670,6 +5678,8 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
}
}
//printf("Line: %d setPaused value: %d clearCaches: %d\n",__LINE__,value,clearCaches);
Lang &lang= Lang::getInstance();
if(value == false) {
console.addLine(lang.get("GameResumed"));
@ -5678,6 +5688,9 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
pauseStateChanged = true;
if(clearCaches == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"game.cpp line: %d Clear Caches for resume in progress game\n",__LINE__);
//printf("Line: %d Clear Caches for resume in progress game\n",__LINE__);
world.clearCaches();
for(int i = 0; i < world.getFactionCount(); ++i) {
Faction *faction = world.getFaction(i);
@ -5704,6 +5717,9 @@ void Game::setPaused(bool value,bool forceAllowPauseStateChange,bool clearCaches
//!!!
if(clearCaches == true) {
//printf("Line: %d Clear Caches for resume in progress game\n",__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled) SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"game.cpp line: %d Clear Caches for resume in progress game\n",__LINE__);
world.clearCaches();
for(int i = 0; i < world.getFactionCount(); ++i) {
Faction *faction = world.getFaction(i);

View File

@ -596,6 +596,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
bool localEcho = lang.isLanguageLocal(languageList[i]);
clientInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
sleep(1);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1905,6 +1906,7 @@ void MenuStateConnectedGame::PlayNow(bool saveGame) {
clientInterface->sendTextMessage(szMsg,-1, localEcho,languageList[i]);
}
sleep(1);
launchingNewGame = true;
clientInterface->broadcastGameStart(&gameSettings);
}
@ -3929,8 +3931,8 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] szMsg [%s] lastProgress.first = %d, fileProgress = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szMsg,lastProgress.first,fileProgress);
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
sleep(1);
}
sleep(1);
}
}
}
@ -3954,6 +3956,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] szMsg [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szMsg);
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
}
sleep(1);
}
else {
char *szBuf = (char *)userdata;
@ -4003,6 +4006,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
}
sleep(1);
}
else {
printf("FAILED map itemName [%s] lastCheckedCRCMapName [%s] gameSettings->getMap() [%s]\n",
@ -4031,6 +4035,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
}
}
sleep(1);
console.addLine(result.second,true);
}
@ -4061,6 +4066,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
}
sleep(1);
// START
// Clear the CRC Cache if it is populated
@ -4122,6 +4128,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
}
}
sleep(1);
console.addLine(result.second,true);
}
@ -4152,6 +4159,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
}
sleep(1);
// START
// Clear the CRC Cache if it is populated
@ -4210,6 +4218,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
}
}
sleep(1);
console.addLine(result.second,true);
}
@ -4241,6 +4250,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
}
sleep(1);
if(itemName == GameConstants::saveNetworkGameFileClientCompressed) {
string saveGameFilePath = "temp/";
@ -4292,6 +4302,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
}
}
}
sleep(1);
console.addLine(result.second,true);
}

View File

@ -207,7 +207,7 @@ void ClientInterface::shutdownNetworkCommandListThread() {
networkCommandListThread->signalQuit();
for(;networkCommandListThread->canShutdown(false) == false &&
difftime((long int)time(NULL),elapsed) <= 15;) {
difftime((long int)time(NULL),elapsed) <= 11;) {
//sleep(150);
}
@ -1686,6 +1686,23 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
//printf("Client signalServerWhenReadyToStartJoinedGame = %d\n",signalServerWhenReadyToStartJoinedGame);
if(signalServerWhenReadyToStartJoinedGame == true) {
Lang &lang= Lang::getInstance();
const vector<string> languageList = this->gameSettings.getUniqueNetworkPlayerLanguages();
for(unsigned int i = 0; i < languageList.size(); ++i) {
string sText = "Player: %s is joining the game now.";
if(lang.hasString("JoinPlayerToCurrentGameLaunchDone",languageList[i]) == true) {
sText = lang.get("JoinPlayerToCurrentGameLaunchDone",languageList[i]);
}
if(clientSocket != NULL && clientSocket->isConnected() == true) {
string playerNameStr = getHumanPlayerName();
char szBuf[8096]="";
snprintf(szBuf,8096,sText.c_str(),playerNameStr.c_str());
sendTextMessage(szBuf,-1,false,languageList[i]);
}
}
this->resumeInGameJoin = true;
safeMutexFlags2.ReleaseLock();
}

View File

@ -1320,6 +1320,19 @@ Vec2i Faction::getClosestResourceTypeTargetFromCache(Unit *unit, const ResourceT
if(cachingDisabled == false) {
if(cacheResourceTargetList.empty() == false) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
char szBuf[8096]="";
snprintf(szBuf,8096,"cacheResourceTargetList.size() [" MG_SIZE_T_SPECIFIER "]",cacheResourceTargetList.size());
if(frameIndex < 0) {
unit->logSynchData(__FILE__,__LINE__,szBuf);
}
else {
unit->logSynchDataThreaded(__FILE__,__LINE__,szBuf);
}
}
std::vector<Vec2i> deleteList;
const int harvestDistance = 5;
@ -1896,13 +1909,34 @@ void Faction::clearCaches() {
cachedCloseResourceTargetLookupList.clear();
mapSharedPathFinderCache.clear();
//Unit *firstUnit = NULL;
unsigned int unitCount = this->getUnitCount();
for(unsigned int i = 0; i < unitCount; ++i) {
Unit *unit = this->getUnit(i);
if(unit != NULL) {
//if(firstUnit == NULL) {
// firstUnit = unit;
//}
unit->clearCaches();
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
// char szBuf[8096]="";
// snprintf(szBuf,8096,"[clearCaches unit check]");
// if(firstUnit != NULL) {
// firstUnit->logSynchData(__FILE__,__LINE__,szBuf);
// }
// }
}
}
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
// char szBuf[8096]="";
// snprintf(szBuf,8096,"[clearCaches] cacheResourceTargetList.size() [" MG_SIZE_T_SPECIFIER "] cacheResourceTargetList.size() [" MG_SIZE_T_SPECIFIER "] mapSharedPathFinderCache" MG_SIZE_T_SPECIFIER "]",
// cacheResourceTargetList.size(),cacheResourceTargetList.size(),mapSharedPathFinderCache.size());
// if(firstUnit != NULL) {
// firstUnit->logSynchData(__FILE__,__LINE__,szBuf);
// }
// }
}
uint64 Faction::getCacheKBytes(uint64 *cache1Size, uint64 *cache2Size) {

View File

@ -2102,7 +2102,7 @@ void World::initUnits() {
}
}
else {
printf("Load game setting unit pos\n");
//printf("Load game setting unit pos\n");
refreshAllUnitExplorations();
}
}