Changeset 101


Ignore:
Timestamp:
Aug 11, 2010, 6:18:41 PM (10 years ago)
Author:
sam
Message:

Implement ticking groups.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/asset.cpp

    r100 r101  
    2929}
    3030
     31Asset::Group Asset::GetGroup()
     32{
     33    return GROUP_DEFAULT;
     34}
     35
    3136void Asset::TickGame(float delta_time)
    3237{
  • trunk/src/asset.h

    r100 r101  
    2020{
    2121    friend class Ticker;
     22    friend class TickerData;
    2223
    2324public:
     
    2526    virtual ~Asset();
    2627
    27     virtual void TickGame(float delta_time);
    28     virtual void TickRender(float delta_time);
    29 
    3028    virtual void Ref();
    3129    virtual int Unref();
    3230
    3331protected:
     32    typedef enum
     33    {
     34        GROUP_BEFORE = 0,
     35        GROUP_DEFAULT,
     36        GROUP_AFTER,
     37        GROUP_COUNT
     38    }
     39    Group;
     40
     41    virtual Group GetGroup();
     42
     43    virtual void TickGame(float delta_time);
     44    virtual void TickRender(float delta_time);
     45
    3446    Asset *next;
    3547    int ref, destroy;
  • trunk/src/ticker.cpp

    r100 r101  
    2525public:
    2626    TickerData() :
    27         list(0),
    2827        nassets(0)
    2928    {
     29        for (int i = 0; i < Asset::GROUP_COUNT; i++)
     30            list[i] = NULL;
    3031    }
    3132
     
    3738
    3839private:
    39     Asset *list;
     40    Asset *list[Asset::GROUP_COUNT];
    4041    int nassets;
    4142}
     
    5051void Ticker::Register(Asset *asset)
    5152{
    52     asset->next = data->list;
    53     data->list = asset;
     53    int i = asset->GetGroup();
     54    asset->next = data->list[i];
     55    data->list[i] = asset;
    5456    data->nassets++;
    5557}
     
    5860{
    5961    /* Garbage collect objects that can be destroyed */
    60     for (Asset *asset = data->list, *prev = NULL;
    61          asset;
    62          prev = asset, asset = asset->next)
    63         if (asset->destroy)
    64         {
    65             if (prev)
    66                 prev->next = asset->next;
    67             else
    68                 data->list = asset->next;
     62    for (int i = 0; i < Asset::GROUP_COUNT; i++)
     63        for (Asset *a = data->list[i], *prev = NULL; a; prev = a, a = a->next)
     64            if (a->destroy)
     65            {
     66                if (prev)
     67                    prev->next = a->next;
     68                else
     69                    data->list[i] = a->next;
    6970
    70             data->nassets--;
    71             delete asset;
    72         }
     71                data->nassets--;
     72                delete a;
     73            }
    7374
    7475    /* Tick objects for the game loop */
    75     for (Asset *asset = data->list; asset; asset = asset->next)
    76         asset->TickGame(delta_time);
     76    for (int i = 0; i < Asset::GROUP_COUNT; i++)
     77        for (Asset *a = data->list[i]; a; a = a->next)
     78            a->TickGame(delta_time);
    7779}
    7880
     
    8082{
    8183    /* Tick objects for the render loop */
    82     for (Asset *asset = data->list; asset; asset = asset->next)
    83         asset->TickRender(delta_time);
     84    for (int i = 0; i < Asset::GROUP_COUNT; i++)
     85        for (Asset *a = data->list[i]; a; a = a->next)
     86            a->TickRender(delta_time);
    8487}
    8588
Note: See TracChangeset for help on using the changeset viewer.