Browse Source

Allow to query for a tileset's size and/or number of tiles.

legacy
Sam Hocevar sam 13 years ago
parent
commit
bcca962ba9
4 changed files with 40 additions and 0 deletions
  1. +26
    -0
      src/tiler.cpp
  2. +2
    -0
      src/tiler.h
  3. +10
    -0
      src/tileset.cpp
  4. +2
    -0
      src/tileset.h

+ 26
- 0
src/tiler.cpp View File

@@ -67,6 +67,32 @@ void Tiler::Deregister(int id)
data->tilesets.RemoveSlot(id - 1); /* ID 0 is for the empty tileset */
}

int2 Tiler::GetSize(int id)
{
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id - 1);
#if !FINAL_RELEASE
if (!tileset)
{
fprintf(stderr, "ERROR: getting size for null tiler #%i\n", id);
return 0;
}
#endif
return tileset->GetSize();
}

int2 Tiler::GetCount(int id)
{
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id - 1);
#if !FINAL_RELEASE
if (!tileset)
{
fprintf(stderr, "ERROR: getting count for null tiler #%i\n", id);
return 0;
}
#endif
return tileset->GetCount();
}

void Tiler::BlitTile(uint32_t code, int x, int y, int z, int o)
{
int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */


+ 2
- 0
src/tiler.h View File

@@ -25,6 +25,8 @@ public:
static int Register(char const *path, int2 size, int2 count, float dilate);
static void Deregister(int id);

static int2 GetSize(int id);
static int2 GetCount(int id);
static void BlitTile(uint32_t code, int x, int y, int z, int o);
};



+ 10
- 0
src/tileset.cpp View File

@@ -157,6 +157,16 @@ char const *TileSet::GetName()
return data->name;
}

int2 TileSet::GetSize() const
{
return data->size;
}

int2 TileSet::GetCount() const
{
return data->count;
}

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


+ 2
- 0
src/tileset.h View File

@@ -38,6 +38,8 @@ protected:

public:
/* New methods */
int2 GetSize() const;
int2 GetCount() const;
void BlitTile(uint32_t id, int x, int y, int z, int o);

private:


Loading…
Cancel
Save