From 0550d06faffc1079ebec53c61aae1cfdd6e94fdb Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Tue, 16 Feb 2010 01:12:48 +0000 Subject: [PATCH] particles for te skills --- mk/linux/configure.ac | 2 +- source/g3d_viewer/main.cpp | 2 +- source/glest_game/facilities/game_util.cpp | 14 +- source/glest_game/graphics/particle_type.cpp | 2 +- source/glest_game/graphics/particle_type.h | 2 +- source/glest_game/graphics/renderer.cpp | 12 +- source/glest_game/type_instances/unit.cpp | 41 +++- source/glest_game/type_instances/unit.h | 5 +- source/glest_game/types/skill_type.cpp | 21 +- source/glest_game/types/skill_type.h | 7 +- source/shared_lib/include/graphics/particle.h | 62 +++++- .../shared_lib/sources/graphics/particle.cpp | 179 +++++++++++++++++- 12 files changed, 327 insertions(+), 22 deletions(-) diff --git a/mk/linux/configure.ac b/mk/linux/configure.ac index d5b0d2bd..ec06b014 100644 --- a/mk/linux/configure.ac +++ b/mk/linux/configure.ac @@ -4,7 +4,7 @@ #---------------------------------------------------------------------------- AC_PREREQ([2.54]) -AC_INIT([megaglest], [3.2.3], [matze@braunis.de]) +AC_INIT([megaglest], [3.2.4-1-beta2], [matze@braunis.de]) AC_CONFIG_SRCDIR([mk/jam/build.jam]) AC_CONFIG_AUX_DIR([mk/autoconf]) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 0fa79042..a0270fbd 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -19,7 +19,7 @@ namespace Shared{ namespace G3dViewer{ // class MainWindow // =============================================== -const string MainWindow::versionString= "v1.3.4"; +const string MainWindow::versionString= "v1.3.5-beta1"; const string MainWindow::winHeader= "G3D viewer " + versionString + " - Built: " + __DATE__; MainWindow::MainWindow(const string &modelPath): diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 19e3d765..564baab1 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -22,7 +22,7 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ const string mailString= "contact_game@glest.org"; -const string glestVersionString= "v3.2.4-4-beta1"; +const string glestVersionString= "v3.2.4-1-beta2"; string getCrashDumpFileName(){ return "glest"+glestVersionString+".dmp"; @@ -52,11 +52,11 @@ string getAboutString2(int i){ string getTeammateName(int i){ switch(i){ - case 0: return "Martiño Figueroa"; - case 1: return "José Luis González"; - case 2: return "Tucho Fernández"; - case 3: return "José Zanni"; - case 4: return "Félix Menéndez"; + case 0: return "Marti�o Figueroa"; + case 1: return "Jos� Luis Gonz�lez"; + case 2: return "Tucho Fern�ndez"; + case 3: return "Jos� Zanni"; + case 4: return "F�lix Men�ndez"; case 5: return "Marcos Caruncho"; case 6: return "Matthias Braun"; } diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 8a30e6f3..ecce0851 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2010-2010 Titus Tscharntke // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index 6cec6b2d..3bb71816 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 53be80a3..23005b46 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -1351,11 +1351,19 @@ void Renderer::renderUnits(){ const Model *model= unit->getCurrentModel(); model->updateInterpolationData(unit->getAnimProgress(), unit->isAlive()); modelRenderer->render(model); - triangleCount+= model->getTriangleCount(); pointCount+= model->getVertexCount(); glPopMatrix(); + if(unit->skillParticleSystem!=NULL){ + unit->skillParticleSystem->setVisible(true); + } + } + else + { + if(unit->skillParticleSystem!=NULL){ + unit->skillParticleSystem->setVisible(false); + } } } } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 6a50ce2d..0f830846 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -13,6 +13,7 @@ #include #include "unit.h" +#include "unit_particle_type.h" #include "world.h" #include "upgrade.h" #include "map.h" @@ -139,11 +140,12 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map if(getType()->getField(fLand)) currField=fLand; fire= NULL; + skillParticleSystem=NULL; computeTotalUpgrade(); //starting skill - currSkill= getType()->getFirstStOfClass(scStop); + this->currSkill=getType()->getFirstStOfClass(scStop); } Unit::~Unit(){ @@ -311,6 +313,22 @@ void Unit::setCurrSkill(const SkillType *currSkill){ if(currSkill->getClass()!=this->currSkill->getClass()){ animProgress= 0; lastAnimProgress= 0; + + if(skillParticleSystem!=NULL){ + skillParticleSystem->fade(); + skillParticleSystem=NULL; + } + } + if((currSkill->getParticleSystemType()!=NULL) + && (skillParticleSystem==NULL) ){ + UnitParticleSystemType *upst=currSkill->getParticleSystemType(); + UnitParticleSystem *ups; + ups= new UnitParticleSystem(200); + upst->setValues(ups); + ups->setPos(getCurrVector()); + ups->setTeamNumber(getTeam()); + skillParticleSystem= ups; + Renderer::getInstance().manageParticleSystem(ups, rsGame); } progress2= 0; this->currSkill= currSkill; @@ -588,6 +606,7 @@ bool Unit::update(){ float heightDiff= map->getCell(pos)->getHeight() - map->getCell(targetPos)->getHeight(); heightFactor= clamp(1.f+heightDiff/5.f, 0.2f, 5.f); } + //update progresses lastAnimProgress= animProgress; @@ -612,6 +631,16 @@ bool Unit::update(){ } } + if (fire!=NULL) + { + fire->setPos(getCurrVector()); + } + if (skillParticleSystem!=NULL) + { + skillParticleSystem->setPos(getCurrVector()); + skillParticleSystem->setRotation(getRotation()); + } + //checks if(animProgress>1.f){ animProgress= currSkill->getClass()==scDie? 1.f: 0.f; @@ -645,7 +674,11 @@ void Unit::tick(){ if(hp>type->getTotalMaxHp(&totalUpgrade)){ hp= type->getTotalMaxHp(&totalUpgrade); } - + //stop fire + if(hp>type->getTotalMaxHp(&totalUpgrade)/2 && fire!=NULL){ + fire->fade(); + fire= NULL; + } //regenerate ep ep+= type->getEpRegeneration(); if(ep>type->getTotalMaxEp(&totalUpgrade)){ @@ -685,7 +718,7 @@ bool Unit::repair(){ } //stop fire - if(hp>type->getMaxHp()/2 && fire!=NULL){ + if(hp>type->getTotalMaxHp(&totalUpgrade)/2 && fire!=NULL){ fire->fade(); fire= NULL; } diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 030d879c..2c68bd29 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -20,6 +20,7 @@ namespace Glest{ namespace Game{ using Shared::Graphics::ParticleSystem; +using Shared::Graphics::UnitParticleSystem; using Shared::Graphics::Vec4f; using Shared::Graphics::Vec2f; using Shared::Graphics::Vec3f; @@ -127,6 +128,7 @@ public: static const int maxDeadCount; static const float highlightTime; static const int invalidId; + UnitParticleSystem *skillParticleSystem; private: int id; @@ -207,6 +209,7 @@ public: float getRotation() const {return rotation;} float getVerticalRotation() const; ParticleSystem *getFire() const {return fire;} + UnitParticleSystem *getSkillParticleSystem() const {return skillParticleSystem;} int getKills() {return kills;} const Level *getLevel() const {return level;} const Level *getNextLevel() const; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index b7dd33d7..8c6e1baa 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -18,6 +18,7 @@ #include "lang.h" #include "renderer.h" #include "particle_type.h" +#include "unit_particle_type.h" #include "tech_tree.h" #include "faction_type.h" #include "leak_dumper.h" @@ -32,6 +33,8 @@ namespace Glest{ namespace Game{ // ===================================================== SkillType::~SkillType(){ + delete particleSystemType; + deleteValues(sounds.getSounds().begin(), sounds.getSounds().end()); } @@ -53,6 +56,22 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c animation= Renderer::getInstance().newModel(rsGame); animation->load(dir + "/" + path); + //particles + if(sn->hasChild("particle")){ + const XmlNode *particleNode= sn->getChild("particle"); + bool particleEnabled= particleNode->getAttribute("value")->getBoolValue(); + if(particleEnabled){ + string path= particleNode->getAttribute("path")->getRestrictedValue(); + particleSystemType= new UnitParticleSystemType(); + particleSystemType->load(dir, dir + "/" + path); + } + } + else + { + particleSystemType=NULL; + } + + //sound const XmlNode *soundNode= sn->getChild("sound"); if(soundNode->getAttribute("enabled")->getBoolValue()){ diff --git a/source/glest_game/types/skill_type.h b/source/glest_game/types/skill_type.h index e2935f16..fecf8a3f 100644 --- a/source/glest_game/types/skill_type.h +++ b/source/glest_game/types/skill_type.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -21,6 +21,7 @@ #include "element_type.h" #include "factory.h" #include "sound_container.h" +#include "particle.h" using Shared::Sound::StaticSound; using Shared::Xml::XmlNode; @@ -33,11 +34,13 @@ using Shared::Util::MultiFactory; class ParticleSystemTypeProjectile; class ParticleSystemTypeSplash; +class UnitParticleSystemType; class FactionType; class TechTree; class Lang; class TotalUpgrade; + enum Field{ fLand, fAir, @@ -77,6 +80,7 @@ protected: Model *animation; SoundContainer sounds; float soundStartTime; + UnitParticleSystemType *particleSystemType; public: //varios @@ -92,6 +96,7 @@ public: const Model *getAnimation() const {return animation;} StaticSound *getSound() const {return sounds.getRandSound();} float getSoundStartTime() const {return soundStartTime;} + UnitParticleSystemType *getParticleSystemType() const {return particleSystemType;} //other virtual string toString() const= 0; diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 5495cc68..031e27d7 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -27,6 +27,7 @@ namespace Shared{ namespace Graphics{ class ParticleSystem; class FireParticleSystem; +class UnitParticleSystem; class RainParticleSystem; class SnowParticleSystem; class ProjectileParticleSystem; @@ -187,6 +188,65 @@ public: void setWind(float windAngle, float windSpeed); }; +// ===================================================== +// class UnitParticleSystem +// ===================================================== + +class UnitParticleSystem: public ParticleSystem{ +private: + float radius; + Vec3f windSpeed; + Vec3f cRotation; + Vec3f fixedAddition; + Vec3f oldPosition; +public: + enum Primitive{ + pQuad, + pLine, + pLineAlpha + }; + bool relative; + bool fixed; + int teamNumber; + bool teamcolorNoEnergy; + bool teamcolorEnergy; + Model *model; + Primitive primitive; + Vec3f offset; + Vec3f direction; + float sizeNoEnergy; + float gravity; + float rotation; + +public: + UnitParticleSystem(int particleCount= 2000); + + //virtual + virtual void initParticle(Particle *p, int particleIndex); + virtual void updateParticle(Particle *p); + virtual void update(); + virtual void setTeamNumber(int teamNumber); + //virtual void render(ParticleRenderer *pr, ModelRenderer *mr); + + //set params + void setRadius(float radius); + void setWind(float windAngle, float windSpeed); + + void setOffset(Vec3f offset) {this->offset= offset;} + void setDirection(Vec3f direction) {this->direction= direction;} + void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} + void setGravity(float gravity) {this->gravity= gravity;} + void setRotation(float rotation) {this->rotation= rotation;} + void setRelative(bool relative) {this->relative= relative;} + void setFixed(bool fixed) {this->fixed= fixed;} + void setTeamcolorNoEnergy(bool teamcolorNoEnergy) {this->teamcolorNoEnergy= teamcolorNoEnergy;} + void setTeamcolorEnergy(bool teamcolorEnergy) {this->teamcolorEnergy= teamcolorEnergy;} + void setPrimitive(Primitive primitive) {this->primitive= primitive;} + + static Primitive strToPrimitive(const string &str); + +}; + // ===================================================== // class RainParticleSystem // ===================================================== diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 7460bc1f..bc07b838 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -276,6 +276,183 @@ void FireParticleSystem::setWind(float windAngle, float windSpeed){ this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed; } + +// =========================================================================== +// UnitParticleSystem +// =========================================================================== + +UnitParticleSystem::UnitParticleSystem(int particleCount): ParticleSystem(particleCount){ + + radius= 0.5f; + speed= 0.01f; + windSpeed= Vec3f(0.0f); + + setParticleSize(0.6f); + setColorNoEnergy(Vec4f(1.0f, 0.5f, 0.0f, 1.0f)); + + primitive= pQuad; + offset= Vec3f(0.0f); + direction= Vec3f(0.0f,1.0f,0.0f); + gravity= 0.0f; + + fixed=false; + teamcolorNoEnergy=false; + teamcolorEnergy=false; + rotation=0.0f; + + cRotation= Vec3f(1.0f,1.0f,1.0f); + fixedAddition = Vec3f(0.0f,0.0f,0.0f); + +} + +/*void UnitParticleSystem::render(ParticleRenderer *pr,ModelRenderer *mr){ + if(active){ + switch(primitive){ + case pQuad: + pr->renderSystem(this); + break; + case pLine: + pr->renderSystemLine(this); + break; + default: + assert(false); + } + } +}*/ + +UnitParticleSystem::Primitive UnitParticleSystem::strToPrimitive(const string &str){ + if(str=="quad"){ + return pQuad; + } + else if(str=="line"){ + return pLine; + } + else{ + throw "Unknown particle primitive: " + str; + } +} + + +void UnitParticleSystem::initParticle(Particle *p, int particleIndex){ + ParticleSystem::initParticle(p, particleIndex); + + float ang= random.randRange(-2.0f*pi, 2.0f*pi); + float mod= fabsf(random.randRange(-radius, radius)); + + float x= sinf(ang)*mod; + float y= cosf(ang)*mod; + + float radRatio= sqrtf(sqrtf(mod/radius)); + float rad=degToRad(rotation); + + //p->color= color*0.5f + color*0.5f*radRatio; + p->color=color; + p->energy= static_cast(maxParticleEnergy*radRatio) + random.randRange(-varParticleEnergy, varParticleEnergy); + + p->lastPos= pos; + oldPosition=pos; + p->size= particleSize; + p->speed= Vec3f(direction.x*speed+direction.x*speed*random.randRange(-0.5f, 0.5f), + direction.y*speed+direction.y*speed*random.randRange(-0.5f, 0.5f), + direction.z*speed+direction.z*speed*random.randRange(-0.5f, 0.5f)); + + if(relative){ + p->pos= Vec3f(pos.x+x+offset.x, pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+offset.z); + } + else + {// rotate it according to rotation + float rad=degToRad(rotation); + p->pos= Vec3f(pos.x+x+offset.x*cosf(rad)-offset.z*sinf(rad)*-1, pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+offset.z*cosf(rad)+offset.x*sinf(rad)); + p->speed=Vec3f(p->speed.x*cosf(rad)-p->speed.z*sinf(rad)*-1,p->speed.y,p->speed.z*cosf(rad)+p->speed.x*sinf(rad)); + }//p->pos=Vec3f(p->pos.x*cosf(rad)-p->pos.z*sinf(rad),p->pos.y,p->pos.z*cosf(rad)+p->pos.z*sinf(rad)); +} + +void UnitParticleSystem::update(){ + if(fixed) + { + fixedAddition= Vec3f(pos.x-oldPosition.x,pos.y-oldPosition.y,pos.z-oldPosition.z); + oldPosition=pos; + } + ParticleSystem::update(); +} + +void UnitParticleSystem::updateParticle(Particle *p){ + + float energyRatio= clamp(static_cast(p->energy)/maxParticleEnergy, 0.f, 1.f); + + p->lastPos+= p->speed; + p->pos+= p->speed; + if(fixed) + { + p->lastPos+= fixedAddition; + p->pos+= fixedAddition; + } + p->speed+= p->accel; + p->color = color * energyRatio + colorNoEnergy * (1.0f-energyRatio); + p->size = particleSize * energyRatio + sizeNoEnergy * (1.0f-energyRatio); + p->energy--; + + /* + p->lastPos= p->pos; + p->pos= p->pos+p->speed; + p->energy--; + + if(p->color.x>0.0f) + p->color.x*= 0.98f; + if(p->color.y>0.0f) + p->color.y*= 0.98f; + if(p->color.w>0.0f) + p->color.w*= 0.98f; + + p->speed.x*=1.001f; + */ + +} + +// ================= SET PARAMS ==================== + +void UnitParticleSystem::setRadius(float radius){ + this->radius= radius; +} + +void UnitParticleSystem::setWind(float windAngle, float windSpeed){ + this->windSpeed.x= sinf(degToRad(windAngle))*windSpeed; + this->windSpeed.y= 0.0f; + this->windSpeed.z= cosf(degToRad(windAngle))*windSpeed; +} + +void UnitParticleSystem::setTeamNumber(int teamNumber){ + this->teamNumber=teamNumber; + Vec3f tmpCol; + + if(teamNumber==0) + { + tmpCol=Vec3f(1,0,0); + } + else if(teamNumber==1) + { + tmpCol=Vec3f(0,0,1); + } + else if(teamNumber==2) + { + tmpCol=Vec3f(0,1,0); + } + else if(teamNumber==3) + { + tmpCol=Vec3f(1,1,0); + } + + if(teamcolorNoEnergy) + { + this->color=Vec4f(tmpCol.x,tmpCol.y,tmpCol.z,this->color.w); + } + if(teamcolorEnergy) + { + this->colorNoEnergy=Vec4f(tmpCol.x,tmpCol.y,tmpCol.z,this->colorNoEnergy.w); + } +} + + // =========================================================================== // RainParticleSystem // ===========================================================================