From 7b15124d28592ee7b9248c9ff3b19e710c1ce4ee Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 26 Jul 2011 21:54:07 +0300 Subject: Small optimisation in reorder sprites function. --- src/being.cpp | 21 +++++++++++---------- src/resources/iteminfo.h | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index 40c41cb64..034478067 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2084,6 +2084,9 @@ void Being::recalcSpritesOrder() // logger->log("preparation start"); std::vector::iterator it; int oldHide[20]; + int dir = mSpriteDirection; + if (dir < 0 || dir >= 9) + dir = 0; for (unsigned slot = 0; slot < sz; slot ++) { @@ -2141,16 +2144,15 @@ void Being::recalcSpritesOrder() } } - if (info.getDrawBefore(mSpriteDirection) > 0) + if (info.mDrawBefore[dir] > 0) { - int id2 = mSpriteIDs[info.getDrawBefore(mSpriteDirection)]; + int id2 = mSpriteIDs[info.mDrawBefore[dir]]; std::map::iterator orderIt = itemSlotRemap.find(id2); if (orderIt != itemSlotRemap.end()) { // logger->log("found duplicate (before)"); const ItemInfo &info2 = ItemDB::get(id2); - if (info.getDrawPriority(mSpriteDirection) - < info2.getDrawPriority(mSpriteDirection)) + if (info.mDrawPriority[dir] < info2.mDrawPriority[dir]) { // logger->log("old more priority"); continue; @@ -2162,19 +2164,18 @@ void Being::recalcSpritesOrder() } } - itemSlotRemap[id] = -info.getDrawBefore(mSpriteDirection); + itemSlotRemap[id] = -info.mDrawBefore[dir]; // logger->log("item slot->slot %d %d->%d", id, slot, itemSlotRemap[id]); } - else if (info.getDrawAfter(mSpriteDirection) > 0) + else if (info.mDrawAfter[dir] > 0) { - int id2 = mSpriteIDs[info.getDrawAfter(mSpriteDirection)]; + int id2 = mSpriteIDs[info.mDrawAfter[dir]]; std::map::iterator orderIt = itemSlotRemap.find(id2); if (orderIt != itemSlotRemap.end()) { // logger->log("found duplicate (after)"); const ItemInfo &info2 = ItemDB::get(id2); - if (info.getDrawPriority(mSpriteDirection) - < info2.getDrawPriority(mSpriteDirection)) + if (info.mDrawPriority[dir] < info2.mDrawPriority[dir]) { // logger->log("old more priority"); continue; @@ -2186,7 +2187,7 @@ void Being::recalcSpritesOrder() } } - itemSlotRemap[id] = info.getDrawAfter(mSpriteDirection); + itemSlotRemap[id] = info.mDrawAfter[dir]; // logger->log("item slot->slot %d %d->%d", id, slot, itemSlotRemap[id]); } } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index d8b8c7b0d..daa9d590c 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -256,6 +256,9 @@ class ItemInfo const std::string replaceColors(std::string str, unsigned char color) const; + int mDrawBefore[9]; + int mDrawAfter[9]; + int mDrawPriority[9]; protected: SpriteDisplay mDisplay; /**< Display info (like icon) */ @@ -267,9 +270,6 @@ class ItemInfo int mWeight; /**< Weight in grams. */ int mView; /**< Item ID of how this item looks. */ int mId; /**< Item ID */ - int mDrawBefore[9]; - int mDrawAfter[9]; - int mDrawPriority[9]; bool mIsRemoveSprites; // sprite, [direction] SpriteToItemMap *mSpriteToItemReplaceMap[9]; -- cgit v1.2.3-70-g09d2