more caching and bug fixes for data synch compare

This commit is contained in:
Mark Vejvoda 2010-04-29 08:36:37 +00:00
parent 4f147b2d89
commit cc08074acf
4 changed files with 81 additions and 18 deletions

View File

@ -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)

View File

@ -275,11 +275,24 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> 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<string,int32> 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<string> 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<string,int32> 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<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, string pathSearchString, string filterFileExt, vector<std::pair<string,int32> > *recursiveMap) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector<std::pair<string,int32> > checksumFiles = (recursiveMap == NULL ? vector<std::pair<string,int32> >() : *recursiveMap);
static std::map<string,vector<std::pair<string,int32> > > 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<std::pair<string,int32> > checksumFiles = (recursiveMap == NULL ? vector<std::pair<string,int32> >() : *recursiveMap);
for(int idx = 0; idx < count; ++idx) {
string path = paths[idx] + pathSearchString;
getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles);
@ -405,7 +433,8 @@ vector<std::pair<string,int32> > 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<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
string cacheKey = path + "_" + filterFileExt;
static std::map<string,vector<std::pair<string,int32> > > 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<std::pair<string,int32> > 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];
}

View File

@ -337,11 +337,24 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> 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<string,int32> 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<string> 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<string,int32> 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<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, string pathSearchString, string filterFileExt, vector<std::pair<string,int32> > *recursiveMap) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector<std::pair<string,int32> > checksumFiles = (recursiveMap == NULL ? vector<std::pair<string,int32> >() : *recursiveMap);
static std::map<string,vector<std::pair<string,int32> > > 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<std::pair<string,int32> > checksumFiles = (recursiveMap == NULL ? vector<std::pair<string,int32> >() : *recursiveMap);
for(int idx = 0; idx < count; ++idx) {
string path = paths[idx] + pathSearchString;
getFolderTreeContentsCheckSumListRecursively(path, filterFileExt, &checksumFiles);
@ -467,7 +495,8 @@ vector<std::pair<string,int32> > 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<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(co
string cacheKey = path + "_" + filterFileExt;
static std::map<string,vector<std::pair<string,int32> > > 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<std::pair<string,int32> > 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];
}

View File

@ -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();
}