From edfa3dfc4b6aef372f32351bf9194f2c32ade391 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 2 Apr 2012 23:25:03 +0000 Subject: [PATCH] core: allow to stretch 2D sprits in both X and Y directions. --- src/font.cpp | 2 +- src/map.cpp | 2 +- src/tiler.cpp | 4 ++-- src/tiler.h | 2 +- src/tileset.cpp | 33 +++++++++++++++++---------------- src/tileset.h | 2 +- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/font.cpp b/src/font.cpp index 98aa75bd..fc6f691e 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -46,7 +46,7 @@ Font::Font(char const *path) data->name = (char *)malloc(7 + strlen(path) + 1); sprintf(data->name, " %s", path); - data->tileset = Tiler::Register(path, ivec2(0), ivec2(16), 1.0f); + data->tileset = Tiler::Register(path, ivec2(0), ivec2(16), vec2(1.0f)); data->size = data->tileset->GetSize(0); m_drawgroup = DRAWGROUP_BEFORE; diff --git a/src/map.cpp b/src/map.cpp index f088b6f6..d86e7c87 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -136,7 +136,7 @@ Map::Map(char const *path) { /* This is a tileset image file. Associate it with firstgid. */ data->tilesets[data->ntilers] = Tiler::Register(str, ivec2(32), - ivec2(0), sqrtf(2)); + ivec2(0), vec2(1.0f, sqrtf(2))); data->ntilers++; //Log::Debug("new tiler %s\n", str); } diff --git a/src/tiler.cpp b/src/tiler.cpp index 07490374..d34e0c29 100644 --- a/src/tiler.cpp +++ b/src/tiler.cpp @@ -41,14 +41,14 @@ static TilerData * const data = &tilerdata; */ TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count, - float dilate) + vec2 scale) { int id = data->tilesets.MakeSlot(path); TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); if (!tileset) { - tileset = new TileSet(path, size, count, dilate); + tileset = new TileSet(path, size, count, scale); data->tilesets.SetEntity(id, tileset); } diff --git a/src/tiler.h b/src/tiler.h index 90e2d083..19ee6827 100644 --- a/src/tiler.h +++ b/src/tiler.h @@ -28,7 +28,7 @@ class Tiler { public: static TileSet *Register(char const *path, ivec2 size, ivec2 count, - float dilate); + vec2 scale); static void Deregister(TileSet *); }; diff --git a/src/tileset.cpp b/src/tileset.cpp index fc0376eb..5670c82b 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -42,7 +42,8 @@ private: char *name, *path; int *tiles, ntiles; ivec2 size, isize, count; - float dilate, tx, ty; + vec2 scale; + float tx, ty; Image *img; #if defined _XBOX @@ -60,7 +61,7 @@ private: * Public TileSet class */ -TileSet::TileSet(char const *path, ivec2 size, ivec2 count, float dilate) +TileSet::TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale) : data(new TileSetData()) { data->name = (char *)malloc(10 + strlen(path) + 1); @@ -97,7 +98,7 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count, float dilate) data->tx = (float)data->size.x / PotUp(data->isize.x); data->ty = (float)data->size.y / PotUp(data->isize.y); - data->dilate = dilate; + data->scale = scale; data->ntiles = data->count.x * data->count.y; m_drawgroup = DRAWGROUP_BEFORE; @@ -223,7 +224,7 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, { float tx = data->tx * ((id & 0xffff) % data->count.x); float ty = data->ty * ((id & 0xffff) / data->count.x); - float dilate = data->dilate; + vec2 scale = data->scale; int dx = data->size.x; int dy = o ? 0 : data->size.y; @@ -240,21 +241,21 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, { float tmp[10]; - *vertex++ = tmp[0] = pos.x; - *vertex++ = tmp[1] = dilate * (pos.y + dy); - *vertex++ = tmp[2] = dilate * (pos.z + dz); + *vertex++ = tmp[0] = scale.x * pos.x; + *vertex++ = tmp[1] = scale.y * (pos.y + dy); + *vertex++ = tmp[2] = scale.y * (pos.z + dz); *texture++ = tmp[3] = tx; *texture++ = tmp[4] = ty; - *vertex++ = pos.x + dx; - *vertex++ = dilate * (pos.y + dy); - *vertex++ = dilate * (pos.z + dz); + *vertex++ = scale.x * (pos.x + dx); + *vertex++ = scale.y * (pos.y + dy); + *vertex++ = scale.y * (pos.z + dz); *texture++ = tx + data->tx; *texture++ = ty; - *vertex++ = tmp[5] = pos.x + dx; - *vertex++ = tmp[6] = dilate * pos.y; - *vertex++ = tmp[7] = dilate * pos.z; + *vertex++ = tmp[5] = scale.x * (pos.x + dx); + *vertex++ = tmp[6] = scale.y * pos.y; + *vertex++ = tmp[7] = scale.y * pos.z; *texture++ = tmp[8] = tx + data->tx; *texture++ = tmp[9] = ty + data->ty; @@ -270,9 +271,9 @@ void TileSet::BlitTile(uint32_t id, vec3 pos, int o, *texture++ = tmp[8]; *texture++ = tmp[9]; - *vertex++ = pos.x; - *vertex++ = dilate * pos.y; - *vertex++ = dilate * pos.z; + *vertex++ = scale.x * pos.x; + *vertex++ = scale.y * pos.y; + *vertex++ = scale.y * pos.z; *texture++ = tx; *texture++ = ty + data->ty; } diff --git a/src/tileset.h b/src/tileset.h index 368bcfdc..bf2fe9f9 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -31,7 +31,7 @@ class TileSetData; class TileSet : public Entity { public: - TileSet(char const *path, ivec2 size, ivec2 count, float dilate); + TileSet(char const *path, ivec2 size, ivec2 count, vec2 scale); virtual ~TileSet(); protected: