switch for non rotatable objets in tilesets; cleaned up the way the particles were bound to tileset objects
This commit is contained in:
parent
e58ddd35b4
commit
8b9d4a662a
|
@ -45,6 +45,10 @@ Object::Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos) {
|
|||
rotation= random.randRange(0.f, 360.f);
|
||||
if(objectType!=NULL){
|
||||
variation = random.randRange(0, objectType->getModelCount()-1);
|
||||
TilesetModelType *tmt=objectType->getTilesetModelType(variation);
|
||||
if(tmt->getRotationAllowed()!=true){
|
||||
rotation=0;
|
||||
}
|
||||
}
|
||||
visible=false;
|
||||
|
||||
|
@ -75,26 +79,26 @@ void Object::end(){
|
|||
|
||||
void Object::initParticles(){
|
||||
if(this->objectType==NULL) return;
|
||||
if(this->objectType->hasParticles()){
|
||||
ObjectParticleSystemTypes *particleTypes= this->objectType->getObjectParticleSystemTypes(variation);
|
||||
if(this->objectType->getTilesetModelType(variation)->hasParticles()){
|
||||
ModelParticleSystemTypes *particleTypes= this->objectType->getTilesetModelType(variation)->getParticleTypes();
|
||||
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::initParticlesFromTypes(const ModelParticleSystemTypes *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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,11 +111,35 @@ void Object::setHeight(float height){
|
|||
}
|
||||
|
||||
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{
|
||||
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{
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "leak_dumper.h"
|
||||
#include "particle.h"
|
||||
#include "object_type.h"
|
||||
#include "tileset_model_type.h"
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
|
@ -64,7 +65,7 @@ public:
|
|||
|
||||
void end(); //to kill particles
|
||||
void initParticles();
|
||||
void initParticlesFromTypes(const ObjectParticleSystemTypes *particleTypes);
|
||||
void initParticlesFromTypes(const ModelParticleSystemTypes *particleTypes);
|
||||
static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; }
|
||||
|
||||
const ObjectType *getType() const {return objectType;}
|
||||
|
|
|
@ -21,24 +21,21 @@ namespace Glest{ namespace Game{
|
|||
// =====================================================
|
||||
|
||||
void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) {
|
||||
models.reserve(modelCount);
|
||||
particles.reserve(modelCount); // one list per model
|
||||
// modeltypes.reserve(modelCount);
|
||||
this->objectClass= objectClass;
|
||||
this->walkable= walkable;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
ObjectType::~ObjectType(){
|
||||
for(int i= 0; i < particles.size(); i++){
|
||||
while(!(particles[i].empty())){
|
||||
delete particles[i].back();
|
||||
particles[i].pop_back();
|
||||
}
|
||||
while(!(modeltypes.empty())){
|
||||
delete modeltypes.back();
|
||||
modeltypes.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) {
|
||||
Model *model= Renderer::getInstance().newModel(rsGame);
|
||||
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();
|
||||
color= p->getPixel3f(p->getW()/2, p->getH()/2);
|
||||
}
|
||||
models.push_back(model);
|
||||
particles.resize(particles.size()+1);
|
||||
}
|
||||
|
||||
void ObjectType::addParticleSystem(ObjectParticleSystemType *particleSystem){
|
||||
particles.back().push_back(particleSystem);
|
||||
TilesetModelType *modelType=new TilesetModelType();
|
||||
modelType->setModel(model);
|
||||
modeltypes.push_back(modelType);
|
||||
return modelType;
|
||||
}
|
||||
|
||||
void ObjectType::deletePixels() {
|
||||
for(int i = 0; i < models.size(); ++i) {
|
||||
Model *model = models[i];
|
||||
if(model != NULL) {
|
||||
model->deletePixels();
|
||||
for(int i = 0; i < modeltypes.size(); ++i) {
|
||||
TilesetModelType *model = modeltypes[i];
|
||||
if(model->getModel() != NULL) {
|
||||
model->getModel()->deletePixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "vec.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "unit_particle_type.h"
|
||||
#include "tileset_model_type.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
|
@ -36,17 +37,14 @@ typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
|
|||
|
||||
class ObjectType{
|
||||
private:
|
||||
typedef vector<Model*> Models;
|
||||
|
||||
|
||||
typedef vector<TilesetModelType*> ModelTypes;
|
||||
private:
|
||||
static const int tree1= 0;
|
||||
static const int tree2= 1;
|
||||
static const int choppedTree= 2;
|
||||
|
||||
private:
|
||||
Models models;
|
||||
ObjectParticleVector particles;
|
||||
ModelTypes modeltypes;
|
||||
Vec3f color;
|
||||
int objectClass;
|
||||
bool walkable;
|
||||
|
@ -56,14 +54,11 @@ public:
|
|||
~ObjectType();
|
||||
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="");
|
||||
void addParticleSystem(ObjectParticleSystemType *particleSystem);
|
||||
|
||||
Model *getModel(int i) {return models[i];}
|
||||
bool hasParticles() const {return !particles.empty();}
|
||||
ObjectParticleSystemTypes *getObjectParticleSystemTypes(int i) {return &particles[i];}
|
||||
int getModelCount() const {return models.size();}
|
||||
TilesetModelType *getTilesetModelType(int i) {return modeltypes[i];}
|
||||
int getModelCount() const {return modeltypes.size();}
|
||||
const Vec3f &getColor() const {return color;}
|
||||
int getClass() const {return objectClass;}
|
||||
bool getWalkable() const {return walkable;}
|
||||
|
|
|
@ -215,7 +215,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||
for(int j=0; j<childCount; ++j) {
|
||||
const XmlNode *modelNode= objectNode->getChild("model", j);
|
||||
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()));
|
||||
|
||||
if(modelNode->hasChild("particles")){
|
||||
|
@ -230,10 +230,19 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
|||
&Renderer::getInstance(), loadedFileList, sourceXMLFile,"");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue