diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 31d304de..d8f00ab3 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -354,19 +354,21 @@ NetworkMessageSynchNetworkGameData::NetworkMessageSynchNetworkGameData(const Gam //data.tilesetCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_tilesets) + "/" + gameSettings->getTileset() + "/*", "xml", NULL); data.tilesetCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTilesets,scenarioDir), string("/") + gameSettings->getTileset() + string("/*"), ".xml", NULL); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] data.tilesetCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.tilesetCRC,gameSettings->getTileset().c_str()); + //tech, load before map because of resources //data.techCRC = getFolderTreeContentsCheckSumRecursively(string(GameConstants::folder_path_techs) + "/" + gameSettings->getTech() + "/*", "xml", NULL); data.techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,scenarioDir), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] data.techCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.techCRC,gameSettings->getTech().c_str()); + //map Checksum checksum; string file = Map::getMapPath(gameSettings->getMap(),scenarioDir); checksum.addFile(file); data.mapCRC = checksum.getSum(); //SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] file = [%s] checksum = %d\n",__FILE__,__FUNCTION__,file.c_str(),data.mapCRC); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] data.mapCRC = %d, [%s]\n",__FILE__,__FUNCTION__,__LINE__, data.mapCRC,gameSettings->getMap().c_str()); } bool NetworkMessageSynchNetworkGameData::receive(Socket* socket) diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index 8f89ef32..20536a81 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -275,11 +275,24 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); + static std::map crcTreeCache; + + string cacheKey = ""; int count = paths.size(); for(int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; + cacheKey += path + "_" + filterFileExt + "_"; + } + if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str()); + return crcTreeCache[cacheKey]; + } + + Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); + for(int idx = 0; idx < count; ++idx) { + string path = paths[idx] + pathSearchString; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s], filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); getFolderTreeContentsCheckSumRecursively(path, filterFileExt, &checksum); @@ -291,7 +304,8 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path *recursiveChecksum = checksum; } - return checksum.getFinalFileListSum(); + crcTreeCache[cacheKey] = checksum.getFinalFileListSum(); + return crcTreeCache[cacheKey]; } //finds all filenames like path and gets their checksum of all files combined @@ -300,6 +314,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string string cacheKey = path + "_" + filterFileExt; static std::map crcTreeCache; if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] found CACHED checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey],cacheKey.c_str()); return crcTreeCache[cacheKey]; } Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); @@ -388,7 +403,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string crcTreeCache[cacheKey] = checksum.getFinalFileListSum(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] ending checksum = %d\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey]); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] ending checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey],cacheKey.c_str()); return crcTreeCache[cacheKey]; } @@ -396,8 +411,21 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string vector > getFolderTreeContentsCheckSumListRecursively(vector paths, string pathSearchString, string filterFileExt, vector > *recursiveMap) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); + static std::map > > crcTreeCache; + + string cacheKey = ""; int count = paths.size(); + for(int idx = 0; idx < count; ++idx) { + string path = paths[idx] + pathSearchString; + + cacheKey += path + "_" + filterFileExt + "_"; + } + if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED result for cacheKey [%s]\n",__FILE__,__FUNCTION__,cacheKey.c_str()); + return crcTreeCache[cacheKey]; + } + + vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); for(int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles); @@ -405,7 +433,8 @@ vector > getFolderTreeContentsCheckSumListRecursively(ve SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - return checksumFiles; + crcTreeCache[cacheKey] = checksumFiles; + return crcTreeCache[cacheKey]; } //finds all filenames like path and gets the checksum of each file @@ -414,6 +443,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co string cacheKey = path + "_" + filterFileExt; static std::map > > crcTreeCache; if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] FOUND CACHED result for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),cacheKey.c_str()); return crcTreeCache[cacheKey]; } @@ -496,10 +526,10 @@ vector > getFolderTreeContentsCheckSumListRecursively(co globfree(&globbuf); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); - crcTreeCache[cacheKey] = checksumFiles; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),cacheKey.c_str()); + return crcTreeCache[cacheKey]; } diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index e2bca548..c0358437 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -337,11 +337,24 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); + static std::map crcTreeCache; + + string cacheKey = ""; int count = paths.size(); for(int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; + cacheKey += path + "_" + filterFileExt + "_"; + } + if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,crcTreeCache[cacheKey],cacheKey.c_str()); + return crcTreeCache[cacheKey]; + } + + Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); + for(int idx = 0; idx < count; ++idx) { + string path = paths[idx] + pathSearchString; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s], filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str()); getFolderTreeContentsCheckSumRecursively(path, filterFileExt, &checksum); @@ -353,7 +366,8 @@ int32 getFolderTreeContentsCheckSumRecursively(vector paths, string path *recursiveChecksum = checksum; } - return checksum.getFinalFileListSum(); + crcTreeCache[cacheKey] = checksum.getFinalFileListSum(); + return crcTreeCache[cacheKey]; } //finds all filenames like path and gets their checksum of all files combined @@ -362,6 +376,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string string cacheKey = path + "_" + filterFileExt; static std::map crcTreeCache; if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] found CACHED checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey],cacheKey.c_str()); return crcTreeCache[cacheKey]; } Checksum checksum = (recursiveChecksum == NULL ? Checksum() : *recursiveChecksum); @@ -450,7 +465,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string crcTreeCache[cacheKey] = checksum.getFinalFileListSum(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] ending checksum = %d\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey]); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] ending checksum = %d for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),crcTreeCache[cacheKey],cacheKey.c_str()); return crcTreeCache[cacheKey]; } @@ -458,8 +473,21 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string vector > getFolderTreeContentsCheckSumListRecursively(vector paths, string pathSearchString, string filterFileExt, vector > *recursiveMap) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); + static std::map > > crcTreeCache; + + string cacheKey = ""; int count = paths.size(); + for(int idx = 0; idx < count; ++idx) { + string path = paths[idx] + pathSearchString; + + cacheKey += path + "_" + filterFileExt + "_"; + } + if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders found CACHED result for cacheKey [%s]\n",__FILE__,__FUNCTION__,cacheKey.c_str()); + return crcTreeCache[cacheKey]; + } + + vector > checksumFiles = (recursiveMap == NULL ? vector >() : *recursiveMap); for(int idx = 0; idx < count; ++idx) { string path = paths[idx] + pathSearchString; getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles); @@ -467,7 +495,8 @@ vector > getFolderTreeContentsCheckSumListRecursively(ve SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - return checksumFiles; + crcTreeCache[cacheKey] = checksumFiles; + return crcTreeCache[cacheKey]; } //finds all filenames like path and gets the checksum of each file @@ -476,6 +505,7 @@ vector > getFolderTreeContentsCheckSumListRecursively(co string cacheKey = path + "_" + filterFileExt; static std::map > > crcTreeCache; if(crcTreeCache.find(cacheKey) != crcTreeCache.end()) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] FOUND CACHED result for cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),cacheKey.c_str()); return crcTreeCache[cacheKey]; } @@ -558,10 +588,10 @@ vector > getFolderTreeContentsCheckSumListRecursively(co globfree(&globbuf); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str()); - crcTreeCache[cacheKey] = checksumFiles; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s] cacheKey [%s]\n",__FILE__,__FUNCTION__,path.c_str(),cacheKey.c_str()); + return crcTreeCache[cacheKey]; } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 698c1016..9d621729 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -141,7 +141,6 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { } string debugLog = currentDebugLog.debugLogFileName; - printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); if(SystemFlags::lockFile == -1) { const string lock_file_name = "debug.lck"; @@ -184,6 +183,8 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { currentDebugLog.fileStreamOwner = true; } + printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); + (*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n"; (*currentDebugLog.fileStream).flush(); }