summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-22 21:47:53 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-22 21:47:53 +0200
commitba5b70974c5dfa0be3105e72a0a012455b28e7a9 (patch)
treeb79f9f46cc30eb2a1196b79392831af144fabc22 /src
parent852ff45c35c422b5264487669934b392a8657465 (diff)
downloadmana-ba5b70974c5dfa0be3105e72a0a012455b28e7a9.tar.gz
mana-ba5b70974c5dfa0be3105e72a0a012455b28e7a9.tar.bz2
mana-ba5b70974c5dfa0be3105e72a0a012455b28e7a9.tar.xz
mana-ba5b70974c5dfa0be3105e72a0a012455b28e7a9.zip
Made possible to separate the dye colors and channels
for particle effects. It is now possible to write, for instance: <particlefx>my-particle-file.xml|#cbcb78,345678</particlefx> and in my-particle-file.xml: ... <property image="my-image.png|W" /> ... This will permit the use (and reuse) of generic particle files.
Diffstat (limited to 'src')
-rw-r--r--src/animationparticle.cpp5
-rw-r--r--src/animationparticle.h3
-rw-r--r--src/particle.cpp20
-rw-r--r--src/particleemitter.cpp11
-rw-r--r--src/particleemitter.h4
-rw-r--r--src/rotationalparticle.cpp5
-rw-r--r--src/rotationalparticle.h3
-rw-r--r--src/simpleanimation.cpp16
-rw-r--r--src/simpleanimation.h6
9 files changed, 53 insertions, 20 deletions
diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp
index 392dc4f4..eb97637c 100644
--- a/src/animationparticle.cpp
+++ b/src/animationparticle.cpp
@@ -30,9 +30,10 @@ AnimationParticle::AnimationParticle(Map *map, Animation *animation):
{
}
-AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode):
+AnimationParticle::AnimationParticle(Map *map, xmlNodePtr animationNode,
+ const std::string& dyePalettes):
ImageParticle(map, 0),
- mAnimation(new SimpleAnimation(animationNode))
+ mAnimation(new SimpleAnimation(animationNode, dyePalettes))
{
}
diff --git a/src/animationparticle.h b/src/animationparticle.h
index 0837fec6..0cd6b328 100644
--- a/src/animationparticle.h
+++ b/src/animationparticle.h
@@ -35,7 +35,8 @@ class AnimationParticle : public ImageParticle
public:
AnimationParticle(Map *map, Animation *animation);
- AnimationParticle(Map *map, xmlNodePtr animationNode);
+ AnimationParticle(Map *map, xmlNodePtr animationNode,
+ const std::string& dyePalettes = std::string());
~AnimationParticle();
diff --git a/src/particle.cpp b/src/particle.cpp
index f147a9f2..4d6882be 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -24,6 +24,7 @@
#include "animationparticle.h"
#include "configuration.h"
+#include "resources/dye.h"
#include "imageparticle.h"
#include "log.h"
#include "map.h"
@@ -280,7 +281,12 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
{
Particle *newParticle = NULL;
- XML::Document doc(particleEffectFile);
+ std::string::size_type pos = particleEffectFile.find('|');
+ std::string dyePalettes;
+ if (pos != std::string::npos)
+ dyePalettes = particleEffectFile.substr(pos + 1);
+
+ XML::Document doc(particleEffectFile.substr(0, pos));
xmlNodePtr rootNode = doc.rootNode();
if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect"))
@@ -304,18 +310,20 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
// Animation
if ((node = XML::findFirstChildByName(effectChildNode, "animation")))
{
- newParticle = new AnimationParticle(mMap, node);
+ newParticle = new AnimationParticle(mMap, node, dyePalettes);
}
// Rotational
else if ((node = XML::findFirstChildByName(effectChildNode, "rotation")))
{
- newParticle = new RotationalParticle(mMap, node);
+ newParticle = new RotationalParticle(mMap, node, dyePalettes);
}
// Image
else if ((node = XML::findFirstChildByName(effectChildNode, "image")))
{
- Image *img= resman->getImage((const char*)
- node->xmlChildrenNode->content);
+ std::string imageSrc = (const char*)node->xmlChildrenNode->content;
+ if (!imageSrc.empty() && !dyePalettes.empty())
+ Dye::instantiate(imageSrc, dyePalettes);
+ Image *img= resman->getImage(imageSrc);
newParticle = new ImageParticle(mMap, img);
}
@@ -346,7 +354,7 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
{
ParticleEmitter *newEmitter;
newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
- rotation);
+ rotation, dyePalettes);
newParticle->addEmitter(newEmitter);
}
else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect"))
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index 32b63c9e..bfeaa139 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -26,6 +26,7 @@
#include "particleemitter.h"
#include "rotationalparticle.h"
+#include "resources/dye.h"
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
@@ -36,7 +37,9 @@
#define SIN45 0.707106781f
#define DEG_RAD_FACTOR 0.017453293f
-ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map, int rotation):
+ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
+ Map *map, int rotation,
+ const std::string& dyePalettes):
mOutputPauseLeft(0),
mParticleImage(0)
{
@@ -95,6 +98,9 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
// Don't leak when multiple images are defined
if (!image.empty() && !mParticleImage)
{
+ if (!dyePalettes.empty())
+ Dye::instantiate(image, dyePalettes);
+
ResourceManager *resman = ResourceManager::getInstance();
mParticleImage = resman->getImage(image);
}
@@ -183,7 +189,8 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
}
else if (xmlStrEqual(propertyNode->name, BAD_CAST "emitter"))
{
- ParticleEmitter newEmitter(propertyNode, mParticleTarget, map);
+ ParticleEmitter newEmitter(propertyNode, mParticleTarget, map,
+ rotation, dyePalettes);
mParticleChildEmitters.push_back(newEmitter);
}
else if (xmlStrEqual(propertyNode->name, BAD_CAST "rotation"))
diff --git a/src/particleemitter.h b/src/particleemitter.h
index 2dd6665e..3d46e5c8 100644
--- a/src/particleemitter.h
+++ b/src/particleemitter.h
@@ -41,7 +41,9 @@ class Particle;
class ParticleEmitter
{
public:
- ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map, int rotation = 0);
+ ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map,
+ int rotation = 0,
+ const std::string& dyePalettes = std::string());
/**
* Copy Constructor (necessary for reference counting of particle images)
diff --git a/src/rotationalparticle.cpp b/src/rotationalparticle.cpp
index 6c414cdb..e1d4824c 100644
--- a/src/rotationalparticle.cpp
+++ b/src/rotationalparticle.cpp
@@ -31,9 +31,10 @@ RotationalParticle::RotationalParticle(Map *map, Animation *animation):
{
}
-RotationalParticle::RotationalParticle(Map *map, xmlNodePtr animationNode):
+RotationalParticle::RotationalParticle(Map *map, xmlNodePtr animationNode,
+ const std::string& dyePalettes):
ImageParticle(map, 0),
- mAnimation(new SimpleAnimation(animationNode))
+ mAnimation(new SimpleAnimation(animationNode, dyePalettes))
{
}
diff --git a/src/rotationalparticle.h b/src/rotationalparticle.h
index 535cfb58..ce15499d 100644
--- a/src/rotationalparticle.h
+++ b/src/rotationalparticle.h
@@ -35,7 +35,8 @@ class RotationalParticle : public ImageParticle
public:
RotationalParticle(Map *map, Animation *animation);
- RotationalParticle(Map *map, xmlNodePtr animationNode);
+ RotationalParticle(Map *map, xmlNodePtr animationNode,
+ const std::string& dyePalettes = std::string());
~RotationalParticle();
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 24a17ce7..c6dc1efe 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -26,6 +26,7 @@
#include "log.h"
#include "resources/animation.h"
+#include "resources/dye.h"
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
@@ -39,13 +40,14 @@ SimpleAnimation::SimpleAnimation(Animation *animation):
{
}
-SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode):
+SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode,
+ const std::string& dyePalettes):
mAnimation(new Animation),
mAnimationTime(0),
mAnimationPhase(0),
mInitialized(false)
{
- initializeAnimation(animationNode);
+ initializeAnimation(animationNode, dyePalettes);
mCurrentFrame = mAnimation->getFrame(0);
}
@@ -116,13 +118,21 @@ Image *SimpleAnimation::getCurrentImage() const
return NULL;
}
-void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode)
+void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode,
+ const std::string& dyePalettes)
{
mInitialized = false;
if (!animationNode)
return;
+ std::string imagePath = XML::getProperty(animationNode,
+ "imageset", "");
+
+ // Instanciate the dye coloration.
+ if (!imagePath.empty() && !dyePalettes.empty())
+ Dye::instantiate(imagePath, dyePalettes);
+
ImageSet *imageset = ResourceManager::getInstance()->getImageSet(
XML::getProperty(animationNode, "imageset", ""),
XML::getProperty(animationNode, "width", 0),
diff --git a/src/simpleanimation.h b/src/simpleanimation.h
index e679442e..b3b21ee2 100644
--- a/src/simpleanimation.h
+++ b/src/simpleanimation.h
@@ -45,7 +45,8 @@ class SimpleAnimation
/**
* Creates a simple animation that creates its animation from XML Data.
*/
- SimpleAnimation(xmlNodePtr animationNode);
+ SimpleAnimation(xmlNodePtr animationNode,
+ const std::string& dyePalettes = std::string());
~SimpleAnimation();
@@ -65,7 +66,8 @@ class SimpleAnimation
Image *getCurrentImage() const;
private:
- void initializeAnimation(xmlNodePtr animationNode);
+ void initializeAnimation(xmlNodePtr animationNode,
+ const std::string& dyePalettes = std::string());
/** The hosted animation. */
Animation *mAnimation;