Ignore:
Timestamp:
Aug 22, 2010, 2:55:39 AM (11 years ago)
Author:
sam
Message:

Factor Forge and Tiler using the new Dict class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tiler.cpp

    r150 r153  
    77#   include "config.h"
    88#endif
    9 
    10 #include <cstring>
    11 #include <cstdio>
    12 #include <cstdlib>
    139
    1410#include "core.h"
     
    2723
    2824public:
    29     TilerData() :
    30         tilesets(0),
    31         ntilesets(0)
    32     {
    33         /* Nothing to do */
    34     }
    35 
    36     ~TilerData()
    37     {
    38         if (ntilesets)
    39             fprintf(stderr, "ERROR: still %i tilesets in tiler\n", ntilesets);
    40         free(tilesets);
    41     }
    42 
    43 private:
    44     TileSet **tilesets;
    45     int ntilesets;
     25    Dict tilesets;
    4626}
    4727tilerdata;
     
    5535int Tiler::Register(char const *path)
    5636{
    57     int id, empty = -1;
     37    int id = data->tilesets.MakeSlot(path);
    5838
    59     /* If the tileset is already registered, remember its ID. Look for an
    60      * empty slot at the same time. */
    61     for (id = 0; id < data->ntilesets; id++)
     39    if (!data->tilesets.GetEntity(id))
    6240    {
    63         TileSet *t = data->tilesets[id];
    64         if (!t)
    65             empty = id;
    66         else if (!strcasecmp(path, t->GetName()))
    67             break;
     41        TileSet *tileset = new TileSet(path);
     42        data->tilesets.SetEntity(id, tileset);
    6843    }
    6944
    70     /* If this is a new tileset, create a new one. */
    71     if (id == data->ntilesets)
    72     {
    73         if (empty == -1)
    74         {
    75             empty = data->ntilesets++;
    76             data->tilesets = (TileSet **)realloc(data->tilesets,
    77                                          data->ntilesets * sizeof(TileSet *));
    78         }
    79 
    80         data->tilesets[empty] = new TileSet(path);
    81         id = empty;
    82     }
    83 
    84     data->tilesets[id]->Ref();
    8545    return id + 1; /* ID 0 is for the empty tileset */
    8646}
     
    8848void Tiler::Deregister(int id)
    8949{
    90     --id; /* ID 0 is for the empty tileset */
    91 
    92     if (data->tilesets[id]->Unref() == 0)
    93         data->tilesets[id] = NULL;
     50    data->tilesets.RemoveSlot(id - 1); /* ID 0 is for the empty tileset */
    9451}
    9552
     
    9855    int id = (code >> 16) - 1; /* ID 0 is for the empty tileset */
    9956
    100     data->tilesets[id]->BlitTile(code & 0xffff, x, y, z, o);
     57    TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
     58    tileset->BlitTile(code & 0xffff, x, y, z, o);
    10159}
    10260
Note: See TracChangeset for help on using the changeset viewer.