summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-09-11 11:58:50 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-09-11 12:16:23 +0200
commit6ed5449ea0b8e7356304dd4f6705dcc0ac11647e (patch)
tree4658407acb50b88e8bd3a990a881feaf53242472
parent248a274ec6c6e4b5e1f1eb76cf4c6f8b43ac02d3 (diff)
downloadmana-6ed5449ea0b8e7356304dd4f6705dcc0ac11647e.tar.gz
mana-6ed5449ea0b8e7356304dd4f6705dcc0ac11647e.tar.bz2
mana-6ed5449ea0b8e7356304dd4f6705dcc0ac11647e.tar.xz
mana-6ed5449ea0b8e7356304dd4f6705dcc0ac11647e.zip
Fixed drawing glitch with overwide tiles
The layer rendering code was not prepared to handle tiles that were wider than the tile width of the map. This commit also fixes the initialization of the maximum tile height, which was based on the map height rather than the tile height. This could slightly reduce overdraw for some maps. Reviewed-by: Stefan Beller <stefanbeller@googlemail.com>
-rw-r--r--NEWS1
-rw-r--r--src/map.cpp13
-rw-r--r--src/map.h2
3 files changed, 11 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index cabbbd44..97478837 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
0.5.3 (11 September 2011)
- Fixed endless loop when a sprite definition promises too many images
- Fixed crash when selecting a character that has a Dark Talisman equipped
+- Fixed drawing glitch with overwide tiles
- Fixed building without OpenGL
0.5.2 (17 April 2011)
diff --git a/src/map.cpp b/src/map.cpp
index f845f2ff..9e6d865d 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -120,8 +120,10 @@ Image* MapLayer::getTile(int x, int y) const
return mTiles[x + y * mWidth];
}
-void MapLayer::draw(Graphics *graphics, int startX, int startY,
- int endX, int endY, int scrollX, int scrollY,
+void MapLayer::draw(Graphics *graphics,
+ int startX, int startY,
+ int endX, int endY,
+ int scrollX, int scrollY,
const MapSprites &sprites, int debugFlags) const
{
startX -= mX;
@@ -178,7 +180,8 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY,
Map::Map(int width, int height, int tileWidth, int tileHeight):
mWidth(width), mHeight(height),
mTileWidth(tileWidth), mTileHeight(tileHeight),
- mMaxTileHeight(height),
+ mMaxTileHeight(tileHeight),
+ mMaxTileWidth(tileWidth),
mDebugFlags(MAP_NORMAL),
mOnClosedList(1), mOnOpenList(2),
mLastScrollX(0.0f), mLastScrollY(0.0f)
@@ -281,6 +284,8 @@ void Map::addTileset(Tileset *tileset)
if (tileset->getHeight() > mMaxTileHeight)
mMaxTileHeight = tileset->getHeight();
+ if (tileset->getWidth() > mMaxTileWidth)
+ mMaxTileWidth = tileset->getWidth();
}
bool spriteCompare(const Sprite *a, const Sprite *b)
@@ -304,7 +309,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
// Calculate range of tiles which are on-screen
int endPixelY = graphics->getHeight() + scrollY + mTileHeight - 1;
endPixelY += mMaxTileHeight - mTileHeight;
- int startX = scrollX / mTileWidth;
+ int startX = (scrollX - mMaxTileWidth + mTileWidth) / mTileWidth;
int startY = scrollY / mTileHeight;
int endX = (graphics->getWidth() + scrollX + mTileWidth - 1) / mTileWidth;
int endY = endPixelY / mTileHeight;
diff --git a/src/map.h b/src/map.h
index 9fc32232..2e0eb614 100644
--- a/src/map.h
+++ b/src/map.h
@@ -360,7 +360,7 @@ class Map : public Properties
int mWidth, mHeight;
int mTileWidth, mTileHeight;
- int mMaxTileHeight;
+ int mMaxTileHeight, mMaxTileWidth;
MetaTile *mMetaTiles;
Layers mLayers;
Tilesets mTilesets;