particles for ressouces ... the gold will glow tomorrow :-D

This commit is contained in:
Titus Tscharntke
2011-03-09 01:32:27 +00:00
parent 5db11ec538
commit 5e844c39e4
6 changed files with 54 additions and 16 deletions

View File

@@ -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);

View File

@@ -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); }
};

View File

@@ -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)

View File

@@ -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;}

View File

@@ -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){

View File

@@ -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();
};