Browse Source

Fix the Dict class. It wasn't even implemented properly.

legacy
Sam Hocevar sam 14 years ago
parent
commit
c1a3d37e7b
1 changed files with 12 additions and 12 deletions
  1. +12
    -12
      src/dict.cpp

+ 12
- 12
src/dict.cpp View File

@@ -33,6 +33,7 @@ class DictData
public: public:
DictData() : DictData() :
entities(0), entities(0),
maxid(0),
nentities(0) nentities(0)
{ {
/* Nothing to do */ /* Nothing to do */
@@ -49,7 +50,7 @@ public:


private: private:
Entity **entities; Entity **entities;
int nentities;
int maxid, nentities;
}; };


/* /*
@@ -72,11 +73,14 @@ int Dict::MakeSlot(char const *name)


/* If the entry is already registered, remember its ID. Look for an /* If the entry is already registered, remember its ID. Look for an
* empty slot at the same time. */ * empty slot at the same time. */
for (id = 0; id < data->nentities; id++)
for (id = 0; id < data->maxid; id++)
{ {
Entity *e = data->entities[id]; Entity *e = data->entities[id];
if (!e) if (!e)
{
empty = id; empty = id;
break;
}
else else
{ {
char const *oldname = e->GetName(); char const *oldname = e->GetName();
@@ -96,17 +100,18 @@ int Dict::MakeSlot(char const *name)
} }


/* If this is a new entry, create a new slot for it. */ /* If this is a new entry, create a new slot for it. */
if (id == data->nentities)
if (id == data->maxid || !data->entities[id])
{ {
if (empty == -1)
if (id == data->maxid)
{ {
empty = data->nentities++;
empty = data->maxid++;
data->entities = (Entity **)realloc(data->entities, data->entities = (Entity **)realloc(data->entities,
data->nentities * sizeof(Entity *));
data->maxid * sizeof(Entity *));
} }


data->entities[empty] = NULL; data->entities[empty] = NULL;
id = empty; id = empty;
data->nentities++;
} }
else else
{ {
@@ -121,12 +126,7 @@ void Dict::RemoveSlot(int id)
if (Ticker::Unref(data->entities[id]) == 0) if (Ticker::Unref(data->entities[id]) == 0)
{ {
data->entities[id] = NULL; data->entities[id] = NULL;
if (data->nentities)
data->nentities--;
#if !FINAL_RELEASE
else
fprintf(stderr, "ERROR: removing entity from empty dict\n");
#endif
data->nentities--;
} }
} }




Loading…
Cancel
Save