summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.h2
-rw-r--r--src/map.cpp15
-rw-r--r--src/map.h2
-rw-r--r--src/openglgraphics.cpp77
4 files changed, 57 insertions, 39 deletions
diff --git a/src/main.h b/src/main.h
index 3fe52f5d..82ece500 100644
--- a/src/main.h
+++ b/src/main.h
@@ -55,7 +55,7 @@
#elif defined WIN32
#include "winver.h"
#elif defined __APPLE__
-#define PACKAGE_VERSION "0.5.2"
+#define PACKAGE_VERSION "0.5.3"
#endif
#ifdef PACKAGE_VERSION
diff --git a/src/map.cpp b/src/map.cpp
index ac287be4..3e5e8e12 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -121,8 +121,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 Actors &actors, int debugFlags) const
{
startX -= mX;
@@ -218,8 +220,9 @@ int MapLayer::getTileDrawWidth(int x1, int y1, int endX, int &width) const
Map::Map(int width, int height, int tileWidth, int tileHeight):
mWidth(width), mHeight(height),
mTileWidth(tileWidth), mTileHeight(tileHeight),
- mMaxTileHeight(height),
- mDebugFlags(0),
+ mMaxTileHeight(tileHeight),
+ mMaxTileWidth(tileWidth),
+ mDebugFlags(MAP_NORMAL),
mOnClosedList(1), mOnOpenList(2),
mLastScrollX(0.0f), mLastScrollY(0.0f)
{
@@ -321,6 +324,8 @@ void Map::addTileset(Tileset *tileset)
if (tileset->getHeight() > mMaxTileHeight)
mMaxTileHeight = tileset->getHeight();
+ if (tileset->getWidth() > mMaxTileWidth)
+ mMaxTileWidth = tileset->getWidth();
}
bool actorCompare(const Actor *a, const Actor *b)
@@ -344,7 +349,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 56ddae11..0c342deb 100644
--- a/src/map.h
+++ b/src/map.h
@@ -386,7 +386,7 @@ class Map : public Properties
int mWidth, mHeight;
int mTileWidth, mTileHeight;
- int mMaxTileHeight;
+ int mMaxTileHeight, mMaxTileWidth;
MetaTile *mMetaTiles;
Layers mLayers;
Tilesets mTilesets;
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index c24b7d64..84f499a4 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -478,24 +478,26 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h)
static_cast<GLubyte>(mColor.a));
}
-void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y,
- int w, int h, int scaledWidth,
+void OpenGLGraphics::drawRescaledImagePattern(Image *image,
+ int x, int y,
+ int w, int h,
+ int scaledWidth,
int scaledHeight)
{
if (!image)
return;
+ if (scaledWidth == 0 || scaledHeight == 0)
+ return;
+
const int srcX = image->mBounds.x;
const int srcY = image->mBounds.y;
- const int iw = scaledWidth;
- const int ih = scaledHeight;
+ const int iw = image->getWidth();
+ const int ih = image->getHeight();
if (iw == 0 || ih == 0)
return;
- const float tw = static_cast<float>(image->getTextureWidth());
- const float th = static_cast<float>(image->getTextureHeight());
-
glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha);
bindTexture(Image::mTextureType, image->mGLImage);
@@ -505,23 +507,31 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y,
unsigned int vp = 0;
const unsigned int vLimit = vertexBufSize * 4;
- float texX1 = static_cast<float>(srcX) / tw;
- float texY1 = static_cast<float>(srcY) / th;
-
// Draw a set of textured rectangles
if (image->getTextureType() == GL_TEXTURE_2D)
{
- for (int py = 0; py < h; py += ih)
+ const float tw = static_cast<float>(image->getTextureWidth());
+ const float th = static_cast<float>(image->getTextureHeight());
+
+ const float texX1 = static_cast<float>(srcX) / tw;
+ const float texY1 = static_cast<float>(srcY) / th;
+
+ const float tFractionW = iw / tw;
+ const float tFractionH = ih / th;
+
+ for (int py = 0; py < h; py += scaledHeight)
{
- const int height = (py + ih >= h) ? h - py : ih;
+ const int height = (py + scaledHeight >= h) ? h - py : scaledHeight;
const int dstY = y + py;
- for (int px = 0; px < w; px += iw)
+ for (int px = 0; px < w; px += scaledWidth)
{
- int width = (px + iw >= w) ? w - px : iw;
+ int width = (px + scaledWidth >= w) ? w - px : scaledWidth;
int dstX = x + px;
+ const float visibleFractionW = (float) width / scaledWidth;
+ const float visibleFractionH = (float) height / scaledHeight;
- float texX2 = static_cast<float>(srcX + width) / tw;
- float texY2 = static_cast<float>(srcY + height) / th;
+ const float texX2 = texX1 + tFractionW * visibleFractionW;
+ const float texY2 = texY1 + tFractionH * visibleFractionH;
mFloatTexArray[vp + 0] = texX1;
mFloatTexArray[vp + 1] = texY1;
@@ -538,14 +548,14 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y,
mIntVertArray[vp + 0] = dstX;
mIntVertArray[vp + 1] = dstY;
- mIntVertArray[vp + 2] = dstX + scaledWidth;
+ mIntVertArray[vp + 2] = dstX + width;
mIntVertArray[vp + 3] = dstY;
- mIntVertArray[vp + 4] = dstX + scaledWidth;
- mIntVertArray[vp + 5] = dstY + scaledHeight;
+ mIntVertArray[vp + 4] = dstX + width;
+ mIntVertArray[vp + 5] = dstY + height;
mIntVertArray[vp + 6] = dstX;
- mIntVertArray[vp + 7] = dstY + scaledHeight;
+ mIntVertArray[vp + 7] = dstY + height;
vp += 8;
if (vp >= vLimit)
@@ -560,38 +570,41 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, int x, int y,
}
else
{
- for (int py = 0; py < h; py += ih)
+ const float scaleFactorW = (float) scaledWidth / iw;
+ const float scaleFactorH = (float) scaledHeight / ih;
+
+ for (int py = 0; py < h; py += scaledHeight)
{
- const int height = (py + ih >= h) ? h - py : ih;
+ const int height = (py + scaledHeight >= h) ? h - py : scaledHeight;
const int dstY = y + py;
- for (int px = 0; px < w; px += iw)
+ for (int px = 0; px < w; px += scaledWidth)
{
- int width = (px + iw >= w) ? w - px : iw;
+ int width = (px + scaledWidth >= w) ? w - px : scaledWidth;
int dstX = x + px;
mIntTexArray[vp + 0] = srcX;
mIntTexArray[vp + 1] = srcY;
- mIntTexArray[vp + 2] = srcX + width;
+ mIntTexArray[vp + 2] = srcX + width / scaleFactorW;
mIntTexArray[vp + 3] = srcY;
- mIntTexArray[vp + 4] = srcX + width;
- mIntTexArray[vp + 5] = srcY + height;
+ mIntTexArray[vp + 4] = srcX + width / scaleFactorW;
+ mIntTexArray[vp + 5] = srcY + height / scaleFactorH;
mIntTexArray[vp + 6] = srcX;
- mIntTexArray[vp + 7] = srcY + height;
+ mIntTexArray[vp + 7] = srcY + height / scaleFactorH;
mIntVertArray[vp + 0] = dstX;
mIntVertArray[vp + 1] = dstY;
- mIntVertArray[vp + 2] = dstX + scaledWidth;
+ mIntVertArray[vp + 2] = dstX + width;
mIntVertArray[vp + 3] = dstY;
- mIntVertArray[vp + 4] = dstX + scaledWidth;
- mIntVertArray[vp + 5] = dstY + scaledHeight;
+ mIntVertArray[vp + 4] = dstX + width;
+ mIntVertArray[vp + 5] = dstY + height;
mIntVertArray[vp + 6] = dstX;
- mIntVertArray[vp + 7] = dstY + scaledHeight;
+ mIntVertArray[vp + 7] = dstY + height;
vp += 8;
if (vp >= vLimit)