diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-14 01:46:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-14 01:52:42 +0300 |
commit | c0a5fffb45f849e224750f27fa8c3be5ac447ad6 (patch) | |
tree | 1fcac5e9836e119970acae9c5702ac83f40a935f | |
parent | 1c62988a9e7ed1038250a2d044889eda046500c5 (diff) | |
download | mv-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.gz mv-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.bz2 mv-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.tar.xz mv-c0a5fffb45f849e224750f27fa8c3be5ac447ad6.zip |
Add more checks.
Fix error in event.cpp from last commits.
Improve party members sorting.
-rw-r--r-- | src/event.cpp | 2 | ||||
-rw-r--r-- | src/mumblemanager.cpp | 2 | ||||
-rw-r--r-- | src/openglgraphics.cpp | 3 | ||||
-rw-r--r-- | src/particle.cpp | 10 | ||||
-rw-r--r-- | src/particle.h | 2 | ||||
-rw-r--r-- | src/particlecontainer.cpp | 1 | ||||
-rw-r--r-- | src/particleemitter.cpp | 9 | ||||
-rw-r--r-- | src/particleemitterprop.h | 2 | ||||
-rw-r--r-- | src/party.cpp | 52 | ||||
-rw-r--r-- | src/playerrelations.cpp | 11 | ||||
-rw-r--r-- | src/resources/animation.h | 6 | ||||
-rw-r--r-- | src/rotationalparticle.cpp | 5 | ||||
-rw-r--r-- | src/shopitem.cpp | 4 |
13 files changed, 68 insertions, 41 deletions
diff --git a/src/event.cpp b/src/event.cpp index 6913e8660..7eaf8aea6 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -78,7 +78,7 @@ const std::string &Event::getString(const std::string &key) if (it == mData.end()) throw BAD_KEY; - if (!! it->second || it->second->getType() != VariableData::DATA_STRING) + if (!it->second || it->second->getType() != VariableData::DATA_STRING) throw BAD_VALUE; return static_cast<StringData *>(it->second)->getData(); diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index bace077cd..2b3f15afa 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -188,7 +188,7 @@ void MumbleManager::setAction(int action) case 3: /* SIT */ mLinkedMemCache.fAvatarPosition[1] = 1.0f; break; - case 4: /* DEAD */ + case 4: /* DEAD */ default: mLinkedMemCache.fAvatarPosition[1] = 0.0f; break; diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 332f79823..03d38e7e2 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -1023,6 +1023,9 @@ SDL_Surface* OpenGLGraphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); + if (!screenshot) + return 0; + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); diff --git a/src/particle.cpp b/src/particle.cpp index 7d7a73e9a..874e49d9a 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -95,6 +95,8 @@ void Particle::setupEngine() Particle::maxCount = config.getIntValue("particleMaxCount"); Particle::fastPhysics = config.getIntValue("particleFastPhysics"); Particle::emitterSkip = config.getIntValue("particleEmitterSkip") + 1; + if (!Particle::emitterSkip) + Particle::emitterSkip = 1; Particle::enabled = config.getBoolValue("particleeffects"); disableAutoDelete(); logger->log1("Particle engine set up"); @@ -200,11 +202,11 @@ bool Particle::update() // Update child emitters if ((mLifetimePast - 1) % Particle::emitterSkip == 0) { - for (EmitterIterator e = mChildEmitters.begin(); + for (EmitterConstIterator e = mChildEmitters.begin(); e != mChildEmitters.end(); ++e) { Particles newParticles = (*e)->createParticles(mLifetimePast); - for (ParticleIterator p = newParticles.begin(); + for (ParticleConstIterator p = newParticles.begin(); p != newParticles.end(); ++p) { (*p)->moveBy(mPos); @@ -258,7 +260,7 @@ bool Particle::update() void Particle::moveBy(const Vector &change) { mPos += change; - for (ParticleIterator p = mChildParticles.begin(); + for (ParticleConstIterator p = mChildParticles.begin(); p != mChildParticles.end(); ++p) { if ((*p)->doesFollow()) @@ -451,7 +453,7 @@ void Particle::adjustEmitterSize(int w, int h) { if (mAllowSizeAdjust) { - for (EmitterIterator e = mChildEmitters.begin(); + for (EmitterConstIterator e = mChildEmitters.begin(); e != mChildEmitters.end(); ++e) { (*e)->adjustSize(w, h); diff --git a/src/particle.h b/src/particle.h index c2b33cc52..c360a5e94 100644 --- a/src/particle.h +++ b/src/particle.h @@ -42,8 +42,10 @@ class ParticleEmitter; typedef std::list<Particle *> Particles; typedef Particles::iterator ParticleIterator; +typedef Particles::const_iterator ParticleConstIterator; typedef std::list<ParticleEmitter *> Emitters; typedef Emitters::iterator EmitterIterator; +typedef Emitters::const_iterator EmitterConstIterator; /** * A particle spawned by a ParticleEmitter. diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index 686390474..5f5b1b257 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -187,4 +187,3 @@ void ParticleVector::moveTo(float x, float y) } } } - diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 9cad0864f..1add452a0 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -225,11 +225,6 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, int offsetX = XML::getProperty(frameNode, "offsetX", 0); int offsetY = XML::getProperty(frameNode, "offsetY", 0); int rand = XML::getProperty(frameNode, "rand", 100); - if (!imageset) - { - logger->log1("Error: no valid imageset"); - continue; - } offsetY -= imageset->getHeight() - 32; offsetX -= imageset->getWidth() / 2 - 16; @@ -532,12 +527,12 @@ std::list<Particle *> ParticleEmitter::createParticles(int tick) newParticle = new ImageParticle(mMap, mParticleImage); } - else if (mParticleRotation.getLength() > 0) + else if (!mParticleRotation.empty()) { Animation *newAnimation = new Animation(mParticleRotation); newParticle = new RotationalParticle(mMap, newAnimation); } - else if (mParticleAnimation.getLength() > 0) + else if (!mParticleAnimation.empty()) { Animation *newAnimation = new Animation(mParticleAnimation); newParticle = new AnimationParticle(mMap, newAnimation); diff --git a/src/particleemitterprop.h b/src/particleemitterprop.h index 5b0b22e4f..76c855e4f 100644 --- a/src/particleemitterprop.h +++ b/src/particleemitterprop.h @@ -60,6 +60,8 @@ template <typename T> struct ParticleEmitterProp changeFunc = func; changeAmplitude = amplitude; changePeriod = period; + if (!changePeriod) + changePeriod = 1; changePhase = phase; } diff --git a/src/party.cpp b/src/party.cpp index 9da1a235d..f561ca49f 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -25,6 +25,8 @@ #include "debug.h" +#include "utils/stringutils.h" + class SortPartyFunctor { public: @@ -37,7 +39,15 @@ class SortPartyFunctor if (p2->getLeader()) return false; - return p1->getName() < p2->getName(); + if (p1->getName() != p2->getName()) + { + std::string s1 = p1->getName(); + std::string s2 = p2->getName(); + toLower(s1); + toLower(s2); + return s1 < s2; + } + return false; } } partySorter; @@ -94,7 +104,7 @@ PartyMember *Party::getMember(const std::string &name) const itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) return (*itr); ++itr; @@ -116,7 +126,7 @@ void Party::removeMember(PartyMember *member) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == member->mId && + if ((*itr) && (*itr)->mId == member->mId && (*itr)->getName() == member->getName()) { PartyMember *m = (*itr); @@ -140,7 +150,7 @@ void Party::removeMember(int id) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == id) + if ((*itr) && (*itr)->mId == id) { PartyMember *member = (*itr); mMembers.erase(itr); @@ -163,7 +173,7 @@ void Party::removeMember(const std::string &name) itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) { PartyMember *member = (*itr); mMembers.erase(itr); @@ -213,11 +223,11 @@ bool Party::isMember(PartyMember *member) const if (member->mParty > 0 && member->mParty != this) return false; - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == member->mId && + if ((*itr) && (*itr)->mId == member->mId && (*itr)->getName() == member->getName()) { return true; @@ -230,11 +240,11 @@ bool Party::isMember(PartyMember *member) const bool Party::isMember(int id) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->mId == id) + if ((*itr) && (*itr)->mId == id) return true; ++itr; } @@ -244,11 +254,11 @@ bool Party::isMember(int id) const bool Party::isMember(const std::string &name) const { - MemberList::const_iterator itr = mMembers.begin(), - itr_end = mMembers.end(); + MemberList::const_iterator itr = mMembers.begin(); + MemberList::const_iterator itr_end = mMembers.end(); while (itr != itr_end) { - if ((*itr)->getName() == name) + if ((*itr) && (*itr)->getName() == name) return true; ++itr; } @@ -259,11 +269,12 @@ bool Party::isMember(const std::string &name) const void Party::getNames(std::vector<std::string> &names) const { names.clear(); - MemberList::const_iterator it = mMembers.begin(), - it_end = mMembers.end(); + MemberList::const_iterator it = mMembers.begin(); + MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { - names.push_back((*it)->getName()); + if (*it) + names.push_back((*it)->getName()); ++it; } } @@ -271,11 +282,12 @@ void Party::getNames(std::vector<std::string> &names) const void Party::getNamesSet(std::set<std::string> &names) const { names.clear(); - MemberList::const_iterator it = mMembers.begin(), - it_end = mMembers.end(); + MemberList::const_iterator it = mMembers.begin(); + MemberList::const_iterator it_end = mMembers.end(); while (it != it_end) { - names.insert((*it)->getName()); + if (*it) + names.insert((*it)->getName()); ++it; } } diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 8af37aa7d..00a9d1cad 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -67,7 +67,7 @@ class PlayerConfSerialiser : std::pair<std::string, PlayerRelation *> value, ConfigurationObject *cobj) { - if (!value.second) + if (!cobj || !value.second) return NULL; cobj->setValue(NAME, value.first); cobj->setValue(RELATION, toString( @@ -80,6 +80,8 @@ class PlayerConfSerialiser : readConfigItem(ConfigurationObject *cobj, std::map<std::string, PlayerRelation *> *container) { + if (!cobj) + return container; std::string name = cobj->getValue(NAME, ""); if (name.empty()) return container; @@ -154,6 +156,9 @@ int PlayerRelationsManager::getPlayerIgnoreStrategyIndex( std::vector<PlayerIgnoreStrategy *> *strategies = getPlayerIgnoreStrategies(); + if (!strategies) + return -1; + for (unsigned int i = 0; i < strategies->size(); i++) { if ((*strategies)[i]->mShortName == name) @@ -231,8 +236,6 @@ void PlayerRelationsManager::store() void PlayerRelationsManager::signalUpdate(const std::string &name) { -// store(); - for (std::list<PlayerRelationsListener *>::const_iterator it = mListeners.begin(); it != mListeners.end(); ++it) { @@ -322,7 +325,7 @@ void PlayerRelationsManager::setRelation(const std::string &player_name, PlayerRelation::Relation relation) { PlayerRelation *r = mRelations[player_name]; - if (r == NULL) + if (!r) mRelations[player_name] = new PlayerRelation(relation); else r->mRelation = relation; diff --git a/src/resources/animation.h b/src/resources/animation.h index 0c6f45681..19b17eb54 100644 --- a/src/resources/animation.h +++ b/src/resources/animation.h @@ -85,6 +85,12 @@ class Animation { return static_cast<unsigned>(mFrames.size()); } /** + * Check for empty animation. + */ + bool empty() const + { return mFrames.empty(); } + + /** * Returns the duration of this animation. */ int getDuration() const diff --git a/src/rotationalparticle.cpp b/src/rotationalparticle.cpp index cd16ddf63..60d818cd9 100644 --- a/src/rotationalparticle.cpp +++ b/src/rotationalparticle.cpp @@ -55,10 +55,13 @@ bool RotationalParticle::update() // TODO: cache velocities to avoid spamming atan2() + int size = mAnimation->getLength(); + if (!size) + return false; + float rad = static_cast<float>(atan2(mVelocity.x, mVelocity.y)); if (rad < 0) rad = static_cast<float>(PI + (PI + rad)); - int size = mAnimation->getLength(); float range = static_cast<float>(PI / size); diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 5000ceb4d..3a9b63ca6 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -40,12 +40,12 @@ ShopItem::ShopItem(int inventoryIndex, int id, unsigned char color, if (serverVersion > 0) { mDisplayName = getInfo().getName(color) + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + + Units::formatCurrency(mPrice).c_str() + ") "; } else { mDisplayName = getInfo().getName() + " (" - + Units::formatCurrency(mPrice).c_str() + ") "; + + Units::formatCurrency(mPrice).c_str() + ") "; } if (quantity > 0) mDisplayName += "[" + toString(quantity) + "]"; |