Merge pull request #24 from titison/feature/particle-speedUp
Feature/particle speed up
This commit is contained in:
commit
bf5125f1c6
|
@ -57,6 +57,8 @@ ParticleSystemType::ParticleSystemType() {
|
||||||
size=0;
|
size=0;
|
||||||
sizeNoEnergy=0;
|
sizeNoEnergy=0;
|
||||||
speed=0;
|
speed=0;
|
||||||
|
speedUpRelative=0;
|
||||||
|
speedUpConstant=0;
|
||||||
gravity=0;
|
gravity=0;
|
||||||
emissionRate=0;
|
emissionRate=0;
|
||||||
energyMax=0;
|
energyMax=0;
|
||||||
|
@ -107,6 +109,8 @@ void ParticleSystemType::copyAll(const ParticleSystemType &src) {
|
||||||
this->size = src.size;
|
this->size = src.size;
|
||||||
this->sizeNoEnergy = src.sizeNoEnergy;
|
this->sizeNoEnergy = src.sizeNoEnergy;
|
||||||
this->speed = src.speed;
|
this->speed = src.speed;
|
||||||
|
this->speedUpRelative = src.speedUpRelative;
|
||||||
|
this->speedUpConstant = src.speedUpConstant;
|
||||||
this->gravity = src.gravity;
|
this->gravity = src.gravity;
|
||||||
this->emissionRate = src.emissionRate;
|
this->emissionRate = src.emissionRate;
|
||||||
this->energyMax = src.energyMax;
|
this->energyMax = src.energyMax;
|
||||||
|
@ -220,6 +224,17 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
|
||||||
const XmlNode *speedNode= particleSystemNode->getChild("speed");
|
const XmlNode *speedNode= particleSystemNode->getChild("speed");
|
||||||
speed= speedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
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
|
//gravity
|
||||||
const XmlNode *gravityNode= particleSystemNode->getChild("gravity");
|
const XmlNode *gravityNode= particleSystemNode->getChild("gravity");
|
||||||
gravity= gravityNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
gravity= gravityNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps;
|
||||||
|
@ -300,6 +315,8 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
|
||||||
ats->setColor(color);
|
ats->setColor(color);
|
||||||
ats->setColorNoEnergy(colorNoEnergy);
|
ats->setColorNoEnergy(colorNoEnergy);
|
||||||
ats->setSpeed(speed);
|
ats->setSpeed(speed);
|
||||||
|
ats->setSpeedUpRelative(speedUpRelative);
|
||||||
|
ats->setSpeedUpConstant(speedUpConstant);
|
||||||
ats->setGravity(gravity);
|
ats->setGravity(gravity);
|
||||||
ats->setParticleSize(size);
|
ats->setParticleSize(size);
|
||||||
ats->setSizeNoEnergy(sizeNoEnergy);
|
ats->setSizeNoEnergy(sizeNoEnergy);
|
||||||
|
@ -328,6 +345,8 @@ void ParticleSystemType::loadGame(const XmlNode *rootNode) {
|
||||||
size = particleSystemTypeNode->getAttribute("size")->getFloatValue();
|
size = particleSystemTypeNode->getAttribute("size")->getFloatValue();
|
||||||
sizeNoEnergy = particleSystemTypeNode->getAttribute("sizeNoEnergy")->getFloatValue();
|
sizeNoEnergy = particleSystemTypeNode->getAttribute("sizeNoEnergy")->getFloatValue();
|
||||||
speed = particleSystemTypeNode->getAttribute("speed")->getFloatValue();
|
speed = particleSystemTypeNode->getAttribute("speed")->getFloatValue();
|
||||||
|
speedUpRelative = particleSystemTypeNode->getAttribute("speedUpRelative")->getFloatValue();
|
||||||
|
speedUpConstant = particleSystemTypeNode->getAttribute("speedUpConstant")->getFloatValue();
|
||||||
gravity = particleSystemTypeNode->getAttribute("gravity")->getFloatValue();
|
gravity = particleSystemTypeNode->getAttribute("gravity")->getFloatValue();
|
||||||
emissionRate = particleSystemTypeNode->getAttribute("emissionRate")->getFloatValue();
|
emissionRate = particleSystemTypeNode->getAttribute("emissionRate")->getFloatValue();
|
||||||
energyMax = particleSystemTypeNode->getAttribute("energyMax")->getIntValue();
|
energyMax = particleSystemTypeNode->getAttribute("energyMax")->getIntValue();
|
||||||
|
@ -379,6 +398,10 @@ void ParticleSystemType::saveGame(XmlNode *rootNode) {
|
||||||
particleSystemTypeNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements);
|
particleSystemTypeNode->addAttribute("sizeNoEnergy",floatToStr(sizeNoEnergy,6), mapTagReplacements);
|
||||||
// float speed;
|
// float speed;
|
||||||
particleSystemTypeNode->addAttribute("speed",floatToStr(speed,6), mapTagReplacements);
|
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;
|
// float gravity;
|
||||||
particleSystemTypeNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements);
|
particleSystemTypeNode->addAttribute("gravity",floatToStr(gravity,6), mapTagReplacements);
|
||||||
// float emissionRate;
|
// float emissionRate;
|
||||||
|
|
|
@ -65,6 +65,8 @@ protected:
|
||||||
float size;
|
float size;
|
||||||
float sizeNoEnergy;
|
float sizeNoEnergy;
|
||||||
float speed;
|
float speed;
|
||||||
|
float speedUpRelative;
|
||||||
|
float speedUpConstant;
|
||||||
float gravity;
|
float gravity;
|
||||||
float emissionRate;
|
float emissionRate;
|
||||||
int energyMax;
|
int energyMax;
|
||||||
|
|
|
@ -233,6 +233,8 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
|
||||||
ups->setColor(color);
|
ups->setColor(color);
|
||||||
ups->setColorNoEnergy(colorNoEnergy);
|
ups->setColorNoEnergy(colorNoEnergy);
|
||||||
ups->setSpeed(speed);
|
ups->setSpeed(speed);
|
||||||
|
ups->setSpeedUpRelative(speedUpRelative);
|
||||||
|
ups->setSpeedUpConstant(speedUpConstant);
|
||||||
ups->setGravity(gravity);
|
ups->setGravity(gravity);
|
||||||
ups->setParticleSize(size);
|
ups->setParticleSize(size);
|
||||||
ups->setSizeNoEnergy(sizeNoEnergy);
|
ups->setSizeNoEnergy(sizeNoEnergy);
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
Vec3f pos;
|
Vec3f pos;
|
||||||
Vec3f lastPos;
|
Vec3f lastPos;
|
||||||
Vec3f speed;
|
Vec3f speed;
|
||||||
|
float speedUpRelative;
|
||||||
|
Vec3f speedUpConstant;
|
||||||
Vec3f accel;
|
Vec3f accel;
|
||||||
Vec4f color;
|
Vec4f color;
|
||||||
float size;
|
float size;
|
||||||
|
@ -147,6 +149,8 @@ protected:
|
||||||
int varParticleEnergy;
|
int varParticleEnergy;
|
||||||
float particleSize;
|
float particleSize;
|
||||||
float speed;
|
float speed;
|
||||||
|
float speedUpRelative;
|
||||||
|
float speedUpConstant;
|
||||||
Vec3f factionColor;
|
Vec3f factionColor;
|
||||||
bool teamcolorNoEnergy;
|
bool teamcolorNoEnergy;
|
||||||
bool teamcolorEnergy;
|
bool teamcolorEnergy;
|
||||||
|
@ -192,6 +196,8 @@ public:
|
||||||
void setVarParticleEnergy(int varParticleEnergy);
|
void setVarParticleEnergy(int varParticleEnergy);
|
||||||
void setParticleSize(float particleSize);
|
void setParticleSize(float particleSize);
|
||||||
void setSpeed(float speed);
|
void setSpeed(float speed);
|
||||||
|
void setSpeedUpRelative(float speedUpRelative);
|
||||||
|
void setSpeedUpConstant(float speedUpConstant);
|
||||||
virtual void setActive(bool active);
|
virtual void setActive(bool active);
|
||||||
void setObserver(ParticleObserver *particleObserver);
|
void setObserver(ParticleObserver *particleObserver);
|
||||||
virtual void setVisible(bool visible);
|
virtual void setVisible(bool visible);
|
||||||
|
|
|
@ -50,6 +50,10 @@ void Particle::saveGame(XmlNode *rootNode) {
|
||||||
particleNode->addAttribute("lastPos",lastPos.getString(), mapTagReplacements);
|
particleNode->addAttribute("lastPos",lastPos.getString(), mapTagReplacements);
|
||||||
// Vec3f speed;
|
// Vec3f speed;
|
||||||
particleNode->addAttribute("speed",speed.getString(), mapTagReplacements);
|
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;
|
// Vec3f accel;
|
||||||
particleNode->addAttribute("accel",accel.getString(), mapTagReplacements);
|
particleNode->addAttribute("accel",accel.getString(), mapTagReplacements);
|
||||||
// Vec4f color;
|
// Vec4f color;
|
||||||
|
@ -70,6 +74,10 @@ void Particle::loadGame(const XmlNode *rootNode) {
|
||||||
lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue());
|
lastPos = Vec3f::strToVec3(particleNode->getAttribute("lastPos")->getValue());
|
||||||
// Vec3f speed;
|
// Vec3f speed;
|
||||||
speed = Vec3f::strToVec3(particleNode->getAttribute("speed")->getValue());
|
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;
|
// Vec3f accel;
|
||||||
accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue());
|
accel = Vec3f::strToVec3(particleNode->getAttribute("accel")->getValue());
|
||||||
// Vec4f color;
|
// Vec4f color;
|
||||||
|
@ -290,6 +298,16 @@ void ParticleSystem::setSpeed(float speed){
|
||||||
this->speed = truncateDecimal<float>(this->speed,6);
|
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){
|
void ParticleSystem::setActive(bool active){
|
||||||
this->active= active;
|
this->active= active;
|
||||||
for(int i=getChildCount()-1; i>=0; i--)
|
for(int i=getChildCount()-1; i>=0; i--)
|
||||||
|
@ -1114,6 +1132,7 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
||||||
p->lastPos= pos;
|
p->lastPos= pos;
|
||||||
oldPosition= pos;
|
oldPosition= pos;
|
||||||
p->size= particleSize;
|
p->size= particleSize;
|
||||||
|
p->speedUpRelative= speedUpRelative;
|
||||||
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
p->accel= Vec3f(0.0f, -gravity, 0.0f);
|
||||||
p->accel.x = truncateDecimal<float>(p->accel.x,6);
|
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,6);
|
||||||
|
@ -1228,6 +1247,8 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
||||||
} break;
|
} break;
|
||||||
default: throw megaglest_runtime_error("bad shape");
|
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(){
|
void UnitParticleSystem::update(){
|
||||||
|
@ -1299,6 +1320,8 @@ void UnitParticleSystem::updateParticle(Particle *p){
|
||||||
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
||||||
}
|
}
|
||||||
p->speed += p->accel;
|
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.x = truncateDecimal<float>(p->speed.x,6);
|
||||||
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
||||||
p->speed.z = truncateDecimal<float>(p->speed.z,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->energy= maxParticleEnergy;
|
||||||
p->size= particleSize;
|
p->size= particleSize;
|
||||||
p->color= color;
|
p->color= color;
|
||||||
|
p->speedUpRelative= speedUpRelative;
|
||||||
|
|
||||||
p->speed= Vec3f(horizontalSpreadA * random.randRange(-1.0f, 1.0f) + horizontalSpreadB, verticalSpreadA
|
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)
|
* 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.y = truncateDecimal<float>(p->accel.y,6);
|
||||||
p->accel.z = truncateDecimal<float>(p->accel.z,6);
|
p->accel.z = truncateDecimal<float>(p->accel.z,6);
|
||||||
|
|
||||||
|
p->speedUpConstant= Vec3f(speedUpConstant)*p->speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashParticleSystem::updateParticle(Particle *p){
|
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.y = truncateDecimal<float>(p->pos.y,6);
|
||||||
p->pos.z = truncateDecimal<float>(p->pos.z,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= p->speed + p->accel;
|
||||||
p->speed.x = truncateDecimal<float>(p->speed.x,6);
|
p->speed.x = truncateDecimal<float>(p->speed.x,6);
|
||||||
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
p->speed.y = truncateDecimal<float>(p->speed.y,6);
|
||||||
|
|
Loading…
Reference in New Issue