Unit and Splash particles can be speeded up.
You can set a constant value and a relative value.
This commit is contained in:
parent
6fc59dc5f2
commit
38ca1fd3f9
|
@ -57,6 +57,8 @@ ParticleSystemType::ParticleSystemType() {
|
|||
size=0;
|
||||
sizeNoEnergy=0;
|
||||
speed=0;
|
||||
speedUpRelative=0;
|
||||
speedUpConstant=0;
|
||||
gravity=0;
|
||||
emissionRate=0;
|
||||
energyMax=0;
|
||||
|
@ -107,6 +109,8 @@ void ParticleSystemType::copyAll(const ParticleSystemType &src) {
|
|||
this->size = src.size;
|
||||
this->sizeNoEnergy = src.sizeNoEnergy;
|
||||
this->speed = src.speed;
|
||||
this->speedUpRelative = src.speedUpRelative;
|
||||
this->speedUpConstant = src.speedUpConstant;
|
||||
this->gravity = src.gravity;
|
||||
this->emissionRate = src.emissionRate;
|
||||
this->energyMax = src.energyMax;
|
||||
|
@ -220,6 +224,17 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
|||
const XmlNode *speedNode= particleSystemNode->getChild("speed");
|
||||
speed= speedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
||||
|
||||
//speedUp
|
||||
if(particleSystemNode->hasChild("speedUp")){
|
||||
const XmlNode *speedUpNode= particleSystemNode->getChild("speedUp");
|
||||
if(speedUpNode->hasAttribute("relative")){
|
||||
speedUpRelative= speedUpNode->getAttribute("relative")->getFloatValue();
|
||||
}
|
||||
if(speedUpNode->hasAttribute("constant")){
|
||||
speedUpConstant= speedUpNode->getAttribute("constant")->getFloatValue();
|
||||
}
|
||||
}
|
||||
|
||||
//gravity
|
||||
const XmlNode *gravityNode= particleSystemNode->getChild("gravity");
|
||||
gravity= gravityNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
||||
|
@ -300,6 +315,8 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
|
|||
ats->setColor(color);
|
||||
ats->setColorNoEnergy(colorNoEnergy);
|
||||
ats->setSpeed(speed);
|
||||
ats->setSpeedUpRelative(speedUpRelative);
|
||||
ats->setSpeedUpConstant(speedUpConstant);
|
||||
ats->setGravity(gravity);
|
||||
ats->setParticleSize(size);
|
||||
ats->setSizeNoEnergy(sizeNoEnergy);
|
||||
|
@ -328,6 +345,8 @@ void ParticleSystemType::loadGame(const XmlNode *rootNode) {
|
|||
size = particleSystemTypeNode->getAttribute("size")->getFloatValue();
|
||||
sizeNoEnergy = particleSystemTypeNode->getAttribute("sizeNoEnergy")->getFloatValue();
|
||||
speed = particleSystemTypeNode->getAttribute("speed")->getFloatValue();
|
||||
speedUpRelative = particleSystemTypeNode->getAttribute("speedUpRelative")->getFloatValue();
|
||||
speedUpConstant = particleSystemTypeNode->getAttribute("speedUpConstant")->getFloatValue();
|
||||
gravity = particleSystemTypeNode->getAttribute("gravity")->getFloatValue();
|
||||
emissionRate = particleSystemTypeNode->getAttribute("emissionRate")->getFloatValue();
|
||||
energyMax = particleSystemTypeNode->getAttribute("energyMax")->getIntValue();
|
||||
|
@ -379,6 +398,10 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) {
|
|||
particleSystemTypeNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements);
|
||||
// float speed;
|
||||
particleSystemTypeNode->addAttribute("speed",floatToStr(speed,6), mapTagReplacements);
|
||||
// float speedUpRelative;
|
||||
particleSystemTypeNode->addAttribute("speedUpRelative",floatToStr(speedUpRelative,6), mapTagReplacements);
|
||||
// float speedUpConstant;
|
||||
particleSystemTypeNode->addAttribute("speedUpConstant",floatToStr(speedUpConstant,6), mapTagReplacements);
|
||||
// float gravity;
|
||||
particleSystemTypeNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements);
|
||||
// float emissionRate;
|
||||
|
|
|
@ -65,6 +65,8 @@ protected:
|
|||
float size;
|
||||
float sizeNoEnergy;
|
||||
float speed;
|
||||
float speedUpRelative;
|
||||
float speedUpConstant;
|
||||
float gravity;
|
||||
float emissionRate;
|
||||
int energyMax;
|
||||
|
|
|
@ -233,6 +233,8 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
|
|||
ups->setColor(color);
|
||||
ups->setColorNoEnergy(colorNoEnergy);
|
||||
ups->setSpeed(speed);
|
||||
ups->setSpeedUpRelative(speedUpRelative);
|
||||
ups->setSpeedUpConstant(speedUpConstant);
|
||||
ups->setGravity(gravity);
|
||||
ups->setParticleSize(size);
|
||||
ups->setSizeNoEnergy(sizeNoEnergy);
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
Vec3f pos;
|
||||
Vec3f lastPos;
|
||||
Vec3f speed;
|
||||
float speedUpRelative;
|
||||
Vec3f speedUpConstant;
|
||||
Vec3f accel;
|
||||
Vec4f color;
|
||||
float size;
|
||||
|
@ -147,6 +149,8 @@ protected:
|
|||
int varParticleEnergy;
|
||||
float particleSize;
|
||||
float speed;
|
||||
float speedUpRelative;
|
||||
float speedUpConstant;
|
||||
Vec3f factionColor;
|
||||
bool teamcolorNoEnergy;
|
||||
bool teamcolorEnergy;
|
||||
|
@ -192,6 +196,8 @@ public:
|
|||
void setVarParticleEnergy(int varParticleEnergy);
|
||||
void setParticleSize(float particleSize);
|
||||
void setSpeed(float speed);
|
||||
void setSpeedUpRelative(float speedUpRelative);
|
||||
void setSpeedUpConstant(float speedUpConstant);
|
||||
virtual void setActive(bool active);
|
||||
void setObserver(ParticleObserver *particleObserver);
|
||||
virtual void setVisible(bool visible);
|
||||
|
|
|
@ -50,6 +50,10 @@ void Particle::saveGame(XmlNode *rootNode) {
|
|||
particleNode->addAttribute("lastPos",lastPos.getString(), mapTagReplacements);
|
||||
// Vec3f speed;
|
||||
particleNode->addAttribute("speed",speed.getString(), mapTagReplacements);
|
||||
// Vec3f speedUpRelative;
|
||||
particleNode->addAttribute("speedUpRelative",floatToStr(speedUpRelative,6), mapTagReplacements);
|
||||
// Vec3f speedUpConstant;
|
||||
particleNode->addAttribute("speedUpConstant",speedUpConstant.getString(), mapTagReplacements);
|
||||
// Vec3f accel;
|
||||
particleNode->addAttribute("accel",accel.getString(), mapTagReplacements);
|
||||
// Vec4f color;
|
||||
|
@ -70,6 +74,10 @@ void Particle::loadGame(const XmlNode *rootNode) {
|
|||
lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue());
|
||||
// Vec3f speed;
|
||||
speed = Vec3f::strToVec3(particleNode->getAttribute("speed")->getValue());
|
||||
// Vec3f speed;
|
||||
speedUpRelative = particleNode->getAttribute("speedUpRelative")->getFloatValue();
|
||||
// Vec3f speed;
|
||||
speedUpConstant = Vec3f::strToVec3(particleNode->getAttribute("speedUpConstant")->getValue());
|
||||
// Vec3f accel;
|
||||
accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue());
|
||||
// Vec4f color;
|
||||
|
@ -290,6 +298,16 @@ void ParticleSystem::setSpeed(float speed){
|
|||
this->speed = truncateDecimal<float>(this->speed,6);
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeedUpRelative(float speedUpRelative){
|
||||
this->speedUpRelative= speedUpRelative;
|
||||
this->speedUpRelative = truncateDecimal<float>(this->speedUpRelative,6);
|
||||
}
|
||||
|
||||
void ParticleSystem::setSpeedUpConstant(float speedUpConstant){
|
||||
this->speedUpConstant= speedUpConstant;
|
||||
this->speedUpConstant = truncateDecimal<float>(this->speedUpConstant,6);
|
||||
}
|
||||
|
||||
void ParticleSystem::setActive(bool active){
|
||||
this->active= active;
|
||||
for(int i=getChildCount()-1; i>=0; i--)
|
||||
|
@ -1114,9 +1132,10 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
|||
p->lastPos= pos;
|
||||
oldPosition= pos;
|
||||
p->size= particleSize;
|
||||
p->speedUpRelative= speedUpRelative;
|
||||
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
||||
p->accel.x = truncateDecimal<float>(p->accel.x,6);
|
||||
p->accel.y = truncateDecimal<float>(p->accel.y,6);
|
||||
p->accel.y = truncateDecimal<float>(p->accel.y-gravity,6);
|
||||
p->accel.z = truncateDecimal<float>(p->accel.z,6);
|
||||
|
||||
// work out where we start for our shape (set speed and pos)
|
||||
|
@ -1228,6 +1247,8 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
|||
} break;
|
||||
default: throw megaglest_runtime_error("bad shape");
|
||||
}
|
||||
//need to do that down here because we need p->speed for it.
|
||||
p->speedUpConstant= Vec3f(speedUpConstant)*p->speed;
|
||||
}
|
||||
|
||||
void UnitParticleSystem::update(){
|
||||
|
@ -1299,6 +1320,8 @@ void UnitParticleSystem::updateParticle(Particle *p){
|
|||
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
||||
}
|
||||
p->speed += p->accel;
|
||||
p->speed += p->speedUpConstant;
|
||||
p->speed=p->speed*(1+p->speedUpRelative);
|
||||
p->speed.x = truncateDecimal<float>(p->speed.x,6);
|
||||
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
||||
p->speed.z = truncateDecimal<float>(p->speed.z,6);
|
||||
|
@ -2220,6 +2243,7 @@ void SplashParticleSystem::initParticle(Particle *p, int particleIndex){
|
|||
p->energy= maxParticleEnergy;
|
||||
p->size= particleSize;
|
||||
p->color= color;
|
||||
p->speedUpRelative= speedUpRelative;
|
||||
|
||||
p->speed= Vec3f(horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB, verticalSpreadA
|
||||
* random.randRange(-1.0f, 1.0f) + verticalSpreadB, horizontalSpreadA * random.randRange(-1.0f, 1.0f)
|
||||
|
@ -2243,6 +2267,7 @@ void SplashParticleSystem::initParticle(Particle *p, int particleIndex){
|
|||
p->accel.y = truncateDecimal<float>(p->accel.y,6);
|
||||
p->accel.z = truncateDecimal<float>(p->accel.z,6);
|
||||
|
||||
p->speedUpConstant= Vec3f(speedUpConstant)*p->speed;
|
||||
}
|
||||
|
||||
void SplashParticleSystem::updateParticle(Particle *p){
|
||||
|
@ -2254,6 +2279,8 @@ void SplashParticleSystem::updateParticle(Particle *p){
|
|||
p->pos.y = truncateDecimal<float>(p->pos.y,6);
|
||||
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
||||
|
||||
p->speed += p->speedUpConstant;
|
||||
p->speed=p->speed*(1+p->speedUpRelative);
|
||||
p->speed= p->speed + p->accel;
|
||||
p->speed.x = truncateDecimal<float>(p->speed.x,6);
|
||||
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
||||
|
|
Loading…
Reference in New Issue