summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2010-03-04 22:54:06 +0100
committerBertram <bertram@cegetel.net>2010-03-04 22:54:06 +0100
commit500920393cd4a579c4d103b1fa8f4a3968d45a75 (patch)
tree10e581ef96ef4bc6a737192ff84cb43d630834ba
parent49dc599f6390fc427e19bd02a1f2e26f242700c8 (diff)
parenteefe244e276634d59d5e6b89217f5747bb2afd97 (diff)
downloadmana-500920393cd4a579c4d103b1fa8f4a3968d45a75.tar.gz
mana-500920393cd4a579c4d103b1fa8f4a3968d45a75.tar.bz2
mana-500920393cd4a579c4d103b1fa8f4a3968d45a75.tar.xz
mana-500920393cd4a579c4d103b1fa8f4a3968d45a75.zip
Merge branch 'master' of gitorious.org:mana/mana
-rw-r--r--src/map.cpp13
-rw-r--r--src/map.h4
-rw-r--r--src/particle.cpp9
-rw-r--r--src/particle.h6
-rw-r--r--src/particleemitter.cpp25
-rw-r--r--src/particleemitter.h6
-rw-r--r--src/resources/mapreader.cpp15
7 files changed, 72 insertions, 6 deletions
diff --git a/src/map.cpp b/src/map.cpp
index da3f2185..b1bd634b 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -778,17 +778,22 @@ Path Map::findPath(int startX, int startY, int destX, int destY,
return path;
}
-void Map::addParticleEffect(const std::string &effectFile, int x, int y)
+void Map::addParticleEffect(const std::string &effectFile, int x, int y, int w, int h)
{
ParticleEffectData newEffect;
newEffect.file = effectFile;
newEffect.x = x;
newEffect.y = y;
+ newEffect.w = w;
+ newEffect.h = h;
particleEffects.push_back(newEffect);
+
}
void Map::initializeParticleEffects(Particle *particleEngine)
{
+ Particle *p;
+
if (config.getValue("particleeffects", 1))
{
for (std::list<ParticleEffectData>::iterator i = particleEffects.begin();
@@ -796,7 +801,11 @@ void Map::initializeParticleEffects(Particle *particleEngine)
i++
)
{
- particleEngine->addEffect(i->file, i->x, i->y);
+ p = particleEngine->addEffect(i->file, i->x, i->y);
+ if (p && i->w > 0 && i->h > 0)
+ {
+ p->adjustEmitterSize(i->w, i->h);
+ }
}
}
}
diff --git a/src/map.h b/src/map.h
index 96bba296..9d5fe021 100644
--- a/src/map.h
+++ b/src/map.h
@@ -290,7 +290,7 @@ class Map : public Properties
/**
* Adds a particle effect
*/
- void addParticleEffect(const std::string &effectFile, int x, int y);
+ void addParticleEffect(const std::string &effectFile, int x, int y, int w = 0, int h = 0);
/**
* Initializes all added particle effects
@@ -367,6 +367,8 @@ class Map : public Properties
std::string file;
int x;
int y;
+ int w;
+ int h;
};
std::list<ParticleEffectData> particleEffects;
diff --git a/src/particle.cpp b/src/particle.cpp
index 560886f8..d3dbfd64 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -378,6 +378,15 @@ Particle *Particle::addTextRiseFadeOutEffect(const std::string &text,
return newParticle;
}
+void Particle::adjustEmitterSize(int w, int h)
+{
+ for (EmitterIterator e = mChildEmitters.begin();
+ e != mChildEmitters.end(); e++)
+ {
+ (*e)->adjustSize(w, h);
+ }
+}
+
void Particle::setMap(Map *map)
{
mMap = map;
diff --git a/src/particle.h b/src/particle.h
index c1e283d4..87360bec 100644
--- a/src/particle.h
+++ b/src/particle.h
@@ -250,6 +250,12 @@ class Particle : public Sprite
void setDieDistance(float dist)
{ mInvDieDistance = 1.0f / dist; }
+ /**
+ * Changes the size of the emitters so that the effect fills a
+ * rectangle of this size
+ */
+ void adjustEmitterSize(int w, int h);
+
bool isAlive()
{ return mAlive; }
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index ee434140..dc9931a5 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -474,3 +474,28 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick)
return newParticles;
}
+
+void ParticleEmitter::adjustSize(int w, int h)
+{
+ if (w == 0 || h == 0) return; // new dimensions are illegal
+
+ // calculate the old rectangle
+ int oldWidth = mParticlePosX.maxVal - mParticlePosX.minVal;
+ int oldHeight = mParticlePosX.maxVal - mParticlePosY.minVal;
+ int oldArea = oldWidth * oldHeight;
+ if (oldArea == 0)
+ {
+ //when the effect has no dimension it is
+ //not designed to be resizeable
+ return;
+ }
+
+ // set the new dimensions
+ mParticlePosX.set(0, w);
+ mParticlePosY.set(0, h);
+ int newArea = w * h;
+ // adjust the output so that the particle density stays the same
+ float outputFactor = (float)newArea / (float)oldArea;
+ mOutput.minVal *= outputFactor;
+ mOutput.maxVal *= outputFactor;
+}
diff --git a/src/particleemitter.h b/src/particleemitter.h
index 6c87755c..cc073c1c 100644
--- a/src/particleemitter.h
+++ b/src/particleemitter.h
@@ -73,6 +73,12 @@ class ParticleEmitter
void setTarget(Particle *target)
{ mParticleTarget = target; };
+ /**
+ * Changes the size of the emitter so that the effect fills a
+ * rectangle of this size
+ */
+ void adjustSize(int w, int h);
+
private:
template <typename T> ParticleEmitterProp<T> readParticleEmitterProp(xmlNodePtr propertyNode, T def);
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index e71ed5a6..d8678362 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -258,8 +258,9 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
std::string objType = XML::getProperty(objectNode, "type", "");
objType = toUpper(objType);
- if (objType == "WARP" || objType == "NPC" ||
- objType == "SCRIPT" || objType == "SPAWN")
+ if (objType == "NPC" ||
+ objType == "SCRIPT" ||
+ objType == "SPAWN")
{
// Silently skip server-side objects.
continue;
@@ -268,6 +269,8 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
const std::string objName = XML::getProperty(objectNode, "name", "");
const int objX = XML::getProperty(objectNode, "x", 0);
const int objY = XML::getProperty(objectNode, "y", 0);
+ const int objW = XML::getProperty(objectNode, "width", 0);
+ const int objH = XML::getProperty(objectNode, "height", 0);
logger->log("- Loading object name: %s type: %s at %d:%d",
objName.c_str(), objType.c_str(),
@@ -283,7 +286,13 @@ Map *MapReader::readMap(xmlNodePtr node, const std::string &path)
map->addParticleEffect(objName,
objX + offsetX,
- objY + offsetY);
+ objY + offsetY,
+ objW, objH);
+ }
+ else if (objType == "WARP")
+ {
+ map->addParticleEffect("graphics/particles/warparea.particle.xml",
+ objX, objY, objW, objH);
}
else
{