From 6afba95ef62b22c303336adba6d891eeffe66c49 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 17 Jul 2011 18:16:49 +0300 Subject: Add basic tiles caching for opengl. --- src/map.cpp | 61 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 26 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index c5a7a8816..d5d74f4df 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -239,13 +239,9 @@ void MapLayer::updateOGL(Graphics *graphics, int startX, int startY, int endX, int endY, int scrollX, int scrollY, int debugFlags) { + delete_all(mTempRows); + mTempRows.clear(); -} - -void MapLayer::drawOGL(Graphics *graphics, int startX, int startY, - int endX, int endY, int scrollX, int scrollY, - int debugFlags) -{ startX -= mX; startY -= mY; endX -= mX; @@ -267,42 +263,56 @@ void MapLayer::drawOGL(Graphics *graphics, int startX, int startY, for (int y = startY; y < endY; y++) { - const int y32 = y * 32; - const int yWidth = y * mWidth; + MapRowVertexes *row = new MapRowVertexes(); + mTempRows.push_back(row); - const int py0 = y32 + dy; + Image *lastImage = 0; + ImageVertexes *imgVert = 0; + + const int yWidth = y * mWidth; + const int py0 = y * 32 + dy; for (int x = startX; x < endX; x++) { - const int x32 = x * 32; - const int tilePtr = x + yWidth; - int c = 0; Image *img = mTiles[tilePtr]; if (img) { - const int px = x32 + dx; + const int px = x * 32 + dx; const int py = py0 - img->mBounds.h; if (flag || img->mBounds.h <= 32) { - int width = 0; - // here need not draw over player position - c = getTileDrawWidth(tilePtr, endX - x, width); - - if (!c) - { - graphics->drawImage(img, px, py); - } - else + if (lastImage != img) { - graphics->drawImagePattern(img, px, py, - width, img->mBounds.h); + imgVert = new ImageVertexes(); + imgVert->image = img; + row->images.push_back(imgVert); + lastImage = img; } + graphics->calcTile(imgVert, px, py); } } + } + } +} - x += c; +void MapLayer::drawOGL(Graphics *graphics, int startX, int startY, + int endX, int endY, int scrollX, int scrollY, + int debugFlags) +{ + MapRows::iterator rit = mTempRows.begin(); + MapRows::iterator rit_end = mTempRows.end(); + while (rit != rit_end) + { + MepRowImages *images = &(*rit)->images; + MepRowImages::iterator iit = images->begin(); + MepRowImages::iterator iit_end = images->end(); + while (iit != iit_end) + { + graphics->drawTile(*iit); + ++ iit; } + ++ rit; } } @@ -743,7 +753,6 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) mLastScrollX = scrollX; mLastScrollY = scrollY; updateFlag = 2; -// updateMapLayer(this, endX, endY, debugFlags); } if (mDebugFlags == MAP_SPECIAL3 || mDebugFlags == MAP_BLACKWHITE) -- cgit v1.2.3-70-g09d2