mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
particles for tilesets ( too much rendered at the moment )
This commit is contained in:
parent
18c863364f
commit
792d0aa665
@ -58,13 +58,15 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
||||
}
|
||||
|
||||
//model
|
||||
const XmlNode *modelNode= particleSystemNode->getChild("model");
|
||||
bool modelEnabled= modelNode->getAttribute("value")->getBoolValue();
|
||||
if(modelEnabled) {
|
||||
string path= modelNode->getAttribute("path")->getRestrictedValue();
|
||||
model= renderer->newModel(rsGame);
|
||||
if(particleSystemNode->hasChild("model")){
|
||||
const XmlNode *modelNode= particleSystemNode->getChild("model");
|
||||
bool modelEnabled= modelNode->getAttribute("value")->getBoolValue();
|
||||
if(modelEnabled){
|
||||
string path= modelNode->getAttribute("path")->getRestrictedValue();
|
||||
model= renderer->newModel(rsGame);
|
||||
|
||||
model->load(dir + "/" + path);
|
||||
model->load(dir + "/" + path);
|
||||
}
|
||||
}
|
||||
else{
|
||||
model= NULL;
|
||||
|
@ -29,101 +29,22 @@ namespace Glest{ namespace Game{
|
||||
// class UnitParticleSystemType
|
||||
// =====================================================
|
||||
|
||||
UnitParticleSystemType::UnitParticleSystemType(){
|
||||
texture = NULL;
|
||||
}
|
||||
|
||||
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer) {
|
||||
//texture
|
||||
const XmlNode *textureNode= particleSystemNode->getChild("texture");
|
||||
bool textureEnabled= textureNode->getAttribute("value")->getBoolValue();
|
||||
if(textureEnabled == true) {
|
||||
//Renderer &renderer= Renderer::getInstance();
|
||||
texture= renderer->newTexture2D(rsGame);
|
||||
//texture = newTexture;
|
||||
|
||||
if(textureNode->getAttribute("luminance")->getBoolValue()){
|
||||
texture->setFormat(Texture::fAlpha);
|
||||
texture->getPixmap()->init(1);
|
||||
}
|
||||
else{
|
||||
texture->getPixmap()->init(4);
|
||||
}
|
||||
texture->load(dir + "/" + textureNode->getAttribute("path")->getRestrictedValue());
|
||||
}
|
||||
else{
|
||||
texture= NULL;
|
||||
|
||||
//delete newTexture;
|
||||
//newTexture = NULL;
|
||||
}
|
||||
|
||||
//primitive
|
||||
const XmlNode *primitiveNode= particleSystemNode->getChild("primitive");
|
||||
primitive= primitiveNode->getAttribute("value")->getRestrictedValue();
|
||||
|
||||
//offset
|
||||
const XmlNode *offsetNode= particleSystemNode->getChild("offset");
|
||||
offset.x= offsetNode->getAttribute("x")->getFloatValue();
|
||||
offset.y= offsetNode->getAttribute("y")->getFloatValue();
|
||||
offset.z= offsetNode->getAttribute("z")->getFloatValue();
|
||||
ParticleSystemType::load(particleSystemNode, dir, renderer);
|
||||
//radius
|
||||
const XmlNode *radiusNode= particleSystemNode->getChild("radius");
|
||||
radius= radiusNode->getAttribute("value")->getFloatValue();
|
||||
|
||||
//relative
|
||||
const XmlNode *relativeNode= particleSystemNode->getChild("relative");
|
||||
relative= relativeNode->getAttribute("value")->getBoolValue();
|
||||
|
||||
//direction
|
||||
const XmlNode *directionNode= particleSystemNode->getChild("direction");
|
||||
direction.x= directionNode->getAttribute("x")->getFloatValue();
|
||||
direction.y= directionNode->getAttribute("y")->getFloatValue();
|
||||
direction.z= directionNode->getAttribute("z")->getFloatValue();
|
||||
|
||||
//color
|
||||
const XmlNode *colorNode= particleSystemNode->getChild("color");
|
||||
color.x= colorNode->getAttribute("red")->getFloatValue(0.f, 1.0f);
|
||||
color.y= colorNode->getAttribute("green")->getFloatValue(0.f, 1.0f);
|
||||
color.z= colorNode->getAttribute("blue")->getFloatValue(0.f, 1.0f);
|
||||
color.w= colorNode->getAttribute("alpha")->getFloatValue(0.f, 1.0f);
|
||||
|
||||
//color
|
||||
const XmlNode *colorNoEnergyNode= particleSystemNode->getChild("color-no-energy");
|
||||
colorNoEnergy.x= colorNoEnergyNode->getAttribute("red")->getFloatValue(0.f, 1.0f);
|
||||
colorNoEnergy.y= colorNoEnergyNode->getAttribute("green")->getFloatValue(0.f, 1.0f);
|
||||
colorNoEnergy.z= colorNoEnergyNode->getAttribute("blue")->getFloatValue(0.f, 1.0f);
|
||||
colorNoEnergy.w= colorNoEnergyNode->getAttribute("alpha")->getFloatValue(0.f, 1.0f);
|
||||
|
||||
//radius
|
||||
const XmlNode *radiusNode= particleSystemNode->getChild("radius");
|
||||
radius= radiusNode->getAttribute("value")->getFloatValue();
|
||||
|
||||
//size
|
||||
const XmlNode *sizeNode= particleSystemNode->getChild("size");
|
||||
size= sizeNode->getAttribute("value")->getFloatValue();
|
||||
|
||||
//sizeNoEnergy
|
||||
const XmlNode *sizeNoEnergyNode= particleSystemNode->getChild("size-no-energy");
|
||||
sizeNoEnergy= sizeNoEnergyNode->getAttribute("value")->getFloatValue();
|
||||
|
||||
//speed
|
||||
const XmlNode *speedNode= particleSystemNode->getChild("speed");
|
||||
speed= speedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
||||
|
||||
//gravity
|
||||
const XmlNode *gravityNode= particleSystemNode->getChild("gravity");
|
||||
gravity= gravityNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
||||
|
||||
//emission rate
|
||||
const XmlNode *emissionRateNode= particleSystemNode->getChild("emission-rate");
|
||||
emissionRate= emissionRateNode->getAttribute("value")->getFloatValue();
|
||||
|
||||
//energy max
|
||||
const XmlNode *energyMaxNode= particleSystemNode->getChild("energy-max");
|
||||
energyMax= energyMaxNode->getAttribute("value")->getIntValue();
|
||||
|
||||
//speed
|
||||
const XmlNode *energyVarNode= particleSystemNode->getChild("energy-var");
|
||||
energyVar= energyVarNode->getAttribute("value")->getIntValue();
|
||||
|
||||
//relative
|
||||
const XmlNode *relativeNode= particleSystemNode->getChild("relative");
|
||||
relative= relativeNode->getAttribute("value")->getBoolValue();
|
||||
|
||||
//relativeDirection
|
||||
if(particleSystemNode->hasChild("relativeDirection")){
|
||||
const XmlNode *relativeDirectionNode= particleSystemNode->getChild("relativeDirection");
|
||||
@ -145,35 +66,6 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin
|
||||
//fixed
|
||||
const XmlNode *fixedNode= particleSystemNode->getChild("fixed");
|
||||
fixed= fixedNode->getAttribute("value")->getBoolValue();
|
||||
|
||||
//teamcolorNoEnergy
|
||||
if(particleSystemNode->hasChild("teamcolorNoEnergy")){
|
||||
const XmlNode *teamcolorNoEnergyNode= particleSystemNode->getChild("teamcolorNoEnergy");
|
||||
teamcolorNoEnergy= teamcolorNoEnergyNode->getAttribute("value")->getBoolValue();
|
||||
}
|
||||
else{
|
||||
teamcolorNoEnergy=false;
|
||||
}
|
||||
|
||||
|
||||
//teamcolorEnergy
|
||||
if(particleSystemNode->hasChild("teamcolorEnergy")){
|
||||
const XmlNode *teamcolorEnergyNode= particleSystemNode->getChild("teamcolorEnergy");
|
||||
teamcolorEnergy= teamcolorEnergyNode->getAttribute("value")->getBoolValue();
|
||||
}
|
||||
else{
|
||||
teamcolorEnergy=false;
|
||||
}
|
||||
|
||||
//mode
|
||||
if(particleSystemNode->hasChild("mode")){
|
||||
const XmlNode *modeNode= particleSystemNode->getChild("mode");
|
||||
mode= modeNode->getAttribute("value")->getRestrictedValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
mode="normal";
|
||||
}
|
||||
}
|
||||
|
||||
void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "xml_parser.h"
|
||||
#include "graphics_interface.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "particle_type.h"
|
||||
|
||||
using std::string;
|
||||
using namespace Shared::Graphics;
|
||||
@ -41,39 +42,26 @@ using Shared::Xml::XmlNode;
|
||||
/// A type of particle system
|
||||
// ===========================================================
|
||||
|
||||
class UnitParticleSystemType{
|
||||
class UnitParticleSystemType: public ParticleSystemType{
|
||||
protected:
|
||||
string type;
|
||||
Texture2D *texture;
|
||||
string primitive;
|
||||
Vec3f offset;
|
||||
Vec3f direction;
|
||||
Vec4f color;
|
||||
Vec4f colorNoEnergy;
|
||||
|
||||
float radius;
|
||||
float size;
|
||||
float sizeNoEnergy;
|
||||
float speed;
|
||||
float gravity;
|
||||
float emissionRate;
|
||||
int energyMax;
|
||||
int energyVar;
|
||||
Vec3f direction;
|
||||
bool relative;
|
||||
bool relativeDirection;
|
||||
bool fixed;
|
||||
bool teamcolorNoEnergy;
|
||||
bool teamcolorEnergy;
|
||||
int staticParticleCount;
|
||||
string mode;
|
||||
|
||||
public:
|
||||
UnitParticleSystemType();
|
||||
void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture);
|
||||
void load(const string &dir, const string &path, RendererInterface *newTexture);
|
||||
void setValues(UnitParticleSystem *uts);
|
||||
bool hasTexture() const { return(texture != NULL); }
|
||||
};
|
||||
|
||||
class ObjectParticleSystemType: public UnitParticleSystemType{
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
||||
#endif
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "object.h"
|
||||
|
||||
#include "faction_type.h"
|
||||
#include "config.h"
|
||||
#include "tech_tree.h"
|
||||
#include "resource.h"
|
||||
#include "upgrade.h"
|
||||
@ -54,9 +55,41 @@ Object::~Object(){
|
||||
stateCallback->removingObjectEvent(this);
|
||||
//renderer.getGame()->getGui()->removeObject(this);
|
||||
}
|
||||
// fade(and by this remove) all unit particle systems
|
||||
while(unitParticleSystems.empty() == false) {
|
||||
unitParticleSystems.back()->fade();
|
||||
unitParticleSystems.pop_back();
|
||||
}
|
||||
delete resource;
|
||||
}
|
||||
|
||||
void Object::initParticles(){
|
||||
if(this->objectType==NULL) return;
|
||||
if(this->objectType->hasParticles()){
|
||||
ObjectParticleSystemTypes *particleTypes= this->objectType->getObjectParticleSystemTypes(variation);
|
||||
if(Config::getInstance().getBool("UnitParticles") && (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));
|
||||
this->unitParticleSystems.push_back(ups);
|
||||
Renderer::getInstance().manageParticleSystem(ups, rsGame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Object::setHeight(float height){
|
||||
pos.y=height;
|
||||
|
||||
for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) {
|
||||
(*it)->setPos(this->pos);
|
||||
}
|
||||
}
|
||||
|
||||
Model *Object::getModelPtr() const {
|
||||
return objectType==NULL ? (resource != NULL && resource->getType() != NULL ? resource->getType()->getModel() : NULL ) : objectType->getModel(variation);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "model.h"
|
||||
#include "vec.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "particle.h"
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
@ -24,6 +25,7 @@ class Resource;
|
||||
using Shared::Graphics::Model;
|
||||
using Shared::Graphics::Vec2i;
|
||||
using Shared::Graphics::Vec3f;
|
||||
using Shared::Graphics::UnitParticleSystem;
|
||||
|
||||
// =====================================================
|
||||
// class Object
|
||||
@ -39,8 +41,12 @@ public:
|
||||
};
|
||||
|
||||
class Object {
|
||||
private:
|
||||
typedef vector<UnitParticleSystem*> UnitParticleSystems;
|
||||
|
||||
private:
|
||||
ObjectType *objectType;
|
||||
vector<UnitParticleSystem*> unitParticleSystems;
|
||||
Resource *resource;
|
||||
Vec3f pos;
|
||||
float rotation;
|
||||
@ -54,10 +60,9 @@ public:
|
||||
Object(ObjectType *objectType, const Vec3f &pos, const Vec2i &mapPos);
|
||||
~Object();
|
||||
|
||||
void initParticles();
|
||||
static void setStateCallback(ObjectStateInterface *value) { stateCallback=value; }
|
||||
|
||||
void setHeight(float height) {pos.y= height;}
|
||||
|
||||
const ObjectType *getType() const {return objectType;}
|
||||
Resource *getResource() const {return resource;}
|
||||
Vec3f getPos() const {return pos;}
|
||||
@ -68,6 +73,7 @@ public:
|
||||
bool getWalkable() const;
|
||||
|
||||
void setResource(const ResourceType *resourceType, const Vec2i &pos);
|
||||
void setHeight(float height);
|
||||
|
||||
int getLastRenderFrame() const { return lastRenderFrame; }
|
||||
void setLastRenderFrame(int value) { lastRenderFrame = value; }
|
||||
|
@ -22,11 +22,23 @@ 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
|
||||
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();
|
||||
}
|
||||
}
|
||||
//Logger::getInstance().add("ObjectType", true);
|
||||
}
|
||||
|
||||
void ObjectType::loadModel(const string &path){
|
||||
Model *model= Renderer::getInstance().newModel(rsGame);
|
||||
model->load(path);
|
||||
@ -36,6 +48,11 @@ void ObjectType::loadModel(const string &path){
|
||||
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);
|
||||
}
|
||||
|
||||
void ObjectType::deletePixels() {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "model.h"
|
||||
#include "vec.h"
|
||||
#include "leak_dumper.h"
|
||||
#include "unit_particle_type.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
@ -30,10 +31,14 @@ using Shared::Graphics::Vec3f;
|
||||
/// Each of the possible objects of the map: trees, stones ...
|
||||
// =====================================================
|
||||
|
||||
typedef vector<ObjectParticleSystemType*> ObjectParticleSystemTypes;
|
||||
typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
|
||||
|
||||
class ObjectType{
|
||||
private:
|
||||
typedef vector<Model*> Models;
|
||||
|
||||
|
||||
private:
|
||||
static const int tree1= 0;
|
||||
static const int tree2= 1;
|
||||
@ -41,17 +46,22 @@ private:
|
||||
|
||||
private:
|
||||
Models models;
|
||||
ObjectParticleVector particles;
|
||||
Vec3f color;
|
||||
int objectClass;
|
||||
bool walkable;
|
||||
int height;
|
||||
|
||||
public:
|
||||
~ObjectType();
|
||||
void init(int modelCount, int objectClass, bool walkable, int height);
|
||||
|
||||
void loadModel(const string &path);
|
||||
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();}
|
||||
const Vec3f &getColor() const {return color;}
|
||||
int getClass() const {return objectClass;}
|
||||
|
@ -179,6 +179,20 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
||||
const XmlNode *modelNode= objectNode->getChild("model", j);
|
||||
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
||||
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
|
||||
|
||||
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());
|
||||
objectTypes[i].addParticleSystem((objectParticleSystemType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@ World::World(){
|
||||
Config &config= Config::getInstance();
|
||||
|
||||
staggeredFactionUpdates = config.getBool("StaggeredFactionUpdates","false");
|
||||
unitParticlesEnabled=config.getBool("UnitParticles");
|
||||
|
||||
ExploredCellsLookupItemCache.clear();
|
||||
ExploredCellsLookupItemCacheTimer.clear();
|
||||
@ -1056,7 +1057,9 @@ void World::initCells(bool fogOfWar) {
|
||||
if(sc == NULL) {
|
||||
throw runtime_error("sc == NULL");
|
||||
}
|
||||
|
||||
if(sc->getObject()!=NULL){
|
||||
sc->getObject()->initParticles();
|
||||
}
|
||||
sc->setFowTexCoord(Vec2f(
|
||||
i/(next2Power(map.getSurfaceW())-1.f),
|
||||
j/(next2Power(map.getSurfaceH())-1.f)));
|
||||
|
@ -135,6 +135,7 @@ private:
|
||||
Chrono chronoPerfTimer;
|
||||
bool perfTimerEnabled;
|
||||
|
||||
bool unitParticlesEnabled;
|
||||
bool staggeredFactionUpdates;
|
||||
std::map<string,StaticSound *> staticSoundList;
|
||||
std::map<string,StrSound *> streamSoundList;
|
||||
|
Loading…
x
Reference in New Issue
Block a user