diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index b9d173413..d2efa351d 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -68,7 +68,7 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin fixed= fixedNode->getAttribute("value")->getBoolValue(); } -void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ +const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ ups->setTexture(texture); ups->setPrimitive(UnitParticleSystem::strToPrimitive(primitive)); ups->setOffset(offset); diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index b7f0e2dbc..23d894cad 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -55,7 +55,7 @@ protected: public: void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture); void load(const string &dir, const string &path, RendererInterface *newTexture); - void setValues(UnitParticleSystem *uts); + const void setValues (UnitParticleSystem *uts); bool hasTexture() const { return(texture != NULL); } }; diff --git a/source/glest_game/type_instances/object.cpp b/source/glest_game/type_instances/object.cpp index 8a726ed02..7b5f8f7a5 100644 --- a/source/glest_game/type_instances/object.cpp +++ b/source/glest_game/type_instances/object.cpp @@ -81,22 +81,27 @@ void Object::initParticles(){ if(this->objectType==NULL) return; if(this->objectType->hasParticles()){ ObjectParticleSystemTypes *particleTypes= this->objectType->getObjectParticleSystemTypes(variation); - if(Config::getInstance().getBool("TilesetParticles","true") && (particleTypes->empty() == false) - && (unitParticleSystems.empty() == true)){ - for(ObjectParticleSystemTypes::const_iterator it= particleTypes->begin(); it != particleTypes->end(); ++it){ - UnitParticleSystem *ups= new UnitParticleSystem(200); - (*it)->setValues(ups); - ups->setPos(this->pos); - ups->setRotation(this->rotation); - ups->setFactionColor(Vec3f(0, 0, 0)); - ups->setVisible(false); - this->unitParticleSystems.push_back(ups); - Renderer::getInstance().manageParticleSystem(ups, rsGame); - } - } + initParticlesFromTypes(particleTypes); } } +void Object::initParticlesFromTypes(const ObjectParticleSystemTypes *particleTypes){ + if(Config::getInstance().getBool("TilesetParticles","true") && (particleTypes->empty() == false) + && (unitParticleSystems.empty() == true)){ + for(ObjectParticleSystemTypes::const_iterator it= particleTypes->begin(); it != particleTypes->end(); ++it){ + UnitParticleSystem *ups= new UnitParticleSystem(200); + (*it)->setValues(ups); + ups->setPos(this->pos); + ups->setRotation(this->rotation); + ups->setFactionColor(Vec3f(0, 0, 0)); + ups->setVisible(false); + this->unitParticleSystems.push_back(ups); + Renderer::getInstance().manageParticleSystem(ups, rsGame); + } + } +} + + void Object::setHeight(float height){ pos.y=height; @@ -120,6 +125,7 @@ bool Object::getWalkable() const{ void Object::setResource(const ResourceType *resourceType, const Vec2i &pos){ resource= new Resource(); resource->init(resourceType, pos); + initParticlesFromTypes(resourceType->getObjectParticleSystemTypes()); } void Object::setVisible( bool visible) diff --git a/source/glest_game/type_instances/object.h b/source/glest_game/type_instances/object.h index 829654427..86a4d1f1d 100644 --- a/source/glest_game/type_instances/object.h +++ b/source/glest_game/type_instances/object.h @@ -15,6 +15,7 @@ #include "vec.h" #include "leak_dumper.h" #include "particle.h" +#include "object_type.h" namespace Glest{ namespace Game{ @@ -63,6 +64,7 @@ public: void end(); //to kill particles void initParticles(); + void initParticlesFromTypes(const ObjectParticleSystemTypes *particleTypes); static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; } const ObjectType *getType() const {return objectType;} diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index b83bf5ad7..34366fe29 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -38,6 +38,13 @@ ResourceType::ResourceType() { model = NULL; } +ResourceType::~ResourceType(){ + while(!(particleTypes.empty())){ + delete particleTypes.back(); + particleTypes.pop_back(); + } +} + void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum) { string path, str; @@ -79,6 +86,21 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre model= renderer.newModel(rsGame); model->load(path); + if(modelNode->hasChild("particles")){ + const XmlNode *particleNode= modelNode->getChild("particles"); + bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); + if(particleEnabled){ + for(int k= 0; k < particleNode->getChildCount(); ++k){ + const XmlNode *particleFileNode= particleNode->getChild("particle-file", k); + string path= particleFileNode->getAttribute("path")->getRestrictedValue(); + + ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); + objectParticleSystemType->load(dir, dir + "/" + path, &Renderer::getInstance()); + particleTypes.push_back(objectParticleSystemType); + } + } + } + //default resources const XmlNode *defaultAmountNode= typeNode->getChild("default-amount"); defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue(); @@ -134,7 +156,6 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre } } - // ==================== misc ==================== ResourceClass ResourceType::strToRc(const string &s){ diff --git a/source/glest_game/types/resource_type.h b/source/glest_game/types/resource_type.h index 670ecd449..6ac6207a2 100644 --- a/source/glest_game/types/resource_type.h +++ b/source/glest_game/types/resource_type.h @@ -16,6 +16,8 @@ #include "model.h" #include "checksum.h" #include "leak_dumper.h" +#include "unit_particle_type.h" +#include "object_type.h" namespace Glest{ namespace Game{ @@ -35,6 +37,7 @@ enum ResourceClass{ /// A type of resource that can be harvested or not // ===================================================== + class ResourceType: public DisplayableType{ private: ResourceClass resourceClass; @@ -45,9 +48,11 @@ private: bool recoup_cost; Model *model; + ObjectParticleSystemTypes particleTypes; public: ResourceType(); + ~ResourceType(); void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum); //get @@ -59,6 +64,10 @@ public: Model *getModel() const {return model;} bool getRecoup_cost() const { return recoup_cost;} + bool hasParticles() const {return !particleTypes.empty();} + const ObjectParticleSystemTypes *getObjectParticleSystemTypes() const {return &particleTypes;} + + static ResourceClass strToRc(const string &s); void deletePixels(); };