diff --git a/src/dict.cpp b/src/dict.cpp index c2f7d3b8..70532cc0 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -36,8 +36,6 @@ class DictData public: DictData() : - entities(0), - maxid(0), nentities(0) { /* Nothing to do */ @@ -49,12 +47,11 @@ public: if (nentities) Log::Error("still %i entities in dict\n", nentities); #endif - free(entities); } private: - Entity **entities; - int maxid, nentities; + Array m_entities; + int nentities; }; /* @@ -77,9 +74,9 @@ int Dict::MakeSlot(char const *name) /* If the entry is already registered, remember its ID. Look for an * empty slot at the same time. */ - for (slotid = 0; slotid < data->maxid; slotid++) + for (slotid = 0; slotid < data->m_entities.Count(); slotid++) { - Entity *e = data->entities[slotid]; + Entity *e = data->m_entities[slotid]; if (!e) { empty = slotid; @@ -104,22 +101,21 @@ int Dict::MakeSlot(char const *name) } /* If this is a new entry, create a new slot for it. */ - if (slotid == data->maxid || !data->entities[slotid]) + if (slotid == data->m_entities.Count() || !data->m_entities[slotid]) { - if (slotid == data->maxid) + if (slotid == data->m_entities.Count()) { - empty = data->maxid++; - data->entities = (Entity **)realloc(data->entities, - data->maxid * sizeof(Entity *)); + empty = data->m_entities.Count(); + data->m_entities.Push(NULL); } - data->entities[empty] = NULL; + data->m_entities[empty] = NULL; slotid = empty; data->nentities++; } else { - Ticker::Ref(data->entities[slotid]); + Ticker::Ref(data->m_entities[slotid]); } return slotid; @@ -127,17 +123,17 @@ int Dict::MakeSlot(char const *name) void Dict::RemoveSlot(int slotid) { - if (Ticker::Unref(data->entities[slotid]) == 0) + if (Ticker::Unref(data->m_entities[slotid]) == 0) { - data->entities[slotid] = NULL; + data->m_entities[slotid] = NULL; data->nentities--; } } void Dict::RemoveSlot(Entity *entity) { - for (int slotid = 0; slotid < data->maxid; slotid++) - if (data->entities[slotid] == entity) + for (int slotid = 0; slotid < data->m_entities.Count(); slotid++) + if (data->m_entities[slotid] == entity) { RemoveSlot(slotid); return; @@ -152,12 +148,12 @@ void Dict::RemoveSlot(Entity *entity) void Dict::SetEntity(int slotid, Entity *entity) { Ticker::Ref(entity); - data->entities[slotid] = entity; + data->m_entities[slotid] = entity; } Entity *Dict::GetEntity(int slotid) { - return data->entities[slotid]; + return data->m_entities[slotid]; } } /* namespace lol */ diff --git a/src/map.cpp b/src/map.cpp index e6e86395..d68fc1d7 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -38,8 +38,7 @@ private: TileSet *tilesets[MAX_TILESETS]; int ntilers; - Layer **layers; - int nlayers; + Array m_layers; int width, height; }; @@ -52,8 +51,6 @@ Map::Map(char const *path) : data(new MapData()) { data->ntilers = 0; - data->layers = NULL; - data->nlayers = 0; data->width = 0; data->height = 0; @@ -120,8 +117,7 @@ Map::Map(char const *path) { Layer *l = new Layer(data->width, data->height, level, orientation, tiles); - data->layers[data->nlayers] = l; - data->nlayers++; + data->m_layers.Push(l); tiles = NULL; //Log::Debug("new layer %ix%i\n", data->width, data->height); } @@ -143,8 +139,6 @@ Map::Map(char const *path) "width=\"%i\" height=\"%i\"", &a, &i, &b, &j, &k) == 5) { /* This is a layer description. Prepare to read the data. */ - data->layers = (Layer **)realloc(data->layers, - sizeof(Layer **) * (data->nlayers + 1)); orientation = toupper(a) == 'V' ? 1 : 0; level = i * 32; data->width = j; @@ -161,16 +155,15 @@ Map::~Map() { for (int i = 0; i < data->ntilers; i++) Tiler::Deregister(data->tilesets[i]); - for (int i = 0; i < data->nlayers; i++) - delete data->layers[i]; - free(data->layers); + for (int i = 0; i < data->m_layers.Count(); i++) + delete data->m_layers[i]; delete data; } void Map::Render(int x, int y, int z) { - for (int i = 0; i < data->nlayers; i++) - data->layers[i]->Render(x, y, z); + for (int i = 0; i < data->m_layers.Count(); i++) + data->m_layers[i]->Render(x, y, z); } int Map::GetWidth()