From 7760ed560001714494d7a7de470123a4cd565873 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 8 Oct 2012 02:52:22 +0300 Subject: improve map draw speed. --- src/maplayer.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/maplayer.cpp') diff --git a/src/maplayer.cpp b/src/maplayer.cpp index f79c8c042..654cb7997 100644 --- a/src/maplayer.cpp +++ b/src/maplayer.cpp @@ -255,18 +255,16 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY, const bool flag = (debugFlags != Map::MAP_SPECIAL && debugFlags != Map::MAP_SPECIAL2); + MapRowVertexes *const row = new MapRowVertexes(); + mTempRows.push_back(row); + Image *lastImage = nullptr; + ImageVertexes *imgVert = nullptr; + std::map imgSet; + for (int y = startY; y < endY; y++) { - MapRowVertexes *const row = new MapRowVertexes(); - mTempRows.push_back(row); - - Image *lastImage = nullptr; - ImageVertexes *imgVert = nullptr; - const int yWidth = y * mWidth; const int py0 = y * 32 + dy; - std::map imgSet; - Image **tilePtr = mTiles + startX + yWidth; for (int x = startX; x < endX; x++, tilePtr++) { @@ -282,20 +280,24 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY, if (img->mBounds.w > 32) imgSet.clear(); - imgSet[lastImage] = imgVert; - if (imgSet.find(img) != imgSet.end()) + if (imgSet.find(img->mGLImage) != imgSet.end()) { - imgVert = imgSet[img]; + imgVert = imgSet[img->mGLImage]; } else { + if (lastImage) + imgSet[lastImage->mGLImage] = imgVert; imgVert = new ImageVertexes(); + imgVert->ogl.init(); imgVert->image = img; row->images.push_back(imgVert); } lastImage = img; } lastImage = img; +// if (imgVert->image->mGLImage != lastImage->mGLImage) +// logger->log("wrong image draw"); graphics->calcTile(imgVert, lastImage, px, py); } } @@ -308,6 +310,7 @@ void MapLayer::drawOGL(Graphics *const graphics) { MapRows::const_iterator rit = mTempRows.begin(); const MapRows::const_iterator rit_end = mTempRows.end(); +// int k = 0; while (rit != rit_end) { MepRowImages *const images = &(*rit)->images; @@ -317,9 +320,11 @@ void MapLayer::drawOGL(Graphics *const graphics) { graphics->drawTile(*iit); ++ iit; +// k ++; } ++ rit; } +// logger->log("draws: %d", k); } void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY, -- cgit v1.2.3-60-g2f50