TilemapVX: Deal correctly with Graphics.resize_screen

This commit is contained in:
Jonas Kulla 2014-08-22 23:51:41 +02:00
parent 50e393fe6e
commit 24ad0990da
1 changed files with 14 additions and 16 deletions

View File

@ -38,14 +38,6 @@
#include <sigc++/connection.h> #include <sigc++/connection.h>
#include <sigc++/bind.h> #include <sigc++/bind.h>
/* Map viewport size */
// FIXME: This will be wrong if resolution is changed
static const int viewpW = 18;
static const int viewpH = 14;
/* How many tiles are max visible on screen at once */
static const Vec2i screenTiles(18, 14);
// FIXME: Implement flash // FIXME: Implement flash
struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
@ -60,7 +52,7 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
Vec2i dispPos; Vec2i dispPos;
/* Map viewport position */ /* Map viewport position */
Vec2i viewpPos; IntRect mapViewp;
Vec2i sceneOffset; Vec2i sceneOffset;
Scene::Geometry sceneGeo; Scene::Geometry sceneGeo;
@ -136,6 +128,8 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
vao.ibo = shState->globalIBO().ibo; vao.ibo = shState->globalIBO().ibo;
GLMeta::vaoInit(vao); GLMeta::vaoInit(vao);
onGeometryChange(scene->getGeometry());
prepareCon = shState->prepareDraw.connect prepareCon = shState->prepareDraw.connect
(sigc::mem_fun(this, &TilemapVXPrivate::prepare)); (sigc::mem_fun(this, &TilemapVXPrivate::prepare));
} }
@ -185,8 +179,8 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
void updatePosition() void updatePosition()
{ {
dispPos.x = -(offset.x - viewpPos.x * 32) + sceneOffset.x; dispPos.x = -(offset.x - mapViewp.x * 32) + sceneOffset.x;
dispPos.y = -(offset.y - viewpPos.y * 32) + sceneOffset.y; dispPos.y = -(offset.y - mapViewp.y * 32) + sceneOffset.y;
} }
void updateMapViewport() void updateMapViewport()
@ -207,15 +201,15 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
bool dirty = false; bool dirty = false;
if (tileOX < viewpPos.x || tileOX + screenTiles.x > viewpPos.x + viewpW) if (tileOX < mapViewp.x || tileOX > mapViewp.x)
{ {
viewpPos.x = tileOX; mapViewp.x = tileOX;
dirty = true; dirty = true;
} }
if (tileOY < viewpPos.y || tileOY + screenTiles.y > viewpPos.y + viewpH) if (tileOY < mapViewp.y || tileOY > mapViewp.y)
{ {
viewpPos.y = tileOY; mapViewp.y = tileOY;
dirty = true; dirty = true;
} }
@ -241,7 +235,7 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
aboveVert.clear(); aboveVert.clear();
TileAtlasVX::readTiles(*this, *mapData, flags, TileAtlasVX::readTiles(*this, *mapData, flags,
viewpPos.x, viewpPos.y, viewpW, viewpH); mapViewp.x, mapViewp.y, mapViewp.w, mapViewp.h);
groundQuads = groundVert.size() / 4; groundQuads = groundVert.size() / 4;
aboveQuads = aboveVert.size() / 4; aboveQuads = aboveVert.size() / 4;
@ -335,10 +329,14 @@ struct TilemapVXPrivate : public ViewportElement, TileAtlasVX::Reader
void onGeometryChange(const Scene::Geometry &geo) void onGeometryChange(const Scene::Geometry &geo)
{ {
mapViewp.w = (geo.rect.w / 32) + !!(geo.rect.w % 32) + 1;
mapViewp.h = (geo.rect.h / 32) + !!(geo.rect.h % 32) + 1;
sceneOffset.x = geo.rect.x - geo.xOrigin; sceneOffset.x = geo.rect.x - geo.xOrigin;
sceneOffset.y = geo.rect.y - geo.yOrigin; sceneOffset.y = geo.rect.y - geo.yOrigin;
sceneGeo = geo; sceneGeo = geo;
buffersDirty = true;
mapViewportDirty = true; mapViewportDirty = true;
} }