浏览代码

TileSets can now be initialised either using the tile size, or the

known number of tiles in a row and a column. Necessary for ticket #24.
legacy
Sam Hocevar sam 15 年前
父节点
当前提交
375d7ee14d
共有 5 个文件被更改,包括 29 次插入24 次删除
  1. +1
    -1
      src/map.cpp
  2. +2
    -2
      src/tiler.cpp
  3. +1
    -1
      src/tiler.h
  4. +24
    -19
      src/tileset.cpp
  5. +1
    -1
      src/tileset.h

+ 1
- 1
src/map.cpp 查看文件

@@ -127,7 +127,7 @@ Map::Map(char const *path)
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1) else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1)
{ {
/* This is a tileset image file. Associate it with firstgid. */ /* This is a tileset image file. Associate it with firstgid. */
data->tilers[data->ntilers] = Tiler::Register(str, 32, 32,
data->tilers[data->ntilers] = Tiler::Register(str, 32, 0,
sqrtf(2)); sqrtf(2));
data->ntilers++; data->ntilers++;
//fprintf(stderr, "new tiler %s\n", str); //fprintf(stderr, "new tiler %s\n", str);


+ 2
- 2
src/tiler.cpp 查看文件

@@ -45,13 +45,13 @@ static TilerData * const data = &tilerdata;
* Public Tiler class * Public Tiler class
*/ */


int Tiler::Register(char const *path, int w, int h, float dilate)
int Tiler::Register(char const *path, int2 size, int2 count, float dilate)
{ {
int id = data->tilesets.MakeSlot(path); int id = data->tilesets.MakeSlot(path);


if (!data->tilesets.GetEntity(id)) if (!data->tilesets.GetEntity(id))
{ {
TileSet *tileset = new TileSet(path, w, h, dilate);
TileSet *tileset = new TileSet(path, size, count, dilate);
data->tilesets.SetEntity(id, tileset); data->tilesets.SetEntity(id, tileset);
#if !FINAL_RELEASE #if !FINAL_RELEASE
if (id == data->lasterror) if (id == data->lasterror)


+ 1
- 1
src/tiler.h 查看文件

@@ -22,7 +22,7 @@
class Tiler class Tiler
{ {
public: public:
static int Register(char const *path, int w, int h, float dilate);
static int Register(char const *path, int2 size, int2 count, float dilate);
static void Deregister(int id); static void Deregister(int id);


static void BlitTile(uint32_t code, int x, int y, int z, int o); static void BlitTile(uint32_t code, int x, int y, int z, int o);


+ 24
- 19
src/tileset.cpp 查看文件

@@ -41,8 +41,8 @@ class TileSetData


private: private:
char *name, *path; char *name, *path;
int *tiles;
int w, h, nw, nh, ntiles;
int *tiles, ntiles;
int2 size, count;
float dilate, tx, ty; float dilate, tx, ty;


SDL_Surface *img; SDL_Surface *img;
@@ -53,7 +53,7 @@ private:
* Public TileSet class * Public TileSet class
*/ */


TileSet::TileSet(char const *path, int w, int h, float dilate)
TileSet::TileSet(char const *path, int2 size, int2 count, float dilate)
: data(new TileSetData()) : data(new TileSetData())
{ {
data->name = (char *)malloc(10 + strlen(path) + 1); data->name = (char *)malloc(10 + strlen(path) + 1);
@@ -77,19 +77,24 @@ TileSet::TileSet(char const *path, int w, int h, float dilate)
exit(1); exit(1);
} }


if (w <= 0)
w = 32;
if (h <= 0)
h = 32;
if (count.i > 0 && count.j > 0)
{
data->count = count;
data->size = int2(data->img->w, data->img->h) / count;
}
else
{
if (size.x <= 0 || size.y <= 0)
size = 32;
data->count.i = data->img->w > size.i ? data->img->w / size.i : 1;
data->count.j = data->img->h > size.j ? data->img->h / size.j : 1;
data->size = size;
}


data->w = w;
data->h = h;
data->dilate = dilate; data->dilate = dilate;
data->nw = data->img->w > w ? data->img->w / w : 1;
data->nh = data->img->h > h ? data->img->h / h : 1;
data->ntiles = data->nw * data->nh;
data->tx = (float)w / PotUp(data->img->w);
data->ty = (float)h / PotUp(data->img->h);
data->ntiles = data->count.i * data->count.j;
data->tx = (float)data->size.x / PotUp(data->img->w);
data->ty = (float)data->size.y / PotUp(data->img->h);


drawgroup = DRAWGROUP_BEFORE; drawgroup = DRAWGROUP_BEFORE;
} }
@@ -154,13 +159,13 @@ char const *TileSet::GetName()


void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o) void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
{ {
float tx = data->tx * ((id & 0xffff) % data->nw);
float ty = data->ty * ((id & 0xffff) / data->nw);
float tx = data->tx * ((id & 0xffff) % data->count.i);
float ty = data->ty * ((id & 0xffff) / data->count.i);
float dilate = data->dilate; float dilate = data->dilate;


int dx = data->w;
int dy = o ? 0 : data->h;
int dz = o ? data->h : 0;
int dx = data->size.x;
int dy = o ? 0 : data->size.y;
int dz = o ? data->size.y : 0;


if (!data->img) if (!data->img)
{ {


+ 1
- 1
src/tileset.h 查看文件

@@ -28,7 +28,7 @@ class TileSetData;
class TileSet : public Entity class TileSet : public Entity
{ {
public: public:
TileSet(char const *path, int w, int h, float dilate);
TileSet(char const *path, int2 size, int2 count, float dilate);
virtual ~TileSet(); virtual ~TileSet();


protected: protected:


正在加载...
取消
保存