mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 10:54:01 +02:00
Fix for meshBound Particles
There was a bug if you used multiple units of the same type with mesh bound particles. The given model was the same for all units with the same unitType/skill.
This commit is contained in:
@@ -336,7 +336,7 @@ void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemTy
|
||||
upst->setValues(ups);
|
||||
ups->setPos(unit->getCurrVectorForParticlesystems());
|
||||
ups->setRotation(unit->getRotation());
|
||||
ups->setUnitModel(unit->getCurrentModelPtr());
|
||||
unit->setMeshPosInParticleSystem(ups);
|
||||
if (unit->getFaction()->getTexture()) {
|
||||
ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0));
|
||||
}
|
||||
@@ -2449,7 +2449,7 @@ void Unit::updateAttackBoostProgress(const Game* game) {
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(
|
||||
getCurrVectorForParticlesystems());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups);
|
||||
|
||||
if (getFaction()->getTexture()) {
|
||||
currentAttackBoostOriginatorEffect.
|
||||
@@ -2562,7 +2562,7 @@ void Unit::updateAttackBoostProgress(const Game* game) {
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(
|
||||
getCurrVectorForParticlesystems());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups);
|
||||
|
||||
if (getFaction()->getTexture()) {
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setFactionColor(
|
||||
@@ -2751,14 +2751,14 @@ bool Unit::update() {
|
||||
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
|
||||
(*it)->setPos(getCurrVectorForParticlesystems());
|
||||
(*it)->setRotation(getRotation());
|
||||
(*it)->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(*it);
|
||||
}
|
||||
}
|
||||
for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) {
|
||||
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
|
||||
(*it)->setPos(getCurrVectorForParticlesystems());
|
||||
(*it)->setRotation(getRotation());
|
||||
(*it)->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(*it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2766,7 +2766,7 @@ bool Unit::update() {
|
||||
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
|
||||
(*it)->setPos(getCurrMidHeightVector());
|
||||
(*it)->setRotation(getRotation());
|
||||
(*it)->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(*it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2778,7 +2778,7 @@ bool Unit::update() {
|
||||
if(particleValid == true) {
|
||||
effect->ups->setPos(getCurrVectorForParticlesystems());
|
||||
effect->ups->setRotation(getRotation());
|
||||
effect->ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(effect->ups);
|
||||
}
|
||||
|
||||
//printf("i = %d particleValid = %d\n",i,particleValid);
|
||||
@@ -2793,7 +2793,7 @@ bool Unit::update() {
|
||||
if(particleValid == true) {
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(getCurrVectorForParticlesystems());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
|
||||
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2850,7 +2850,7 @@ void Unit::updateTimedParticles() {
|
||||
pst->setValues(ups);
|
||||
ups->setPos(getCurrVectorForParticlesystems());
|
||||
ups->setRotation(getRotation());
|
||||
ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(ups);
|
||||
|
||||
if(getFaction()->getTexture()) {
|
||||
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
|
||||
@@ -2993,7 +2993,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) {
|
||||
effect->upst->setValues(effect->ups);
|
||||
effect->ups->setPos(getCurrVectorForParticlesystems());
|
||||
effect->ups->setRotation(getRotation());
|
||||
effect->ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(effect->ups);
|
||||
if(getFaction()->getTexture()) {
|
||||
effect->ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
|
||||
}
|
||||
@@ -4138,7 +4138,7 @@ void Unit::checkCustomizedUnitParticleListTriggers(const UnitParticleSystemTypes
|
||||
pst->setValues(ups);
|
||||
ups->setPos(getCurrVectorForParticlesystems());
|
||||
ups->setRotation(getRotation());
|
||||
ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(ups);
|
||||
if(getFaction()->getTexture()) {
|
||||
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
|
||||
}
|
||||
@@ -4168,6 +4168,36 @@ void Unit::queueTimedParticles(const UnitParticleSystemTypes &unitParticleSystem
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setMeshPosInParticleSystem(UnitParticleSystem *ups){
|
||||
if(ups->getMeshName()!=""){
|
||||
string meshName=ups->getMeshName();
|
||||
Model *model= getCurrentModelPtr();
|
||||
model->updateInterpolationVertices(getAnimProgressAsFloat(), isAlive() && !isAnimProgressBound());
|
||||
|
||||
bool foundMesh=false;
|
||||
for(unsigned int i=0; i<model->getMeshCount() ; i++){
|
||||
//printf("meshName=%s\n",unitModel->getMesh(i)->getName().c_str());
|
||||
if(model->getMesh(i)->getName()==meshName){
|
||||
const InterpolationData *data=model->getMesh(i)->getInterpolationData();
|
||||
const Vec3f *verticepos=data->getVertices();
|
||||
ups->setMeshPos(Vec3f(verticepos->x,verticepos->y,verticepos->z));
|
||||
foundMesh=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( foundMesh == false ) {
|
||||
string meshesFound="";
|
||||
for(unsigned i=0; i<model->getMeshCount() ; i++){
|
||||
meshesFound+= model->getMesh(i)->getName()+", ";
|
||||
}
|
||||
|
||||
string errorString = "Warning: Particle system is trying to find mesh'"+meshName+"', but just found:\n'"+meshesFound+"' in file:\n'"+model->getFileName()+"'\n";
|
||||
//throw megaglest_runtime_error(errorString);
|
||||
printf("%s",errorString.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::checkCustomizedUnitParticleTriggers() {
|
||||
if(currSkill != NULL) {
|
||||
checkCustomizedUnitParticleListTriggers(currSkill->unitParticleSystemTypes,false);
|
||||
@@ -4265,7 +4295,7 @@ void Unit::checkCustomizedParticleTriggers(bool force) {
|
||||
pst->setValues(ups);
|
||||
ups->setPos(getCurrVectorForParticlesystems());
|
||||
ups->setRotation(getRotation());
|
||||
ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(ups);
|
||||
if(getFaction()->getTexture()) {
|
||||
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
|
||||
}
|
||||
@@ -4296,7 +4326,7 @@ void Unit::startDamageParticles() {
|
||||
pst->setValues(ups);
|
||||
ups->setPos(getCurrVectorForParticlesystems());
|
||||
ups->setRotation(getRotation());
|
||||
ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(ups);
|
||||
if(getFaction()->getTexture()) {
|
||||
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
|
||||
}
|
||||
@@ -4329,7 +4359,7 @@ void Unit::startDamageParticles() {
|
||||
ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f));
|
||||
ups->setPos(getCurrBurnVector());
|
||||
ups->setRotation(getRotation());
|
||||
ups->setUnitModel(getCurrentModelPtr());
|
||||
setMeshPosInParticleSystem(ups);
|
||||
ups->setBlendMode(ups->strToBlendMode("black"));
|
||||
ups->setOffset(Vec3f(0,2,0));
|
||||
ups->setDirection(Vec3f(0,1,-0.2f));
|
||||
|
@@ -789,6 +789,7 @@ public:
|
||||
inline void setUsePathfinderExtendedMaxNodes(bool value) { usePathfinderExtendedMaxNodes = value; }
|
||||
|
||||
void updateTimedParticles();
|
||||
void setMeshPosInParticleSystem(UnitParticleSystem *ups);
|
||||
|
||||
virtual string getUniquePickName() const;
|
||||
void saveGame(XmlNode *rootNode);
|
||||
|
@@ -377,6 +377,7 @@ public:
|
||||
float gravity;
|
||||
float rotation;
|
||||
const Model *unitModel;
|
||||
Vec3f meshPos;
|
||||
string meshName;
|
||||
bool isVisibleAtNight;
|
||||
bool isVisibleAtDay;
|
||||
@@ -425,7 +426,8 @@ public:
|
||||
void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;}
|
||||
void setGravity(float gravity) {this->gravity= gravity;}
|
||||
void setRotation(float rotation);
|
||||
const void setUnitModel(const Model* unitModel) {this->unitModel= unitModel;}
|
||||
void setMeshPos(Vec3f meshPos) {this->meshPos=meshPos;}
|
||||
string getMeshName() {return meshName;}
|
||||
void setMeshName(string meshName) {this->meshName= meshName;}
|
||||
void setRelative(bool relative) {this->relative= relative;}
|
||||
void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;}
|
||||
|
@@ -1054,6 +1054,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) :
|
||||
endTime = 1;
|
||||
unitModel=NULL;
|
||||
meshName="";
|
||||
meshPos=Vec3f(0,0,0);
|
||||
|
||||
radiusBasedStartenergy = false;
|
||||
}
|
||||
@@ -1182,36 +1183,17 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
||||
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
||||
|
||||
}
|
||||
else {// rotate it according to rotation
|
||||
else {
|
||||
Vec3f combinedOffset=Vec3f(offset);
|
||||
if(meshName!="" && unitModel!=NULL){
|
||||
//printf("meshName set unitModel given\n");
|
||||
bool foundMesh=false;
|
||||
for(unsigned int i=0; i<unitModel->getMeshCount() ; i++){
|
||||
//printf("meshName=%s\n",unitModel->getMesh(i)->getName().c_str());
|
||||
if(unitModel->getMesh(i)->getName()==meshName){
|
||||
const InterpolationData *data=unitModel->getMesh(i)->getInterpolationData();
|
||||
const Vec3f *verticepos=data->getVertices();
|
||||
//printf("verticepos %f %f %f\n",verticepos->x,verticepos->y,verticepos->z);
|
||||
combinedOffset.x+=verticepos->x;
|
||||
combinedOffset.y+=verticepos->y;
|
||||
combinedOffset.z+=verticepos->z;
|
||||
foundMesh=true;
|
||||
break;
|
||||
if(meshName!=""){
|
||||
combinedOffset.x+=meshPos.x;
|
||||
combinedOffset.y+=meshPos.y;
|
||||
combinedOffset.z+=meshPos.z;
|
||||
if(meshPos.x==0 && meshPos.y==0 && meshPos.z==0) {
|
||||
printf("meshPosFail\n");
|
||||
}
|
||||
}
|
||||
if( foundMesh == false ) {
|
||||
string meshesFound="";
|
||||
for(unsigned i=0; i<unitModel->getMeshCount() ; i++){
|
||||
meshesFound+= unitModel->getMesh(i)->getName()+", ";
|
||||
}
|
||||
|
||||
string errorString = "Warning: Particle system is trying to find mesh'"+meshName+"', but just found:\n'"+meshesFound+"' in file:\n'"+unitModel->getFileName()+"'\n";
|
||||
//throw megaglest_runtime_error(errorString);
|
||||
printf("%s",errorString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// rotate it according to rotation
|
||||
#ifdef USE_STREFLOP
|
||||
p->pos= Vec3f(pos.x+x+combinedOffset.z*streflop::sinf(static_cast<streflop::Simple>(rad))+combinedOffset.x*streflop::cosf(static_cast<streflop::Simple>(rad)), pos.y+random.randRange(-radius/2, radius/2)+combinedOffset.y, pos.z+y+(combinedOffset.z*streflop::cosf(static_cast<streflop::Simple>(rad))-combinedOffset.x*streflop::sinf(static_cast<streflop::Simple>(rad))));
|
||||
#else
|
||||
@@ -1399,6 +1381,10 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
unitParticleSystemNode->addAttribute("fixedAddition",fixedAddition.getString(), mapTagReplacements);
|
||||
// Vec3f oldPosition;
|
||||
unitParticleSystemNode->addAttribute("oldPosition",oldPosition.getString(), mapTagReplacements);
|
||||
// Vec3f meshPos;
|
||||
unitParticleSystemNode->addAttribute("meshPos",meshPos.getString(), mapTagReplacements);
|
||||
// string meshName;
|
||||
unitParticleSystemNode->addAttribute("meshName",meshName, mapTagReplacements);
|
||||
// bool energyUp;
|
||||
unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements);
|
||||
// float startTime;
|
||||
@@ -1461,6 +1447,14 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
fixedAddition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue());
|
||||
// Vec3f oldPosition;
|
||||
oldPosition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue());
|
||||
// Vec3f meshPos;
|
||||
if(unitParticleSystemNode->hasAttribute("meshPos")){
|
||||
meshPos = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("meshPos")->getValue());
|
||||
}
|
||||
// Vec3f meshName;
|
||||
if(unitParticleSystemNode->hasAttribute("meshName")){
|
||||
meshName = unitParticleSystemNode->getAttribute("meshName")->getValue();
|
||||
}
|
||||
// bool energyUp;
|
||||
energyUp = unitParticleSystemNode->getAttribute("energyUp")->getIntValue() != 0;
|
||||
// float startTime;
|
||||
|
Reference in New Issue
Block a user