- new commandline options to discover and optional delete unused files in techtrees

This commit is contained in:
Mark Vejvoda
2011-03-15 15:30:28 +00:00
parent 6eab8f905e
commit 7d38aec84a
33 changed files with 609 additions and 252 deletions

View File

@@ -1072,8 +1072,10 @@ void MainWindow::loadParticle(string path) {
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
std::map<string,int> loadedFileList;
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType();
unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath, renderer); unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath,
renderer,loadedFileList);
unitParticleSystemTypes.push_back(unitParticleSystemType); unitParticleSystemTypes.push_back(unitParticleSystemType);
for(std::vector<UnitParticleSystemType *>::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) { for(std::vector<UnitParticleSystemType *>::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::cout << "Loaded successfully, loading values..." << std::endl;
std::map<string,int> loadedFileList;
ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile(); 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; // 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::cout << "Loaded successfully, loading values..." << std::endl;
std::map<string,int> loadedFileList;
ParticleSystemTypeSplash *splashParticleSystemType= new ParticleSystemTypeSplash(); 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; // std::cout << "Values loaded, about to read..." << std::endl;

View File

@@ -370,6 +370,7 @@ void Game::load() {
} }
void Game::load(LoadGameItem loadTypes) { void Game::load(LoadGameItem loadTypes) {
std::map<string,int> loadedFileList;
originalDisplayMsgCallback = NetworkInterface::getDisplayMessageFunction(); originalDisplayMsgCallback = NetworkInterface::getDisplayMessageFunction();
NetworkInterface::setDisplayMessageFunction(ErrorDisplayMessage); NetworkInterface::setDisplayMessageFunction(ErrorDisplayMessage);
@@ -411,7 +412,7 @@ void Game::load(LoadGameItem loadTypes) {
if((loadTypes & lgt_TileSet) == lgt_TileSet) { if((loadTypes & lgt_TileSet) == lgt_TileSet) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
world.loadTileset( config.getPathListForType(ptTilesets,scenarioDir), world.loadTileset( config.getPathListForType(ptTilesets,scenarioDir),
tilesetName, &checksum); tilesetName, &checksum, loadedFileList);
} }
// give CPU time to update other things to avoid apperance of hanging // 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 //tech, load before map because of resources
world.loadTech( config.getPathListForType(ptTechs,scenarioDir), techName, 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 // Validate the faction setup to ensure we don't have any bad associations
/* /*

View File

@@ -40,7 +40,8 @@ ParticleSystemType::ParticleSystemType() {
model=NULL; 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<string,int> &loadedFileList) {
//texture //texture
const XmlNode *textureNode= particleSystemNode->getChild("texture"); const XmlNode *textureNode= particleSystemNode->getChild("texture");
bool textureEnabled= textureNode->getAttribute("value")->getBoolValue(); bool textureEnabled= textureNode->getAttribute("value")->getBoolValue();
@@ -57,6 +58,7 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++;
} }
else { else {
texture= NULL; texture= NULL;
@@ -73,7 +75,8 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
model->load(currentPath + path); model->load(currentPath + path, false, &loadedFileList);
loadedFileList[currentPath + path]++;
} }
} }
else{ else{
@@ -182,14 +185,17 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
// class ParticleSystemTypeProjectile // 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<string,int> &loadedFileList) {
try{ try{
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *particleSystemNode= xmlTree.getRootNode(); const XmlNode *particleSystemNode= xmlTree.getRootNode();
ParticleSystemType::load(particleSystemNode, dir, renderer); ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList);
//trajectory values //trajectory values
const XmlNode *tajectoryNode= particleSystemNode->getChild("trajectory"); const XmlNode *tajectoryNode= particleSystemNode->getChild("trajectory");
@@ -240,14 +246,17 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() {
// class ParticleSystemTypeSplash // 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<string,int> &loadedFileList) {
try{ try{
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *particleSystemNode= xmlTree.getRootNode(); const XmlNode *particleSystemNode= xmlTree.getRootNode();
ParticleSystemType::load(particleSystemNode, dir, renderer); ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList);
//emission rate fade //emission rate fade
const XmlNode *emissionRateFadeNode= particleSystemNode->getChild("emission-rate-fade"); const XmlNode *emissionRateFadeNode= particleSystemNode->getChild("emission-rate-fade");

View File

@@ -44,7 +44,7 @@ using Shared::Xml::XmlNode;
/// A type of particle system /// A type of particle system
// =========================================================== // ===========================================================
class ParticleSystemType{ class ParticleSystemType {
protected: protected:
string type; string type;
Texture2D *texture; Texture2D *texture;
@@ -67,7 +67,8 @@ protected:
public: public:
ParticleSystemType(); ParticleSystemType();
void load(const XmlNode *particleSystemNode, const string &dir,RendererInterface *renderer); void load(const XmlNode *particleSystemNode, const string &dir,
RendererInterface *renderer, std::map<string,int> &loadedFileList);
void setValues(AttackParticleSystem *ats); void setValues(AttackParticleSystem *ats);
bool hasTexture() const { return(texture != NULL); } bool hasTexture() const { return(texture != NULL); }
bool hasModel() const { return(model != NULL); } bool hasModel() const { return(model != NULL); }
@@ -88,7 +89,8 @@ private:
float trajectoryFrequency; float trajectoryFrequency;
public: public:
void load(const string &dir, const string &path,RendererInterface *renderer); void load(const string &dir, const string &path,
RendererInterface *renderer, std::map<string,int> &loadedFileList);
ProjectileParticleSystem *create(); ProjectileParticleSystem *create();
}; };
@@ -97,9 +99,10 @@ public:
// class ParticleSystemTypeSplash // class ParticleSystemTypeSplash
// =========================================================== // ===========================================================
class ParticleSystemTypeSplash: public ParticleSystemType{ class ParticleSystemTypeSplash: public ParticleSystemType {
public: public:
void load(const string &dir, const string &path,RendererInterface *renderer); void load(const string &dir, const string &path,
RendererInterface *renderer, std::map<string,int> &loadedFileList);
SplashParticleSystem *create(); SplashParticleSystem *create();
private: private:

View File

@@ -29,8 +29,9 @@ namespace Glest{ namespace Game{
// class UnitParticleSystemType // class UnitParticleSystemType
// ===================================================== // =====================================================
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer) { void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir,
ParticleSystemType::load(particleSystemNode, dir, renderer); RendererInterface *renderer, std::map<string,int> &loadedFileList) {
ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList);
//radius //radius
const XmlNode *radiusNode= particleSystemNode->getChild("radius"); const XmlNode *radiusNode= particleSystemNode->getChild("radius");
radius= radiusNode->getAttribute("value")->getFloatValue(); 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<string,int> &loadedFileList) {
try{ try{
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *particleSystemNode= xmlTree.getRootNode(); const XmlNode *particleSystemNode= xmlTree.getRootNode();
UnitParticleSystemType::load(particleSystemNode, dir, renderer); UnitParticleSystemType::load(particleSystemNode, dir, renderer,
loadedFileList);
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());

View File

@@ -42,7 +42,7 @@ using Shared::Xml::XmlNode;
/// A type of particle system /// A type of particle system
// =========================================================== // ===========================================================
class UnitParticleSystemType: public ParticleSystemType{ class UnitParticleSystemType: public ParticleSystemType {
protected: protected:
float radius; float radius;
@@ -56,8 +56,10 @@ protected:
bool radiusBasedStartenergy; bool radiusBasedStartenergy;
public: public:
void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture); void load(const XmlNode *particleSystemNode, const string &dir,
void load(const string &dir, const string &path, RendererInterface *newTexture); RendererInterface *newTexture, std::map<string,int> &loadedFileList);
void load(const string &dir, const string &path, RendererInterface *newTexture,
std::map<string,int> &loadedFileList);
const void setValues (UnitParticleSystem *uts); const void setValues (UnitParticleSystem *uts);
bool hasTexture() const { return(texture != NULL); } bool hasTexture() const { return(texture != NULL); }
}; };

View File

@@ -126,7 +126,7 @@ enum GAME_ARG_TYPE {
GAME_ARG_LOG_PATH, GAME_ARG_LOG_PATH,
GAME_ARG_SHOW_INI_SETTINGS, GAME_ARG_SHOW_INI_SETTINGS,
GAME_ARG_CONVERT_MODELS, GAME_ARG_CONVERT_MODELS,
GAME_ARG_CONVERT_TEXTURES, // GAME_ARG_CONVERT_TEXTURES,
GAME_ARG_DISABLE_BACKTRACE, GAME_ARG_DISABLE_BACKTRACE,
GAME_ARG_DISABLE_VBO, GAME_ARG_DISABLE_VBO,
GAME_ARG_VERBOSE_MODE 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 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 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\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\tto your selected techtrees game data.");
printf("\n \t\tWhere x is a comma-delimited list of techtrees to validate."); 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 \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\tto your selected factions game data.");
printf("\n \t\tWhere x is a comma-delimited list of factions to validate."); 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*NOTE: leaving the list empty is the same as running");
printf("\n \t\t%s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); 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]); 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\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 \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%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 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\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 \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 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]); 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) { void runTechValidationReport(int argc, char** argv) {
//disableBacktrace=true; //disableBacktrace=true;
printf("====== Started Validation ======\n"); printf("====== Started Validation ======\n");
bool purgeUnusedFiles = false;
Config &config = Config::getInstance();
// Did the user pass a specific list of factions to validate? // Did the user pass a specific list of factions to validate?
std::vector<string> filteredFactionList; std::vector<string> filteredFactionList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("=")) == true) { 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()); printf("%s\n",filteredFactionList[idx].c_str());
} }
} }
}
}
Config &config = Config::getInstance(); if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused faction files will be deleted!\n");
}
}
}
}
vector<string> results; vector<string> results;
findDirs(config.getPathListForType(ptTechs), results); findDirs(config.getPathListForType(ptTechs), results);
vector<string> techTreeFiles = results; vector<string> techTreeFiles = results;
@@ -1148,6 +1157,13 @@ void runTechValidationReport(int argc, char** argv) {
printf("%s\n",filteredTechTreeList[idx].c_str()); 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()) { std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) {
vector<string> factionsList; vector<string> factionsList;
findAll(techPath + techName + "/factions/*.", factionsList, false, false); findDirs(techPath + techName + "/factions/", factionsList, false, false);
if(factionsList.size() > 0) { if(factionsList.size() > 0) {
Checksum checksum; Checksum checksum;
@@ -1193,7 +1209,26 @@ void runTechValidationReport(int argc, char** argv) {
if(factions.size() > 0) { if(factions.size() > 0) {
bool techtree_errors = false; bool techtree_errors = false;
world.loadTech(config.getPathListForType(ptTechs,""), techName, factions, &checksum);
std::map<string,int> loadedFileList;
vector<string> pathList = config.getPathListForType(ptTechs,"");
world.loadTech(pathList, techName, factions, &checksum, loadedFileList);
// Fixup paths with ..
{
std::map<string,int> newLoadedFileList;
for( std::map<string,int>::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 // Validate the faction setup to ensure we don't have any bad associations
std::vector<std::string> resultErrors = world.validateFactionTypes(); std::vector<std::string> resultErrors = world.validateFactionTypes();
if(resultErrors.size() > 0) { if(resultErrors.size() > 0) {
@@ -1234,6 +1269,78 @@ void runTechValidationReport(int argc, char** argv) {
printf("%s",errorText.c_str()); printf("%s",errorText.c_str());
} }
// Now check for unused files in the techtree
std::map<string,int> foundFileList;
for(unsigned int i = 0; i < pathList.size(); ++i) {
string path = pathList[i];
endPathWithSlash(path);
path = path + techName + "/";
vector<string> 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<string>::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<string,int>::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<string,int>::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) { 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()); 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<string>::iterator it = factions.begin(); it != factions.end(); ++it ) { for ( set<string>::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) { // if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]) == true) {
//!!! // //!!!
printf("\nComing soon (not yet implemented)\n\n"); // printf("\nComing soon (not yet implemented)\n\n");
delete mainWindow; // delete mainWindow;
return -1; // return -1;
} // }
if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true || if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) {

View File

@@ -501,6 +501,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
ftpClientThread->addMapToRequests(getMissingMapFromFTPServer); ftpClientThread->addMapToRequests(getMissingMapFromFTPServer);
MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
fileFTPProgressList[getMissingMapFromFTPServer] = pair<int,string>(0,""); fileFTPProgressList[getMissingMapFromFTPServer] = pair<int,string>(0,"");
safeMutexFTPProgress.ReleaseLock();
} }
} }
else if(ftpMissingDataType == ftpmsg_MissingTileset) { else if(ftpMissingDataType == ftpmsg_MissingTileset) {
@@ -519,6 +520,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
ftpClientThread->addTilesetToRequests(getMissingTilesetFromFTPServer); ftpClientThread->addTilesetToRequests(getMissingTilesetFromFTPServer);
MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
fileFTPProgressList[getMissingTilesetFromFTPServer] = pair<int,string>(0,""); fileFTPProgressList[getMissingTilesetFromFTPServer] = pair<int,string>(0,"");
safeMutexFTPProgress.ReleaseLock();
} }
} }
else if(ftpMissingDataType == ftpmsg_MissingTechtree) { else if(ftpMissingDataType == ftpmsg_MissingTechtree) {
@@ -537,6 +539,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){
ftpClientThread->addTechtreeToRequests(getMissingTechtreeFromFTPServer); ftpClientThread->addTechtreeToRequests(getMissingTechtreeFromFTPServer);
MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__));
fileFTPProgressList[getMissingTechtreeFromFTPServer] = pair<int,string>(0,""); fileFTPProgressList[getMissingTechtreeFromFTPServer] = pair<int,string>(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); //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<int,string>(fileProgress,stats->currentFilename); fileFTPProgressList[itemName] = pair<int,string>(fileProgress,stats->currentFilename);
safeMutexFTPProgress.ReleaseLock();
} }
} }
else if(type == ftp_cct_Map) { else if(type == ftp_cct_Map) {
getMissingMapFromFTPServerInProgress = false; getMissingMapFromFTPServerInProgress = false;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); 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); fileFTPProgressList.erase(itemName);
safeMutexFTPProgress.ReleaseLock(); safeMutexFTPProgress.ReleaseLock();
@@ -2034,7 +2039,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client
getMissingTilesetFromFTPServerInProgress = false; getMissingTilesetFromFTPServerInProgress = false;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); 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); fileFTPProgressList.erase(itemName);
safeMutexFTPProgress.ReleaseLock(true); safeMutexFTPProgress.ReleaseLock(true);
@@ -2092,7 +2097,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client
getMissingTechtreeFromFTPServerInProgress = false; getMissingTechtreeFromFTPServerInProgress = false;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result); 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); fileFTPProgressList.erase(itemName);
safeMutexFTPProgress.ReleaseLock(true); safeMutexFTPProgress.ReleaseLock(true);

View File

@@ -42,7 +42,9 @@ CommandClass CommandType::getClass() const{
return commandTypeClass; 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<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
this->id= id; this->id= id;
@@ -55,10 +57,11 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, const TechTr
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
//unit requirements //unit requirements
const XmlNode *unitRequirementsNode= n->getChild("unit-requirements"); const XmlNode *unitRequirementsNode= n->getChild("unit-requirements");
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){ for(int i = 0; i < unitRequirementsNode->getChildCount(); ++i) {
const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i);
string name= unitNode->getAttribute("name")->getRestrictedValue(); string name= unitNode->getAttribute("name")->getRestrictedValue();
unitReqs.push_back(ft->getUnitType(name)); 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 //upgrade requirements
const XmlNode *upgradeRequirementsNode= n->getChild("upgrade-requirements"); const XmlNode *upgradeRequirementsNode= n->getChild("upgrade-requirements");
for(int i=0; i<upgradeRequirementsNode->getChildCount(); ++i){ for(int i = 0; i < upgradeRequirementsNode->getChildCount(); ++i) {
const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i);
string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
upgradeReqs.push_back(ft->getUpgradeType(name)); upgradeReqs.push_back(ft->getUpgradeType(name));
@@ -107,8 +110,10 @@ string StopCommandType::toString() const{
return lang.get("Stop"); return lang.get("Stop");
} }
void StopCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void StopCommandType::load(int id, const XmlNode *n, const string &dir,
CommandType::load(id, n, dir, tt, ft, ut); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//stop //stop
string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue();
@@ -130,8 +135,10 @@ void MoveCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateMove(unit); unitUpdater->updateMove(unit);
} }
void MoveCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void MoveCommandType::load(int id, const XmlNode *n, const string &dir,
CommandType::load(id, n, dir, tt, ft, ut); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//move //move
string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue();
@@ -177,8 +184,10 @@ void AttackCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateAttack(unit); unitUpdater->updateAttack(unit);
} }
void AttackCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void AttackCommandType::load(int id, const XmlNode *n, const string &dir,
CommandType::load(id, n, dir, tt, ft, ut); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//move //move
string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue();
@@ -267,8 +276,10 @@ void AttackStoppedCommandType::update(UnitUpdater *unitUpdater, Unit *unit) cons
unitUpdater->updateAttackStopped(unit); unitUpdater->updateAttackStopped(unit);
} }
void AttackStoppedCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void AttackStoppedCommandType::load(int id, const XmlNode *n, const string &dir,
CommandType::load(id, n, dir, tt, ft, ut); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//stop //stop
string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("stop-skill")->getAttribute("value")->getRestrictedValue();
@@ -352,10 +363,11 @@ void BuildCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateBuild(unit); unitUpdater->updateBuild(unit);
} }
void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void BuildCommandType::load(int id, const XmlNode *n, const string &dir,
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//move //move
string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); 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; i<startSoundNode->getChildCount(); ++i){ for(int i=0; i<startSoundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i); const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
trimPathWithStartingSlash(path);
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
startSounds[i]= sound; startSounds[i]= sound;
} }
} }
@@ -396,11 +411,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, const T
for(int i=0; i<builtSoundNode->getChildCount(); ++i){ for(int i=0; i<builtSoundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i); const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
trimPathWithStartingSlash(path);
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
builtSounds[i]= sound; builtSounds[i]= sound;
} }
} }
@@ -443,9 +461,10 @@ void HarvestCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateHarvest(unit); unitUpdater->updateHarvest(unit);
} }
void HarvestCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ 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); std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//move //move
string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue();
@@ -523,11 +542,10 @@ void RepairCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateRepair(unit); unitUpdater->updateRepair(unit);
} }
void RepairCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ 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__); std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
CommandType::load(id, n, dir, tt, ft, ut);
//move //move
string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("move-skill")->getAttribute("value")->getRestrictedValue();
@@ -601,10 +619,10 @@ void ProduceCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateProduce(unit); unitUpdater->updateProduce(unit);
} }
void ProduceCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void ProduceCommandType::load(int id, const XmlNode *n, const string &dir,
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut); CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//produce //produce
string skillName= n->getChild("produce-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("produce-skill")->getAttribute("value")->getRestrictedValue();
@@ -666,9 +684,11 @@ void UpgradeCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateUpgrade(unit); 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<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut); CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//upgrade //upgrade
string skillName= n->getChild("upgrade-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("upgrade-skill")->getAttribute("value")->getRestrictedValue();
@@ -721,10 +741,10 @@ void MorphCommandType::update(UnitUpdater *unitUpdater, Unit *unit) const{
unitUpdater->updateMorph(unit); unitUpdater->updateMorph(unit);
} }
void MorphCommandType::load(int id, const XmlNode *n, const string &dir, const TechTree *tt, const FactionType *ft, const UnitType &ut){ void MorphCommandType::load(int id, const XmlNode *n, const string &dir,
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); const TechTree *tt, const FactionType *ft, const UnitType &ut,
std::map<string,int> &loadedFileList) {
CommandType::load(id, n, dir, tt, ft, ut); CommandType::load(id, n, dir, tt, ft, ut, loadedFileList);
//morph skill //morph skill
string skillName= n->getChild("morph-skill")->getAttribute("value")->getRestrictedValue(); string skillName= n->getChild("morph-skill")->getAttribute("value")->getRestrictedValue();

View File

@@ -81,7 +81,9 @@ public:
id = -1; id = -1;
} }
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const= 0; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const= 0; virtual string getDesc(const TotalUpgrade *totalUpgrade) const= 0;
virtual string toString() const= 0; virtual string toString() const= 0;
virtual const ProducibleType *getProduced() const {return NULL;} virtual const ProducibleType *getProduced() const {return NULL;}
@@ -114,7 +116,8 @@ private:
public: public:
StopCommandType(); StopCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
virtual Queueability isQueuable() const {return qNever;} virtual Queueability isQueuable() const {return qNever;}
@@ -135,7 +138,9 @@ private:
public: public:
MoveCommandType(); MoveCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
@@ -156,7 +161,9 @@ private:
public: public:
AttackCommandType(); AttackCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
@@ -178,7 +185,9 @@ private:
public: public:
AttackStoppedCommandType(); AttackStoppedCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
@@ -204,7 +213,9 @@ public:
BuildCommandType(); BuildCommandType();
~BuildCommandType(); ~BuildCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
@@ -235,7 +246,9 @@ private:
public: public:
HarvestCommandType(); HarvestCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
virtual Queueability isQueuable() const {return qOnRequest;} virtual Queueability isQueuable() const {return qOnRequest;}
@@ -267,7 +280,9 @@ public:
RepairCommandType(); RepairCommandType();
~RepairCommandType(); ~RepairCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
@@ -294,7 +309,9 @@ private:
public: public:
ProduceCommandType(); ProduceCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string getReqDesc() const; virtual string getReqDesc() const;
virtual string toString() const; virtual string toString() const;
@@ -319,7 +336,9 @@ private:
public: public:
UpgradeCommandType(); UpgradeCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
virtual string getReqDesc() const; virtual string getReqDesc() const;
@@ -344,7 +363,9 @@ private:
public: public:
MorphCommandType(); MorphCommandType();
virtual void update(UnitUpdater *unitUpdater, Unit *unit) const; 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<string,int> &loadedFileList);
virtual string getDesc(const TotalUpgrade *totalUpgrade) const; virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const; virtual string toString() const;
virtual string getReqDesc() const; virtual string getReqDesc() const;

View File

@@ -30,17 +30,21 @@ namespace Glest{ namespace Game{
// Class FactionType // Class FactionType
// ====================================================== // ======================================================
FactionType::FactionType(){ FactionType::FactionType() {
music = NULL; music = NULL;
personalityType = fpt_Normal; personalityType = fpt_Normal;
} }
//load a faction, given a directory //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<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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 // Add special Observer Faction
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
@@ -52,75 +56,78 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
if(personalityType == fpt_Normal) { if(personalityType == fpt_Normal) {
// a1) preload units // a1) preload units
string unitsPath= dir + "/units/*."; string unitsPath= currentPath + "units/*.";
vector<string> unitFilenames; vector<string> unitFilenames;
findAll(unitsPath, unitFilenames); findAll(unitsPath, unitFilenames);
unitTypes.resize(unitFilenames.size()); unitTypes.resize(unitFilenames.size());
for(int i=0; i<unitTypes.size(); ++i) {
string str= dir + "/units/" + unitFilenames[i]; for(int i = 0; i < unitTypes.size(); ++i) {
string str= currentPath + "units/" + unitFilenames[i];
unitTypes[i].preLoad(str); unitTypes[i].preLoad(str);
SDL_PumpEvents(); SDL_PumpEvents();
} }
// a2) preload upgrades // a2) preload upgrades
string upgradesPath= dir + "/upgrades/*."; string upgradesPath= currentPath + "upgrades/*.";
vector<string> upgradeFilenames; vector<string> upgradeFilenames;
findAll(upgradesPath, upgradeFilenames, false, false); findAll(upgradesPath, upgradeFilenames, false, false);
upgradeTypes.resize(upgradeFilenames.size()); upgradeTypes.resize(upgradeFilenames.size());
for(int i=0; i<upgradeTypes.size(); ++i) { for(int i = 0; i < upgradeTypes.size(); ++i) {
string str= dir + "/upgrades/" + upgradeFilenames[i]; string str= currentPath + "upgrades/" + upgradeFilenames[i];
upgradeTypes[i].preLoad(str); upgradeTypes[i].preLoad(str);
SDL_PumpEvents(); SDL_PumpEvents();
} }
// b1) load units // b1) load units
try{ try {
Logger &logger= Logger::getInstance(); Logger &logger= Logger::getInstance();
int progressBaseValue=logger.getProgress(); int progressBaseValue=logger.getProgress();
for(int i = 0; i < unitTypes.size(); ++i) { for(int i = 0; i < unitTypes.size(); ++i) {
string str= dir + "/units/" + unitTypes[i].getName(); string str= currentPath + "units/" + unitTypes[i].getName();
unitTypes[i].load(i, str, techTree, this, checksum,techtreeChecksum); unitTypes[i].load(i, str, techTree, this, checksum,techtreeChecksum,
loadedFileList);
logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount())); logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount()));
SDL_PumpEvents(); SDL_PumpEvents();
} }
} }
catch(const exception &e) { catch(const exception &e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); 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 // b2) load upgrades
try{ try{
for(int i = 0; i < upgradeTypes.size(); ++i) { for(int i = 0; i < upgradeTypes.size(); ++i) {
string str= dir + "/upgrades/" + upgradeTypes[i].getName(); string str= currentPath + "upgrades/" + upgradeTypes[i].getName();
upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum); upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum,
loadedFileList);
SDL_PumpEvents(); SDL_PumpEvents();
} }
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); 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 //open xml file
string currentPath = dir;
endPathWithSlash(currentPath);
string path= currentPath + name + ".xml"; string path= currentPath + name + ".xml";
checksum->addFile(path); checksum->addFile(path);
techtreeChecksum->addFile(path); techtreeChecksum->addFile(path);
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *factionNode= xmlTree.getRootNode(); const XmlNode *factionNode= xmlTree.getRootNode();
//read starting resources //read starting resources
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources"); const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
startingResources.resize(startingResourcesNode->getChildCount()); startingResources.resize(startingResourcesNode->getChildCount());
for(int i=0; i<startingResources.size(); ++i){ for(int i = 0; i < startingResources.size(); ++i) {
const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i); const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i);
string name= resourceNode->getAttribute("name")->getRestrictedValue(); string name= resourceNode->getAttribute("name")->getRestrictedValue();
int amount= resourceNode->getAttribute("amount")->getIntValue(); int amount= resourceNode->getAttribute("amount")->getIntValue();
@@ -131,7 +138,7 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
//read starting units //read starting units
const XmlNode *startingUnitsNode= factionNode->getChild("starting-units"); const XmlNode *startingUnitsNode= factionNode->getChild("starting-units");
for(int i=0; i<startingUnitsNode->getChildCount(); ++i){ for(int i = 0; i < startingUnitsNode->getChildCount(); ++i) {
const XmlNode *unitNode= startingUnitsNode->getChild("unit", i); const XmlNode *unitNode= startingUnitsNode->getChild("unit", i);
string name= unitNode->getAttribute("name")->getRestrictedValue(); string name= unitNode->getAttribute("name")->getRestrictedValue();
int amount= unitNode->getAttribute("amount")->getIntValue(); int amount= unitNode->getAttribute("amount")->getIntValue();
@@ -143,12 +150,10 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch
//read music //read music
const XmlNode *musicNode= factionNode->getChild("music"); const XmlNode *musicNode= factionNode->getChild("music");
bool value= musicNode->getAttribute("value")->getBoolValue(); bool value= musicNode->getAttribute("value")->getBoolValue();
if(value){ if(value) {
music= new StrSound(); music= new StrSound();
string currentPath = dir;
endPathWithSlash(currentPath);
music->open(currentPath + musicNode->getAttribute("path")->getRestrictedValue()); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@@ -27,7 +27,7 @@ namespace Glest{ namespace Game{
/// Each of the possible factions the user can select /// Each of the possible factions the user can select
// ===================================================== // =====================================================
class FactionType{ class FactionType {
private: private:
typedef pair<const UnitType*, int> PairPUnitTypeInt; typedef pair<const UnitType*, int> PairPUnitTypeInt;
typedef vector<UnitType> UnitTypes; typedef vector<UnitType> UnitTypes;
@@ -47,7 +47,8 @@ private:
public: public:
//init //init
FactionType(); 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<string,int> &loadedFileList);
~FactionType(); ~FactionType();
//get //get

View File

@@ -38,9 +38,9 @@ ObjectType::~ObjectType(){
//Logger::getInstance().add("ObjectType", true); //Logger::getInstance().add("ObjectType", true);
} }
void ObjectType::loadModel(const string &path){ void ObjectType::loadModel(const string &path, std::map<string,int> *loadedFileList) {
Model *model= Renderer::getInstance().newModel(rsGame); Model *model= Renderer::getInstance().newModel(rsGame);
model->load(path); model->load(path, false, loadedFileList);
color= Vec3f(0.f); color= Vec3f(0.f);
if(model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) { if(model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) {
const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst(); const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst();

View File

@@ -56,7 +56,7 @@ public:
~ObjectType(); ~ObjectType();
void init(int modelCount, int objectClass, bool walkable, int height); void init(int modelCount, int objectClass, bool walkable, int height);
void loadModel(const string &path); void loadModel(const string &path, std::map<string,int> *loadedFileList=NULL);
void addParticleSystem(ObjectParticleSystemType *particleSystem); void addParticleSystem(ObjectParticleSystemType *particleSystem);
Model *getModel(int i) {return models[i];} Model *getModel(int i) {return models[i];}

View File

@@ -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<string,int> &loadedFileList) {
string path, str; string path, str;
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
@@ -66,16 +67,19 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
//tree //tree
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *resourceNode= xmlTree.getRootNode(); const XmlNode *resourceNode= xmlTree.getRootNode();
//image //image
const XmlNode *imageNode= resourceNode->getChild("image"); const XmlNode *imageNode= resourceNode->getChild("image");
image= renderer.newTexture2D(rsGame); image= renderer.newTexture2D(rsGame);
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
//type //type
const XmlNode *typeNode= resourceNode->getChild("type"); const XmlNode *typeNode= resourceNode->getChild("type");
resourceClass= strToRc(typeNode->getAttribute("value")->getRestrictedValue()); resourceClass = strToRc(typeNode->getAttribute("value")->getRestrictedValue());
switch(resourceClass) switch(resourceClass)
{ {
@@ -83,21 +87,25 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
{ {
//model //model
const XmlNode *modelNode= typeNode->getChild("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= renderer.newModel(rsGame);
model->load(path); model->load(modelPath, false, &loadedFileList);
loadedFileList[modelPath]++;
if(modelNode->hasChild("particles")){ if(modelNode->hasChild("particles")){
const XmlNode *particleNode= modelNode->getChild("particles"); const XmlNode *particleNode= modelNode->getChild("particles");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled){ if(particleEnabled == true) {
for(int k= 0; k < particleNode->getChildCount(); ++k){ for(int k= 0; k < particleNode->getChildCount(); ++k) {
const XmlNode *particleFileNode= particleNode->getChild("particle-file", 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 *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); particleTypes.push_back(objectParticleSystemType);
} }
} }
@@ -110,7 +118,6 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
//resource number //resource number
const XmlNode *resourceNumberNode= typeNode->getChild("resource-number"); const XmlNode *resourceNumberNode= typeNode->getChild("resource-number");
resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue(); resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue();
} }
break; break;
@@ -137,11 +144,9 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre
case rcStatic: case rcStatic:
{ {
//recoup_cost //recoup_cost
if(typeNode->hasChild("recoup_cost") == true) if(typeNode->hasChild("recoup_cost") == true) {
{
const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost"); const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost");
if(recoup_costNode != NULL) if(recoup_costNode != NULL) {
{
recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue(); recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue();
} }
} }

View File

@@ -53,7 +53,8 @@ private:
public: public:
ResourceType(); ResourceType();
~ResourceType(); ~ResourceType();
void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum); void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum,
std::map<string,int> &loadedFileList);
//get //get
int getClass() const {return resourceClass;} int getClass() const {return resourceClass;}

View File

@@ -32,16 +32,17 @@ namespace Glest{ namespace Game{
// class SkillType // class SkillType
// ===================================================== // =====================================================
SkillType::~SkillType(){ SkillType::~SkillType() {
deleteValues(sounds.getSounds().begin(), sounds.getSounds().end()); deleteValues(sounds.getSounds().begin(), sounds.getSounds().end());
//remove unitParticleSystemTypes //remove unitParticleSystemTypes
while(!unitParticleSystemTypes.empty()){ while(!unitParticleSystemTypes.empty()) {
delete unitParticleSystemTypes.back(); delete unitParticleSystemTypes.back();
unitParticleSystemTypes.pop_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<string,int> &loadedFileList) {
//name //name
name= sn->getChild("name")->getAttribute("value")->getRestrictedValue(); 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); animation= Renderer::getInstance().newModel(rsGame);
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
animation->load(currentPath + path); animation->load(currentPath + path, false, &loadedFileList);
loadedFileList[currentPath + path]++;
//particles //particles
if(sn->hasChild("particles")){ if(sn->hasChild("particles")) {
const XmlNode *particleNode= sn->getChild("particles"); const XmlNode *particleNode= sn->getChild("particles");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled){ if(particleEnabled) {
for(int i=0; i<particleNode->getChildCount(); ++i){ for(int i = 0; i < particleNode->getChildCount(); ++i) {
const XmlNode *particleFileNode= particleNode->getChild("particle-file", i); const XmlNode *particleFileNode= particleNode->getChild("particle-file", i);
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); 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); unitParticleSystemTypes.push_back(unitParticleSystemType);
} }
} }
} }
//sound //sound
const XmlNode *soundNode= sn->getChild("sound"); const XmlNode *soundNode= sn->getChild("sound");
if(soundNode->getAttribute("enabled")->getBoolValue()){ if(soundNode->getAttribute("enabled")->getBoolValue()) {
soundStartTime= soundNode->getAttribute("start-time")->getFloatValue(); soundStartTime= soundNode->getAttribute("start-time")->getFloatValue();
sounds.resize(soundNode->getChildCount()); sounds.resize(soundNode->getChildCount());
for(int i=0; i<soundNode->getChildCount(); ++i){ for(int i = 0; i < soundNode->getChildCount(); ++i) {
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
trimPathWithStartingSlash(path);
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
sounds[i]= sound; sounds[i]= sound;
} }
} }
} }
string SkillType::skillClassToStr(SkillClass skillClass){ string SkillType::skillClassToStr(SkillClass skillClass) {
switch(skillClass){ switch(skillClass){
case scStop: return "Stop"; case scStop: return "Stop";
case scMove: return "Move"; case scMove: return "Move";
@@ -188,8 +191,9 @@ AttackSkillType::~AttackSkillType() {
deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end()); deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end());
} }
void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft) { void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
SkillType::load(sn, dir, tt, ft); const FactionType *ft, std::map<string,int> &loadedFileList) {
SkillType::load(sn, dir, tt, ft, loadedFileList);
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
@@ -244,7 +248,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); projectileParticleSystemType->load(dir, currentPath + path,
&Renderer::getInstance(), loadedFileList);
} }
//proj sounds //proj sounds
@@ -255,8 +260,11 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
for(int i=0; i<soundNode->getChildCount(); ++i){ for(int i=0; i<soundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(); string path= soundFileNode->getAttribute("path")->getRestrictedValue();
trimPathWithStartingSlash(path);
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
projSounds[i]= sound; projSounds[i]= sound;
} }
} }
@@ -275,7 +283,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
if(particleEnabled){ if(particleEnabled){
string path= particleNode->getAttribute("path")->getRestrictedValue(); string path= particleNode->getAttribute("path")->getRestrictedValue();
splashParticleSystemType= new ParticleSystemTypeSplash(); 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; skillClass= scDie;
} }
void DieSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, const FactionType *ft){ void DieSkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
SkillType::load(sn, dir, tt, ft); const FactionType *ft, std::map<string,int> &loadedFileList) {
SkillType::load(sn, dir, tt, ft, loadedFileList);
fade= sn->getChild("fade")->getAttribute("value")->getBoolValue(); fade= sn->getChild("fade")->getAttribute("value")->getBoolValue();
} }

View File

@@ -72,7 +72,7 @@ typedef list<UnitParticleSystemType*> UnitParticleSystemTypes;
/// A basic action that an unit can perform /// A basic action that an unit can perform
// ===================================================== // =====================================================
class SkillType{ class SkillType {
protected: protected:
@@ -91,7 +91,8 @@ public:
public: public:
//varios //varios
virtual ~SkillType(); 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<string,int> &loadedFileList);
//get //get
const string &getName() const {return name;} const string &getName() const {return name;}
@@ -160,7 +161,8 @@ private:
public: public:
AttackSkillType(); AttackSkillType();
~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<string,int> &loadedFileList);
virtual string toString() const; virtual string toString() const;
//get //get
@@ -279,7 +281,8 @@ public:
DieSkillType(); DieSkillType();
bool getFade() const {return fade;} 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<string,int> &loadedFileList);
virtual string toString() const; virtual string toString() const;
}; };

View File

@@ -32,7 +32,8 @@ namespace Glest{ namespace Game{
// class TechTree // class TechTree
// ===================================================== // =====================================================
Checksum TechTree::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum) { Checksum TechTree::loadTech(const vector<string> pathList, const string &techName,
set<string> &factions, Checksum* checksum, std::map<string,int> &loadedFileList) {
Checksum techtreeChecksum; Checksum techtreeChecksum;
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
string currentPath = pathList[idx]; string currentPath = pathList[idx];
@@ -40,44 +41,47 @@ Checksum TechTree::loadTech(const vector<string> pathList, const string &techNam
string path = currentPath + techName; string path = currentPath + techName;
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
load(path, factions, checksum, &techtreeChecksum); load(path, factions, checksum, &techtreeChecksum, loadedFileList);
break; break;
} }
} }
return techtreeChecksum; return techtreeChecksum;
} }
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum, Checksum *techtreeChecksum) { void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum,
Checksum *techtreeChecksum, std::map<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string str; string currentPath = dir;
endPathWithSlash(currentPath);
vector<string> filenames; vector<string> filenames;
string name= lastDir(dir); string name= lastDir(currentPath);
Logger::getInstance().add("TechTree: "+ formatString(name), true); Logger::getInstance().add("TechTree: "+ formatString(name), true);
//load resources //load resources
str= dir+"/resources/*."; string str= currentPath + "resources/*.";
try{ try {
findAll(str, filenames); findAll(str, filenames);
resourceTypes.resize(filenames.size()); resourceTypes.resize(filenames.size());
for(int i=0; i<filenames.size(); ++i){ for(int i=0; i<filenames.size(); ++i){
str=dir+"/resources/"+filenames[i]; str= currentPath + "resources/" + filenames[i];
resourceTypes[i].load(str, checksum, &checksumValue); resourceTypes[i].load(str, checksum, &checksumValue, loadedFileList);
Window::handleEvent(); Window::handleEvent();
SDL_PumpEvents(); SDL_PumpEvents();
} }
// Cleanup pixmap memory // Cleanup pixmap memory
for(int i=0; i<filenames.size(); ++i) { for(int i = 0; i < filenames.size(); ++i) {
resourceTypes[i].deletePixels(); resourceTypes[i].deletePixels();
} }
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw runtime_error("Error loading Resource Types: "+ dir + "\n" + e.what()); throw runtime_error("Error loading Resource Types in: [" + currentPath + "]\n" + e.what());
} }
// give CPU time to update other things to avoid apperance of hanging // give CPU time to update other things to avoid apperance of hanging
@@ -86,7 +90,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
SDL_PumpEvents(); SDL_PumpEvents();
//load tech tree xml info //load tech tree xml info
try{ try {
XmlTree xmlTree; XmlTree xmlTree;
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
@@ -96,15 +100,18 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
checksumValue.addFile(path); checksumValue.addFile(path);
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *techTreeNode= xmlTree.getRootNode(); const XmlNode *techTreeNode= xmlTree.getRootNode();
//attack types //attack types
const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types"); const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types");
attackTypes.resize(attackTypesNode->getChildCount()); attackTypes.resize(attackTypesNode->getChildCount());
for(int i=0; i<attackTypes.size(); ++i){ for(int i = 0; i < attackTypes.size(); ++i) {
const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i); const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i);
attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue()); attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue());
attackTypes[i].setId(i); attackTypes[i].setId(i);
Window::handleEvent(); Window::handleEvent();
SDL_PumpEvents(); SDL_PumpEvents();
} }
@@ -116,10 +123,11 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
//armor types //armor types
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types"); const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
armorTypes.resize(armorTypesNode->getChildCount()); armorTypes.resize(armorTypesNode->getChildCount());
for(int i=0; i<armorTypes.size(); ++i){ for(int i = 0; i < armorTypes.size(); ++i) {
const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i); const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i);
armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue()); armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue());
armorTypes[i].setId(i); armorTypes[i].setId(i);
Window::handleEvent(); Window::handleEvent();
SDL_PumpEvents(); SDL_PumpEvents();
} }
@@ -127,19 +135,20 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
//damage multipliers //damage multipliers
damageMultiplierTable.init(attackTypes.size(), armorTypes.size()); damageMultiplierTable.init(attackTypes.size(), armorTypes.size());
const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers"); const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers");
for(int i=0; i<damageMultipliersNode->getChildCount(); ++i){ for(int i = 0; i < damageMultipliersNode->getChildCount(); ++i) {
const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i); const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i);
const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue()); const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue());
const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue()); const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue());
float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue(); float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue();
damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier); damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier);
Window::handleEvent(); Window::handleEvent();
SDL_PumpEvents(); SDL_PumpEvents();
} }
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); 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 // give CPU time to update other things to avoid apperance of hanging
@@ -147,7 +156,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
//SDL_PumpEvents(); //SDL_PumpEvents();
//load factions //load factions
str = dir + "/factions/*."; str = currentPath + "factions/*.";
try{ try{
factionTypes.resize(factions.size()); factionTypes.resize(factions.size());
@@ -156,13 +165,17 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
string factionName = *it; string factionName = *it;
char szBuf[1024]=""; 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 &logger= Logger::getInstance();
logger.setState(szBuf); logger.setState(szBuf);
logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0)); logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0));
str=dir+"/factions/" + factionName; str = currentPath + "factions/" + factionName;
factionTypes[i++].load(str, this, checksum,&checksumValue); factionTypes[i++].load(str, this, checksum,&checksumValue,loadedFileList);
// give CPU time to update other things to avoid apperance of hanging // give CPU time to update other things to avoid apperance of hanging
sleep(0); sleep(0);
@@ -172,7 +185,7 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); 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) { if(techtreeChecksum != NULL) {

View File

@@ -45,8 +45,10 @@ private:
Checksum checksumValue; Checksum checksumValue;
public: public:
Checksum loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum); Checksum loadTech(const vector<string> pathList, const string &techName,
void load(const string &dir, set<string> &factions, Checksum* checksum,Checksum *techtreeChecksum); set<string> &factions, Checksum* checksum, std::map<string,int> &loadedFileList);
void load(const string &dir, set<string> &factions, Checksum* checksum,
Checksum *techtreeChecksum, std::map<string,int> &loadedFileList);
~TechTree(); ~TechTree();
Checksum * getChecksumValue() { return &checksumValue; } Checksum * getChecksumValue() { return &checksumValue; }

View File

@@ -113,11 +113,13 @@ UnitType::~UnitType(){
} }
} }
void UnitType::preLoad(const string &dir){ void UnitType::preLoad(const string &dir) {
name= lastDir(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<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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 xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters"); 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]) { if (fields[fLand]) {
field = fLand; field = fLand;
} else if (fields[fAir]) { }
else if (fields[fAir]) {
field = fAir; field = fAir;
} else { }
else {
throw runtime_error("Unit has no field: " + path); throw runtime_error("Unit has no field: " + path);
} }
//properties //properties
const XmlNode *propertiesNode= parametersNode->getChild("properties"); const XmlNode *propertiesNode= parametersNode->getChild("properties");
for(int i=0; i<propertiesNode->getChildCount(); ++i){ for(int i = 0; i < propertiesNode->getChildCount(); ++i) {
const XmlNode *propertyNode= propertiesNode->getChild("property", i); const XmlNode *propertyNode= propertiesNode->getChild("property", i);
string propertyName= propertyNode->getAttribute("value")->getRestrictedValue(); string propertyName= propertyNode->getAttribute("value")->getRestrictedValue();
bool found= false; bool found= false;
for(int i=0; i<pCount; ++i){ for(int i = 0; i < pCount; ++i) {
if(propertyName==propertyNames[i]){ if(propertyName == propertyNames[i]) {
properties[i]= true; properties[i]= true;
found= true; found= true;
break; break;
} }
} }
if(!found){ if(!found) {
throw runtime_error("Unknown property: " + propertyName); throw runtime_error("Unknown property: " + propertyName);
} }
} }
//damage-particles //damage-particles
if(parametersNode->hasChild("damage-particles")){ if(parametersNode->hasChild("damage-particles")) {
const XmlNode *particleNode= parametersNode->getChild("damage-particles"); const XmlNode *particleNode= parametersNode->getChild("damage-particles");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled){
for(int i=0; i<particleNode->getChildCount(); ++i){ if(particleEnabled) {
for(int i = 0; i < particleNode->getChildCount(); ++i) {
const XmlNode *particleFileNode= particleNode->getChild("particle-file", i); const XmlNode *particleFileNode= particleNode->getChild("particle-file", i);
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); 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 = Renderer::getInstance().newTexture2D(rsGame);
Texture2D *newTexture = NULL; Texture2D *newTexture = NULL;
unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance()); unitParticleSystemType->load(dir, currentPath + path,
if(unitParticleSystemType->hasTexture() == false) { &Renderer::getInstance(),loadedFileList);
loadedFileList[currentPath + path]++;
//if(unitParticleSystemType->hasTexture() == false) {
//Renderer::getInstance().endLastTexture(rsGame,true); //Renderer::getInstance().endLastTexture(rsGame,true);
} //}
damageParticleSystemTypes.push_back(unitParticleSystemType); damageParticleSystemTypes.push_back(unitParticleSystemType);
} }
@@ -306,7 +316,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
} }
//rotationAllowed //rotationAllowed
if(parametersNode->hasChild("rotationAllowed")){ if(parametersNode->hasChild("rotationAllowed")) {
const XmlNode *rotationAllowedNode= parametersNode->getChild("rotationAllowed"); const XmlNode *rotationAllowedNode= parametersNode->getChild("rotationAllowed");
rotationAllowed= rotationAllowedNode->getAttribute("value")->getBoolValue(); 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"); const XmlNode *imageNode= parametersNode->getChild("image");
image= Renderer::getInstance().newTexture2D(rsGame); image= Renderer::getInstance().newTexture2D(rsGame);
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
//image cancel //image cancel
const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel"); const XmlNode *imageCancelNode= parametersNode->getChild("image-cancel");
cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage= Renderer::getInstance().newTexture2D(rsGame);
cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++;
//meeting point //meeting point
const XmlNode *meetingPointNode= parametersNode->getChild("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){ if(meetingPoint){
meetingPointImage= Renderer::getInstance().newTexture2D(rsGame); meetingPointImage= Renderer::getInstance().newTexture2D(rsGame);
meetingPointImage->load(currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue()); meetingPointImage->load(currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue());
loadedFileList[currentPath + meetingPointNode->getAttribute("image-path")->getRestrictedValue()]++;
} }
//selection sounds //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(); string path= soundNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
selectionSounds[i]= sound; 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(); string path= soundNode->getAttribute("path")->getRestrictedValue();
StaticSound *sound= new StaticSound(); StaticSound *sound= new StaticSound();
sound->load(currentPath + path); sound->load(currentPath + path);
loadedFileList[currentPath + path]++;
commandSounds[i]= sound; commandSounds[i]= sound;
} }
} }
@@ -399,24 +414,25 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
//skills //skills
const XmlNode *skillsNode= unitNode->getChild("skills"); const XmlNode *skillsNode= unitNode->getChild("skills");
skillTypes.resize(skillsNode->getChildCount()); skillTypes.resize(skillsNode->getChildCount());
for(int i=0; i<skillTypes.size(); ++i){ for(int i = 0; i < skillTypes.size(); ++i) {
const XmlNode *sn= skillsNode->getChild("skill", i); const XmlNode *sn= skillsNode->getChild("skill", i);
const XmlNode *typeNode= sn->getChild("type"); const XmlNode *typeNode= sn->getChild("type");
string classId= typeNode->getAttribute("value")->getRestrictedValue(); string classId= typeNode->getAttribute("value")->getRestrictedValue();
SkillType *skillType= SkillTypeFactory::getInstance().newInstance(classId); SkillType *skillType= SkillTypeFactory::getInstance().newInstance(classId);
skillType->load(sn, dir, techTree, factionType); skillType->load(sn, dir, techTree, factionType, loadedFileList);
skillTypes[i]= skillType; skillTypes[i]= skillType;
} }
//commands //commands
const XmlNode *commandsNode= unitNode->getChild("commands"); const XmlNode *commandsNode= unitNode->getChild("commands");
commandTypes.resize(commandsNode->getChildCount()); commandTypes.resize(commandsNode->getChildCount());
for(int i=0; i<commandTypes.size(); ++i){ for(int i = 0; i < commandTypes.size(); ++i) {
const XmlNode *commandNode= commandsNode->getChild("command", i); const XmlNode *commandNode= commandsNode->getChild("command", i);
const XmlNode *typeNode= commandNode->getChild("type"); const XmlNode *typeNode= commandNode->getChild("type");
string classId= typeNode->getAttribute("value")->getRestrictedValue(); string classId= typeNode->getAttribute("value")->getRestrictedValue();
CommandType *commandType= CommandTypeFactory::getInstance().newInstance(classId); 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; commandTypes[i]= commandType;
} }

View File

@@ -136,7 +136,9 @@ public:
UnitType(); UnitType();
virtual ~UnitType(); virtual ~UnitType();
void preLoad(const string &dir); 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<string,int> &loadedFileList);
//get //get
int getId() const {return id;} int getId() const {return id;}

View File

@@ -47,16 +47,16 @@ void UpgradeType::preLoad(const string &dir){
name=lastDir(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<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
string path;
Logger::getInstance().add("Upgrade type: "+ formatString(name), true); Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
path = currentPath + name + ".xml"; string path = currentPath + name + ".xml";
try{ try{
checksum->addFile(path); checksum->addFile(path);
@@ -64,17 +64,20 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
const XmlNode *upgradeNode= xmlTree.getRootNode(); const XmlNode *upgradeNode= xmlTree.getRootNode();
//image //image
const XmlNode *imageNode= upgradeNode->getChild("image"); const XmlNode *imageNode= upgradeNode->getChild("image");
image= Renderer::getInstance().newTexture2D(rsGame); image= Renderer::getInstance().newTexture2D(rsGame);
image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++;
//image cancel //image cancel
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel"); const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
cancelImage= Renderer::getInstance().newTexture2D(rsGame); cancelImage= Renderer::getInstance().newTexture2D(rsGame);
cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()); cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++;
//upgrade time //upgrade time
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time"); const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
@@ -82,7 +85,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//unit requirements //unit requirements
const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements"); const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements");
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){ for(int i = 0; i < unitRequirementsNode->getChildCount(); ++i) {
const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i); const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i);
string name= unitNode->getAttribute("name")->getRestrictedValue(); string name= unitNode->getAttribute("name")->getRestrictedValue();
unitReqs.push_back(factionType->getUnitType(name)); unitReqs.push_back(factionType->getUnitType(name));
@@ -90,7 +93,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//upgrade requirements //upgrade requirements
const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements"); const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements");
for(int i=0; i<upgradeRequirementsNode->getChildCount(); ++i){ for(int i = 0; i < upgradeRequirementsNode->getChildCount(); ++i) {
const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i); const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i);
string name= upgradeReqNode->getAttribute("name")->getRestrictedValue(); string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
upgradeReqs.push_back(factionType->getUpgradeType(name)); upgradeReqs.push_back(factionType->getUpgradeType(name));
@@ -99,7 +102,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//resource requirements //resource requirements
const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements"); const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements");
costs.resize(resourceRequirementsNode->getChildCount()); costs.resize(resourceRequirementsNode->getChildCount());
for(int i=0; i<costs.size(); ++i){ for(int i = 0; i < costs.size(); ++i) {
const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i); const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i);
string name= resourceNode->getAttribute("name")->getRestrictedValue(); string name= resourceNode->getAttribute("name")->getRestrictedValue();
int amount= resourceNode->getAttribute("amount")->getIntValue(); int amount= resourceNode->getAttribute("amount")->getIntValue();
@@ -108,7 +111,7 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, const Factio
//effects //effects
const XmlNode *effectsNode= upgradeNode->getChild("effects"); const XmlNode *effectsNode= upgradeNode->getChild("effects");
for(int i=0; i<effectsNode->getChildCount(); ++i){ for(int i = 0; i < effectsNode->getChildCount(); ++i) {
const XmlNode *unitNode= effectsNode->getChild("unit", i); const XmlNode *unitNode= effectsNode->getChild("unit", i);
string name= unitNode->getAttribute("name")->getRestrictedValue(); string name= unitNode->getAttribute("name")->getRestrictedValue();
effects.push_back(factionType->getUnitType(name)); 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(); armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue(); moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue(); prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
} }
catch(const exception &e){ catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());

View File

@@ -77,7 +77,9 @@ private:
public: public:
void preLoad(const string &dir); 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<string,int> &loadedFileList);
//get all //get all
int getEffectCount() const {return effects.size();} int getEffectCount() const {return effects.size();}

View File

@@ -31,13 +31,14 @@ namespace Glest{ namespace Game{
// class AmbientSounds // class AmbientSounds
// ===================================================== // =====================================================
void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode,
std::map<string,int> &loadedFileList) {
string path; string path;
//day //day
const XmlNode *dayNode= xmlNode->getChild("day-sound"); const XmlNode *dayNode= xmlNode->getChild("day-sound");
enabledDay= dayNode->getAttribute("enabled")->getBoolValue(); enabledDay= dayNode->getAttribute("enabled")->getBoolValue();
if(enabledDay){ if(enabledDay) {
path= dayNode->getAttribute("path")->getRestrictedValue(); path= dayNode->getAttribute("path")->getRestrictedValue();
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
@@ -84,6 +85,7 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
dayStart.load(currentPath + path); dayStart.load(currentPath + path);
loadedFileList[currentPath + path]++;
} }
//nightStart //nightStart
@@ -94,6 +96,7 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
string currentPath = dir; string currentPath = dir;
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
nightStart.load(currentPath + path); nightStart.load(currentPath + path);
loadedFileList[currentPath + path]++;
} }
} }
@@ -101,14 +104,15 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
// class Tileset // class Tileset
// ===================================================== // =====================================================
Checksum Tileset::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) { Checksum Tileset::loadTileset(const vector<string> pathList, const string &tilesetName,
Checksum* checksum, std::map<string,int> &loadedFileList) {
Checksum tilesetChecksum; Checksum tilesetChecksum;
for(int idx = 0; idx < pathList.size(); idx++) { for(int idx = 0; idx < pathList.size(); idx++) {
string currentPath = pathList[idx]; string currentPath = pathList[idx];
endPathWithSlash(currentPath); endPathWithSlash(currentPath);
string path = currentPath + tilesetName; string path = currentPath + tilesetName;
if(isdir(path.c_str()) == true) { if(isdir(path.c_str()) == true) {
load(path, checksum, &tilesetChecksum); load(path, checksum, &tilesetChecksum, loadedFileList);
break; break;
} }
} }
@@ -116,7 +120,8 @@ Checksum Tileset::loadTileset(const vector<string> 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<string,int> &loadedFileList) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
random.init(time(NULL)); random.init(time(NULL));
@@ -141,6 +146,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
//parse xml //parse xml
XmlTree xmlTree; XmlTree xmlTree;
xmlTree.load(path); xmlTree.load(path);
loadedFileList[path]++;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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); const XmlNode *textureNode= surfaceNode->getChild("texture", j);
surfPixmaps[i][j].init(3); surfPixmaps[i][j].init(3);
surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue());
loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++;
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue(); 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; j<childCount; ++j) { for(int j=0; j<childCount; ++j) {
const XmlNode *modelNode= objectNode->getChild("model", j); const XmlNode *modelNode= objectNode->getChild("model", j);
const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); 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")){ if(modelNode->hasChild("particles")){
const XmlNode *particleNode= modelNode->getChild("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); const XmlNode *particleFileNode= particleNode->getChild("particle-file", k);
string path= particleFileNode->getAttribute("path")->getRestrictedValue(); string path= particleFileNode->getAttribute("path")->getRestrictedValue();
ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); 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)); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//ambient sounds //ambient sounds
ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds")); ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds"), loadedFileList);
//parameters //parameters
const XmlNode *parametersNode= tilesetNode->getChild("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; i<waterFrameCount; ++i){ for(int i=0; i<waterFrameCount; ++i){
const XmlNode *waterFrameNode= waterNode->getChild("texture", i); const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
waterTex->getPixmap()->loadSlice(currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue(), 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@@ -88,7 +88,8 @@ public:
StaticSound *getDayStart() {return &dayStart;} StaticSound *getDayStart() {return &dayStart;}
StaticSound *getNightStart() {return &nightStart;} StaticSound *getNightStart() {return &nightStart;}
void load(const string &dir, const XmlNode *xmlNode); void load(const string &dir, const XmlNode *xmlNode,
std::map<string,int> &loadedFileList);
}; };
// ===================================================== // =====================================================
@@ -97,7 +98,7 @@ public:
/// Containt textures, models and parameters for a tileset /// Containt textures, models and parameters for a tileset
// ===================================================== // =====================================================
class Tileset{ class Tileset {
public: public:
static const int waterTexCount= 1; static const int waterTexCount= 1;
static const int surfCount= 6; static const int surfCount= 6;
@@ -131,8 +132,10 @@ private:
public: public:
~Tileset(); ~Tileset();
Checksum loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum); Checksum loadTileset(const vector<string> pathList, const string &tilesetName,
void load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum); Checksum* checksum, std::map<string,int> &loadedFileList);
void load(const string &dir, Checksum *checksum, Checksum *tilesetChecksum,
std::map<string,int> &loadedFileList);
Checksum * getChecksumValue() { return &checksumValue; } Checksum * getChecksumValue() { return &checksumValue; }
//get //get

View File

@@ -198,11 +198,12 @@ void World::init(Game *game, bool createUnits){
} }
//load tileset //load tileset
Checksum World::loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum) { Checksum World::loadTileset(const vector<string> pathList, const string &tilesetName,
Checksum* checksum, std::map<string,int> &loadedFileList) {
Checksum tilsetChecksum; Checksum tilsetChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
timeFlow.init(&tileset); timeFlow.init(&tileset);
@@ -211,11 +212,11 @@ Checksum World::loadTileset(const vector<string> pathList, const string &tileset
return tilsetChecksum; return tilsetChecksum;
} }
Checksum World::loadTileset(const string &dir, Checksum *checksum) { Checksum World::loadTileset(const string &dir, Checksum *checksum, std::map<string,int> &loadedFileList) {
Checksum tilesetChecksum; Checksum tilesetChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
timeFlow.init(&tileset); timeFlow.init(&tileset);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); 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 //load tech
Checksum World::loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum *checksum) { Checksum World::loadTech(const vector<string> pathList, const string &techName,
set<string> &factions, Checksum *checksum, std::map<string,int> &loadedFileList) {
Checksum techtreeChecksum; Checksum techtreeChecksum;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
techTree = new TechTree(); techTree = new TechTree();
techtreeChecksum = techTree->loadTech(pathList, techName, factions, checksum); techtreeChecksum = techTree->loadTech(pathList, techName, factions,
checksum,loadedFileList);
return techtreeChecksum; return techtreeChecksum;
} }

View File

@@ -173,9 +173,12 @@ public:
//init & load //init & load
void init(Game *game, bool createUnits); void init(Game *game, bool createUnits);
Checksum loadTileset(const vector<string> pathList, const string &tilesetName, Checksum* checksum); Checksum loadTileset(const vector<string> pathList, const string &tilesetName,
Checksum loadTileset(const string &dir, Checksum* checksum); Checksum* checksum, std::map<string,int> &loadedFileList);
Checksum loadTech(const vector<string> pathList, const string &techName, set<string> &factions, Checksum* checksum); Checksum loadTileset(const string &dir, Checksum* checksum,
std::map<string,int> &loadedFileList);
Checksum loadTech(const vector<string> pathList, const string &techName,
set<string> &factions, Checksum* checksum,std::map<string,int> &loadedFileList);
Checksum loadMap(const string &path, Checksum* checksum); Checksum loadMap(const string &path, Checksum* checksum);
Checksum loadScenario(const string &path, Checksum* checksum); Checksum loadScenario(const string &path, Checksum* checksum);

View File

@@ -133,12 +133,14 @@ public:
Texture2D *loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile, Texture2D *loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, int textureChannelCount, bool &textureOwned,
bool deletePixMapAfterLoad); bool deletePixMapAfterLoad, std::map<string,int> *loadedFileList=NULL);
//load //load
void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); bool deletePixMapAfterLoad,std::map<string,int> *loadedFileList=NULL);
void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
bool deletePixMapAfterLoad,std::map<string,int> *loadedFileList=NULL);
void load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad,std::map<string,int> *loadedFileList=NULL);
void save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager, void save(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
string convertTextureToFormat, std::map<string,int> &textureDeleteList, string convertTextureToFormat, std::map<string,int> &textureDeleteList,
bool keepsmallest); bool keepsmallest);
@@ -194,9 +196,9 @@ public:
uint32 getVertexCount() const; uint32 getVertexCount() const;
//io //io
void load(const string &path,bool deletePixMapAfterLoad=false); void load(const string &path,bool deletePixMapAfterLoad=false,std::map<string,int> *loadedFileList=NULL);
void save(const string &path, string convertTextureToFormat,bool keepsmallest); 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<string,int> *loadedFileList=NULL);
void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest); void saveG3d(const string &path, string convertTextureToFormat,bool keepsmallest);
void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;} void setTextureManager(TextureManager *textureManager) {this->textureManager= textureManager;}

View File

@@ -109,6 +109,7 @@ public:
// ===================================================== // =====================================================
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " "); void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
bool isdir(const char *path); bool isdir(const char *path);
void findDirs(string path, vector<string> &results, bool errorOnNotFound,bool keepDuplicates);
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false,bool keepDuplicates=false); void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false,bool keepDuplicates=false);
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false); void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false);
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true); void findAll(const string &path, vector<string> &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); bool EndsWith(const string &str, const string& key);
void endPathWithSlash(string &path); void endPathWithSlash(string &path);
void trimPathWithStartingSlash(string &path);
void updatePathClimbingParts(string &path);
string replaceAll(string& context, const string& from, const string& to); string replaceAll(string& context, const string& from, const string& to);
bool removeFile(string file); bool removeFile(string file);

View File

@@ -207,7 +207,8 @@ string Mesh::findAlternateTexture(vector<string> conversionList, string textureF
return result; 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<string,int> *loadedFileList) {
this->textureManager = textureManager; this->textureManager = textureManager;
//read header //read header
MeshHeaderV2 meshHeader; MeshHeaderV2 meshHeader;
@@ -267,6 +268,9 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
if(fileExists(texPath) == true) { if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D(); textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath); textures[mtDiffuse]->load(texPath);
if(loadedFileList) {
(*loadedFileList)[texPath]++;
}
texturesOwned[mtDiffuse]=true; texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) { 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); 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<string,int> *loadedFileList) {
this->textureManager = textureManager; this->textureManager = textureManager;
//read header //read header
@@ -348,6 +354,10 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *tex
if(fileExists(texPath) == true) { if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D(); textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath); textures[mtDiffuse]->load(texPath);
if(loadedFileList) {
(*loadedFileList)[texPath]++;
}
texturesOwned[mtDiffuse]=true; texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy()); textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) { 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); readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
} }
Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile, Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex,
int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad) { TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #1 load texture [%s]\n",__FUNCTION__,textureFile.c_str()); 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->getPixmap()->init(textureChannelCount);
} }
texture->load(textureFile); texture->load(textureFile);
if(loadedFileList) {
(*loadedFileList)[textureFile]++;
}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture loaded [%s]\n",__FUNCTION__,textureFile.c_str()); //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, void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
bool deletePixMapAfterLoad) { bool deletePixMapAfterLoad,std::map<string,int> *loadedFileList) {
this->textureManager = textureManager; this->textureManager = textureManager;
//read header //read header
@@ -470,7 +485,8 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
mapFullPath += mapPath; mapFullPath += mapPath;
textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath, textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath,
meshTextureChannelCount[i],texturesOwned[i],deletePixMapAfterLoad); meshTextureChannelCount[i],texturesOwned[i],
deletePixMapAfterLoad, loadedFileList);
} }
flag *= 2; flag *= 2;
} }
@@ -749,10 +765,11 @@ uint32 Model::getVertexCount() const {
// ==================== io ==================== // ==================== io ====================
void Model::load(const string &path, bool deletePixMapAfterLoad) { void Model::load(const string &path, bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
string extension= path.substr(path.find_last_of('.')+1); string extension= path.substr(path.find_last_of('.')+1);
if(extension=="g3d" || extension=="G3D"){ if(extension=="g3d" || extension=="G3D"){
loadG3d(path,deletePixMapAfterLoad); loadG3d(path,deletePixMapAfterLoad,loadedFileList);
} }
else{ else{
throw runtime_error("Unknown model format: " + extension); 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 //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<string,int> *loadedFileList) {
try{ try{
FILE *f=fopen(path.c_str(),"rb"); 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 + "]"); throw runtime_error("Error opening g3d model file [" + path + "]");
} }
if(loadedFileList) {
(*loadedFileList)[path]++;
}
string dir= extractDirectoryPathFromFile(path); string dir= extractDirectoryPathFromFile(path);
//file header //file header
@@ -811,7 +833,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
//load meshes //load meshes
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i) { 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(); meshes[i].buildInterpolationData();
} }
} }
@@ -823,7 +846,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i) { 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(); meshes[i].buildInterpolationData();
} }
} }
@@ -835,7 +859,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
meshes= new Mesh[meshCount]; meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i){ 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(); meshes[i].buildInterpolationData();
} }
} }

View File

@@ -65,7 +65,6 @@ using namespace std;
namespace Shared { namespace PlatformCommon { namespace Shared { namespace PlatformCommon {
// Refresh every 3 days
const time_t REFRESH_CRC_DAY_SECONDS = 1 * 60 * 24; const time_t REFRESH_CRC_DAY_SECONDS = 1 * 60 * 24;
static string crcCachePath = ""; static string crcCachePath = "";
@@ -210,6 +209,30 @@ void Tokenize(const string& str,vector<string>& tokens,const string& delimiters)
} }
} }
void findDirs(string path, vector<string> &results, bool errorOnNotFound,bool keepDuplicates) {
results.clear();
string currentPath = path;
endPathWithSlash(currentPath);
string searchpath = currentPath + "*.";
vector<string> 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<string> &paths, vector<string> &results, bool errorOnNotFound,bool keepDuplicates) { void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound,bool keepDuplicates) {
results.clear(); results.clear();
size_t pathCount = paths.size(); 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() { string getCRCCacheFilePath() {
return crcCachePath; return crcCachePath;
} }
@@ -467,7 +521,7 @@ void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) {
FILE *fp = fopen(crcCacheFile.c_str(),"w"); FILE *fp = fopen(crcCacheFile.c_str(),"w");
if(fp != NULL) { if(fp != NULL) {
RandomGen random; RandomGen random;
int offset = random.randRange(1, 5); int offset = random.randRange(5, 15);
time_t refreshDate = time(NULL) + (REFRESH_CRC_DAY_SECONDS * offset); time_t refreshDate = time(NULL) + (REFRESH_CRC_DAY_SECONDS * offset);
fprintf(fp,"%ld,%d",refreshDate,crcValue); fprintf(fp,"%ld,%d",refreshDate,crcValue);
fclose(fp); fclose(fp);

View File

@@ -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 i= s.find_last_of('/');
size_t j= s.find_last_of('\\'); size_t j= s.find_last_of('\\');
size_t pos; size_t pos;
@@ -513,7 +513,18 @@ string lastDir(const string &s){
throw runtime_error(string(__FILE__)+" lastDir - i==string::npos"); 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){ string lastFile(const string &s){