switch for non rotatable objets in tilesets; cleaned up the way the particles were bound to tileset objects

This commit is contained in:
Titus Tscharntke 2011-06-22 20:26:39 +00:00
parent e58ddd35b4
commit 8b9d4a662a
5 changed files with 79 additions and 51 deletions

View File

@ -45,6 +45,10 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) {
rotation= random.randRange(0.f, 360.f); rotation= random.randRange(0.f, 360.f);
if(objectType!=NULL){ if(objectType!=NULL){
variation = random.randRange(0, objectType->getModelCount()-1); variation = random.randRange(0, objectType->getModelCount()-1);
TilesetModelType *tmt=objectType->getTilesetModelType(variation);
if(tmt->getRotationAllowed()!=true){
rotation=0;
}
} }
visible=false; visible=false;
@ -75,26 +79,26 @@ void Object::end(){
void Object::initParticles(){ void Object::initParticles(){
if(this->objectType==NULL) return; if(this->objectType==NULL) return;
if(this->objectType->hasParticles()){ if(this->objectType->getTilesetModelType(variation)->hasParticles()){
ObjectParticleSystemTypes *particleTypes= this->objectType->getObjectParticleSystemTypes(variation); ModelParticleSystemTypes *particleTypes= this->objectType->getTilesetModelType(variation)->getParticleTypes();
initParticlesFromTypes(particleTypes); initParticlesFromTypes(particleTypes);
} }
} }
void Object::initParticlesFromTypes(const ObjectParticleSystemTypes *particleTypes){ void Object::initParticlesFromTypes(const ModelParticleSystemTypes *particleTypes){
if(Config::getInstance().getBool("TilesetParticles","true") && (particleTypes->empty() == false) if(Config::getInstance().getBool("TilesetParticles", "true") && (particleTypes->empty() == false)
&& (unitParticleSystems.empty() == true)){ && (unitParticleSystems.empty() == true)){
for(ObjectParticleSystemTypes::const_iterator it= particleTypes->begin(); it != particleTypes->end(); ++it){ for(ObjectParticleSystemTypes::const_iterator it= particleTypes->begin(); it != particleTypes->end(); ++it){
UnitParticleSystem *ups= new UnitParticleSystem(200); UnitParticleSystem *ups= new UnitParticleSystem(200);
(*it)->setValues(ups); (*it)->setValues(ups);
ups->setPos(this->pos); ups->setPos(this->pos);
ups->setRotation(this->rotation); ups->setRotation(this->rotation);
ups->setFactionColor(Vec3f(0, 0, 0)); ups->setFactionColor(Vec3f(0, 0, 0));
ups->setVisible(false); ups->setVisible(false);
this->unitParticleSystems.push_back(ups); this->unitParticleSystems.push_back(ups);
Renderer::getInstance().manageParticleSystem(ups, rsGame); Renderer::getInstance().manageParticleSystem(ups, rsGame);
} }
} }
} }
@ -107,11 +111,35 @@ void Object::setHeight(float height){
} }
Model *Object::getModelPtr() const { Model *Object::getModelPtr() const {
return objectType==NULL ? (resource != NULL && resource->getType() != NULL ? resource->getType()->getModel() : NULL ) : objectType->getModel(variation); Model* result;
if(objectType==NULL){
if(resource != NULL && resource->getType() != NULL){
result=resource->getType()->getModel();
}
else
{
result=NULL;
}
} else {
result=objectType->getTilesetModelType(variation)->getModel();
}
return result;
} }
const Model *Object::getModel() const{ const Model *Object::getModel() const{
return objectType==NULL ? (resource != NULL && resource->getType() != NULL ? resource->getType()->getModel() : NULL ) : objectType->getModel(variation); Model* result;
if(objectType==NULL){
if(resource != NULL && resource->getType() != NULL){
result=resource->getType()->getModel();
}
else
{
result=NULL;
}
} else {
result=objectType->getTilesetModelType(variation)->getModel();
}
return result;
} }
bool Object::getWalkable() const{ bool Object::getWalkable() const{

View File

@ -16,6 +16,7 @@
#include "leak_dumper.h" #include "leak_dumper.h"
#include "particle.h" #include "particle.h"
#include "object_type.h" #include "object_type.h"
#include "tileset_model_type.h"
namespace Glest{ namespace Game{ namespace Glest{ namespace Game{
@ -64,7 +65,7 @@ public:
void end(); //to kill particles void end(); //to kill particles
void initParticles(); void initParticles();
void initParticlesFromTypes(const ObjectParticleSystemTypes *particleTypes); void initParticlesFromTypes(const ModelParticleSystemTypes *particleTypes);
static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; } static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; }
const ObjectType *getType() const {return objectType;} const ObjectType *getType() const {return objectType;}

View File

@ -21,24 +21,21 @@ namespace Glest{ namespace Game{
// ===================================================== // =====================================================
void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) { void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) {
models.reserve(modelCount); // modeltypes.reserve(modelCount);
particles.reserve(modelCount); // one list per model
this->objectClass= objectClass; this->objectClass= objectClass;
this->walkable= walkable; this->walkable= walkable;
this->height = height; this->height = height;
} }
ObjectType::~ObjectType(){ ObjectType::~ObjectType(){
for(int i= 0; i < particles.size(); i++){ while(!(modeltypes.empty())){
while(!(particles[i].empty())){ delete modeltypes.back();
delete particles[i].back(); modeltypes.pop_back();
particles[i].pop_back(); //Logger::getInstance().add("ObjectType", true);
}
} }
//Logger::getInstance().add("ObjectType", true);
} }
void ObjectType::loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList, TilesetModelType* ObjectType::loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList,
string parentLoader) { string parentLoader) {
Model *model= Renderer::getInstance().newModel(rsGame); Model *model= Renderer::getInstance().newModel(rsGame);
model->load(path, false, loadedFileList, &parentLoader); model->load(path, false, loadedFileList, &parentLoader);
@ -47,19 +44,17 @@ void ObjectType::loadModel(const string &path, std::map<string,vector<pair<strin
const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst(); const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst();
color= p->getPixel3f(p->getW()/2, p->getH()/2); color= p->getPixel3f(p->getW()/2, p->getH()/2);
} }
models.push_back(model); TilesetModelType *modelType=new TilesetModelType();
particles.resize(particles.size()+1); modelType->setModel(model);
} modeltypes.push_back(modelType);
return modelType;
void ObjectType::addParticleSystem(ObjectParticleSystemType *particleSystem){
particles.back().push_back(particleSystem);
} }
void ObjectType::deletePixels() { void ObjectType::deletePixels() {
for(int i = 0; i < models.size(); ++i) { for(int i = 0; i < modeltypes.size(); ++i) {
Model *model = models[i]; TilesetModelType *model = modeltypes[i];
if(model != NULL) { if(model->getModel() != NULL) {
model->deletePixels(); model->getModel()->deletePixels();
} }
} }
} }

View File

@ -17,6 +17,7 @@
#include "vec.h" #include "vec.h"
#include "leak_dumper.h" #include "leak_dumper.h"
#include "unit_particle_type.h" #include "unit_particle_type.h"
#include "tileset_model_type.h"
using std::vector; using std::vector;
@ -36,17 +37,14 @@ typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
class ObjectType{ class ObjectType{
private: private:
typedef vector<Model*> Models; typedef vector<TilesetModelType*> ModelTypes;
private: private:
static const int tree1= 0; static const int tree1= 0;
static const int tree2= 1; static const int tree2= 1;
static const int choppedTree= 2; static const int choppedTree= 2;
private: private:
Models models; ModelTypes modeltypes;
ObjectParticleVector particles;
Vec3f color; Vec3f color;
int objectClass; int objectClass;
bool walkable; bool walkable;
@ -56,14 +54,11 @@ public:
~ObjectType(); ~ObjectType();
void init(int modelCount, int objectClass, bool walkable, int height); void init(int modelCount, int objectClass, bool walkable, int height);
void loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, TilesetModelType* loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,
string parentLoader=""); string parentLoader="");
void addParticleSystem(ObjectParticleSystemType *particleSystem);
Model *getModel(int i) {return models[i];} TilesetModelType *getTilesetModelType(int i) {return modeltypes[i];}
bool hasParticles() const {return !particles.empty();} int getModelCount() const {return modeltypes.size();}
ObjectParticleSystemTypes *getObjectParticleSystemTypes(int i) {return &particles[i];}
int getModelCount() const {return models.size();}
const Vec3f &getColor() const {return color;} const Vec3f &getColor() const {return color;}
int getClass() const {return objectClass;} int getClass() const {return objectClass;}
bool getWalkable() const {return walkable;} bool getWalkable() const {return walkable;}

View File

@ -215,7 +215,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
for(int j=0; j<childCount; ++j) { for(int j=0; j<childCount; ++j) {
const XmlNode *modelNode= objectNode->getChild("model", j); const XmlNode *modelNode= objectNode->getChild("model", j);
const XmlAttribute *pathAttribute= modelNode->getAttribute("path"); const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
objectTypes[i].loadModel(pathAttribute->getRestrictedValue(currentPath),&loadedFileList, sourceXMLFile); TilesetModelType* tmt=objectTypes[i].loadModel(pathAttribute->getRestrictedValue(currentPath),&loadedFileList, sourceXMLFile);
loadedFileList[pathAttribute->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,pathAttribute->getRestrictedValue())); loadedFileList[pathAttribute->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,pathAttribute->getRestrictedValue()));
if(modelNode->hasChild("particles")){ if(modelNode->hasChild("particles")){
@ -230,10 +230,19 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
&Renderer::getInstance(), loadedFileList, sourceXMLFile,""); &Renderer::getInstance(), loadedFileList, sourceXMLFile,"");
loadedFileList[currentPath + path].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue())); loadedFileList[currentPath + path].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue()));
objectTypes[i].addParticleSystem((objectParticleSystemType)); tmt->addParticleSystem(objectParticleSystemType);
} }
} }
} }
//rotationAllowed
if(modelNode->hasChild("rotationAllowed")){
const XmlNode *rotationAllowedNode= modelNode->getChild("rotationAllowed");
tmt->setRotationAllowed(rotationAllowedNode->getAttribute("value")->getBoolValue());
}
else{
tmt->setRotationAllowed(true);
}
} }
} }