Changeset 633


Ignore:
Timestamp:
Feb 11, 2011, 10:45:37 PM (8 years ago)
Author:
sam
Message:

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.

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/deushax/debugsprite.cpp

    r297 r633  
    3838    Ticker::Ref(game);
    3939    data->tiler = Tiler::Register("art/test/character-dress.png",
    40                                   32, 32, sqrtf(2));
     40                                  32, 0, sqrtf(2));
    4141    data->pos = float3(320, 206, 0);
    4242}
  • trunk/monsterz/board.cpp

    r384 r633  
    103103    data->npieces = minnpieces;
    104104    data->maxnpieces = maxnpieces;
    105     data->board = Tiler::Register(PNG_BOARD, 384, 384, 1.0f);
    106     data->tiles = Tiler::Register(PNG_TILES, data->size.x, data->size.y, 1.0f);
    107     data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f);
     105    data->board = Tiler::Register(PNG_BOARD, 384, 0, 1.0f);
     106    data->tiles = Tiler::Register(PNG_TILES, data->size, 0, 1.0f);
     107    data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f);
    108108    data->click = Sampler::Register(WAV_CLICK);
    109109    data->whip = Sampler::Register(WAV_WHIP);
  • trunk/monsterz/interface.cpp

    r353 r633  
    5555    data->title = NULL;
    5656    data->board = NULL;
    57     data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f);
    58     data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
     57    data->screen = Tiler::Register(PNG_BACKGROUND, int2(640, 480), 0, 1.0f);
     58    data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f);
    5959    data->state = InterfaceData::INIT;
    6060
  • trunk/monsterz/piece.cpp

    r419 r633  
    7676    case PIECE_HUNT:
    7777        data->size = 48;
    78         data->tiler = Tiler::Register(PNG_TILES,
    79                                       data->size.x, data->size.y, 1.0f);
     78        data->tiler = Tiler::Register(PNG_TILES, data->size, 0, 1.0f);
    8079        data->id = 80 + 20 * id;
    8180        break;
    8281    case PIECE_FUSION:
    8382        data->size = 40;
    84         data->tiler = Tiler::Register(PNG_ELEMENTS,
    85                                       data->size.x, data->size.y, 1.0f);
     83        data->tiler = Tiler::Register(PNG_ELEMENTS, data->size, 0, 1.0f);
    8684        data->id = id - 1;
    8785        break;
  • trunk/monsterz/thumbs.cpp

    r586 r633  
    4545  : data(new ThumbsData())
    4646{
    47     data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f);
     47    data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f);
    4848
    4949    data->npieces = 0;
  • trunk/monsterz/title.cpp

    r612 r633  
    118118    srand(rand() ^ time(NULL));
    119119
    120     data->logo = Tiler::Register(PNG_LOGO, 380, 181, 1.0f);
    121     data->title = Tiler::Register(PNG_TITLE, 384, 384, 1.0f);
    122     data->stars = Tiler::Register(PNG_STARS, 384, 144, 1.0f);
    123     data->clouds = Tiler::Register(PNG_CLOUDS, 160, 32, 1.0f);
    124     data->eagle = Tiler::Register(PNG_EAGLE, 16, 16, 1.0f);
     120    data->logo = Tiler::Register(PNG_LOGO, int2(380, 181), 0, 1.0f);
     121    data->title = Tiler::Register(PNG_TITLE, 384, 0, 1.0f);
     122    data->stars = Tiler::Register(PNG_STARS, int2(384, 144), 0, 1.0f);
     123    data->clouds = Tiler::Register(PNG_CLOUDS, int2(160, 32), 0, 1.0f);
     124    data->eagle = Tiler::Register(PNG_EAGLE, 16, 0, 1.0f);
    125125    for (int n = 0; n < 6; n++)
    126126        data->anim[n] = Tiler::Register(PNG_TITLEANIM[n],
    127                                         animsize[n].x, animsize[n].y, 1.0f);
     127                                        animsize[n], 0, 1.0f);
    128128    for (int n = 0; n < 7; n++)
    129129        data->event[n] = Tiler::Register(PNG_TITLEEVENT[n],
    130                                          eventsize[n].x, eventsize[n].y, 1.0f);
     130                                         eventsize[n], 0, 1.0f);
    131131    data->state = TitleData::IDLE;
    132132    data->period = TitleData::DAY;
  • trunk/src/map.cpp

    r289 r633  
    128128        {
    129129            /* This is a tileset image file. Associate it with firstgid. */
    130             data->tilers[data->ntilers] = Tiler::Register(str, 32, 32,
     130            data->tilers[data->ntilers] = Tiler::Register(str, 32, 0,
    131131                                                          sqrtf(2));
    132132            data->ntilers++;
  • trunk/src/tiler.cpp

    r418 r633  
    4646 */
    4747
    48 int Tiler::Register(char const *path, int w, int h, float dilate)
     48int Tiler::Register(char const *path, int2 size, int2 count, float dilate)
    4949{
    5050    int id = data->tilesets.MakeSlot(path);
     
    5252    if (!data->tilesets.GetEntity(id))
    5353    {
    54         TileSet *tileset = new TileSet(path, w, h, dilate);
     54        TileSet *tileset = new TileSet(path, size, count, dilate);
    5555        data->tilesets.SetEntity(id, tileset);
    5656#if !FINAL_RELEASE
  • trunk/src/tiler.h

    r222 r633  
    2323{
    2424public:
    25     static int Register(char const *path, int w, int h, float dilate);
     25    static int Register(char const *path, int2 size, int2 count, float dilate);
    2626    static void Deregister(int id);
    2727
  • trunk/src/tileset.cpp

    r419 r633  
    4242private:
    4343    char *name, *path;
    44     int *tiles;
    45     int w, h, nw, nh, ntiles;
     44    int *tiles, ntiles;
     45    int2 size, count;
    4646    float dilate, tx, ty;
    4747
     
    5454 */
    5555
    56 TileSet::TileSet(char const *path, int w, int h, float dilate)
     56TileSet::TileSet(char const *path, int2 size, int2 count, float dilate)
    5757  : data(new TileSetData())
    5858{
     
    7878    }
    7979
    80     if (w <= 0)
    81         w = 32;
    82     if (h <= 0)
    83         h = 32;
     80    if (count.i > 0 && count.j > 0)
     81    {
     82        data->count = count;
     83        data->size = int2(data->img->w, data->img->h) / count;
     84    }
     85    else
     86    {
     87        if (size.x <= 0 || size.y <= 0)
     88            size = 32;
     89        data->count.i = data->img->w > size.i ? data->img->w / size.i : 1;
     90        data->count.j = data->img->h > size.j ? data->img->h / size.j : 1;
     91        data->size = size;
     92    }
    8493
    85     data->w = w;
    86     data->h = h;
    8794    data->dilate = dilate;
    88     data->nw = data->img->w > w ? data->img->w / w : 1;
    89     data->nh = data->img->h > h ? data->img->h / h : 1;
    90     data->ntiles = data->nw * data->nh;
    91     data->tx = (float)w / PotUp(data->img->w);
    92     data->ty = (float)h / PotUp(data->img->h);
     95    data->ntiles = data->count.i * data->count.j;
     96    data->tx = (float)data->size.x / PotUp(data->img->w);
     97    data->ty = (float)data->size.y / PotUp(data->img->h);
    9398
    9499    drawgroup = DRAWGROUP_BEFORE;
     
    155160void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
    156161{
    157     float tx = data->tx * ((id & 0xffff) % data->nw);
    158     float ty = data->ty * ((id & 0xffff) / data->nw);
     162    float tx = data->tx * ((id & 0xffff) % data->count.i);
     163    float ty = data->ty * ((id & 0xffff) / data->count.i);
    159164    float dilate = data->dilate;
    160165
    161     int dx = data->w;
    162     int dy = o ? 0 : data->h;
    163     int dz = o ? data->h : 0;
     166    int dx = data->size.x;
     167    int dy = o ? 0 : data->size.y;
     168    int dz = o ? data->size.y : 0;
    164169
    165170    if (!data->img)
  • trunk/src/tileset.h

    r222 r633  
    2929{
    3030public:
    31     TileSet(char const *path, int w, int h, float dilate);
     31    TileSet(char const *path, int2 size, int2 count, float dilate);
    3232    virtual ~TileSet();
    3333
Note: See TracChangeset for help on using the changeset viewer.