Browse Source

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 years ago
parent
commit
375d7ee14d
5 changed files with 29 additions and 24 deletions
  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 View File

@@ -127,7 +127,7 @@ Map::Map(char const *path)
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1)
{
/* 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));
data->ntilers++;
//fprintf(stderr, "new tiler %s\n", str);


+ 2
- 2
src/tiler.cpp View File

@@ -45,13 +45,13 @@ static TilerData * const data = &tilerdata;
* 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);

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);
#if !FINAL_RELEASE
if (id == data->lasterror)


+ 1
- 1
src/tiler.h View File

@@ -22,7 +22,7 @@
class Tiler
{
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 BlitTile(uint32_t code, int x, int y, int z, int o);


+ 24
- 19
src/tileset.cpp View File

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

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

SDL_Surface *img;
@@ -53,7 +53,7 @@ private:
* 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->name = (char *)malloc(10 + strlen(path) + 1);
@@ -77,19 +77,24 @@ TileSet::TileSet(char const *path, int w, int h, float dilate)
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->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;
}
@@ -154,13 +159,13 @@ char const *TileSet::GetName()

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;

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)
{


+ 1
- 1
src/tileset.h View File

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

protected:


Loading…
Cancel
Save