diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 2c4a54dda..a43a26b3c 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -949,7 +949,7 @@ void MainWindow::loadUnit(string path, string skillName) { foundSkillName = true; if(sn->getChild("animation") != NULL) { - skillModelFile = unitPath + '/' + sn->getChild("animation")->getAttribute("path")->getRestrictedValue(); + skillModelFile = sn->getChild("animation")->getAttribute("path")->getRestrictedValue(unitPath + '/'); printf("Found skill model [%s]\n",skillModelFile.c_str()); } @@ -962,7 +962,7 @@ void MainWindow::loadUnit(string path, string skillName) { const XmlNode *pf= particlesNode->getChild("particle-file"); if(pf != NULL) { skillParticleFile = unitPath + '/' + pf->getAttribute("path")->getRestrictedValue(); - printf("Found skill skill particle [%s]\n",skillParticleFile.c_str()); + printf("Found skill particle [%s]\n",skillParticleFile.c_str()); } } } diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 595f48f2b..6b821ef9e 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -57,8 +57,8 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d } string currentPath = dir; endPathWithSlash(currentPath); - texture->load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++; + texture->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)]++; } else { texture= NULL; @@ -68,18 +68,18 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d if(particleSystemNode->hasChild("model")){ const XmlNode *modelNode= particleSystemNode->getChild("model"); bool modelEnabled= modelNode->getAttribute("value")->getBoolValue(); - if(modelEnabled){ - string path= modelNode->getAttribute("path")->getRestrictedValue(); - model= renderer->newModel(rsGame); - + if(modelEnabled) { string currentPath = dir; endPathWithSlash(currentPath); - model->load(currentPath + path, false, &loadedFileList); - loadedFileList[currentPath + path]++; + string path= modelNode->getAttribute("path")->getRestrictedValue(currentPath); + model= renderer->newModel(rsGame); + + model->load(path, false, &loadedFileList); + loadedFileList[path]++; } } - else{ + else { model= NULL; } @@ -151,7 +151,7 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d alternations= alternatingNode->getAttribute("value")->getIntValue(); } //mode - if(particleSystemNode->hasChild("mode")){ + if(particleSystemNode->hasChild("mode")) { const XmlNode *modeNode= particleSystemNode->getChild("mode"); mode= modeNode->getAttribute("value")->getRestrictedValue(); } diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index b50ec765e..15fdafdc3 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -56,8 +56,8 @@ void CommandType::load(int id, const XmlNode *n, const string &dir, string currentPath = dir; endPathWithSlash(currentPath); - image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; + image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++; //unit requirements const XmlNode *unitRequirementsNode= n->getChild("unit-requirements"); @@ -390,15 +390,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, startSounds.resize(startSoundNode->getChildCount()); for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= startSoundNode->getChild("sound-file", i); - string path= soundFileNode->getAttribute("path")->getRestrictedValue(); - trimPathWithStartingSlash(path); + string currentPath = dir; + endPathWithSlash(currentPath); + string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath,true); StaticSound *sound= new StaticSound(); - string currentPath = dir; - endPathWithSlash(currentPath); - sound->load(currentPath + path); - loadedFileList[currentPath + path]++; + sound->load(path); + loadedFileList[path]++; startSounds[i]= sound; } } @@ -409,15 +408,14 @@ void BuildCommandType::load(int id, const XmlNode *n, const string &dir, builtSounds.resize(builtSoundNode->getChildCount()); for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= builtSoundNode->getChild("sound-file", i); - string path= soundFileNode->getAttribute("path")->getRestrictedValue(); - trimPathWithStartingSlash(path); + string currentPath = dir; + endPathWithSlash(currentPath); + string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath,true); StaticSound *sound= new StaticSound(); - string currentPath = dir; - endPathWithSlash(currentPath); - sound->load(currentPath + path); - loadedFileList[currentPath + path]++; + sound->load(path); + loadedFileList[path]++; builtSounds[i]= sound; } } diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 4af3c7340..32a8b290e 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -152,8 +152,8 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch bool value= musicNode->getAttribute("value")->getBoolValue(); if(value) { music= new StrSound(); - music->open(currentPath + musicNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + musicNode->getAttribute("path")->getRestrictedValue()]++; + music->open(musicNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[musicNode->getAttribute("path")->getRestrictedValue(currentPath)]++; } } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index 914539e01..e62853c35 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -74,8 +74,8 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre //image const XmlNode *imageNode= resourceNode->getChild("image"); image= renderer.newTexture2D(rsGame); - image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; + image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++; //type const XmlNode *typeNode= resourceNode->getChild("type"); @@ -87,7 +87,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre { //model const XmlNode *modelNode= typeNode->getChild("model"); - string modelPath= currentPath + modelNode->getAttribute("path")->getRestrictedValue(); + string modelPath= modelNode->getAttribute("path")->getRestrictedValue(currentPath); model= renderer.newModel(rsGame); model->load(modelPath, false, &loadedFileList); diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 2acc091a3..188c942ca 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -62,12 +62,13 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, animSpeed= sn->getChild("anim-speed")->getAttribute("value")->getIntValue(); //model - string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(); - animation= Renderer::getInstance().newModel(rsGame); string currentPath = dir; endPathWithSlash(currentPath); - animation->load(currentPath + path, false, &loadedFileList); - loadedFileList[currentPath + path]++; + + string path= sn->getChild("animation")->getAttribute("path")->getRestrictedValue(currentPath); + animation= Renderer::getInstance().newModel(rsGame); + animation->load(path, false, &loadedFileList); + loadedFileList[path]++; //particles if(sn->hasChild("particles")) { @@ -93,12 +94,11 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, sounds.resize(soundNode->getChildCount()); for(int i = 0; i < soundNode->getChildCount(); ++i) { const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); - string path= soundFileNode->getAttribute("path")->getRestrictedValue(); - trimPathWithStartingSlash(path); + string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true); StaticSound *sound= new StaticSound(); - sound->load(currentPath + path); - loadedFileList[currentPath + path]++; + sound->load(path); + loadedFileList[path]++; sounds[i]= sound; } } @@ -259,12 +259,11 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree projSounds.resize(soundNode->getChildCount()); for(int i=0; igetChildCount(); ++i){ const XmlNode *soundFileNode= soundNode->getChild("sound-file", i); - string path= soundFileNode->getAttribute("path")->getRestrictedValue(); - trimPathWithStartingSlash(path); + string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true); StaticSound *sound= new StaticSound(); - sound->load(currentPath + path); - loadedFileList[currentPath + path]++; + sound->load(path); + loadedFileList[path]++; projSounds[i]= sound; } } diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 4f5c58838..dc1086ed8 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -70,14 +70,14 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, //image const XmlNode *imageNode= upgradeNode->getChild("image"); image= Renderer::getInstance().newTexture2D(rsGame); - image->load(currentPath + imageNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + imageNode->getAttribute("path")->getRestrictedValue()]++; + image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)]++; //image cancel const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel"); cancelImage= Renderer::getInstance().newTexture2D(rsGame); - cancelImage->load(currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + imageCancelNode->getAttribute("path")->getRestrictedValue()]++; + cancelImage->load(imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath)]++; //upgrade time const XmlNode *upgradeTimeNode= upgradeNode->getChild("time"); diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index b1e678f1e..4717bbeb0 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -39,64 +39,76 @@ void AmbientSounds::load(const string &dir, const XmlNode *xmlNode, const XmlNode *dayNode= xmlNode->getChild("day-sound"); enabledDay= dayNode->getAttribute("enabled")->getBoolValue(); if(enabledDay) { - path= dayNode->getAttribute("path")->getRestrictedValue(); string currentPath = dir; endPathWithSlash(currentPath); - day.open(currentPath + path); + + path= dayNode->getAttribute("path")->getRestrictedValue(currentPath); + day.open(path); + loadedFileList[path]++; + alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue(); } //night const XmlNode *nightNode= xmlNode->getChild("night-sound"); enabledNight= nightNode->getAttribute("enabled")->getBoolValue(); - if(enabledNight){ - path= nightNode->getAttribute("path")->getRestrictedValue(); + if(enabledNight) { string currentPath = dir; endPathWithSlash(currentPath); - night.open(currentPath + path); + + path= nightNode->getAttribute("path")->getRestrictedValue(currentPath); + night.open(path); + loadedFileList[path]++; + alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue(); } //rain const XmlNode *rainNode= xmlNode->getChild("rain-sound"); enabledRain= rainNode->getAttribute("enabled")->getBoolValue(); - if(enabledRain){ - path= rainNode->getAttribute("path")->getRestrictedValue(); + if(enabledRain) { string currentPath = dir; endPathWithSlash(currentPath); - rain.open(currentPath + path); + + path= rainNode->getAttribute("path")->getRestrictedValue(currentPath); + rain.open(path); + loadedFileList[path]++; } //snow const XmlNode *snowNode= xmlNode->getChild("snow-sound"); enabledSnow= snowNode->getAttribute("enabled")->getBoolValue(); - if(enabledSnow){ - path= snowNode->getAttribute("path")->getRestrictedValue(); + if(enabledSnow) { string currentPath = dir; endPathWithSlash(currentPath); - snow.open(currentPath + path); + + path= snowNode->getAttribute("path")->getRestrictedValue(currentPath); + snow.open(path); + loadedFileList[path]++; } //dayStart const XmlNode *dayStartNode= xmlNode->getChild("day-start-sound"); enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue(); - if(enabledDayStart){ - path= dayStartNode->getAttribute("path")->getRestrictedValue(); + if(enabledDayStart) { string currentPath = dir; endPathWithSlash(currentPath); - dayStart.load(currentPath + path); - loadedFileList[currentPath + path]++; + + path= dayStartNode->getAttribute("path")->getRestrictedValue(currentPath); + dayStart.load(path); + loadedFileList[path]++; } //nightStart const XmlNode *nightStartNode= xmlNode->getChild("night-start-sound"); enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue(); - if(enabledNightStart){ - path= nightStartNode->getAttribute("path")->getRestrictedValue(); + if(enabledNightStart) { string currentPath = dir; endPathWithSlash(currentPath); - nightStart.load(currentPath + path); - loadedFileList[currentPath + path]++; + + path= nightStartNode->getAttribute("path")->getRestrictedValue(currentPath); + nightStart.load(path); + loadedFileList[path]++; } } @@ -173,8 +185,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck for(int j=0; jgetChild("texture", j); surfPixmaps[i][j].init(3); - surfPixmaps[i][j].load(currentPath + textureNode->getAttribute("path")->getRestrictedValue()); - loadedFileList[currentPath + textureNode->getAttribute("path")->getRestrictedValue()]++; + surfPixmaps[i][j].load(textureNode->getAttribute("path")->getRestrictedValue(currentPath)); + loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)]++; surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue(); } @@ -201,8 +213,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck for(int j=0; jgetChild("model", j); const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); - objectTypes[i].loadModel(currentPath + pathAttribute->getRestrictedValue(),&loadedFileList); - loadedFileList[currentPath + pathAttribute->getRestrictedValue()]++; + objectTypes[i].loadModel(pathAttribute->getRestrictedValue(currentPath),&loadedFileList); + loadedFileList[pathAttribute->getRestrictedValue(currentPath)]++; if(modelNode->hasChild("particles")){ const XmlNode *particleNode= modelNode->getChild("particles"); @@ -249,8 +261,8 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck waterTex->getPixmap()->init(waterFrameCount, 4); for(int i=0; igetChild("texture", i); - waterTex->getPixmap()->loadSlice(currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue(), i); - loadedFileList[currentPath + waterFrameNode->getAttribute("path")->getRestrictedValue()]++; + waterTex->getPixmap()->loadSlice(waterFrameNode->getAttribute("path")->getRestrictedValue(currentPath), i); + loadedFileList[waterFrameNode->getAttribute("path")->getRestrictedValue(currentPath)]++; } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 7fc5c655f..844fefa24 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -144,14 +144,14 @@ public: public: const string getName() const {return name;} - const string getValue(string prefixValue="") const; + const string getValue(string prefixValue="", bool trimValueWithStartingSlash=false) const; bool getBoolValue() const; int getIntValue() const; int getIntValue(int min, int max) const; float getFloatValue() const; float getFloatValue(float min, float max) const; - const string getRestrictedValue(string prefixValue="") const; + const string getRestrictedValue(string prefixValue="", bool trimValueWithStartingSlash=false) const; }; diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index fc1b561f4..4e0a9ef08 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -21,14 +21,16 @@ #include "util.h" #include "types.h" #include "properties.h" +#include "platform_common.h" #include "leak_dumper.h" XERCES_CPP_NAMESPACE_USE using namespace std; +using namespace Shared::PlatformCommon; -namespace Shared{ namespace Xml{ +namespace Shared { namespace Xml { using namespace Util; @@ -428,15 +430,18 @@ float XmlAttribute::getFloatValue(float min, float max) const{ return f; } -const string XmlAttribute::getValue(string prefixValue) const { +const string XmlAttribute::getValue(string prefixValue, bool trimValueWithStartingSlash) const { string result = value; if(skipRestrictionCheck == false && usesCommondata == false) { - result = prefixValue + value; + if(trimValueWithStartingSlash == true) { + trimPathWithStartingSlash(result); + } + result = prefixValue + result; } return result; } -const string XmlAttribute::getRestrictedValue(string prefixValue) const { +const string XmlAttribute::getRestrictedValue(string prefixValue, bool trimValueWithStartingSlash) const { if(skipRestrictionCheck == false && usesCommondata == false) { const string allowedCharacters = "abcdefghijklmnopqrstuvwxyz1234567890._-/"; @@ -451,7 +456,10 @@ const string XmlAttribute::getRestrictedValue(string prefixValue) const { string result = value; if(skipRestrictionCheck == false && usesCommondata == false) { - result = prefixValue + value; + if(trimValueWithStartingSlash == true) { + trimPathWithStartingSlash(result); + } + result = prefixValue + result; } return result; }