diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-05-14 18:03:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-14 18:05:55 +0300 |
commit | f03dfb3f143ee10329a10d093d6d31c1ab480007 (patch) | |
tree | 6ab0bfd9694e8bf6cb6e6cf45cf0fd065d18cf97 /src/particleemitter.cpp | |
parent | 750d3348b363716cf82136c337dac5da06bf5390 (diff) | |
download | manaplus-f03dfb3f143ee10329a10d093d6d31c1ab480007.tar.gz manaplus-f03dfb3f143ee10329a10d093d6d31c1ab480007.tar.bz2 manaplus-f03dfb3f143ee10329a10d093d6d31c1ab480007.tar.xz manaplus-f03dfb3f143ee10329a10d093d6d31c1ab480007.zip |
extend particle effects.
add new effect "subimage".
allow for "animation" and "rotation" use subimages.
Diffstat (limited to 'src/particleemitter.cpp')
-rw-r--r-- | src/particleemitter.cpp | 78 |
1 files changed, 68 insertions, 10 deletions
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 5e7fcb2c6..a90853cdf 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -112,6 +112,34 @@ ParticleEmitter::ParticleEmitter(const XmlNodePtr emitterNode, mParticleImage = resman->getImage(image); } } + else if (name == "subimage") + { + std::string image = XML::getProperty( + propertyNode, "value", ""); + // Don't leak when multiple images are defined + if (!image.empty() && !mParticleImage) + { + if (!dyePalettes.empty()) + Dye::instantiate(image, dyePalettes); + + ResourceManager *const resman + = ResourceManager::getInstance(); + Image *img = resman->getImage(image); + if (img) + { + mParticleImage = resman->getSubImage(img, + XML::getProperty(propertyNode, "x", 0), + XML::getProperty(propertyNode, "y", 0), + XML::getProperty(propertyNode, "width", 0), + XML::getProperty(propertyNode, "height", 0)); + img->decRef(); + } + else + { + mParticleImage = nullptr; + } + } + } else if (name == "horizontal-angle") { mParticleAngleHorizontal = @@ -210,11 +238,7 @@ ParticleEmitter::ParticleEmitter(const XmlNodePtr emitterNode, } else if (xmlNameEqual(propertyNode, "rotation")) { - ImageSet *const imageset = ResourceManager::getInstance() - ->getImageSet(XML::getProperty(propertyNode, "imageset", ""), - XML::getProperty(propertyNode, "width", 0), - XML::getProperty(propertyNode, "height", 0)); - + ImageSet *const imageset = getImageSet(propertyNode); if (!imageset) { logger->log1("Error: no valid imageset"); @@ -288,11 +312,7 @@ ParticleEmitter::ParticleEmitter(const XmlNodePtr emitterNode, } else if (xmlNameEqual(propertyNode, "animation")) { - ImageSet *const imageset = ResourceManager::getInstance() - ->getImageSet(XML::getProperty(propertyNode, "imageset", ""), - XML::getProperty(propertyNode, "width", 0), - XML::getProperty(propertyNode, "height", 0)); - + ImageSet *const imageset = getImageSet(propertyNode); if (!imageset) { logger->log1("Error: no valid imageset"); @@ -403,6 +423,44 @@ ParticleEmitter::ParticleEmitter(const ParticleEmitter &o) *this = o; } +ImageSet *ParticleEmitter::getImageSet(XmlNodePtr node) +{ + ResourceManager *const resman = ResourceManager::getInstance(); + ImageSet *imageset = nullptr; + const int subX = XML::getProperty(node, "subX", -1); + if (subX != -1) + { + Image *const img = resman->getImage(XML::getProperty( + node, "imageset", "")); + if (!img) + return nullptr; + + Image *const img2 = resman->getSubImage(img, subX, + XML::getProperty(node, "subY", 0), + XML::getProperty(node, "subWidth", 0), + XML::getProperty(node, "subHeight", 0)); + if (!img2) + { + img->decRef(); + return nullptr; + } + + imageset = resman->getSubImageSet(img2, + XML::getProperty(node, "width", 0), + XML::getProperty(node, "height", 0)); + img2->decRef(); + img->decRef(); + } + else + { + imageset = resman->getImageSet( + XML::getProperty(node, "imageset", ""), + XML::getProperty(node, "width", 0), + XML::getProperty(node, "height", 0)); + } + return imageset; +} + ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) { mParticlePosX = o.mParticlePosX; |