summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-09 18:49:05 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-09 18:49:05 +0300
commitb9d66c41246fef56e41f600b5523a5ff1a29a1c8 (patch)
tree3e6e546d393975b83ae951561cb6b05d920ef048 /src/map.cpp
parent8bed92098b94ebe14dfd9d622585fbfc150a8757 (diff)
downloadmv-b9d66c41246fef56e41f600b5523a5ff1a29a1c8.tar.gz
mv-b9d66c41246fef56e41f600b5523a5ff1a29a1c8.tar.bz2
mv-b9d66c41246fef56e41f600b5523a5ff1a29a1c8.tar.xz
mv-b9d66c41246fef56e41f600b5523a5ff1a29a1c8.zip
Improve map loading speed.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp65
1 files changed, 55 insertions, 10 deletions
diff --git a/src/map.cpp b/src/map.cpp
index eafdc88ec..4437b55a2 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -378,7 +378,10 @@ Map::Map(int width, int height, int tileWidth, int tileHeight):
mLastScrollX(0.0f), mLastScrollY(0.0f),
mOverlayDetail(config.getIntValue("OverlayDetail")),
mOpacity(config.getFloatValue("guialpha")),
- mPvp(0)
+ mPvp(0),
+ mTilesetsIndexed(false),
+ mIndexedTilesets(0),
+ mIndexedTilesetsSize(0)
// mSpritesUpdated(true)
{
const int size = mWidth * mHeight;
@@ -758,15 +761,10 @@ void Map::drawAmbientLayers(Graphics *graphics, LayerType type,
Tileset *Map::getTilesetWithGid(int gid) const
{
- Tileset *s = NULL;
- for (Tilesets::const_iterator it = mTilesets.begin(),
- it_end = mTilesets.end(); it < it_end && (*it)->getFirstGid() <= gid;
- ++it)
- {
- s = *it;
- }
-
- return s;
+ if (gid < mIndexedTilesetsSize)
+ return mIndexedTilesets[gid];
+ else
+ return 0;
}
void Map::blockTile(int x, int y, BlockType type)
@@ -1409,6 +1407,9 @@ MapItem *Map::findPortalXY(int x, int y)
TileAnimation *Map::getAnimationForGid(int gid) const
{
+ if (mTileAnimations.empty())
+ return 0;
+
std::map<int, TileAnimation*>::const_iterator
i = mTileAnimations.find(gid);
return (i == mTileAnimations.end()) ? NULL : i->second;
@@ -1465,6 +1466,50 @@ std::string Map::getObjectData(unsigned x, unsigned y, int type)
return "";
}
+void Map::indexTilesets()
+{
+ if (mTilesetsIndexed)
+ return;
+
+ mTilesetsIndexed = true;
+
+ Tileset *s = 0;
+ for (Tilesets::const_iterator it = mTilesets.begin(),
+ it_end = mTilesets.end(); it < it_end;
+ ++it)
+ {
+ if (!s || s->getFirstGid() < (*it)->getFirstGid())
+ s = *it;
+ }
+ if (!s)
+ return;
+
+ const int size = s->getFirstGid() + s->size();
+ mIndexedTilesetsSize = size;
+ mIndexedTilesets = new Tileset*[size];
+ std::fill_n(mIndexedTilesets, size, static_cast<Tileset*>(0));
+ for (Tilesets::const_iterator it = mTilesets.begin(),
+ it_end = mTilesets.end(); it < it_end;
+ ++it)
+ {
+ s = *it;
+ const int start = s->getFirstGid();
+ const int end = start + s->size();
+ for (int f = start; f < end; f ++)
+ mIndexedTilesets[f] = s;
+ }
+}
+
+void Map::clearIndexedTilesets()
+{
+ if (!mTilesetsIndexed)
+ return;
+
+ mTilesetsIndexed = false;
+ delete[] mIndexedTilesets;
+ mIndexedTilesetsSize = 0;
+}
+
SpecialLayer::SpecialLayer(int width, int height, bool drawSprites):
mWidth(width), mHeight(height)
{