From 8d5de12d423a652e2283883574010dd047025c81 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 14 Mar 2012 07:23:41 +0000 Subject: [PATCH] - added some particles to load game logic --- source/glest_game/game/game.cpp | 5 + source/glest_game/graphics/renderer.cpp | 48 +++ source/glest_game/graphics/renderer.h | 5 + source/glest_game/type_instances/unit.cpp | 162 ++++++++-- source/shared_lib/include/graphics/particle.h | 19 +- .../shared_lib/sources/graphics/particle.cpp | 278 +++++++++++++++++- 6 files changed, 477 insertions(+), 40 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 127e1c2c..59b98c22 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -960,12 +960,17 @@ void Game::init(bool initForPreviewOnly) { else if(world.getTileset()->getWeather() == wRainy) { world.getTileset()->setWeather(wSunny); } + + renderer.manageDeferredParticleSystems(); } //init renderer state if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Initializing renderer\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__); logger.add(Lang::getInstance().get("LogScreenGameLoadingInitRenderer","",true), true); + + //printf("Before renderer.initGame\n"); renderer.initGame(this,this->getGameCameraPtr()); + //printf("After renderer.initGame\n"); for(int i=0; i < world.getFactionCount(); ++i) { Faction *faction= world.getFaction(i); diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 625ad486..d568f438 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -459,6 +459,50 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) { init3dList(); } +void Renderer::manageDeferredParticleSystems() { + //std::vector > deferredParticleSystems + //printf("Before deferredParticleSystems.size() = %d\n",deferredParticleSystems.size()); + for(unsigned int i = 0; i < deferredParticleSystems.size(); ++i) { + std::pair &deferredParticleSystem = deferredParticleSystems[i]; + ParticleSystem *ps = deferredParticleSystem.first; + ResourceScope rs = deferredParticleSystem.second; + if(ps->getTextureFileLoadDeferred() != "" && ps->getTexture() == NULL) { + Texture2D *texture= newTexture2D(rsGame); + if(texture) { +// if(textureNode->getAttribute("luminance")->getBoolValue()){ +// texture->setFormat(Texture::fAlpha); +// texture->getPixmap()->init(1); +// } +// else{ + texture->getPixmap()->init(4); +// } + } +// string currentPath = dir; +// endPathWithSlash(currentPath); + if(texture) { + texture->load(ps->getTextureFileLoadDeferred()); + ps->setTexture(texture); + } +// loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(parentLoader,textureNode->getAttribute("path")->getRestrictedValue())); + } + if(dynamic_cast(ps) != NULL) { + GameParticleSystem *gps = dynamic_cast(ps); + if(gps->getModelFileLoadDeferred() != "" && gps->getModel() == NULL) { + Model *model= newModel(rsGame); + if(model) { + std::map > > loadedFileList; + model->load(gps->getModelFileLoadDeferred(), false, &loadedFileList, NULL); + gps->setModel(model); + } + //loadedFileList[path].push_back(make_pair(parentLoader,modelNode->getAttribute("path")->getRestrictedValue())); + } + } + manageParticleSystem(deferredParticleSystem.first, deferredParticleSystem.second); + } + deferredParticleSystems.clear(); + //printf("After deferredParticleSystems.size() = %d\n",deferredParticleSystems.size()); +} + void Renderer::initMenu(const MainMenu *mm) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -783,6 +827,10 @@ void Renderer::resetFontManager(ResourceScope rs) { fontManager[rsGlobal]->init(); } +void Renderer::addToDeferredParticleSystemList(std::pair deferredParticleSystem) { + deferredParticleSystems.push_back(deferredParticleSystem); +} + void Renderer::manageParticleSystem(ParticleSystem *particleSystem, ResourceScope rs){ particleManager[rs]->manage(particleSystem); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 0d68e766..c94cc381 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -299,6 +299,8 @@ private: float smoothedRenderFps; bool shadowsOffDueToMinRender; + std::vector > deferredParticleSystems; + SimpleTaskThread *saveScreenShotThread; Mutex saveScreenShotThreadAccessor; std::list > saveScreenQueue; @@ -387,6 +389,9 @@ public: static bool isEnded(); //bool isMasterserverMode() const { return masterserverMode; } + void addToDeferredParticleSystemList(std::pair deferredParticleSystem); + void manageDeferredParticleSystems(); + void reinitAll(); //init diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 69292a91..ec91500e 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -3551,51 +3551,70 @@ void Unit::saveGame(XmlNode *rootNode) { //} // vector unitParticleSystems; - for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) { - UnitParticleSystem *ups= unitParticleSystems[i]; - if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { - ups->saveGame(unitNode); + if(unitParticleSystems.size() > 0) { + XmlNode *unitParticleSystemsNode = rootNode->addChild("unitParticleSystems"); + + for(unsigned int i = 0; i < unitParticleSystems.size(); ++i) { + UnitParticleSystem *ups= unitParticleSystems[i]; + if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { + ups->saveGame(unitParticleSystemsNode); + } } } // vector queuedUnitParticleSystemTypes; - for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) { - UnitParticleSystemType *upst= queuedUnitParticleSystemTypes[i]; - if(upst != NULL) { - upst->saveGame(unitNode); + if(queuedUnitParticleSystemTypes.size() > 0) { + XmlNode *queuedUnitParticleSystemTypesNode = rootNode->addChild("queuedUnitParticleSystemTypes"); + for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) { + UnitParticleSystemType *upst= queuedUnitParticleSystemTypes[i]; + if(upst != NULL) { + upst->saveGame(queuedUnitParticleSystemTypesNode); + } } } - // UnitParticleSystems damageParticleSystems; - for(unsigned int i = 0; i < damageParticleSystems.size(); ++i) { - UnitParticleSystem *ups= damageParticleSystems[i]; - if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { - ups->saveGame(unitNode); + if(damageParticleSystems.size() > 0) { + XmlNode *damageParticleSystemsNode = rootNode->addChild("damageParticleSystems"); + for(unsigned int i = 0; i < damageParticleSystems.size(); ++i) { + UnitParticleSystem *ups= damageParticleSystems[i]; + if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { + ups->saveGame(damageParticleSystemsNode); + } } } - // std::map damageParticleSystemsInUse; - for(std::map::const_iterator iterMap = damageParticleSystemsInUse.begin(); - iterMap != damageParticleSystemsInUse.end(); ++iterMap) { - if(iterMap->second != NULL && Renderer::getInstance().validateParticleSystemStillExists(iterMap->second,rsGame) == true) { - XmlNode *damageParticleSystemsInUseNode = unitNode->addChild("damageParticleSystemsInUse"); + if(damageParticleSystemsInUse.size() > 0) { + XmlNode *damageParticleSystemsInUseNode = rootNode->addChild("damageParticleSystemsInUse"); - damageParticleSystemsInUseNode->addAttribute("key",intToStr(iterMap->first), mapTagReplacements); - iterMap->second->saveGame(damageParticleSystemsInUseNode); + for(std::map::const_iterator iterMap = damageParticleSystemsInUse.begin(); + iterMap != damageParticleSystemsInUse.end(); ++iterMap) { + if(iterMap->second != NULL && Renderer::getInstance().validateParticleSystemStillExists(iterMap->second,rsGame) == true) { + XmlNode *damageParticleSystemsInUseNode2 = damageParticleSystemsInUseNode->addChild("damageParticleSystemsInUse"); + + damageParticleSystemsInUseNode2->addAttribute("key",intToStr(iterMap->first), mapTagReplacements); + iterMap->second->saveGame(damageParticleSystemsInUseNode2); + } } } + // vector fireParticleSystems; - for(unsigned int i = 0; i < fireParticleSystems.size(); ++i) { - ParticleSystem *ps= fireParticleSystems[i]; - if(ps != NULL && Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { - ps->saveGame(unitNode); + if(fireParticleSystems.size() > 0) { + XmlNode *fireParticleSystemsNode = rootNode->addChild("fireParticleSystems"); + for(unsigned int i = 0; i < fireParticleSystems.size(); ++i) { + ParticleSystem *ps= fireParticleSystems[i]; + if(ps != NULL && Renderer::getInstance().validateParticleSystemStillExists(ps,rsGame) == true) { + ps->saveGame(fireParticleSystemsNode); + } } } // vector smokeParticleSystems; - for(unsigned int i = 0; i < smokeParticleSystems.size(); ++i) { - UnitParticleSystem *ups= smokeParticleSystems[i]; - if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { - ups->saveGame(unitNode); + if(smokeParticleSystems.size() > 0) { + XmlNode *smokeParticleSystemsNode = rootNode->addChild("smokeParticleSystems"); + for(unsigned int i = 0; i < smokeParticleSystems.size(); ++i) { + UnitParticleSystem *ups= smokeParticleSystems[i]; + if(ups != NULL && Renderer::getInstance().validateParticleSystemStillExists(ups,rsGame) == true) { + ups->saveGame(smokeParticleSystemsNode); + } } } @@ -3815,6 +3834,16 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // if(fire != NULL) { // fire->saveGame(unitNode); // } + if(unitNode->hasChild("FireParticleSystem") == true) { + XmlNode *fireNode = unitNode->getChild("FireParticleSystem"); + result->fire = new FireParticleSystem(); + result->fire->loadGame(fireNode); + result->fireParticleSystems.push_back(result->fire); + + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(result->fire, rsGame)); + } + // TotalUpgrade totalUpgrade; result->totalUpgrade.loadGame(unitNode); // Map *map; @@ -3847,6 +3876,20 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // UnitParticleSystem *ups= unitParticleSystems[i]; // ups->saveGame(unitNode); // } + if(unitNode->hasChild("unitParticleSystems") == true) { + XmlNode *unitParticleSystemsNode = unitNode->getChild("unitParticleSystems"); + vector unitParticleSystemNodeList = unitParticleSystemsNode->getChildList("UnitParticleSystem"); + for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { + XmlNode *node = unitParticleSystemNodeList[i]; + + UnitParticleSystem *ups = new UnitParticleSystem(); + ups->loadGame(node); + result->unitParticleSystems.push_back(ups); + + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } + } // vector queuedUnitParticleSystemTypes; // for(unsigned int i = 0; i < queuedUnitParticleSystemTypes.size(); ++i) { @@ -3859,6 +3902,21 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // UnitParticleSystem *ups= damageParticleSystems[i]; // ups->saveGame(unitNode); // } + if(unitNode->hasChild("damageParticleSystems") == true) { + XmlNode *damageParticleSystemsNode = unitNode->getChild("damageParticleSystems"); + vector unitParticleSystemNodeList = damageParticleSystemsNode->getChildList("UnitParticleSystem"); + for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { + XmlNode *node = unitParticleSystemNodeList[i]; + + UnitParticleSystem *ups = new UnitParticleSystem(); + ups->loadGame(node); + result->damageParticleSystems.push_back(ups); + result->damageParticleSystemsInUse[i]=ups; + + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } + } // std::map damageParticleSystemsInUse; // for(std::map::const_iterator iterMap = damageParticleSystemsInUse.begin(); @@ -3868,17 +3926,65 @@ Unit * Unit::loadGame(const XmlNode *rootNode, GameSettings *settings, Faction * // damageParticleSystemsInUseNode->addAttribute("key",intToStr(iterMap->first), mapTagReplacements); // iterMap->second->saveGame(damageParticleSystemsInUseNode); // } +// if(unitNode->hasChild("damageParticleSystemsInUse") == true) { +// XmlNode *damageParticleSystemsInUseNode = unitNode->getChild("damageParticleSystemsInUse"); +// vector damageParticleSystemsInUseNode2 = damageParticleSystemsInUseNode->getChildList("damageParticleSystemsInUse"); +// for(unsigned int i = 0; i < damageParticleSystemsInUseNode2.size(); ++i) { +// XmlNode *d2Node = damageParticleSystemsInUseNode2[i]; +// +// vector unitParticleSystemNodeList = damageParticleSystemsInUseNode->getChildList("UnitParticleSystem"); +// for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { +// XmlNode *node = unitParticleSystemNodeList[i]; +// +// UnitParticleSystem *ups = new UnitParticleSystem(); +// ups->loadGame(node); +// result->unitParticleSystems.push_back(ups); +// +// //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); +// Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); +// } +// +// } + // vector fireParticleSystems; // for(unsigned int i = 0; i < fireParticleSystems.size(); ++i) { // ParticleSystem *ps= fireParticleSystems[i]; // ps->saveGame(unitNode); // } + if(unitNode->hasChild("fireParticleSystems") == true) { + XmlNode *fireParticleSystemsNode = unitNode->getChild("fireParticleSystems"); + vector unitParticleSystemNodeList = fireParticleSystemsNode->getChildList("FireParticleSystem"); + for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { + XmlNode *node = unitParticleSystemNodeList[i]; + + FireParticleSystem *ups = new FireParticleSystem(); + ups->loadGame(node); + result->fireParticleSystems.push_back(ups); + + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } + } // vector smokeParticleSystems; // for(unsigned int i = 0; i < smokeParticleSystems.size(); ++i) { // UnitParticleSystem *ups= smokeParticleSystems[i]; // ups->saveGame(unitNode); // } + if(unitNode->hasChild("smokeParticleSystems") == true) { + XmlNode *smokeParticleSystemsNode = unitNode->getChild("smokeParticleSystems"); + vector unitParticleSystemNodeList = smokeParticleSystemsNode->getChildList("UnitParticleSystem"); + for(unsigned int i = 0; i < unitParticleSystemNodeList.size(); ++i) { + XmlNode *node = unitParticleSystemNodeList[i]; + + UnitParticleSystem *ups = new UnitParticleSystem(); + ups->loadGame(node); + result->smokeParticleSystems.push_back(ups); + + //Renderer::getInstance().manageParticleSystem(result->fire, rsGame); + Renderer::getInstance().addToDeferredParticleSystemList(make_pair(ups, rsGame)); + } + } // CardinalDir modelFacing; // unitNode->addAttribute("modelFacing",intToStr(modelFacing), mapTagReplacements); diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 07442252..d91db347 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -124,7 +124,7 @@ protected: int aliveParticleCount; int particleCount; - + string textureFileLoadDeferred; Texture *texture; Vec3f pos; Vec4f color; @@ -163,6 +163,7 @@ public: bool getActive() const {return active;} virtual bool getVisible() const {return visible;} + virtual string getTextureFileLoadDeferred(); //set virtual void setState(State state); void setTexture(Texture *texture); @@ -259,6 +260,8 @@ public: virtual void render(ParticleRenderer *pr, ModelRenderer *mr); float getTween() { return tween; } // 0.0 -> 1.0 for animation of model Model *getModel() const {return model;} + virtual string getModelFileLoadDeferred(); + void setPrimitive(Primitive primitive) {this->primitive= primitive;} Vec3f getDirection() const {return direction;} void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;} @@ -270,6 +273,8 @@ protected: typedef std::vector Children; Children children; Primitive primitive; + + string modelFileLoadDeferred; Model *model; float modelCycle; Vec3f offset; @@ -375,7 +380,6 @@ public: virtual void saveGame(XmlNode *rootNode); virtual void loadGame(const XmlNode *rootNode); - }; // ===================================================== @@ -428,7 +432,7 @@ public: /// Base class for Projectiles and Splashes // =========================================================================== -class AttackParticleSystem: public GameParticleSystem{ +class AttackParticleSystem: public GameParticleSystem { protected: float sizeNoEnergy; @@ -442,6 +446,9 @@ public: void setGravity(float gravity) {this->gravity= gravity;} virtual void initParticleSystem() {} // opportunity to do any initialization when the system has been created and all settings set + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); }; // ===================================================== @@ -499,6 +506,9 @@ public: void setPath(Vec3f startPos, Vec3f endPos); static Trajectory strToTrajectory(const string &str); + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); }; // ===================================================== @@ -535,6 +545,9 @@ public: void setVerticalSpreadB(float verticalSpreadB) {this->verticalSpreadB= verticalSpreadB;} void setHorizontalSpreadA(float horizontalSpreadA) {this->horizontalSpreadA= horizontalSpreadA;} void setHorizontalSpreadB(float horizontalSpreadB) {this->horizontalSpreadB= horizontalSpreadB;} + + virtual void saveGame(XmlNode *rootNode); + virtual void loadGame(const XmlNode *rootNode); }; diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 2f7f315b..3126c822 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -282,6 +282,9 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { particleSystemNode->addAttribute("particleCount",intToStr(particleCount), mapTagReplacements); // // Texture *texture; + if(texture != NULL) { + particleSystemNode->addAttribute("texture",texture->getPath(), mapTagReplacements); + } // Vec3f pos; particleSystemNode->addAttribute("pos",pos.getString(), mapTagReplacements); // Vec4f color; @@ -316,6 +319,10 @@ void ParticleSystem::saveGame(XmlNode *rootNode) { } } +string ParticleSystem::getTextureFileLoadDeferred() { + return textureFileLoadDeferred; +} + void ParticleSystem::loadGame(const XmlNode *rootNode) { const XmlNode *particleSystemNode = rootNode->getChild("ParticleSystem"); @@ -350,6 +357,10 @@ void ParticleSystem::loadGame(const XmlNode *rootNode) { particleCount = particleSystemNode->getAttribute("particleCount")->getIntValue(); // // Texture *texture; + if(particleSystemNode->hasAttribute("texture") == true) { + textureFileLoadDeferred = particleSystemNode->getAttribute("texture")->getValue(); + } + // Vec3f pos; pos = Vec3f::strToVec3(particleSystemNode->getAttribute("pos")->getValue()); // Vec4f color; @@ -719,6 +730,10 @@ void GameParticleSystem::setTween(float relative,float absolute) { (*it)->setTween(relative,absolute); } +string GameParticleSystem::getModelFileLoadDeferred() { + return modelFileLoadDeferred; +} + void GameParticleSystem::saveGame(XmlNode *rootNode) { std::map mapTagReplacements; XmlNode *gameParticleSystemNode = rootNode->addChild("GameParticleSystem"); @@ -751,8 +766,6 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { ParticleSystem::loadGame(gameParticleSystemNode); - //radius = fireParticleSystemNode->getAttribute("radius")->getFloatValue(); - // Children children; // for(unsigned int i = 0; i < children.size(); ++i) { // children[i]->saveGame(gameParticleSystemNode); @@ -764,7 +777,8 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { UnitParticleSystem *ups = new UnitParticleSystem(); ups->loadGame(node); - children.push_back(ups); + //children.push_back(ups); + addChild(ups); } // Primitive primitive; @@ -773,6 +787,10 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { //if(model != NULL) { // gameParticleSystemNode->addAttribute("model",model->getFileName(), mapTagReplacements); //} + if(gameParticleSystemNode->hasAttribute("model") == true) { + modelFileLoadDeferred = gameParticleSystemNode->getAttribute("model")->getValue(); + } + // float modelCycle; //gameParticleSystemNode->addAttribute("modelCycle",floatToStr(modelCycle), mapTagReplacements); modelCycle = gameParticleSystemNode->getAttribute("modelCycle")->getFloatValue(); @@ -790,9 +808,8 @@ void GameParticleSystem::loadGame(const XmlNode *rootNode) { bool UnitParticleSystem::isNight= false; Vec3f UnitParticleSystem::lightColor=Vec3f(1.0f,1.0f,1.0f); -UnitParticleSystem::UnitParticleSystem(int particleCount): - GameParticleSystem(particleCount), - parent(NULL){ +UnitParticleSystem::UnitParticleSystem(int particleCount) : + GameParticleSystem(particleCount), parent(NULL) { radius= 0.5f; speed= 0.01f; windSpeed= Vec3f(0.0f); @@ -1052,40 +1069,129 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { GameParticleSystem::saveGame(unitParticleSystemNode); - //unitParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements); - // float radius; + unitParticleSystemNode->addAttribute("radius",floatToStr(radius), mapTagReplacements); // float minRadius; + unitParticleSystemNode->addAttribute("minRadius",floatToStr(minRadius), mapTagReplacements); // Vec3f windSpeed; + unitParticleSystemNode->addAttribute("windSpeed",windSpeed.getString(), mapTagReplacements); // Vec3f cRotation; + unitParticleSystemNode->addAttribute("cRotation",cRotation.getString(), mapTagReplacements); // Vec3f fixedAddition; + unitParticleSystemNode->addAttribute("fixedAddition",fixedAddition.getString(), mapTagReplacements); // Vec3f oldPosition; + unitParticleSystemNode->addAttribute("oldPosition",oldPosition.getString(), mapTagReplacements); // bool energyUp; + unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements); // float startTime; + unitParticleSystemNode->addAttribute("startTime",floatToStr(startTime), mapTagReplacements); // float endTime; + unitParticleSystemNode->addAttribute("endTime",floatToStr(endTime), mapTagReplacements); // bool relative; + unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements); // bool relativeDirection; + unitParticleSystemNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements); // bool fixed; + unitParticleSystemNode->addAttribute("fixed",intToStr(fixed), mapTagReplacements); // Shape shape; + unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements); // float angle; + unitParticleSystemNode->addAttribute("angle",floatToStr(angle), mapTagReplacements); // float sizeNoEnergy; + unitParticleSystemNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy), mapTagReplacements); // float gravity; + unitParticleSystemNode->addAttribute("gravity",floatToStr(gravity), mapTagReplacements); // float rotation; + unitParticleSystemNode->addAttribute("rotation",floatToStr(rotation), mapTagReplacements); // bool isVisibleAtNight; + unitParticleSystemNode->addAttribute("isVisibleAtNight",intToStr(isVisibleAtNight), mapTagReplacements); // bool isVisibleAtDay; + unitParticleSystemNode->addAttribute("isVisibleAtDay",intToStr(isVisibleAtDay), mapTagReplacements); // bool isDaylightAffected; + unitParticleSystemNode->addAttribute("isDaylightAffected",intToStr(isDaylightAffected), mapTagReplacements); // bool radiusBasedStartenergy; + unitParticleSystemNode->addAttribute("radiusBasedStartenergy",intToStr(radiusBasedStartenergy), mapTagReplacements); // int staticParticleCount; + unitParticleSystemNode->addAttribute("staticParticleCount",intToStr(staticParticleCount), mapTagReplacements); // int delay; + unitParticleSystemNode->addAttribute("delay",intToStr(delay), mapTagReplacements); // int lifetime; + unitParticleSystemNode->addAttribute("lifetime",intToStr(lifetime), mapTagReplacements); // float emissionRateFade; + unitParticleSystemNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade), mapTagReplacements); // GameParticleSystem* parent; - + //if(parent != NULL) { + // parent->saveGame(unitParticleSystemNode); + //} } + void UnitParticleSystem::loadGame(const XmlNode *rootNode) { const XmlNode *unitParticleSystemNode = rootNode; GameParticleSystem::loadGame(unitParticleSystemNode); + +// float radius; + radius = unitParticleSystemNode->getAttribute("radius")->getFloatValue(); +// float minRadius; + minRadius = unitParticleSystemNode->getAttribute("minRadius")->getFloatValue(); +// Vec3f windSpeed; + windSpeed = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("windSpeed")->getValue()); +// Vec3f cRotation; + windSpeed = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("cRotation")->getValue()); +// Vec3f fixedAddition; + fixedAddition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue()); +// Vec3f oldPosition; + oldPosition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue()); +// bool energyUp; + energyUp = unitParticleSystemNode->getAttribute("energyUp")->getIntValue(); +// float startTime; + startTime = unitParticleSystemNode->getAttribute("startTime")->getFloatValue(); +// float endTime; + endTime = unitParticleSystemNode->getAttribute("endTime")->getFloatValue(); +// bool relative; + relative = unitParticleSystemNode->getAttribute("relative")->getIntValue(); +// bool relativeDirection; + relativeDirection = unitParticleSystemNode->getAttribute("relativeDirection")->getIntValue(); +// bool fixed; + fixed = unitParticleSystemNode->getAttribute("fixed")->getIntValue(); +// Shape shape; + shape = static_cast(unitParticleSystemNode->getAttribute("shape")->getIntValue()); +// float angle; + angle = unitParticleSystemNode->getAttribute("angle")->getFloatValue(); +// float sizeNoEnergy; + sizeNoEnergy = unitParticleSystemNode->getAttribute("sizeNoEnergy")->getFloatValue(); +// float gravity; + gravity = unitParticleSystemNode->getAttribute("gravity")->getFloatValue(); +// float rotation; + rotation = unitParticleSystemNode->getAttribute("rotation")->getFloatValue(); +// bool isVisibleAtNight; + isVisibleAtNight = unitParticleSystemNode->getAttribute("isVisibleAtNight")->getIntValue(); +// bool isVisibleAtDay; + isVisibleAtDay = unitParticleSystemNode->getAttribute("isVisibleAtDay")->getIntValue(); +// bool isDaylightAffected; + isDaylightAffected = unitParticleSystemNode->getAttribute("isDaylightAffected")->getIntValue(); +// bool radiusBasedStartenergy; + radiusBasedStartenergy = unitParticleSystemNode->getAttribute("radiusBasedStartenergy")->getIntValue(); +// int staticParticleCount; + staticParticleCount = unitParticleSystemNode->getAttribute("staticParticleCount")->getIntValue(); +// int delay; + delay = unitParticleSystemNode->getAttribute("delay")->getIntValue(); +// int lifetime; + lifetime = unitParticleSystemNode->getAttribute("lifetime")->getIntValue(); +// float emissionRateFade; + emissionRateFade = unitParticleSystemNode->getAttribute("emissionRateFade")->getFloatValue(); +// GameParticleSystem* parent; + //if(parent != NULL) { + // parent->saveGame(unitParticleSystemNode); + //} + + //if(unitParticleSystemNode->hasChild("GameParticleSystem") == true) { +// void GameParticleSystem::saveGame(XmlNode *rootNode) +// std::map mapTagReplacements; +// XmlNode *gameParticleSystemNode = rootNode->addChild("GameParticleSystem"); + XmlNode *gameParticleSystemNode = unitParticleSystemNode->getChild("GameParticleSystem"); + //!!! + //} } // =========================================================================== @@ -1204,6 +1310,29 @@ AttackParticleSystem::AttackParticleSystem(int particleCount) : gravity= 0.0f; } +void AttackParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *attackParticleSystemNode = rootNode->addChild("AttackParticleSystem"); + + GameParticleSystem::saveGame(attackParticleSystemNode); + +// float sizeNoEnergy; + attackParticleSystemNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy), mapTagReplacements); +// float gravity; + attackParticleSystemNode->addAttribute("gravity",floatToStr(gravity), mapTagReplacements); + +} +void AttackParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *attackParticleSystemNode = rootNode; + + GameParticleSystem::loadGame(attackParticleSystemNode); + + // float sizeNoEnergy; + sizeNoEnergy = attackParticleSystemNode->getAttribute("sizeNoEnergy")->getFloatValue(); + // float gravity; + gravity = attackParticleSystemNode->getAttribute("gravity")->getFloatValue(); +} + // =========================================================================== // ProjectileParticleSystem // =========================================================================== @@ -1400,6 +1529,82 @@ ProjectileParticleSystem::Trajectory ProjectileParticleSystem::strToTrajectory(c } } +void ProjectileParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *projectileParticleSystemNode = rootNode->addChild("ProjectileParticleSystem"); + + AttackParticleSystem::saveGame(projectileParticleSystemNode); + +// SplashParticleSystem *nextParticleSystem; + if(nextParticleSystem != NULL) { + nextParticleSystem->saveGame(projectileParticleSystemNode); + } +// Vec3f lastPos; + projectileParticleSystemNode->addAttribute("lastPos",lastPos.getString(), mapTagReplacements); +// Vec3f startPos; + projectileParticleSystemNode->addAttribute("startPos",startPos.getString(), mapTagReplacements); +// Vec3f endPos; + projectileParticleSystemNode->addAttribute("endPos",endPos.getString(), mapTagReplacements); +// Vec3f flatPos; + projectileParticleSystemNode->addAttribute("flatPos",flatPos.getString(), mapTagReplacements); +// +// Vec3f xVector; + projectileParticleSystemNode->addAttribute("xVector",xVector.getString(), mapTagReplacements); +// Vec3f yVector; + projectileParticleSystemNode->addAttribute("yVector",yVector.getString(), mapTagReplacements); +// Vec3f zVector; + projectileParticleSystemNode->addAttribute("zVector",zVector.getString(), mapTagReplacements); +// Trajectory trajectory; + projectileParticleSystemNode->addAttribute("trajectory",intToStr(trajectory), mapTagReplacements); +// float trajectorySpeed; + projectileParticleSystemNode->addAttribute("trajectorySpeed",floatToStr(trajectorySpeed), mapTagReplacements); +// //parabolic +// float trajectoryScale; + projectileParticleSystemNode->addAttribute("trajectoryScale",floatToStr(trajectoryScale), mapTagReplacements); +// float trajectoryFrequency; + projectileParticleSystemNode->addAttribute("trajectoryFrequency",floatToStr(trajectoryFrequency), mapTagReplacements); +} + +void ProjectileParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *projectileParticleSystemNode = rootNode; + + AttackParticleSystem::loadGame(projectileParticleSystemNode); + + // SplashParticleSystem *nextParticleSystem; +// if(nextParticleSystem != NULL) { +// nextParticleSystem->saveGame(projectileParticleSystemNode); +// } + if(projectileParticleSystemNode->hasChild("SplashParticleSystem") == true) { + XmlNode *splashParticleSystemNode = projectileParticleSystemNode->getChild("SplashParticleSystem"); + nextParticleSystem = new SplashParticleSystem(); + nextParticleSystem->loadGame(splashParticleSystemNode); + } + // Vec3f lastPos; + lastPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("lastPos")->getValue()); + // Vec3f startPos; + startPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("startPos")->getValue()); + // Vec3f endPos; + endPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("endPos")->getValue()); + // Vec3f flatPos; + flatPos = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("flatPos")->getValue()); + // + // Vec3f xVector; + xVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("xVector")->getValue()); + // Vec3f yVector; + yVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("yVector")->getValue()); + // Vec3f zVector; + zVector = Vec3f::strToVec3(projectileParticleSystemNode->getAttribute("zVector")->getValue()); + // Trajectory trajectory; + trajectory = static_cast(projectileParticleSystemNode->getAttribute("trajectory")->getIntValue()); + // float trajectorySpeed; + trajectorySpeed = projectileParticleSystemNode->getAttribute("trajectorySpeed")->getFloatValue(); + // //parabolic + // float trajectoryScale; + trajectoryScale = projectileParticleSystemNode->getAttribute("trajectoryScale")->getFloatValue(); + // float trajectoryFrequency; + trajectoryFrequency = projectileParticleSystemNode->getAttribute("trajectoryFrequency")->getFloatValue(); +} + // =========================================================================== // SplashParticleSystem // =========================================================================== @@ -1473,6 +1678,61 @@ void SplashParticleSystem::updateParticle(Particle *p){ p->size= particleSize * energyRatio + sizeNoEnergy * (1.0f - energyRatio); } +void SplashParticleSystem::saveGame(XmlNode *rootNode) { + std::map mapTagReplacements; + XmlNode *splashParticleSystemNode = rootNode->addChild("SplashParticleSystem"); + + AttackParticleSystem::saveGame(splashParticleSystemNode); + +// ProjectileParticleSystem *prevParticleSystem; + if(prevParticleSystem != NULL) { + prevParticleSystem->saveGame(splashParticleSystemNode); + } + +// float emissionRateFade; + splashParticleSystemNode->addAttribute("emissionRateFade",floatToStr(emissionRateFade), mapTagReplacements); +// float verticalSpreadA; + splashParticleSystemNode->addAttribute("verticalSpreadA",floatToStr(verticalSpreadA), mapTagReplacements); +// float verticalSpreadB; + splashParticleSystemNode->addAttribute("verticalSpreadB",floatToStr(verticalSpreadB), mapTagReplacements); +// float horizontalSpreadA; + splashParticleSystemNode->addAttribute("horizontalSpreadA",floatToStr(horizontalSpreadA), mapTagReplacements); +// float horizontalSpreadB; + splashParticleSystemNode->addAttribute("horizontalSpreadB",floatToStr(horizontalSpreadB), mapTagReplacements); +// +// float startEmissionRate; + splashParticleSystemNode->addAttribute("startEmissionRate",floatToStr(startEmissionRate), mapTagReplacements); +} + +void SplashParticleSystem::loadGame(const XmlNode *rootNode) { + const XmlNode *splashParticleSystemNode = rootNode; + + AttackParticleSystem::loadGame(splashParticleSystemNode); + + // ProjectileParticleSystem *prevParticleSystem; +// if(nextParticleSystem != NULL) { +// nextParticleSystem->saveGame(projectileParticleSystemNode); +// } + if(splashParticleSystemNode->hasChild("ProjectileParticleSystem") == true) { + XmlNode *projectileParticleSystemNode = splashParticleSystemNode->getChild("ProjectileParticleSystem"); + prevParticleSystem = new ProjectileParticleSystem(); + prevParticleSystem->loadGame(projectileParticleSystemNode); + } + +// float emissionRateFade; + emissionRateFade = splashParticleSystemNode->getAttribute("emissionRateFade")->getFloatValue(); +// float verticalSpreadA; + verticalSpreadA = splashParticleSystemNode->getAttribute("verticalSpreadA")->getFloatValue(); +// float verticalSpreadB; + verticalSpreadB = splashParticleSystemNode->getAttribute("verticalSpreadB")->getFloatValue(); +// float horizontalSpreadA; + horizontalSpreadA = splashParticleSystemNode->getAttribute("horizontalSpreadA")->getFloatValue(); +// float horizontalSpreadB; + horizontalSpreadB = splashParticleSystemNode->getAttribute("horizontalSpreadB")->getFloatValue(); +// float startEmissionRate; + startEmissionRate = splashParticleSystemNode->getAttribute("startEmissionRate")->getFloatValue(); +} + // =========================================================================== // ParticleManager // ===========================================================================