diff options
author | Andrei Karas <akaras@inbox.ru> | 2010-07-20 23:09:11 +0300 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-07-22 00:14:39 +0200 |
commit | 682b632b26bcc0dc1e375858d23e15d645ec2fdb (patch) | |
tree | 21d6cf30f53fecb5026f2682cd943abe93d3bcdd /src | |
parent | 3d27cb14160fb17eb7fc149ac82318bcec6f1bd6 (diff) | |
download | mana-682b632b26bcc0dc1e375858d23e15d645ec2fdb.tar.gz mana-682b632b26bcc0dc1e375858d23e15d645ec2fdb.tar.bz2 mana-682b632b26bcc0dc1e375858d23e15d645ec2fdb.tar.xz mana-682b632b26bcc0dc1e375858d23e15d645ec2fdb.zip |
Add two debug map modes and improve slightly map drawing.
Reviewed-by: Bertram
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/viewport.cpp | 2 | ||||
-rw-r--r-- | src/map.cpp | 87 | ||||
-rw-r--r-- | src/map.h | 9 |
3 files changed, 84 insertions, 14 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 66f614a8..120106cb 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -532,7 +532,7 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) void Viewport::toggleDebugPath() { mShowDebugPath++; - if (mShowDebugPath > Map::MAP_SPECIAL) + if (mShowDebugPath > Map::MAP_SPECIAL3) mShowDebugPath = Map::MAP_NORMAL; if (mMap) { diff --git a/src/map.cpp b/src/map.cpp index f5214420..3727efdc 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -135,8 +135,13 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, Actors::const_iterator ai = actors.begin(); + int dx = (mX * 32) - scrollX; + int dy = (mY * 32) - scrollY + 32; + for (int y = startY; y < endY; y++) { + int y32 = y * 32; + // If drawing the fringe layer, make sure all actors above this row of // tiles have been drawn if (mIsFringeLayer) @@ -148,15 +153,35 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, } } - for (int x = startX; x < endX; x++) + if (debugFlags != Map::MAP_SPECIAL3) { - Image *img = getTile(x, y); - if (img) + const int py0 = y32 + dy; + + for (int x = startX; x < endX; x++) { - const int px = (x + mX) * 32 - scrollX; - const int py = (y + mY) * 32 - scrollY + 32 - img->getHeight(); - if (debugFlags != Map::MAP_SPECIAL || img->getHeight() <= 32) - graphics->drawImage(img, px, py); + Image *img = getTile(x, y); + if (img) + { + const int px = (x * 32) + dx; + const int py = py0 - img->getHeight(); + if ((debugFlags != Map::MAP_SPECIAL + && debugFlags != Map::MAP_SPECIAL2) + || img->getHeight() <= 32) + { + int width = 0; + int c = getTileDrawWidth(x, y, endX, width); + if (!c) + { + graphics->drawImage(img, px, py); + } + else + { + graphics->drawImagePattern(img, px, py, + width, img->getHeight()); + } + x += c; + } + } } } } @@ -172,6 +197,22 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, } } +int MapLayer::getTileDrawWidth(int x1, int y1, int endX, int &width) const +{ + Image *img1 = getTile(x1, y1); + int c = 0; + width = img1->getWidth(); + for (int x = x1 + 1; x < endX; x++) + { + Image *img = getTile(x, y1); + if (img != img1) + break; + c ++; + width += img->getWidth(); + } + return c; +} + Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), @@ -319,12 +360,34 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) // draw the game world Layers::const_iterator layeri = mLayers.begin(); - for (; layeri != mLayers.end(); ++layeri) + + bool overFringe = false; + + if (mDebugFlags == MAP_SPECIAL3) + { + for (; layeri != mLayers.end(); ++layeri) + { + if ((*layeri)->isFringeLayer()) + { + (*layeri)->draw(graphics, + startX, startY, endX, endY, + scrollX, scrollY, + mActors, mDebugFlags); + } + } + } + else { - (*layeri)->draw(graphics, - startX, startY, endX, endY, - scrollX, scrollY, - mActors, mDebugFlags); + for (; layeri != mLayers.end() && !overFringe; ++layeri) + { + if ((*layeri)->isFringeLayer() && mDebugFlags == MAP_SPECIAL2) + overFringe = true; + + (*layeri)->draw(graphics, + startX, startY, endX, endY, + scrollX, scrollY, + mActors, mDebugFlags); + } } // Draws beings with a lower opacity to make them visible @@ -128,6 +128,11 @@ class MapLayer const Actors &actors, int mDebugFlags) const; + bool isFringeLayer() + { return mIsFringeLayer; } + + int getTileDrawWidth(int x1, int y1, int endX, int &width) const; + private: int mX, mY; int mWidth, mHeight; @@ -161,7 +166,9 @@ class Map : public Properties { MAP_NORMAL = 0, MAP_DEBUG = 1, - MAP_SPECIAL = 2 + MAP_SPECIAL = 2, + MAP_SPECIAL2 = 3, + MAP_SPECIAL3 = 4 }; /** |