2010-10-28 02:51:25 +02:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#include "object_type.h"
|
|
|
|
|
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class ObjectType
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-10-30 06:05:48 +02:00
|
|
|
|
void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) {
|
2010-10-28 02:51:25 +02:00
|
|
|
|
models.reserve(modelCount);
|
2011-03-02 00:36:33 +01:00
|
|
|
|
particles.reserve(modelCount); // one list per model
|
2010-10-28 02:51:25 +02:00
|
|
|
|
this->objectClass= objectClass;
|
|
|
|
|
this->walkable= walkable;
|
2010-10-30 06:05:48 +02:00
|
|
|
|
this->height = height;
|
2010-10-28 02:51:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-02 00:36:33 +01:00
|
|
|
|
ObjectType::~ObjectType(){
|
2011-03-05 15:34:36 +01:00
|
|
|
|
for(int i= 0; i < particles.size(); i++){
|
2011-03-02 00:36:33 +01:00
|
|
|
|
while(!(particles[i].empty())){
|
2011-03-05 15:34:36 +01:00
|
|
|
|
delete particles[i].back();
|
|
|
|
|
particles[i].pop_back();
|
|
|
|
|
}
|
2011-03-02 00:36:33 +01:00
|
|
|
|
}
|
|
|
|
|
//Logger::getInstance().add("ObjectType", true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-15 16:30:28 +01:00
|
|
|
|
void ObjectType::loadModel(const string &path, std::map<string,int> *loadedFileList) {
|
2010-10-28 02:51:25 +02:00
|
|
|
|
Model *model= Renderer::getInstance().newModel(rsGame);
|
2011-03-15 16:30:28 +01:00
|
|
|
|
model->load(path, false, loadedFileList);
|
2010-10-28 02:51:25 +02:00
|
|
|
|
color= Vec3f(0.f);
|
|
|
|
|
if(model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) {
|
2010-11-09 10:06:52 +01:00
|
|
|
|
const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst();
|
2010-10-28 02:51:25 +02:00
|
|
|
|
color= p->getPixel3f(p->getW()/2, p->getH()/2);
|
|
|
|
|
}
|
|
|
|
|
models.push_back(model);
|
2011-03-02 00:36:33 +01:00
|
|
|
|
particles.resize(particles.size()+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectType::addParticleSystem(ObjectParticleSystemType *particleSystem){
|
|
|
|
|
particles.back().push_back(particleSystem);
|
2010-10-28 02:51:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ObjectType::deletePixels() {
|
|
|
|
|
for(int i = 0; i < models.size(); ++i) {
|
|
|
|
|
Model *model = models[i];
|
|
|
|
|
if(model != NULL) {
|
|
|
|
|
model->deletePixels();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|