diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 39caf1523..f5274689b 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -1072,8 +1072,10 @@ void MainWindow::loadParticle(string path) { // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; + std::map loadedFileList; UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); - unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath, renderer); + unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath, + renderer,loadedFileList); unitParticleSystemTypes.push_back(unitParticleSystemType); for(std::vector::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) { @@ -1167,8 +1169,10 @@ void MainWindow::loadProjectileParticle(string path) { // std::cout << "Loaded successfully, loading values..." << std::endl; + std::map loadedFileList; ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile(); - projectileParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer); + projectileParticleSystemType->load(dir, + dir + folderDelimiter + particlePath,renderer, loadedFileList); // std::cout << "Values loaded, about to read..." << std::endl; @@ -1267,8 +1271,10 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp // std::cout << "Loaded successfully, loading values..." << std::endl; + std::map loadedFileList; ParticleSystemTypeSplash *splashParticleSystemType= new ParticleSystemTypeSplash(); - splashParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer); // <---- only that must be splash... + splashParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer, + loadedFileList); // <---- only that must be splash... // std::cout << "Values loaded, about to read..." << std::endl; diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 0a34f4eae..e37a54a33 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -370,6 +370,7 @@ void Game::load() { } void Game::load(LoadGameItem loadTypes) { + std::map loadedFileList; originalDisplayMsgCallback = NetworkInterface::getDisplayMessageFunction(); NetworkInterface::setDisplayMessageFunction(ErrorDisplayMessage); @@ -411,7 +412,7 @@ void Game::load(LoadGameItem loadTypes) { if((loadTypes & lgt_TileSet) == lgt_TileSet) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); world.loadTileset( config.getPathListForType(ptTilesets,scenarioDir), - tilesetName, &checksum); + tilesetName, &checksum, loadedFileList); } // give CPU time to update other things to avoid apperance of hanging @@ -433,7 +434,7 @@ void Game::load(LoadGameItem loadTypes) { //tech, load before map because of resources world.loadTech( config.getPathListForType(ptTechs,scenarioDir), techName, - factions, &checksum); + factions, &checksum,loadedFileList); // Validate the faction setup to ensure we don't have any bad associations /* diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 1c8ebe696..595f48f2b 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -40,7 +40,8 @@ ParticleSystemType::ParticleSystemType() { model=NULL; } -void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir,RendererInterface *renderer) { +void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, + RendererInterface *renderer, std::map &loadedFileList) { //texture const XmlNode *textureNode= particleSystemNode->getChild("texture"); bool textureEnabled= textureNode->getAttribute("value")->getBoolValue(); @@ -57,6 +58,7 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d string currentPath = dir; endPathWithSlash(currentPath); texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++; } else { texture= NULL; @@ -73,7 +75,8 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d string currentPath = dir; endPathWithSlash(currentPath); - model->load(currentPath + path); + model->load(currentPath + path, false, &loadedFileList); + loadedFileList[currentPath + path]++; } } else{ @@ -182,14 +185,17 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){ // class ParticleSystemTypeProjectile // =========================================================== -void ParticleSystemTypeProjectile::load(const string &dir, const string &path,RendererInterface *renderer) { +void ParticleSystemTypeProjectile::load(const string &dir, const string &path, + RendererInterface *renderer, std::map &loadedFileList) { try{ XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *particleSystemNode= xmlTree.getRootNode(); - ParticleSystemType::load(particleSystemNode, dir, renderer); + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList); //trajectory values const XmlNode *tajectoryNode= particleSystemNode->getChild("trajectory"); @@ -240,14 +246,17 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() { // class ParticleSystemTypeSplash // =========================================================== -void ParticleSystemTypeSplash::load(const string &dir, const string &path,RendererInterface *renderer) { +void ParticleSystemTypeSplash::load(const string &dir, const string &path, + RendererInterface *renderer, std::map &loadedFileList) { try{ XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *particleSystemNode= xmlTree.getRootNode(); - ParticleSystemType::load(particleSystemNode, dir, renderer); + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList); //emission rate fade const XmlNode *emissionRateFadeNode= particleSystemNode->getChild("emission-rate-fade"); diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index aa22fa6d5..abaf486a6 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -44,7 +44,7 @@ using Shared::Xml::XmlNode; /// A type of particle system // =========================================================== -class ParticleSystemType{ +class ParticleSystemType { protected: string type; Texture2D *texture; @@ -67,7 +67,8 @@ protected: public: ParticleSystemType(); - void load(const XmlNode *particleSystemNode, const string &dir,RendererInterface *renderer); + void load(const XmlNode *particleSystemNode, const string &dir, + RendererInterface *renderer, std::map &loadedFileList); void setValues(AttackParticleSystem *ats); bool hasTexture() const { return(texture != NULL); } bool hasModel() const { return(model != NULL); } @@ -88,7 +89,8 @@ private: float trajectoryFrequency; public: - void load(const string &dir, const string &path,RendererInterface *renderer); + void load(const string &dir, const string &path, + RendererInterface *renderer, std::map &loadedFileList); ProjectileParticleSystem *create(); }; @@ -97,9 +99,10 @@ public: // class ParticleSystemTypeSplash // =========================================================== -class ParticleSystemTypeSplash: public ParticleSystemType{ +class ParticleSystemTypeSplash: public ParticleSystemType { public: - void load(const string &dir, const string &path,RendererInterface *renderer); + void load(const string &dir, const string &path, + RendererInterface *renderer, std::map &loadedFileList); SplashParticleSystem *create(); private: diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index 1d6a3feeb..4d56c89d9 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -29,8 +29,9 @@ namespace Glest{ namespace Game{ // class UnitParticleSystemType // ===================================================== -void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer) { - ParticleSystemType::load(particleSystemNode, dir, renderer); +void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, + RendererInterface *renderer, std::map &loadedFileList) { + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList); //radius const XmlNode *radiusNode= particleSystemNode->getChild("radius"); radius= radiusNode->getAttribute("value")->getFloatValue(); @@ -134,14 +135,17 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ } } -void UnitParticleSystemType::load(const string &dir, const string &path, RendererInterface *renderer){ +void UnitParticleSystemType::load(const string &dir, const string &path, + RendererInterface *renderer, std::map &loadedFileList) { try{ XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; const XmlNode *particleSystemNode= xmlTree.getRootNode(); - UnitParticleSystemType::load(particleSystemNode, dir, renderer); + UnitParticleSystemType::load(particleSystemNode, dir, renderer, + loadedFileList); } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index 22d808d75..2315e4a34 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -42,7 +42,7 @@ using Shared::Xml::XmlNode; /// A type of particle system // =========================================================== -class UnitParticleSystemType: public ParticleSystemType{ +class UnitParticleSystemType: public ParticleSystemType { protected: float radius; @@ -56,8 +56,10 @@ protected: bool radiusBasedStartenergy; public: - void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture); - void load(const string &dir, const string &path, RendererInterface *newTexture); + void load(const XmlNode *particleSystemNode, const string &dir, + RendererInterface *newTexture, std::map &loadedFileList); + void load(const string &dir, const string &path, RendererInterface *newTexture, + std::map &loadedFileList); const void setValues (UnitParticleSystem *uts); bool hasTexture() const { return(texture != NULL); } }; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 7cecd32a0..76b9bbdd8 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -126,7 +126,7 @@ enum GAME_ARG_TYPE { GAME_ARG_LOG_PATH, GAME_ARG_SHOW_INI_SETTINGS, GAME_ARG_CONVERT_MODELS, - GAME_ARG_CONVERT_TEXTURES, +// GAME_ARG_CONVERT_TEXTURES, GAME_ARG_DISABLE_BACKTRACE, GAME_ARG_DISABLE_VBO, GAME_ARG_VERBOSE_MODE @@ -843,13 +843,15 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\t\t\tdisplays your SDL version information.",GAME_ARGS[GAME_ARG_SDL_INFO]); printf("\n%s\t\t\tdisplays your LUA version information.",GAME_ARGS[GAME_ARG_LUA_INFO]); printf("\n%s\t\t\tdisplays your CURL version information.",GAME_ARGS[GAME_ARG_CURL_INFO]); - printf("\n%s=x\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); + printf("\n%s=x=purgeunused\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); printf("\n \t\tto your selected techtrees game data."); printf("\n \t\tWhere x is a comma-delimited list of techtrees to validate."); + printf("\n \t\tWhere purgeunused is an optional parameter telling the validation to delete extra files in the techtree that are not used."); printf("\n \t\texample: %s %s=megapack,vbros_pack_5",argv0,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); - printf("\n%s=x\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]); + printf("\n%s=x=purgeunused\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]); printf("\n \t\tto your selected factions game data."); printf("\n \t\tWhere x is a comma-delimited list of factions to validate."); + printf("\n \t\tWhere purgeunused is an optional parameter telling the validation to delete extra files in the faction that are not used."); printf("\n \t\t*NOTE: leaving the list empty is the same as running"); printf("\n \t\t%s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); printf("\n \t\texample: %s %s=tech,egypt",argv0,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]); @@ -869,10 +871,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\tWhere keepsmallest is an optional flag indicating to keep original texture if its filesize is smaller than the converted format."); printf("\n \t\texample: %s %s=techs/megapack/factions/tech/units/castle/models/castle.g3d=png=keepsmallest",argv0,GAME_ARGS[GAME_ARG_CONVERT_MODELS]); - printf("\n%s=x=textureformat\t\t\tconvert a texture file or folder to the format textureformat.",GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]); - printf("\n \t\tWhere x is a filename or folder containing the texture(s)."); - printf("\n \t\tWhere textureformat is a supported texture format to convert to (tga,bmp,jpg,png)."); - printf("\n \t\texample: %s %s=data/core/misc_textures/fire_particle.tga=png",argv0,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]); +// printf("\n%s=x=textureformat\t\t\tconvert a texture file or folder to the format textureformat.",GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]); +// printf("\n \t\tWhere x is a filename or folder containing the texture(s)."); +// printf("\n \t\tWhere textureformat is a supported texture format to convert to (tga,bmp,jpg,png)."); +// printf("\n \t\texample: %s %s=data/core/misc_textures/fire_particle.tga=png",argv0,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]); printf("\n%s\t\tdisables stack backtrace on errors.",GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]); printf("\n%s\t\tdisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]); @@ -1098,9 +1100,11 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) { void runTechValidationReport(int argc, char** argv) { //disableBacktrace=true; - printf("====== Started Validation ======\n"); + bool purgeUnusedFiles = false; + Config &config = Config::getInstance(); + // Did the user pass a specific list of factions to validate? std::vector filteredFactionList; if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("=")) == true) { @@ -1122,10 +1126,15 @@ void runTechValidationReport(int argc, char** argv) { printf("%s\n",filteredFactionList[idx].c_str()); } } + + if(paramPartTokens.size() >= 3) { + if(paramPartTokens[2] == "purgeunused") { + purgeUnusedFiles = true; + printf("*NOTE All unused faction files will be deleted!\n"); + } + } } } - - Config &config = Config::getInstance(); vector results; findDirs(config.getPathListForType(ptTechs), results); vector techTreeFiles = results; @@ -1148,6 +1157,13 @@ void runTechValidationReport(int argc, char** argv) { printf("%s\n",filteredTechTreeList[idx].c_str()); } } + + if(paramPartTokens.size() >= 3) { + if(paramPartTokens[2] == "purgeunused") { + purgeUnusedFiles = true; + printf("*NOTE All unused techtree files will be deleted!\n"); + } + } } } @@ -1170,7 +1186,7 @@ void runTechValidationReport(int argc, char** argv) { std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) { vector factionsList; - findAll(techPath + techName + "/factions/*.", factionsList, false, false); + findDirs(techPath + techName + "/factions/", factionsList, false, false); if(factionsList.size() > 0) { Checksum checksum; @@ -1193,7 +1209,26 @@ void runTechValidationReport(int argc, char** argv) { if(factions.size() > 0) { bool techtree_errors = false; - world.loadTech(config.getPathListForType(ptTechs,""), techName, factions, &checksum); + + std::map loadedFileList; + vector pathList = config.getPathListForType(ptTechs,""); + world.loadTech(pathList, techName, factions, &checksum, loadedFileList); + + // Fixup paths with .. + { + std::map newLoadedFileList; + for( std::map::iterator iterMap = loadedFileList.begin(); + iterMap != loadedFileList.end(); ++iterMap) { + string loadedFile = iterMap->first; + + replaceAll(loadedFile,"//","/"); + replaceAll(loadedFile,"\\\\","\\"); + updatePathClimbingParts(loadedFile); + newLoadedFileList[loadedFile] = iterMap->second; + } + loadedFileList = newLoadedFileList; + } + // Validate the faction setup to ensure we don't have any bad associations std::vector resultErrors = world.validateFactionTypes(); if(resultErrors.size() > 0) { @@ -1234,6 +1269,78 @@ void runTechValidationReport(int argc, char** argv) { printf("%s",errorText.c_str()); } + // Now check for unused files in the techtree + std::map foundFileList; + for(unsigned int i = 0; i < pathList.size(); ++i) { + string path = pathList[i]; + endPathWithSlash(path); + path = path + techName + "/"; + + vector foundFiles = getFolderTreeContentsListRecursively(path + "*.", ""); + for(unsigned int j = 0; j < foundFiles.size(); ++j) { + string file = foundFiles[j]; + if( file.find("loading_screen") != string::npos || + file.find("preview_screen") != string::npos) { + continue; + } + if(file.find("/factions/") != string::npos) { + bool includeFaction = false; + for ( set::iterator it = factions.begin(); it != factions.end(); ++it ) { + string currentFaction = *it; + if(file.find("/factions/" + currentFaction) != string::npos) { + includeFaction = true; + break; + } + } + if(includeFaction == false) { + continue; + } + } + + replaceAll(file,"//","/"); + replaceAll(file,"\\\\","\\"); + + foundFileList[file]++; + } + } + + printf("Found techtree filecount = %lu, used = %lu\n",(unsigned long)foundFileList.size(),(unsigned long)loadedFileList.size()); + +// for( std::map::iterator iterMap = loadedFileList.begin(); +// iterMap != loadedFileList.end(); ++iterMap) { +// string foundFile = iterMap->first; +// +// if(foundFile.find("golem_ack1.wav") != string::npos) { +// printf("FOUND file [%s]\n",foundFile.c_str()); +// } +// } + + bool foundUnusedFile = false; + for( std::map::iterator iterMap = foundFileList.begin(); + iterMap != foundFileList.end(); ++iterMap) { + string foundFile = iterMap->first; + + if(loadedFileList.find(foundFile) == loadedFileList.end()) { + if(foundUnusedFile == false) { + printf("\nWarning, unused files were detected - START:\n=====================\n"); + } + foundUnusedFile = true; + + printf("[%s]\n",foundFile.c_str()); + + string fileName = extractFileFromDirectoryPath(foundFile); + if(loadedFileList.find(fileName) != loadedFileList.end()) { + printf("possible match on [%s] ?\n",loadedFileList.find(fileName)->first.c_str()); + } + else if(purgeUnusedFiles == true) { + removeFile(foundFile); + } + } + } + if(foundUnusedFile == true) { + printf("\nWarning, unused files were detected - END:\n"); + } + if(techtree_errors == false) { printf("\nValidation found NO ERRORS for techPath [%s] techName [%s] factions checked (count = %d):\n",techPath.c_str(), techName.c_str(),(int)factions.size()); for ( set::iterator it = factions.begin(); it != factions.end(); ++it ) { @@ -1895,12 +2002,12 @@ int glestMain(int argc, char** argv) { } } - if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]) == true) { - //!!! - printf("\nComing soon (not yet implemented)\n\n"); - delete mainWindow; - return -1; - } +// if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]) == true) { +// //!!! +// printf("\nComing soon (not yet implemented)\n\n"); +// delete mainWindow; +// return -1; +// } if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) { diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 2056f4a80..7533875c8 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -501,6 +501,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ ftpClientThread->addMapToRequests(getMissingMapFromFTPServer); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList[getMissingMapFromFTPServer] = pair(0,""); + safeMutexFTPProgress.ReleaseLock(); } } else if(ftpMissingDataType == ftpmsg_MissingTileset) { @@ -519,6 +520,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ ftpClientThread->addTilesetToRequests(getMissingTilesetFromFTPServer); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList[getMissingTilesetFromFTPServer] = pair(0,""); + safeMutexFTPProgress.ReleaseLock(); } } else if(ftpMissingDataType == ftpmsg_MissingTechtree) { @@ -537,6 +539,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ ftpClientThread->addTechtreeToRequests(getMissingTechtreeFromFTPServer); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList[getMissingTechtreeFromFTPServer] = pair(0,""); + safeMutexFTPProgress.ReleaseLock(); } } } @@ -1989,14 +1992,16 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client } //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] current file [%s] fileProgress = %d [now = %f, total = %f]\n",itemName.c_str(),stats->currentFilename.c_str(), fileProgress,stats->download_now,stats->download_total); + MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList[itemName] = pair(fileProgress,stats->currentFilename); + safeMutexFTPProgress.ReleaseLock(); } } else if(type == ftp_cct_Map) { getMissingMapFromFTPServerInProgress = false; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); - MutexSafeWrapper safeMutexFTPProgress(ftpClientThread->getProgressMutex(),string(__FILE__) + "_" + intToStr(__LINE__)); + MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList.erase(itemName); safeMutexFTPProgress.ReleaseLock(); @@ -2034,7 +2039,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client getMissingTilesetFromFTPServerInProgress = false; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); - MutexSafeWrapper safeMutexFTPProgress(ftpClientThread->getProgressMutex(),string(__FILE__) + "_" + intToStr(__LINE__)); + MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList.erase(itemName); safeMutexFTPProgress.ReleaseLock(true); @@ -2092,7 +2097,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client getMissingTechtreeFromFTPServerInProgress = false; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); - MutexSafeWrapper safeMutexFTPProgress(ftpClientThread->getProgressMutex(),string(__FILE__) + "_" + intToStr(__LINE__)); + MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); fileFTPProgressList.erase(itemName); safeMutexFTPProgress.ReleaseLock(true); diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index 17052e34f..6aa2978b5 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -42,7 +42,9 @@ CommandClass CommandType::getClass() const{ return commandTypeClass; } -void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ +void CommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); this->id= id; @@ -55,10 +57,11 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTr string currentPath = dir; endPathWithSlash(currentPath); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; //unit requirements const XmlNode *unitRequirementsNode= n->getChild("unit-requirements"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < unitRequirementsNode->getChildCount(); ++i) { const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); unitReqs.push_back(ft->getUnitType(name)); @@ -66,7 +69,7 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTr //upgrade requirements const XmlNode *upgradeRequirementsNode= n->getChild("upgrade-requirements"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < upgradeRequirementsNode->getChildCount(); ++i) { const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); upgradeReqs.push_back(ft->getUpgradeType(name)); @@ -107,8 +110,10 @@ string StopCommandType::toString() const{ return lang.get("Stop"); } -void StopCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); +void StopCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //stop string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue(); @@ -130,8 +135,10 @@ void MoveCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateMove(unit); } -void MoveCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); +void MoveCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //move string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); @@ -177,8 +184,10 @@ void AttackCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateAttack(unit); } -void AttackCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); +void AttackCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //move string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); @@ -267,8 +276,10 @@ void AttackStoppedCommandType::update(UnitUpdater *unitUpdater, Unit *unit) cons unitUpdater->updateAttackStopped(unit); } -void AttackStoppedCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - CommandType::load(id, n, dir, tt, ft, ut); +void AttackStoppedCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //stop string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue(); @@ -352,10 +363,11 @@ void BuildCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateBuild(unit); } -void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - CommandType::load(id, n, dir, tt, ft, ut); +void BuildCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //move string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); @@ -380,11 +392,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i); string path= soundFileNode->getAttribute("path")->getRestrictedValue(); + trimPathWithStartingSlash(path); + StaticSound *sound= new StaticSound(); string currentPath = dir; endPathWithSlash(currentPath); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; startSounds[i]= sound; } } @@ -396,11 +411,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i); string path= soundFileNode->getAttribute("path")->getRestrictedValue(); + trimPathWithStartingSlash(path); + StaticSound *sound= new StaticSound(); string currentPath = dir; endPathWithSlash(currentPath); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; builtSounds[i]= sound; } } @@ -443,9 +461,10 @@ void HarvestCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateHarvest(unit); } -void HarvestCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - - CommandType::load(id, n, dir, tt, ft, ut); +void HarvestCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //move string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); @@ -523,11 +542,10 @@ void RepairCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateRepair(unit); } -void RepairCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - CommandType::load(id, n, dir, tt, ft, ut); +void RepairCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //move string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); @@ -601,10 +619,10 @@ void ProduceCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateProduce(unit); } -void ProduceCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - CommandType::load(id, n, dir, tt, ft, ut); +void ProduceCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //produce string skillName= n->getChild("produce-skill")->getAttribute("value")->getRestrictedValue(); @@ -666,9 +684,11 @@ void UpgradeCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateUpgrade(unit); } -void UpgradeCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ +void UpgradeCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { - CommandType::load(id, n, dir, tt, ft, ut); + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //upgrade string skillName= n->getChild("upgrade-skill")->getAttribute("value")->getRestrictedValue(); @@ -721,10 +741,10 @@ void MorphCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{ unitUpdater->updateMorph(unit); } -void MorphCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - - CommandType::load(id, n, dir, tt, ft, ut); +void MorphCommandType::load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList) { + CommandType::load(id, n, dir, tt, ft, ut, loadedFileList); //morph skill string skillName= n->getChild("morph-skill")->getAttribute("value")->getRestrictedValue(); diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 0a580eba5..34d0e1062 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -81,7 +81,9 @@ public: id = -1; } virtual void update(UnitUpdater *unitUpdater, Unit *unit) const= 0; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const= 0; virtual string toString() const= 0; virtual const ProducibleType *getProduced() const {return NULL;} @@ -114,7 +116,8 @@ private: public: StopCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, + const FactionType *ft, const UnitType &ut, std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; virtual Queueability isQueuable() const {return qNever;} @@ -135,7 +138,9 @@ private: public: MoveCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; @@ -156,7 +161,9 @@ private: public: AttackCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; @@ -178,7 +185,9 @@ private: public: AttackStoppedCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; @@ -204,7 +213,9 @@ public: BuildCommandType(); ~BuildCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; @@ -235,7 +246,9 @@ private: public: HarvestCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; virtual Queueability isQueuable() const {return qOnRequest;} @@ -267,7 +280,9 @@ public: RepairCommandType(); ~RepairCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; @@ -294,7 +309,9 @@ private: public: ProduceCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getReqDesc() const; virtual string toString() const; @@ -319,7 +336,9 @@ private: public: UpgradeCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; virtual string getReqDesc() const; @@ -344,7 +363,9 @@ private: public: MorphCommandType(); virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; - virtual void load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut); + virtual void load(int id, const XmlNode *n, const string &dir, + const TechTree *tt, const FactionType *ft, const UnitType &ut, + std::map &loadedFileList); virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string toString() const; virtual string getReqDesc() const; diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index f8c960a67..8c1198b29 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -30,17 +30,21 @@ namespace Glest{ namespace Game{ // Class FactionType // ====================================================== -FactionType::FactionType(){ +FactionType::FactionType() { music = NULL; personalityType = fpt_Normal; } //load a faction, given a directory -void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum,Checksum *techtreeChecksum) { +void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum, + Checksum *techtreeChecksum, std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - name= lastDir(dir); + string currentPath = dir; + endPathWithSlash(currentPath); + + name= lastDir(currentPath); // Add special Observer Faction Lang &lang= Lang::getInstance(); @@ -52,75 +56,78 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch if(personalityType == fpt_Normal) { // a1) preload units - string unitsPath= dir + "/units/*."; + string unitsPath= currentPath + "units/*."; vector unitFilenames; findAll(unitsPath, unitFilenames); unitTypes.resize(unitFilenames.size()); - for(int i=0; i upgradeFilenames; findAll(upgradesPath, upgradeFilenames, false, false); upgradeTypes.resize(upgradeFilenames.size()); - for(int i=0; igetTypeCount())); SDL_PumpEvents(); } } catch(const exception &e) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw runtime_error("Error loading units: "+ dir + "\n" + e.what()); + throw runtime_error("Error loading units: "+ currentPath + "\n" + e.what()); } // b2) load upgrades try{ for(int i = 0; i < upgradeTypes.size(); ++i) { - string str= dir + "/upgrades/" + upgradeTypes[i].getName(); - upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum); + string str= currentPath + "upgrades/" + upgradeTypes[i].getName(); + upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum, + loadedFileList); SDL_PumpEvents(); } } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw runtime_error("Error loading upgrades: "+ dir + "\n" + e.what()); + throw runtime_error("Error loading upgrades: "+ currentPath + "\n" + e.what()); } //open xml file - string currentPath = dir; - endPathWithSlash(currentPath); string path= currentPath + name + ".xml"; checksum->addFile(path); techtreeChecksum->addFile(path); XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *factionNode= xmlTree.getRootNode(); //read starting resources const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources"); startingResources.resize(startingResourcesNode->getChildCount()); - for(int i=0; igetChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); @@ -131,7 +138,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch //read starting units const XmlNode *startingUnitsNode= factionNode->getChild("starting-units"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < startingUnitsNode->getChildCount(); ++i) { const XmlNode *unitNode= startingUnitsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); int amount= unitNode->getAttribute("amount")->getIntValue(); @@ -143,12 +150,10 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch //read music const XmlNode *musicNode= factionNode->getChild("music"); bool value= musicNode->getAttribute("value")->getBoolValue(); - if(value){ + if(value) { music= new StrSound(); - - string currentPath = dir; - endPathWithSlash(currentPath); music->open(currentPath + musicNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + musicNode->getAttribute("path")->getRestrictedValue()]++; } } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/types/faction_type.h b/source/glest_game/types/faction_type.h index 31faf210b..06d89de45 100644 --- a/source/glest_game/types/faction_type.h +++ b/source/glest_game/types/faction_type.h @@ -27,7 +27,7 @@ namespace Glest{ namespace Game{ /// Each of the possible factions the user can select // ===================================================== -class FactionType{ +class FactionType { private: typedef pair PairPUnitTypeInt; typedef vector UnitTypes; @@ -47,7 +47,8 @@ private: public: //init FactionType(); - void load(const string &dir, const TechTree *techTree, Checksum* checksum,Checksum *techtreeChecksum); + void load(const string &dir, const TechTree *techTree, Checksum* checksum, + Checksum *techtreeChecksum, std::map &loadedFileList); ~FactionType(); //get diff --git a/source/glest_game/types/object_type.cpp b/source/glest_game/types/object_type.cpp index 052cc159b..ee9969ebf 100644 --- a/source/glest_game/types/object_type.cpp +++ b/source/glest_game/types/object_type.cpp @@ -38,9 +38,9 @@ ObjectType::~ObjectType(){ //Logger::getInstance().add("ObjectType", true); } -void ObjectType::loadModel(const string &path){ +void ObjectType::loadModel(const string &path, std::map *loadedFileList) { Model *model= Renderer::getInstance().newModel(rsGame); - model->load(path); + model->load(path, false, loadedFileList); color= Vec3f(0.f); if(model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) { const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst(); diff --git a/source/glest_game/types/object_type.h b/source/glest_game/types/object_type.h index e3da2db32..9583e6b56 100644 --- a/source/glest_game/types/object_type.h +++ b/source/glest_game/types/object_type.h @@ -56,7 +56,7 @@ public: ~ObjectType(); void init(int modelCount, int objectClass, bool walkable, int height); - void loadModel(const string &path); + void loadModel(const string &path, std::map *loadedFileList=NULL); void addParticleSystem(ObjectParticleSystemType *particleSystem); Model *getModel(int i) {return models[i];} diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index d6f1bf144..914539e01 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -45,7 +45,8 @@ ResourceType::~ResourceType(){ } } -void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum) { +void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum, + std::map &loadedFileList) { string path, str; Renderer &renderer= Renderer::getInstance(); @@ -66,16 +67,19 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre //tree XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *resourceNode= xmlTree.getRootNode(); //image const XmlNode *imageNode= resourceNode->getChild("image"); image= renderer.newTexture2D(rsGame); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; //type const XmlNode *typeNode= resourceNode->getChild("type"); - resourceClass= strToRc(typeNode->getAttribute("value")->getRestrictedValue()); + resourceClass = strToRc(typeNode->getAttribute("value")->getRestrictedValue()); switch(resourceClass) { @@ -83,21 +87,25 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre { //model const XmlNode *modelNode= typeNode->getChild("model"); - string path= currentPath + modelNode->getAttribute("path")->getRestrictedValue(); + string modelPath= currentPath + modelNode->getAttribute("path")->getRestrictedValue(); model= renderer.newModel(rsGame); - model->load(path); + model->load(modelPath, false, &loadedFileList); + loadedFileList[modelPath]++; if(modelNode->hasChild("particles")){ const XmlNode *particleNode= modelNode->getChild("particles"); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); - if(particleEnabled){ - for(int k= 0; k < particleNode->getChildCount(); ++k){ + if(particleEnabled == true) { + for(int k= 0; k < particleNode->getChildCount(); ++k) { const XmlNode *particleFileNode= particleNode->getChild("particle-file", k); - string path= particleFileNode->getAttribute("path")->getRestrictedValue(); + string particlePath= particleFileNode->getAttribute("path")->getRestrictedValue(); ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); - objectParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); + objectParticleSystemType->load(dir, currentPath + particlePath, + &Renderer::getInstance(), loadedFileList); + loadedFileList[currentPath + particlePath]++; + particleTypes.push_back(objectParticleSystemType); } } @@ -110,7 +118,6 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre //resource number const XmlNode *resourceNumberNode= typeNode->getChild("resource-number"); resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue(); - } break; @@ -137,11 +144,9 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre case rcStatic: { //recoup_cost - if(typeNode->hasChild("recoup_cost") == true) - { + if(typeNode->hasChild("recoup_cost") == true) { const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost"); - if(recoup_costNode != NULL) - { + if(recoup_costNode != NULL) { recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue(); } } diff --git a/source/glest_game/types/resource_type.h b/source/glest_game/types/resource_type.h index 6ac6207a2..505ab7b3d 100644 --- a/source/glest_game/types/resource_type.h +++ b/source/glest_game/types/resource_type.h @@ -53,7 +53,8 @@ private: public: ResourceType(); ~ResourceType(); - void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum); + void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum, + std::map &loadedFileList); //get int getClass() const {return resourceClass;} diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 28db55f6e..2acc091a3 100755 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -32,16 +32,17 @@ namespace Glest{ namespace Game{ // class SkillType // ===================================================== -SkillType::~SkillType(){ +SkillType::~SkillType() { deleteValues(sounds.getSounds().begin(), sounds.getSounds().end()); //remove unitParticleSystemTypes - while(!unitParticleSystemTypes.empty()){ + while(!unitParticleSystemTypes.empty()) { delete unitParticleSystemTypes.back(); unitParticleSystemTypes.pop_back(); } } -void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){ +void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList) { //name name= sn->getChild("name")->getAttribute("value")->getRestrictedValue(); @@ -65,43 +66,45 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c animation= Renderer::getInstance().newModel(rsGame); string currentPath = dir; endPathWithSlash(currentPath); - animation->load(currentPath + path); + animation->load(currentPath + path, false, &loadedFileList); + loadedFileList[currentPath + path]++; //particles - if(sn->hasChild("particles")){ + if(sn->hasChild("particles")) { const XmlNode *particleNode= sn->getChild("particles"); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); - if(particleEnabled){ - for(int i=0; igetChildCount(); ++i){ + if(particleEnabled) { + for(int i = 0; i < particleNode->getChildCount(); ++i) { const XmlNode *particleFileNode= particleNode->getChild("particle-file", i); string path= particleFileNode->getAttribute("path")->getRestrictedValue(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); - unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); + unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance(), + loadedFileList); + loadedFileList[currentPath + path]++; unitParticleSystemTypes.push_back(unitParticleSystemType); } } } - - //sound const XmlNode *soundNode= sn->getChild("sound"); - if(soundNode->getAttribute("enabled")->getBoolValue()){ - + if(soundNode->getAttribute("enabled")->getBoolValue()) { soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); - sounds.resize(soundNode->getChildCount()); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < soundNode->getChildCount(); ++i) { const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); string path= soundFileNode->getAttribute("path")->getRestrictedValue(); + trimPathWithStartingSlash(path); + StaticSound *sound= new StaticSound(); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; sounds[i]= sound; } } } -string SkillType::skillClassToStr(SkillClass skillClass){ +string SkillType::skillClassToStr(SkillClass skillClass) { switch(skillClass){ case scStop: return "Stop"; case scMove: return "Move"; @@ -188,8 +191,9 @@ AttackSkillType::~AttackSkillType() { deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end()); } -void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft) { - SkillType::load(sn, dir, tt, ft); +void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList) { + SkillType::load(sn, dir, tt, ft, loadedFileList); string currentPath = dir; endPathWithSlash(currentPath); @@ -244,7 +248,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree if(particleEnabled){ string path= particleNode->getAttribute("path")->getRestrictedValue(); projectileParticleSystemType= new ParticleSystemTypeProjectile(); - projectileParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); + projectileParticleSystemType->load(dir, currentPath + path, + &Renderer::getInstance(), loadedFileList); } //proj sounds @@ -255,8 +260,11 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); string path= soundFileNode->getAttribute("path")->getRestrictedValue(); + trimPathWithStartingSlash(path); + StaticSound *sound= new StaticSound(); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; projSounds[i]= sound; } } @@ -275,7 +283,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree if(particleEnabled){ string path= particleNode->getAttribute("path")->getRestrictedValue(); splashParticleSystemType= new ParticleSystemTypeSplash(); - splashParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); + splashParticleSystemType->load(dir, currentPath + path, + &Renderer::getInstance(),loadedFileList); } } } @@ -397,8 +406,9 @@ DieSkillType::DieSkillType(){ skillClass= scDie; } -void DieSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){ - SkillType::load(sn, dir, tt, ft); +void DieSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList) { + SkillType::load(sn, dir, tt, ft, loadedFileList); fade= sn->getChild("fade")->getAttribute("value")->getBoolValue(); } diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index a3c6a9197..4472dff8f 100755 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -72,7 +72,7 @@ typedef list UnitParticleSystemTypes; /// A basic action that an unit can perform // ===================================================== -class SkillType{ +class SkillType { protected: @@ -91,7 +91,8 @@ public: public: //varios virtual ~SkillType(); - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft); + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList); //get const string &getName() const {return name;} @@ -160,7 +161,8 @@ private: public: AttackSkillType(); ~AttackSkillType(); - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft); + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList); virtual string toString() const; //get @@ -279,7 +281,8 @@ public: DieSkillType(); bool getFade() const {return fade;} - virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft); + virtual void load(const XmlNode *sn, const string &dir, const TechTree *tt, + const FactionType *ft, std::map &loadedFileList); virtual string toString() const; }; diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index 23977bda1..3f862ae4b 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -32,7 +32,8 @@ namespace Glest{ namespace Game{ // class TechTree // ===================================================== -Checksum TechTree::loadTech(const vector pathList, const string &techName, set &factions, Checksum* checksum) { +Checksum TechTree::loadTech(const vector pathList, const string &techName, + set &factions, Checksum* checksum, std::map &loadedFileList) { Checksum techtreeChecksum; for(int idx = 0; idx < pathList.size(); idx++) { string currentPath = pathList[idx]; @@ -40,44 +41,47 @@ Checksum TechTree::loadTech(const vector pathList, const string &techNam string path = currentPath + techName; if(isdir(path.c_str()) == true) { - load(path, factions, checksum, &techtreeChecksum); + load(path, factions, checksum, &techtreeChecksum, loadedFileList); break; } } return techtreeChecksum; } -void TechTree::load(const string &dir, set &factions, Checksum* checksum, Checksum *techtreeChecksum) { +void TechTree::load(const string &dir, set &factions, Checksum* checksum, + Checksum *techtreeChecksum, std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - string str; + string currentPath = dir; + endPathWithSlash(currentPath); + vector filenames; - string name= lastDir(dir); + string name= lastDir(currentPath); Logger::getInstance().add("TechTree: "+ formatString(name), true); //load resources - str= dir+"/resources/*."; + string str= currentPath + "resources/*."; - try{ + try { findAll(str, filenames); resourceTypes.resize(filenames.size()); for(int i=0; i &factions, Checksum* checksum SDL_PumpEvents(); //load tech tree xml info - try{ + try { XmlTree xmlTree; string currentPath = dir; endPathWithSlash(currentPath); @@ -96,15 +100,18 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum checksumValue.addFile(path); xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *techTreeNode= xmlTree.getRootNode(); //attack types const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types"); attackTypes.resize(attackTypesNode->getChildCount()); - for(int i=0; igetChild("attack-type", i); attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue()); attackTypes[i].setId(i); + Window::handleEvent(); SDL_PumpEvents(); } @@ -116,10 +123,11 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum //armor types const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types"); armorTypes.resize(armorTypesNode->getChildCount()); - for(int i=0; igetChild("armor-type", i); armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue()); armorTypes[i].setId(i); + Window::handleEvent(); SDL_PumpEvents(); } @@ -127,19 +135,20 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum //damage multipliers damageMultiplierTable.init(attackTypes.size(), armorTypes.size()); const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < damageMultipliersNode->getChildCount(); ++i) { const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i); const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue()); const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue()); float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue(); damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier); + Window::handleEvent(); SDL_PumpEvents(); } } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw runtime_error("Error loading Tech Tree: "+ dir + "\n" + e.what()); + throw runtime_error("Error loading Tech Tree: "+ currentPath + "\n" + e.what()); } // give CPU time to update other things to avoid apperance of hanging @@ -147,7 +156,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum //SDL_PumpEvents(); //load factions - str = dir + "/factions/*."; + str = currentPath + "factions/*."; try{ factionTypes.resize(factions.size()); @@ -156,13 +165,17 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum string factionName = *it; char szBuf[1024]=""; - sprintf(szBuf,"%s %s [%d / %d] - %s",Lang::getInstance().get("Loading").c_str(),Lang::getInstance().get("Faction").c_str(),i+1,(int)factions.size(),factionName.c_str()); + sprintf(szBuf,"%s %s [%d / %d] - %s",Lang::getInstance().get("Loading").c_str(), + Lang::getInstance().get("Faction").c_str(), + i+1, + (int)factions.size(), + factionName.c_str()); Logger &logger= Logger::getInstance(); logger.setState(szBuf); logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0)); - str=dir+"/factions/" + factionName; - factionTypes[i++].load(str, this, checksum,&checksumValue); + str = currentPath + "factions/" + factionName; + factionTypes[i++].load(str, this, checksum,&checksumValue,loadedFileList); // give CPU time to update other things to avoid apperance of hanging sleep(0); @@ -172,7 +185,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what()); + throw runtime_error("Error loading Faction Types: "+ currentPath + "\n" + e.what()); } if(techtreeChecksum != NULL) { diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 0275b005c..685746284 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -45,8 +45,10 @@ private: Checksum checksumValue; public: - Checksum loadTech(const vector pathList, const string &techName, set &factions, Checksum* checksum); - void load(const string &dir, set &factions, Checksum* checksum,Checksum *techtreeChecksum); + Checksum loadTech(const vector pathList, const string &techName, + set &factions, Checksum* checksum, std::map &loadedFileList); + void load(const string &dir, set &factions, Checksum* checksum, + Checksum *techtreeChecksum, std::map &loadedFileList); ~TechTree(); Checksum * getChecksumValue() { return &checksumValue; } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index afd54e011..0289c4dbd 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -113,11 +113,13 @@ UnitType::~UnitType(){ } } -void UnitType::preLoad(const string &dir){ +void UnitType::preLoad(const string &dir) { name= lastDir(dir); } -void UnitType::load(int id,const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum,Checksum* techtreeChecksum) { +void UnitType::load(int id,const string &dir, const TechTree *techTree, + const FactionType *factionType, Checksum* checksum, + Checksum* techtreeChecksum, std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -137,6 +139,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; + const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *parametersNode= unitNode->getChild("parameters"); @@ -250,35 +254,38 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa if (fields[fLand]) { field = fLand; - } else if (fields[fAir]) { + } + else if (fields[fAir]) { field = fAir; - } else { + } + else { throw runtime_error("Unit has no field: " + path); } //properties const XmlNode *propertiesNode= parametersNode->getChild("properties"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < propertiesNode->getChildCount(); ++i) { const XmlNode *propertyNode= propertiesNode->getChild("property", i); string propertyName= propertyNode->getAttribute("value")->getRestrictedValue(); bool found= false; - for(int i=0; ihasChild("damage-particles")){ + if(parametersNode->hasChild("damage-particles")) { const XmlNode *particleNode= parametersNode->getChild("damage-particles"); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); - if(particleEnabled){ - for(int i=0; igetChildCount(); ++i){ + + if(particleEnabled) { + for(int i = 0; i < particleNode->getChildCount(); ++i) { const XmlNode *particleFileNode= particleNode->getChild("particle-file", i); string path= particleFileNode->getAttribute("path")->getRestrictedValue(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); @@ -286,10 +293,13 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa //Texture2D *newTexture = Renderer::getInstance().newTexture2D(rsGame); Texture2D *newTexture = NULL; - unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); - if(unitParticleSystemType->hasTexture() == false) { + unitParticleSystemType->load(dir, currentPath + path, + &Renderer::getInstance(),loadedFileList); + loadedFileList[currentPath + path]++; + + //if(unitParticleSystemType->hasTexture() == false) { //Renderer::getInstance().endLastTexture(rsGame,true); - } + //} damageParticleSystemTypes.push_back(unitParticleSystemType); } @@ -306,7 +316,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa } //rotationAllowed - if(parametersNode->hasChild("rotationAllowed")){ + if(parametersNode->hasChild("rotationAllowed")) { const XmlNode *rotationAllowedNode= parametersNode->getChild("rotationAllowed"); rotationAllowed= rotationAllowedNode->getAttribute("value")->getBoolValue(); } @@ -356,11 +366,13 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa const XmlNode *imageNode= parametersNode->getChild("image"); image= Renderer::getInstance().newTexture2D(rsGame); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; //image cancel const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel"); cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++; //meeting point const XmlNode *meetingPointNode= parametersNode->getChild("meeting-point"); @@ -368,6 +380,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa if(meetingPoint){ meetingPointImage= Renderer::getInstance().newTexture2D(rsGame); meetingPointImage->load(currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue()); + loadedFileList[currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue()]++; } //selection sounds @@ -379,6 +392,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa string path= soundNode->getAttribute("path")->getRestrictedValue(); StaticSound *sound= new StaticSound(); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; selectionSounds[i]= sound; } } @@ -392,6 +406,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa string path= soundNode->getAttribute("path")->getRestrictedValue(); StaticSound *sound= new StaticSound(); sound->load(currentPath + path); + loadedFileList[currentPath + path]++; commandSounds[i]= sound; } } @@ -399,24 +414,25 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa //skills const XmlNode *skillsNode= unitNode->getChild("skills"); skillTypes.resize(skillsNode->getChildCount()); - for(int i=0; igetChild("skill", i); const XmlNode *typeNode= sn->getChild("type"); string classId= typeNode->getAttribute("value")->getRestrictedValue(); SkillType *skillType= SkillTypeFactory::getInstance().newInstance(classId); - skillType->load(sn, dir, techTree, factionType); + skillType->load(sn, dir, techTree, factionType, loadedFileList); skillTypes[i]= skillType; } //commands const XmlNode *commandsNode= unitNode->getChild("commands"); commandTypes.resize(commandsNode->getChildCount()); - for(int i=0; igetChild("command", i); const XmlNode *typeNode= commandNode->getChild("type"); string classId= typeNode->getAttribute("value")->getRestrictedValue(); CommandType *commandType= CommandTypeFactory::getInstance().newInstance(classId); - commandType->load(i, commandNode, dir, techTree, factionType, *this); + commandType->load(i, commandNode, dir, techTree, factionType, *this, + loadedFileList); commandTypes[i]= commandType; } diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 42809d65f..649b9747b 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -136,7 +136,9 @@ public: UnitType(); virtual ~UnitType(); void preLoad(const string &dir); - void load(int id, const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum); + void load(int id, const string &dir, const TechTree *techTree, + const FactionType *factionType, Checksum* checksum, + Checksum* techtreeChecksum, std::map &loadedFileList); //get int getId() const {return id;} diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index e9eddf359..73e8d4206 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -47,16 +47,16 @@ void UpgradeType::preLoad(const string &dir){ name=lastDir(dir); } -void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum) { +void UpgradeType::load(const string &dir, const TechTree *techTree, + const FactionType *factionType, Checksum* checksum, + Checksum* techtreeChecksum, std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - string path; - Logger::getInstance().add("Upgrade type: "+ formatString(name), true); string currentPath = dir; endPathWithSlash(currentPath); - path = currentPath + name + ".xml"; + string path = currentPath + name + ".xml"; try{ checksum->addFile(path); @@ -64,17 +64,20 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; const XmlNode *upgradeNode= xmlTree.getRootNode(); //image const XmlNode *imageNode= upgradeNode->getChild("image"); image= Renderer::getInstance().newTexture2D(rsGame); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; //image cancel const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel"); cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++; //upgrade time const XmlNode *upgradeTimeNode= upgradeNode->getChild("time"); @@ -82,7 +85,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio //unit requirements const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < unitRequirementsNode->getChildCount(); ++i) { const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); unitReqs.push_back(factionType->getUnitType(name)); @@ -90,7 +93,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio //upgrade requirements const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < upgradeRequirementsNode->getChildCount(); ++i) { const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); upgradeReqs.push_back(factionType->getUpgradeType(name)); @@ -99,7 +102,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio //resource requirements const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements"); costs.resize(resourceRequirementsNode->getChildCount()); - for(int i=0; igetChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); @@ -108,7 +111,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio //effects const XmlNode *effectsNode= upgradeNode->getChild("effects"); - for(int i=0; igetChildCount(); ++i){ + for(int i = 0; i < effectsNode->getChildCount(); ++i) { const XmlNode *unitNode= effectsNode->getChild("unit", i); string name= unitNode->getAttribute("name")->getRestrictedValue(); effects.push_back(factionType->getUnitType(name)); @@ -123,7 +126,6 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue(); moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); - } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); diff --git a/source/glest_game/types/upgrade_type.h b/source/glest_game/types/upgrade_type.h index 97ffc5a23..af631596f 100644 --- a/source/glest_game/types/upgrade_type.h +++ b/source/glest_game/types/upgrade_type.h @@ -77,7 +77,9 @@ private: public: void preLoad(const string &dir); - void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, Checksum* techtreeChecksum); + void load(const string &dir, const TechTree *techTree, + const FactionType *factionType, Checksum* checksum, + Checksum* techtreeChecksum, std::map &loadedFileList); //get all int getEffectCount() const {return effects.size();} diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index 6729e777c..877828184 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -31,13 +31,14 @@ namespace Glest{ namespace Game{ // class AmbientSounds // ===================================================== -void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){ +void AmbientSounds::load(const string &dir, const XmlNode *xmlNode, + std::map &loadedFileList) { string path; //day const XmlNode *dayNode= xmlNode->getChild("day-sound"); enabledDay= dayNode->getAttribute("enabled")->getBoolValue(); - if(enabledDay){ + if(enabledDay) { path= dayNode->getAttribute("path")->getRestrictedValue(); string currentPath = dir; endPathWithSlash(currentPath); @@ -84,6 +85,7 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){ string currentPath = dir; endPathWithSlash(currentPath); dayStart.load(currentPath + path); + loadedFileList[currentPath + path]++; } //nightStart @@ -94,6 +96,7 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){ string currentPath = dir; endPathWithSlash(currentPath); nightStart.load(currentPath + path); + loadedFileList[currentPath + path]++; } } @@ -101,14 +104,15 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){ // class Tileset // ===================================================== -Checksum Tileset::loadTileset(const vector pathList, const string &tilesetName, Checksum* checksum) { +Checksum Tileset::loadTileset(const vector pathList, const string &tilesetName, + Checksum* checksum, std::map &loadedFileList) { Checksum tilesetChecksum; for(int idx = 0; idx < pathList.size(); idx++) { string currentPath = pathList[idx]; endPathWithSlash(currentPath); string path = currentPath + tilesetName; if(isdir(path.c_str()) == true) { - load(path, checksum, &tilesetChecksum); + load(path, checksum, &tilesetChecksum, loadedFileList); break; } } @@ -116,7 +120,8 @@ Checksum Tileset::loadTileset(const vector pathList, const string &tiles } -void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum) { +void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum, + std::map &loadedFileList) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); random.init(time(NULL)); @@ -141,6 +146,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck //parse xml XmlTree xmlTree; xmlTree.load(path); + loadedFileList[path]++; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -168,6 +174,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck const XmlNode *textureNode= surfaceNode->getChild("texture", j); surfPixmaps[i][j].init(3); surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); + loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++; + surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue(); } } @@ -193,7 +201,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck for(int j=0; jgetChild("model", j); const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); - objectTypes[i].loadModel(currentPath + pathAttribute->getRestrictedValue()); + objectTypes[i].loadModel(currentPath + pathAttribute->getRestrictedValue(),&loadedFileList); + loadedFileList[currentPath + pathAttribute->getRestrictedValue()]++; if(modelNode->hasChild("particles")){ const XmlNode *particleNode= modelNode->getChild("particles"); @@ -203,7 +212,10 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck const XmlNode *particleFileNode= particleNode->getChild("particle-file", k); string path= particleFileNode->getAttribute("path")->getRestrictedValue(); ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); - objectParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); + objectParticleSystemType->load(dir, currentPath + path, + &Renderer::getInstance(), loadedFileList); + loadedFileList[currentPath + path]++; + objectTypes[i].addParticleSystem((objectParticleSystemType)); } } @@ -219,7 +231,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //ambient sounds - ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds")); + ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds"), loadedFileList); //parameters const XmlNode *parametersNode= tilesetNode->getChild("parameters"); @@ -238,6 +250,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck for(int i=0; igetChild("texture", i); waterTex->getPixmap()->loadSlice(currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue(), i); + loadedFileList[currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue()]++; } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/world/tileset.h b/source/glest_game/world/tileset.h index d822d87ed..d13b53333 100644 --- a/source/glest_game/world/tileset.h +++ b/source/glest_game/world/tileset.h @@ -88,7 +88,8 @@ public: StaticSound *getDayStart() {return &dayStart;} StaticSound *getNightStart() {return &nightStart;} - void load(const string &dir, const XmlNode *xmlNode); + void load(const string &dir, const XmlNode *xmlNode, + std::map &loadedFileList); }; // ===================================================== @@ -97,7 +98,7 @@ public: /// Containt textures, models and parameters for a tileset // ===================================================== -class Tileset{ +class Tileset { public: static const int waterTexCount= 1; static const int surfCount= 6; @@ -131,8 +132,10 @@ private: public: ~Tileset(); - Checksum loadTileset(const vector pathList, const string &tilesetName, Checksum* checksum); - void load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum); + Checksum loadTileset(const vector pathList, const string &tilesetName, + Checksum* checksum, std::map &loadedFileList); + void load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum, + std::map &loadedFileList); Checksum * getChecksumValue() { return &checksumValue; } //get diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index c02c83e0a..a892baed3 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -198,11 +198,12 @@ void World::init(Game *game, bool createUnits){ } //load tileset -Checksum World::loadTileset(const vector pathList, const string &tilesetName, Checksum* checksum) { +Checksum World::loadTileset(const vector pathList, const string &tilesetName, + Checksum* checksum, std::map &loadedFileList) { Checksum tilsetChecksum; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - tilsetChecksum = tileset.loadTileset(pathList, tilesetName, checksum); + tilsetChecksum = tileset.loadTileset(pathList, tilesetName, checksum, loadedFileList); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); timeFlow.init(&tileset); @@ -211,11 +212,11 @@ Checksum World::loadTileset(const vector pathList, const string &tileset return tilsetChecksum; } -Checksum World::loadTileset(const string &dir, Checksum *checksum) { +Checksum World::loadTileset(const string &dir, Checksum *checksum, std::map &loadedFileList) { Checksum tilesetChecksum; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - tileset.load(dir, checksum, &tilesetChecksum); + tileset.load(dir, checksum, &tilesetChecksum, loadedFileList); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); timeFlow.init(&tileset); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -224,13 +225,15 @@ Checksum World::loadTileset(const string &dir, Checksum *checksum) { } //load tech -Checksum World::loadTech(const vector pathList, const string &techName, set &factions, Checksum *checksum) { +Checksum World::loadTech(const vector pathList, const string &techName, + set &factions, Checksum *checksum, std::map &loadedFileList) { Checksum techtreeChecksum; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); techTree = new TechTree(); - techtreeChecksum = techTree->loadTech(pathList, techName, factions, checksum); + techtreeChecksum = techTree->loadTech(pathList, techName, factions, + checksum,loadedFileList); return techtreeChecksum; } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 242ba5658..dfde27305 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -173,9 +173,12 @@ public: //init & load void init(Game *game, bool createUnits); - Checksum loadTileset(const vector pathList, const string &tilesetName, Checksum* checksum); - Checksum loadTileset(const string &dir, Checksum* checksum); - Checksum loadTech(const vector pathList, const string &techName, set &factions, Checksum* checksum); + Checksum loadTileset(const vector pathList, const string &tilesetName, + Checksum* checksum, std::map &loadedFileList); + Checksum loadTileset(const string &dir, Checksum* checksum, + std::map &loadedFileList); + Checksum loadTech(const vector pathList, const string &techName, + set &factions, Checksum* checksum,std::map &loadedFileList); Checksum loadMap(const string &path, Checksum* checksum); Checksum loadScenario(const string &path, Checksum* checksum); diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 1bbb0e4af..1ed6d2f02 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -133,12 +133,14 @@ public: Texture2D *loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile, int textureChannelCount, bool &textureOwned, - bool deletePixMapAfterLoad); + bool deletePixMapAfterLoad, std::map *loadedFileList=NULL); //load - void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); - void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); - void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); + void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, + bool deletePixMapAfterLoad,std::map *loadedFileList=NULL); + void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, + bool deletePixMapAfterLoad,std::map *loadedFileList=NULL); + void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad,std::map *loadedFileList=NULL); void save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, string convertTextureToFormat, std::map &textureDeleteList, bool keepsmallest); @@ -194,9 +196,9 @@ public: uint32 getVertexCount() const; //io - void load(const string &path,bool deletePixMapAfterLoad=false); + void load(const string &path,bool deletePixMapAfterLoad=false,std::map *loadedFileList=NULL); void save(const string &path, string convertTextureToFormat,bool keepsmallest); - void loadG3d(const string &path,bool deletePixMapAfterLoad=false); + void loadG3d(const string &path,bool deletePixMapAfterLoad=false,std::map *loadedFileList=NULL); void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest); void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;} diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index b65f87248..7c889d6cd 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -109,6 +109,7 @@ public: // ===================================================== void Tokenize(const string& str,vector& tokens,const string& delimiters = " "); bool isdir(const char *path); +void findDirs(string path, vector &results, bool errorOnNotFound,bool keepDuplicates); void findDirs(const vector &paths, vector &results, bool errorOnNotFound=false,bool keepDuplicates=false); void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false); void findAll(const string &path, vector &results, bool cutExtension=false, bool errorOnNotFound=true); @@ -148,6 +149,8 @@ bool StartsWith(const std::string &str, const std::string &key); bool EndsWith(const string &str, const string& key); void endPathWithSlash(string &path); +void trimPathWithStartingSlash(string &path); +void updatePathClimbingParts(string &path); string replaceAll(string& context, const string& from, const string& to); bool removeFile(string file); diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index d866f2924..4f359c67d 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -207,7 +207,8 @@ string Mesh::findAlternateTexture(vector conversionList, string textureF return result; } -void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) { +void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, + bool deletePixMapAfterLoad, std::map *loadedFileList) { this->textureManager = textureManager; //read header MeshHeaderV2 meshHeader; @@ -267,6 +268,9 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex if(fileExists(texPath) == true) { textures[mtDiffuse]= textureManager->newTexture2D(); textures[mtDiffuse]->load(texPath); + if(loadedFileList) { + (*loadedFileList)[texPath]++; + } texturesOwned[mtDiffuse]=true; textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); if(deletePixMapAfterLoad == true) { @@ -291,7 +295,9 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); } -void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) { +void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, + TextureManager *textureManager,bool deletePixMapAfterLoad, + std::map *loadedFileList) { this->textureManager = textureManager; //read header @@ -348,6 +354,10 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *tex if(fileExists(texPath) == true) { textures[mtDiffuse]= textureManager->newTexture2D(); textures[mtDiffuse]->load(texPath); + if(loadedFileList) { + (*loadedFileList)[texPath]++; + } + texturesOwned[mtDiffuse]=true; textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); if(deletePixMapAfterLoad == true) { @@ -374,8 +384,10 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *tex readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f); } -Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile, - int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad) { +Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, + TextureManager *textureManager, string textureFile, + int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad, + std::map *loadedFileList) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #1 load texture [%s]\n",__FUNCTION__,textureFile.c_str()); @@ -400,6 +412,9 @@ Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager texture->getPixmap()->init(textureChannelCount); } texture->load(textureFile); + if(loadedFileList) { + (*loadedFileList)[textureFile]++; + } //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture loaded [%s]\n",__FUNCTION__,textureFile.c_str()); @@ -421,7 +436,7 @@ Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager } void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, - bool deletePixMapAfterLoad) { + bool deletePixMapAfterLoad,std::map *loadedFileList) { this->textureManager = textureManager; //read header @@ -470,7 +485,8 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu mapFullPath += mapPath; textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath, - meshTextureChannelCount[i],texturesOwned[i],deletePixMapAfterLoad); + meshTextureChannelCount[i],texturesOwned[i], + deletePixMapAfterLoad, loadedFileList); } flag *= 2; } @@ -749,10 +765,11 @@ uint32 Model::getVertexCount() const { // ==================== io ==================== -void Model::load(const string &path, bool deletePixMapAfterLoad) { +void Model::load(const string &path, bool deletePixMapAfterLoad, + std::map *loadedFileList) { string extension= path.substr(path.find_last_of('.')+1); if(extension=="g3d" || extension=="G3D"){ - loadG3d(path,deletePixMapAfterLoad); + loadG3d(path,deletePixMapAfterLoad,loadedFileList); } else{ throw runtime_error("Unknown model format: " + extension); @@ -773,7 +790,8 @@ void Model::save(const string &path, string convertTextureToFormat, } //load a model from a g3d file -void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) { +void Model::loadG3d(const string &path, bool deletePixMapAfterLoad, + std::map *loadedFileList) { try{ FILE *f=fopen(path.c_str(),"rb"); @@ -782,6 +800,10 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) { throw runtime_error("Error opening g3d model file [" + path + "]"); } + if(loadedFileList) { + (*loadedFileList)[path]++; + } + string dir= extractDirectoryPathFromFile(path); //file header @@ -811,7 +833,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) { //load meshes meshes= new Mesh[meshCount]; for(uint32 i = 0; i < meshCount; ++i) { - meshes[i].load(i, dir, f, textureManager,deletePixMapAfterLoad); + meshes[i].load(i, dir, f, textureManager,deletePixMapAfterLoad, + loadedFileList); meshes[i].buildInterpolationData(); } } @@ -823,7 +846,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) { meshes= new Mesh[meshCount]; for(uint32 i = 0; i < meshCount; ++i) { - meshes[i].loadV3(i, dir, f, textureManager,deletePixMapAfterLoad); + meshes[i].loadV3(i, dir, f, textureManager,deletePixMapAfterLoad, + loadedFileList); meshes[i].buildInterpolationData(); } } @@ -835,7 +859,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) { meshes= new Mesh[meshCount]; for(uint32 i = 0; i < meshCount; ++i){ - meshes[i].loadV2(i,dir, f, textureManager,deletePixMapAfterLoad); + meshes[i].loadV2(i,dir, f, textureManager,deletePixMapAfterLoad, + loadedFileList); meshes[i].buildInterpolationData(); } } diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index d0bef8e56..c8a76bc87 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -65,7 +65,6 @@ using namespace std; namespace Shared { namespace PlatformCommon { -// Refresh every 3 days const time_t REFRESH_CRC_DAY_SECONDS = 1 * 60 * 24; static string crcCachePath = ""; @@ -210,6 +209,30 @@ void Tokenize(const string& str,vector& tokens,const string& delimiters) } } +void findDirs(string path, vector &results, bool errorOnNotFound,bool keepDuplicates) { + results.clear(); + string currentPath = path; + endPathWithSlash(currentPath); + + string searchpath = currentPath + "*."; + vector current_results; + findAll(searchpath, current_results, false, errorOnNotFound); + if(current_results.size() > 0) { + for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) { + const string current_folder = current_results[folder_index]; + const string current_folder_path = currentPath + current_folder; + + if(isdir(current_folder_path.c_str()) == true) { + if(keepDuplicates == true || std::find(results.begin(),results.end(),current_folder) == results.end()) { + results.push_back(current_folder); + } + } + } + } + + std::sort(results.begin(),results.end()); +} + void findDirs(const vector &paths, vector &results, bool errorOnNotFound,bool keepDuplicates) { results.clear(); size_t pathCount = paths.size(); @@ -412,6 +435,37 @@ void endPathWithSlash(string &path) { } } +void trimPathWithStartingSlash(string &path) { + if(StartsWith(path, "/") == true || StartsWith(path, "\\") == true) { + path.erase(path.begin(),path.begin()+1); + //printf("************* trimPathWithStartingSlash changed path [%s]\n",path.c_str()); + } +} + +void updatePathClimbingParts(string &path) { + // Update paths with .. + string::size_type pos = path.rfind(".."); + if(pos != string::npos && pos != 0) { + string orig = path; + path.erase(pos,2); + pos--; + if(path[pos] == '/' || path[pos] == '\\') { + path.erase(pos,1); + } + + for(int x = pos; x >= 0; --x) { + //printf("x [%d][%c] pos [%ld][%c] [%s]\n",x,path[x],(long int)pos,path[pos],path.substr(0,x+1).c_str()); + + if((path[x] == '/' || path[x] == '\\') && x != pos) { + path.erase(x,pos-x); + break; + } + } + + //printf("CHANGED relative path from [%s] to [%s]\n",orig.c_str(),path.c_str()); + } +} + string getCRCCacheFilePath() { return crcCachePath; } @@ -467,7 +521,7 @@ void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) { FILE *fp = fopen(crcCacheFile.c_str(),"w"); if(fp != NULL) { RandomGen random; - int offset = random.randRange(1, 5); + int offset = random.randRange(5, 15); time_t refreshDate = time(NULL) + (REFRESH_CRC_DAY_SECONDS * offset); fprintf(fp,"%ld,%d",refreshDate,crcValue); fclose(fp); diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 9b7678965..1e546b228 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -494,7 +494,7 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT } -string lastDir(const string &s){ +string lastDir(const string &s) { size_t i= s.find_last_of('/'); size_t j= s.find_last_of('\\'); size_t pos; @@ -513,7 +513,18 @@ string lastDir(const string &s){ throw runtime_error(string(__FILE__)+" lastDir - i==string::npos"); } - return (s.substr(pos+1, s.length())); + if( pos + 1 == s.length() && s.length() > 0 && + (s[pos] == '/' || s[pos] == '\\')) { + string retry = s.substr(0, pos); + return lastDir(retry); + } + string result = s.substr(pos+1, s.length()); + replaceAll(result,"/",""); + replaceAll(result,"\\",""); + + //printf("=-=-=-=- LASTDIR in [%s] out [%s]\n",s.c_str(),result.c_str()); + + return result; } string lastFile(const string &s){