forgot 2 files for the particles
This commit is contained in:
parent
0550d06faf
commit
e4b3c3117e
171
source/glest_game/graphics/unit_particle_type.cpp
Normal file
171
source/glest_game/graphics/unit_particle_type.cpp
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
// ==============================================================
|
||||||
|
// 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 "unit_particle_type.h"
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "core_data.h"
|
||||||
|
#include "xml_parser.h"
|
||||||
|
#include "renderer.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "game_constants.h"
|
||||||
|
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace Shared::Xml;
|
||||||
|
using namespace Shared::Graphics;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class UnitParticleSystemType
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
UnitParticleSystemType::UnitParticleSystemType(){
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir){
|
||||||
|
|
||||||
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
|
//texture
|
||||||
|
const XmlNode *textureNode= particleSystemNode->getChild("texture");
|
||||||
|
bool textureEnabled= textureNode->getAttribute("value")->getBoolValue();
|
||||||
|
if(textureEnabled){
|
||||||
|
texture= renderer.newTexture2D(rsGame);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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();
|
||||||
|
|
||||||
|
//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")->getIntValue();
|
||||||
|
|
||||||
|
//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();
|
||||||
|
|
||||||
|
//fixed
|
||||||
|
const XmlNode *fixedNode= particleSystemNode->getChild("fixed");
|
||||||
|
fixed= fixedNode->getAttribute("value")->getBoolValue();
|
||||||
|
|
||||||
|
//teamcolorNoEnergy
|
||||||
|
const XmlNode *teamcolorNoEnergyNode= particleSystemNode->getChild("teamcolorNoEnergy");
|
||||||
|
teamcolorNoEnergy= teamcolorNoEnergyNode->getAttribute("value")->getBoolValue();
|
||||||
|
|
||||||
|
//teamcolorEnergy
|
||||||
|
const XmlNode *teamcolorEnergyNode= particleSystemNode->getChild("teamcolorEnergy");
|
||||||
|
teamcolorEnergy= teamcolorEnergyNode->getAttribute("value")->getBoolValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
|
||||||
|
ups->setTexture(texture);
|
||||||
|
ups->setPrimitive(UnitParticleSystem::strToPrimitive(primitive));
|
||||||
|
ups->setOffset(offset);
|
||||||
|
ups->setDirection(direction);
|
||||||
|
ups->setColor(color);
|
||||||
|
ups->setColorNoEnergy(colorNoEnergy);
|
||||||
|
ups->setSpeed(speed);
|
||||||
|
ups->setGravity(gravity);
|
||||||
|
ups->setParticleSize(size);
|
||||||
|
ups->setSizeNoEnergy(sizeNoEnergy);
|
||||||
|
ups->setEmissionRate(emissionRate);
|
||||||
|
ups->setMaxParticleEnergy(energyMax);
|
||||||
|
ups->setVarParticleEnergy(energyVar);
|
||||||
|
ups->setFixed(fixed);
|
||||||
|
ups->setTeamcolorNoEnergy(teamcolorNoEnergy);
|
||||||
|
ups->setTeamcolorEnergy(teamcolorEnergy);
|
||||||
|
ups->setRadius(radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitParticleSystemType::load(const string &dir, const string &path){
|
||||||
|
|
||||||
|
try{
|
||||||
|
XmlTree xmlTree;
|
||||||
|
xmlTree.load(path);
|
||||||
|
const XmlNode *particleSystemNode= xmlTree.getRootNode();
|
||||||
|
|
||||||
|
UnitParticleSystemType::load(particleSystemNode, dir);
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
throw runtime_error("Error loading ParticleSystem: "+ path + "\n" +e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}}//end mamespace
|
72
source/glest_game/graphics/unit_particle_type.h
Normal file
72
source/glest_game/graphics/unit_particle_type.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
// ==============================================================
|
||||||
|
// 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
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _GLEST_GAME_UNITPARTICLETYPE_H_
|
||||||
|
#define _GLEST_GAME_UNITPARTICLETYPE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "particle.h"
|
||||||
|
#include "factory.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "vec.h"
|
||||||
|
#include "xml_parser.h"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
using Shared::Graphics::ParticleSystem;
|
||||||
|
using Shared::Graphics::UnitParticleSystem;
|
||||||
|
using Shared::Graphics::Texture2D;
|
||||||
|
using Shared::Graphics::Vec3f;
|
||||||
|
using Shared::Graphics::Vec4f;
|
||||||
|
using Shared::Util::MultiFactory;
|
||||||
|
using Shared::Xml::XmlNode;
|
||||||
|
|
||||||
|
// ===========================================================
|
||||||
|
// class ParticleSystemType
|
||||||
|
//
|
||||||
|
/// A type of particle system
|
||||||
|
// ===========================================================
|
||||||
|
|
||||||
|
class UnitParticleSystemType{
|
||||||
|
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;
|
||||||
|
int emissionRate;
|
||||||
|
int energyMax;
|
||||||
|
int energyVar;
|
||||||
|
bool relative;
|
||||||
|
bool fixed;
|
||||||
|
bool teamcolorNoEnergy;
|
||||||
|
bool teamcolorEnergy;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UnitParticleSystemType();
|
||||||
|
void load(const XmlNode *particleSystemNode, const string &dir);
|
||||||
|
void load(const string &dir, const string &path);
|
||||||
|
void setValues(UnitParticleSystem *uts);
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user