summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-07-20 23:09:11 +0300
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-07-22 00:14:39 +0200
commit682b632b26bcc0dc1e375858d23e15d645ec2fdb (patch)
tree21d6cf30f53fecb5026f2682cd943abe93d3bcdd /src/map.cpp
parent3d27cb14160fb17eb7fc149ac82318bcec6f1bd6 (diff)
downloadmana-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/map.cpp')
-rw-r--r--src/map.cpp87
1 files changed, 75 insertions, 12 deletions
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