diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-23 02:16:53 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-23 02:16:53 +0000 |
commit | d83e795dc3c8a07238939ee0b581cbfd1807cf1b (patch) | |
tree | 5ce6c06c867c61fffe934a67b2636c6c7a9e8b79 /src | |
parent | 8d3e43a7510dd7367c3bb62aae6841836f727493 (diff) | |
download | Mana-d83e795dc3c8a07238939ee0b581cbfd1807cf1b.tar.gz Mana-d83e795dc3c8a07238939ee0b581cbfd1807cf1b.tar.bz2 Mana-d83e795dc3c8a07238939ee0b581cbfd1807cf1b.tar.xz Mana-d83e795dc3c8a07238939ee0b581cbfd1807cf1b.zip |
Particle images are now reference-counted properly. Avoided attempts to load "data/graphics/" when a monster or equipment piece has no sprite. Error placeholder is now used when attempting to load a sprite definition file that doesn't exist.
Diffstat (limited to 'src')
-rw-r--r-- | src/monster.cpp | 12 | ||||
-rw-r--r-- | src/particleemitter.cpp | 33 | ||||
-rw-r--r-- | src/particleemitter.h | 10 | ||||
-rw-r--r-- | src/player.cpp | 11 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 5 |
5 files changed, 66 insertions, 5 deletions
diff --git a/src/monster.cpp b/src/monster.cpp index 40b36849..779b4f56 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -35,8 +35,16 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): Being(id, job, map) { - mSprites[BASE_SPRITE] = AnimatedSprite::load( - "graphics/sprites/" + MonsterDB::get(job - 1002).getSprite()); + std::string filename = MonsterDB::get(job - 1002).getSprite(); + if (filename != "") + { + mSprites[BASE_SPRITE] = AnimatedSprite::load( + "graphics/sprites/" + filename); + } + else + { + mSprites[BASE_SPRITE] = AnimatedSprite::load("graphics/sprites/error.xml"); + } } void diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 035882b6..7a465ec3 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -237,9 +237,42 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * } } +ParticleEmitter::ParticleEmitter(const ParticleEmitter &o) +{ + *this = o; +} + +ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) +{ + mParticlePosX = o.mParticlePosX; + mParticlePosY = o.mParticlePosY; + mParticlePosZ = o.mParticlePosZ; + mParticleAngleHorizontal = o.mParticleAngleHorizontal; + mParticleAngleVertical = o.mParticleAngleVertical; + mParticlePower = o.mParticlePower; + mParticleGravity = o.mParticleGravity; + mParticleRandomnes = o.mParticleRandomnes; + mParticleBounce = o.mParticleBounce; + mParticleTarget = o.mParticleTarget; + mParticleAcceleration = o.mParticleAcceleration; + mParticleDieDistance = o.mParticleDieDistance; + mParticleMomentum = o.mParticleMomentum; + mParticleLifetime = o.mParticleLifetime; + mParticleFadeOut = o.mParticleFadeOut; + mParticleFadeIn = o.mParticleFadeIn; + mMap = o.mMap; + mOutput = o.mOutput; + mParticleImage = o.mParticleImage; + mParticleAnimation = o.mParticleAnimation; + mParticleChildEmitters = o.mParticleChildEmitters; + + if (mParticleImage) mParticleImage->incRef(); +} + ParticleEmitter::~ParticleEmitter() { + if (mParticleImage) mParticleImage->decRef(); } diff --git a/src/particleemitter.h b/src/particleemitter.h index 37d067a6..c9524488 100644 --- a/src/particleemitter.h +++ b/src/particleemitter.h @@ -48,6 +48,16 @@ class ParticleEmitter ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map); /** + * Copy Constructor (necessary for reference counting of particle images) + */ + ParticleEmitter(const ParticleEmitter &o); + + /** + * Assignment operator that calls the copy constructor + */ + ParticleEmitter & operator=(const ParticleEmitter &o); + + /** * Destructor. */ ~ParticleEmitter(); diff --git a/src/player.cpp b/src/player.cpp index a1a86587..3d8a8b6e 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -153,8 +153,15 @@ void Player::setSprite(int slot, int id, std::string color) } else { - AnimatedSprite *equipmentSprite = AnimatedSprite::load( - "graphics/sprites/" + ItemDB::get(id).getSprite(mGender) + "|" + color); + std::string filename = ItemDB::get(id).getSprite(mGender); + AnimatedSprite *equipmentSprite = NULL; + + if (filename != "") + { + if (color!="") filename += "|" + color; + equipmentSprite = AnimatedSprite::load( + "graphics/sprites/" + filename); + } if (equipmentSprite) equipmentSprite->setDirection(getSpriteDirection()); diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index de6f8d0b..ee823c3f 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -62,7 +62,10 @@ SpriteDef *SpriteDef::load(std::string const &animationFile, int variant) char *data = (char*) resman->loadFile (animationFile.substr(0, pos).c_str(), size); - if (!data) return NULL; + if (!data && animationFile != "graphics/sprites/error.xml") + { + return load("graphics/sprites/error.xml", 0); + } xmlDocPtr doc = xmlParseMemory(data, size); free(data); |