diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 9d154cac..0cce4e9b 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -3833,6 +3833,7 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // UnitParticleSystem *ups= unitParticleSystems[i]; // ups->saveGame(unitNode); // } + // vector queuedUnitParticleSystemTypes; // for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) { // UnitParticleSystemType *upst= queuedUnitParticleSystemTypes[i]; diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index ae1ddc97..447e3b4e 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -1864,6 +1864,10 @@ void Map::saveGame(XmlNode *rootNode) const { for(unsigned int i = 0; i < getSurfaceCellArraySize(); ++i) { SurfaceCell &surfaceCell = surfaceCells[i]; + if(exploredList != "") { + exploredList += ","; + } + for(unsigned int j = 0; j < GameConstants::maxPlayers; ++j) { if(exploredList != "") { exploredList += "|"; @@ -1871,7 +1875,11 @@ void Map::saveGame(XmlNode *rootNode) const { exploredList += intToStr(surfaceCell.isExplored(j)); } - exploredList += ","; + + if(visibleList != "") { + visibleList += ","; + } + for(unsigned int j = 0; j < GameConstants::maxPlayers; ++j) { if(visibleList != "") { visibleList += "|"; @@ -1879,14 +1887,24 @@ void Map::saveGame(XmlNode *rootNode) const { visibleList += intToStr(surfaceCell.isVisible(j)); } - visibleList += ","; surfaceCell.saveGame(mapNode,i); + + if(i % 100 == 0) { + XmlNode *surfaceCellNode = mapNode->addChild("SurfaceCell"); + surfaceCellNode->addAttribute("exploredList",exploredList, mapTagReplacements); + surfaceCellNode->addAttribute("visibleList",visibleList, mapTagReplacements); + + exploredList = ""; + visibleList = ""; + } } - XmlNode *surfaceCellNode = mapNode->addChild("SurfaceCell"); - surfaceCellNode->addAttribute("exploredList",exploredList, mapTagReplacements); - surfaceCellNode->addAttribute("visibleList",visibleList, mapTagReplacements); + if(exploredList != "") { + XmlNode *surfaceCellNode = mapNode->addChild("SurfaceCell"); + surfaceCellNode->addAttribute("exploredList",exploredList, mapTagReplacements); + surfaceCellNode->addAttribute("visibleList",visibleList, mapTagReplacements); + } // Vec2i *startLocations; for(unsigned int i = 0; i < maxPlayers; ++i) { @@ -1927,40 +1945,44 @@ void Map::loadGame(const XmlNode *rootNode, World *world) { surfaceCell.loadGame(mapNode,i,world); } - XmlNode *surfaceCellNode = mapNode->getChild("SurfaceCell"); - string exploredList = surfaceCellNode->getAttribute("exploredList")->getValue(); - string visibleList = surfaceCellNode->getAttribute("visibleList")->getValue(); + vector surfaceCellNodeList = mapNode->getChildList("SurfaceCell"); + for(unsigned int i = 0; i < surfaceCellNodeList.size(); ++i) { + XmlNode *surfaceCellNode = surfaceCellNodeList[i]; - vector tokensExplored; - Tokenize(exploredList,tokensExplored,","); - for(unsigned int i = 0; i < tokensExplored.size(); ++i) { - string valueList = tokensExplored[i]; + //XmlNode *surfaceCellNode = mapNode->getChild("SurfaceCell"); + string exploredList = surfaceCellNode->getAttribute("exploredList")->getValue(); + string visibleList = surfaceCellNode->getAttribute("visibleList")->getValue(); - vector tokensExploredValue; - Tokenize(valueList,tokensExploredValue,"|"); - for(unsigned int j = 0; j < tokensExploredValue.size(); ++j) { - string value = tokensExploredValue[j]; + vector tokensExplored; + Tokenize(exploredList,tokensExplored,","); + for(unsigned int i = 0; i < tokensExplored.size(); ++i) { + string valueList = tokensExplored[i]; - SurfaceCell &surfaceCell = surfaceCells[i]; - surfaceCell.setExplored(j,strToInt(value)); + vector tokensExploredValue; + Tokenize(valueList,tokensExploredValue,"|"); + for(unsigned int j = 0; j < tokensExploredValue.size(); ++j) { + string value = tokensExploredValue[j]; + + SurfaceCell &surfaceCell = surfaceCells[i]; + surfaceCell.setExplored(j,strToInt(value)); + } + } + + vector tokensVisible; + Tokenize(visibleList,tokensVisible,","); + for(unsigned int i = 0; i < tokensVisible.size(); ++i) { + string valueList = tokensVisible[i]; + + vector tokensVisibleValue; + Tokenize(valueList,tokensVisibleValue,"|"); + for(unsigned int j = 0; j < tokensVisibleValue.size(); ++j) { + string value = tokensVisibleValue[j]; + + SurfaceCell &surfaceCell = surfaceCells[i]; + surfaceCell.setVisible(j,strToInt(value)); + } } } - - vector tokensVisible; - Tokenize(visibleList,tokensVisible,","); - for(unsigned int i = 0; i < tokensVisible.size(); ++i) { - string valueList = tokensVisible[i]; - - vector tokensVisibleValue; - Tokenize(valueList,tokensVisibleValue,"|"); - for(unsigned int j = 0; j < tokensVisibleValue.size(); ++j) { - string value = tokensVisibleValue[j]; - - SurfaceCell &surfaceCell = surfaceCells[i]; - surfaceCell.setVisible(j,strToInt(value)); - } - } - } // ===================================================== diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 6f1a123b..1c11750a 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -2645,6 +2645,8 @@ void ParticleDamager::saveGame(XmlNode *rootNode) { attackerRef.saveGame(particleDamagerNode); // const AttackSkillType* ast; + particleDamagerNode->addAttribute("astName",ast->getName(), mapTagReplacements); + particleDamagerNode->addAttribute("astClass",intToStr(ast->getClass()), mapTagReplacements); // UnitUpdater *unitUpdater; // const GameCamera *gameCamera; // Vec2i targetPos; @@ -2653,4 +2655,27 @@ void ParticleDamager::saveGame(XmlNode *rootNode) { particleDamagerNode->addAttribute("targetField",intToStr(targetField), mapTagReplacements); } +void ParticleDamager::loadGame(const XmlNode *rootNode, void *genericData) { + const XmlNode *particleDamagerNode = rootNode->getChild("ParticleDamager"); + + std::pair *pairData = (std::pair*)genericData; + //UnitType *ut, Game *game + attackerRef.loadGame(particleDamagerNode,pairData->first->getWorld()); + + //random.setLastNumber(particleSystemNode->getAttribute("random")->getIntValue()); + + // const AttackSkillType* ast; + string astName = particleDamagerNode->getAttribute("astName")->getValue(); + SkillClass astClass = static_cast(particleDamagerNode->getAttribute("astClass")->getIntValue()); + ast = dynamic_cast(pairData->second->getType()->getSkillType(astName,astClass)); + // UnitUpdater *unitUpdater; + unitUpdater = pairData->first->getWorld()->getUnitUpdater(); + // const GameCamera *gameCamera; + gameCamera = pairData->first->getGameCamera(); + // Vec2i targetPos; + targetPos = Vec2i::strToVec2(particleDamagerNode->getAttribute("targetPos")->getValue()); + // Field targetField; + targetField = static_cast(particleDamagerNode->getAttribute("targetField")->getIntValue()); +} + }}//end namespace diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index f1c0841d..e7e62562 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -157,7 +157,8 @@ private: // class ParticleDamager // ===================================================== -class ParticleDamager: public ParticleObserver{ +class ParticleDamager: public ParticleObserver { + public: UnitReference attackerRef; const AttackSkillType* ast; @@ -169,7 +170,9 @@ public: public: ParticleDamager(Unit *attacker, UnitUpdater *unitUpdater, const GameCamera *gameCamera); virtual void update(ParticleSystem *particleSystem); + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode,void *genericData); }; }}//end namespace diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index f1a9be9d..07442252 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -68,6 +68,7 @@ public: int getEnergy() const {return energy;} void saveGame(XmlNode *rootNode); + void loadGame(const XmlNode *rootNode); }; // ===================================================== @@ -79,6 +80,7 @@ public: virtual ~ParticleObserver(){}; virtual void update(ParticleSystem *particleSystem)= 0; virtual void saveGame(XmlNode *rootNode) = 0; + virtual void loadGame(const XmlNode *rootNode, void *genericData) = 0; }; // ===================================================== @@ -191,7 +193,8 @@ public: virtual int getChildCount() { return 0; } virtual ParticleSystem* getChild(int i); - void saveGame(XmlNode *rootNode); + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); protected: //protected @@ -225,6 +228,9 @@ public: //set params void setRadius(float radius); void setWind(float windAngle, float windSpeed); + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); }; // ===================================================== @@ -256,6 +262,10 @@ public: void setPrimitive(Primitive primitive) {this->primitive= primitive;} Vec3f getDirection() const {return direction;} void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;} + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); + protected: typedef std::vector Children; Children children; @@ -362,6 +372,10 @@ public: void setParentDirection(Vec3f parentDirection); static Shape strToShape(const string& str); + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); + }; // ===================================================== diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index ebf3d81f..eee7917f 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -658,6 +658,48 @@ public: return result; } + // playerColor="x [1] y [0] z [0] w [0]" + static inline Vec4 strToVec4(std::string value) { + Vec4 result; + + std::vector tokens = TokenizeString(value,"["); + //for(unsigned int i = 0; i < tokens.size(); ++i) { + //printf("#1 Vec2T i = %d [%s]\n",i,tokens[i].c_str()); + //} + if(tokens.size() == 5) { + std::vector tokens2 = TokenizeString(tokens[1],"]"); + //for(unsigned int i = 0; i < tokens2.size(); ++i) { + //printf("#2 Vec2T i = %d [%s]\n",i,tokens2[i].c_str()); + //} + std::vector tokens3 = TokenizeString(tokens[2],"]"); + //for(unsigned int i = 0; i < tokens3.size(); ++i) { + //printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str()); + //} + + std::vector tokens4 = TokenizeString(tokens[3],"]"); + //for(unsigned int i = 0; i < tokens3.size(); ++i) { + //printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str()); + //} + + std::vector tokens5 = TokenizeString(tokens[4],"]"); + //for(unsigned int i = 0; i < tokens3.size(); ++i) { + //printf("#3 Vec2T i = %d [%s]\n",i,tokens3[i].c_str()); + //} + + if(tokens2.size() == 2 && tokens3.size() == 2 && + tokens4.size() == 2 && tokens5.size() == 2) { + result.x = (T)strToType(tokens2[0]); + result.y = (T)strToType(tokens3[0]); + result.z = (T)strToType(tokens4[0]); + result.w = (T)strToType(tokens5[0]); + + //printf("#3 Vec2T [%s]\n",result.getString().c_str()); + } + } + + return result; + } + }; typedef Vec4 Vec4i; diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 82a201bf..8bd5eb7a 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -29,7 +29,7 @@ namespace XERCES_CPP_NAMESPACE{ namespace Shared{ namespace Xml{ -const int strSize= 4096; +const int strSize= 8094; class XmlIo; class XmlTree; diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 21988abd..ad2a0f32 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -21,6 +21,7 @@ #include "math_util.h" #include "platform_common.h" #include "conversion.h" +#include "model.h" #include "leak_dumper.h" using namespace std; @@ -58,6 +59,26 @@ void Particle::saveGame(XmlNode *rootNode) { } +void Particle::loadGame(const XmlNode *rootNode) { + const XmlNode *particleNode = rootNode; + + //particleNode = aiNode->getAttribute("startLoc")->getIntValue(); + // Vec3f pos; + pos = Vec3f::strToVec3(particleNode->getAttribute("pos")->getValue()); + // Vec3f lastPos; + lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue()); + // Vec3f speed; + speed = Vec3f::strToVec3(particleNode->getAttribute("speed")->getValue()); + // Vec3f accel; + accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue()); + // Vec4f color; + color = Vec4f::strToVec4(particleNode->getAttribute("color")->getValue()); + // float size; + size = particleNode->getAttribute("size")->getFloatValue(); + // int energy; + energy = particleNode->getAttribute("energy")->getIntValue(); +} + ParticleSystem::ParticleSystem(int particleCount) { if(checkMemory) { printf("++ Create ParticleSystem [%p]\n",this); @@ -294,6 +315,75 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { particleObserver->saveGame(particleSystemNode); } } + +void ParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *particleSystemNode = rootNode->getChild("ParticleSystem"); + + // std::vector particles; +// for(unsigned int i = 0; i < particles.size(); ++i) { +// Particle &particle = particles[i]; +// particle.saveGame(particleSystemNode); +// } + vector particleNodeList = particleSystemNode->getChildList("Particle"); + for(unsigned int i = 0; i < particleNodeList.size(); ++i) { + XmlNode *node = particleNodeList[i]; + + Particle particle; + particle.loadGame(node); + particles.push_back(particle); + } + + // RandomGen random; + random.setLastNumber(particleSystemNode->getAttribute("random")->getIntValue()); + + // BlendMode blendMode; + blendMode = static_cast(particleSystemNode->getAttribute("blendMode")->getIntValue()); + // State state; + state = static_cast(particleSystemNode->getAttribute("state")->getIntValue()); + // bool active; + active = particleSystemNode->getAttribute("active")->getIntValue(); + // bool visible; + visible = particleSystemNode->getAttribute("visible")->getIntValue(); + // int aliveParticleCount; + aliveParticleCount = particleSystemNode->getAttribute("aliveParticleCount")->getIntValue(); + // int particleCount; + particleCount = particleSystemNode->getAttribute("particleCount")->getIntValue(); + // + // Texture *texture; + // Vec3f pos; + pos = Vec3f::strToVec3(particleSystemNode->getAttribute("pos")->getValue()); + // Vec4f color; + color = Vec4f::strToVec4(particleSystemNode->getAttribute("color")->getValue()); + // Vec4f colorNoEnergy; + colorNoEnergy = Vec4f::strToVec4(particleSystemNode->getAttribute("colorNoEnergy")->getValue()); + // float emissionRate; + emissionRate = particleSystemNode->getAttribute("emissionRate")->getFloatValue(); + // float emissionState; + emissionState = particleSystemNode->getAttribute("emissionState")->getFloatValue(); + // int maxParticleEnergy; + maxParticleEnergy = particleSystemNode->getAttribute("maxParticleEnergy")->getIntValue(); + // int varParticleEnergy; + varParticleEnergy = particleSystemNode->getAttribute("varParticleEnergy")->getIntValue(); + // float particleSize; + particleSize = particleSystemNode->getAttribute("particleSize")->getFloatValue(); + // float speed; + speed = particleSystemNode->getAttribute("speed")->getFloatValue(); + // Vec3f factionColor; + factionColor = Vec3f::strToVec3(particleSystemNode->getAttribute("factionColor")->getValue()); + // bool teamcolorNoEnergy; + teamcolorNoEnergy = particleSystemNode->getAttribute("teamcolorNoEnergy")->getIntValue(); + // bool teamcolorEnergy; + teamcolorEnergy = particleSystemNode->getAttribute("teamcolorEnergy")->getIntValue(); + // int alternations; + alternations = particleSystemNode->getAttribute("alternations")->getIntValue(); + // int particleSystemStartDelay; + particleSystemStartDelay = particleSystemNode->getAttribute("particleSystemStartDelay")->getIntValue(); + // ParticleObserver *particleObserver; + //if(particleObserver != NULL) { + // particleObserver->loadGame(particleSystemNode); + //} +} + // =============== MISC ========================= void ParticleSystem::fade(){ if(particleObserver != NULL){ @@ -483,6 +573,28 @@ void FireParticleSystem::setWind(float windAngle, float windSpeed){ #endif } +void FireParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *fireParticleSystemNode = rootNode->addChild("FireParticleSystem"); + + ParticleSystem::saveGame(fireParticleSystemNode); + +// float radius; + fireParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements); +// Vec3f windSpeed; + fireParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); +} +void FireParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *fireParticleSystemNode = rootNode; + + ParticleSystem::loadGame(fireParticleSystemNode); + +// float radius; + radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue(); +// Vec3f windSpeed; + windSpeed = Vec3f::strToVec3(fireParticleSystemNode->getAttribute("windSpeed")->getValue()); +} + // =========================================================================== // GameParticleSystem // =========================================================================== @@ -607,6 +719,69 @@ void GameParticleSystem::setTween(float relative,float absolute) { (*it)->setTween(relative,absolute); } +void GameParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *gameParticleSystemNode = rootNode->addChild("GameParticleSystem"); + + ParticleSystem::saveGame(gameParticleSystemNode); + +// Children children; + for(unsigned int i = 0; i < children.size(); ++i) { + children[i]->saveGame(gameParticleSystemNode); + } +// Primitive primitive; + gameParticleSystemNode->addAttribute("primitive",intToStr(primitive), mapTagReplacements); +// Model *model; + if(model != NULL) { + gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements); + } +// float modelCycle; + gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements); +// Vec3f offset; + gameParticleSystemNode->addAttribute("offset",offset.getString(), mapTagReplacements); +// Vec3f direction; + gameParticleSystemNode->addAttribute("direction",direction.getString(), mapTagReplacements); +// float tween; + gameParticleSystemNode->addAttribute("tween",floatToStr(tween), mapTagReplacements); +} +void GameParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *gameParticleSystemNode = rootNode; + + ParticleSystem::loadGame(gameParticleSystemNode); + + //radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue(); + + // Children children; +// for(unsigned int i = 0; i < children.size(); ++i) { +// children[i]->saveGame(gameParticleSystemNode); +// } + vector childrenNodeList = gameParticleSystemNode->getChildList("UnitParticleSystem"); + for(unsigned int i = 0; i < childrenNodeList.size(); ++i) { + XmlNode *node = childrenNodeList[i]; + + UnitParticleSystem *ups = new UnitParticleSystem(); + ups->loadGame(node); + + children.push_back(ups); + } + + // Primitive primitive; + primitive = static_cast(gameParticleSystemNode->getAttribute("primitive")->getIntValue()); + // Model *model; + //if(model != NULL) { + // gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements); + //} + // float modelCycle; + //gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements); + modelCycle = gameParticleSystemNode->getAttribute("modelCycle")->getFloatValue(); + // Vec3f offset; + offset = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("modelCycle")->getValue()); + // Vec3f direction; + direction = Vec3f::strToVec3(gameParticleSystemNode->getAttribute("direction")->getValue()); + // float tween; + tween = gameParticleSystemNode->getAttribute("tween")->getFloatValue(); +} + // =========================================================================== // UnitParticleSystem // =========================================================================== @@ -869,6 +1044,48 @@ void UnitParticleSystem::setWind(float windAngle, float windSpeed){ #endif } +void UnitParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *unitParticleSystemNode = rootNode->addChild("UnitParticleSystem"); + + GameParticleSystem::saveGame(unitParticleSystemNode); + + //unitParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements); + +// float radius; +// float minRadius; +// Vec3f windSpeed; +// Vec3f cRotation; +// Vec3f fixedAddition; +// Vec3f oldPosition; +// bool energyUp; +// float startTime; +// float endTime; +// bool relative; +// bool relativeDirection; +// bool fixed; +// Shape shape; +// float angle; +// float sizeNoEnergy; +// float gravity; +// float rotation; +// bool isVisibleAtNight; +// bool isVisibleAtDay; +// bool isDaylightAffected; +// bool radiusBasedStartenergy; +// int staticParticleCount; +// int delay; +// int lifetime; +// float emissionRateFade; +// GameParticleSystem* parent; + +} +void UnitParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *unitParticleSystemNode = rootNode; + + GameParticleSystem::loadGame(unitParticleSystemNode); +} + // =========================================================================== // RainParticleSystem // ===========================================================================