Ignore:
Timestamp:
Feb 7, 2011, 9:21:41 PM (9 years ago)
Author:
sam
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dict.cpp

    r419 r420  
    3434    DictData() :
    3535        entities(0),
     36        maxid(0),
    3637        nentities(0)
    3738    {
     
    5051private:
    5152    Entity **entities;
    52     int nentities;
     53    int maxid, nentities;
    5354};
    5455
     
    7374    /* If the entry is already registered, remember its ID. Look for an
    7475     * empty slot at the same time. */
    75     for (id = 0; id < data->nentities; id++)
     76    for (id = 0; id < data->maxid; id++)
    7677    {
    7778        Entity *e = data->entities[id];
    7879        if (!e)
     80        {
    7981            empty = id;
     82            break;
     83        }
    8084        else
    8185        {
     
    97101
    98102    /* If this is a new entry, create a new slot for it. */
    99     if (id == data->nentities)
     103    if (id == data->maxid || !data->entities[id])
    100104    {
    101         if (empty == -1)
     105        if (id == data->maxid)
    102106        {
    103             empty = data->nentities++;
     107            empty = data->maxid++;
    104108            data->entities = (Entity **)realloc(data->entities,
    105                                            data->nentities * sizeof(Entity *));
     109                                                data->maxid * sizeof(Entity *));
    106110        }
    107111
    108112        data->entities[empty] = NULL;
    109113        id = empty;
     114        data->nentities++;
    110115    }
    111116    else
     
    122127    {
    123128        data->entities[id] = NULL;
    124         if (data->nentities)
    125             data->nentities--;
    126 #if !FINAL_RELEASE
    127         else
    128             fprintf(stderr, "ERROR: removing entity from empty dict\n");
    129 #endif
     129        data->nentities--;
    130130    }
    131131}
Note: See TracChangeset for help on using the changeset viewer.