Changeset 210


Ignore:
Timestamp:
Sep 13, 2010, 1:24:54 AM (10 years ago)
Author:
sam
Message:

Allow for different priorities in game and draw tick levels.

Location:
trunk/src
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugfps.cpp

    r167 r210  
    3434
    3535    data->fontid = Forge::Register("gfx/font/ascii.png");
    36 }
    3736
    38 Entity::Group DebugFps::GetGroup()
    39 {
    40     return GROUP_AFTER;
     37    drawgroup = DRAWGROUP_HUD;
    4138}
    4239
  • trunk/src/debugfps.h

    r154 r210  
    2323
    2424protected:
    25     virtual Group GetGroup();
    2625    virtual void TickDraw(float deltams);
    2726
  • trunk/src/debugrecord.cpp

    r178 r210  
    4747    data->sequence = NULL;
    4848#endif
    49 }
    5049
    51 Entity::Group DebugRecord::GetGroup()
    52 {
    53     return GROUP_DRAW_CAPTURE;
     50    drawgroup = DRAWGROUP_CAPTURE;
    5451}
    5552
  • trunk/src/debugrecord.h

    r154 r210  
    2323
    2424protected:
    25     virtual Group GetGroup();
    2625    virtual void TickGame(float deltams);
    2726    virtual void TickDraw(float deltams);
  • trunk/src/debugsphere.cpp

    r208 r210  
    111111}
    112112
    113 Entity::Group DebugSphere::GetGroup()
    114 {
    115     return GROUP_DEFAULT;
    116 }
    117 
    118113void DebugSphere::TickGame(float deltams)
    119114{
  • trunk/src/debugsphere.h

    r208 r210  
    2323
    2424protected:
    25     virtual Group GetGroup();
    2625    virtual void TickGame(float deltams);
    2726    virtual void TickDraw(float deltams);
  • trunk/src/debugsprite.cpp

    r205 r210  
    4343}
    4444
    45 Entity::Group DebugSprite::GetGroup()
    46 {
    47     return GROUP_DEFAULT;
    48 }
    49 
    5045void DebugSprite::TickGame(float deltams)
    5146{
  • trunk/src/debugsprite.h

    r154 r210  
    2424
    2525protected:
    26     virtual Group GetGroup();
    2726    virtual void TickGame(float deltams);
    2827    virtual void TickDraw(float deltams);
  • trunk/src/debugstats.cpp

    r203 r210  
    3333    data = new DebugStatsData();
    3434    data->fp = fopen(path, "w+");
    35 }
    3635
    37 Entity::Group DebugStats::GetGroup()
    38 {
    39     return GROUP_AFTER;
     36    gamegroup = GAMEGROUP_AFTER;
    4037}
    4138
  • trunk/src/debugstats.h

    r203 r210  
    2323
    2424protected:
    25     virtual Group GetGroup();
    2625    virtual void TickGame(float deltams);
    2726
  • trunk/src/entity.cpp

    r170 r210  
    1818
    1919Entity::Entity() :
    20     next(0),
     20    gamenext(0),
     21    drawnext(0),
    2122    ref(0),
    2223    destroy(0)
     
    2526    state = STATE_IDLE;
    2627#endif
     28    gamegroup = GAMEGROUP_DEFAULT;
     29    drawgroup = DRAWGROUP_DEFAULT;
    2730    Ticker::Register(this);
    2831}
     
    3942{
    4043    return "<entity>";
    41 }
    42 
    43 Entity::Group Entity::GetGroup()
    44 {
    45     return GROUP_DEFAULT;
    4644}
    4745
  • trunk/src/entity.h

    r170 r210  
    2424
    2525protected:
    26     typedef enum
    27     {
    28         GROUP_BEFORE = 0,
    29         GROUP_DEFAULT,
    30         GROUP_AFTER,
    31         GROUP_DRAW_CAPTURE,
    32         // Must be the last element
    33         GROUP_COUNT
    34     }
    35     Group;
    36 
    3726    Entity();
    3827    virtual ~Entity();
    3928
    4029    virtual char const *GetName();
    41     virtual Group GetGroup();
    4230
    4331    virtual void TickGame(float deltams);
    4432    virtual void TickDraw(float deltams);
    4533
    46     Entity *next, *autonext;
     34    Entity *gamenext, *drawnext, *autonext;
    4735    int ref, autorelease, destroy;
     36
     37    enum
     38    {
     39        GAMEGROUP_BEFORE = 0,
     40        GAMEGROUP_DEFAULT,
     41        GAMEGROUP_AFTER,
     42        // Must be the last element
     43        GAMEGROUP_END
     44    }
     45    gamegroup;
     46
     47    enum
     48    {
     49        DRAWGROUP_BEFORE = GAMEGROUP_END,
     50        DRAWGROUP_DEFAULT,
     51        DRAWGROUP_HUD,
     52        DRAWGROUP_CAPTURE,
     53        // Must be the last element
     54        DRAWGROUP_END
     55    }
     56    drawgroup;
     57
     58    static int const GAMEGROUP_BEGIN = 0;
     59    static int const DRAWGROUP_BEGIN = GAMEGROUP_END;
     60    static int const ALLGROUP_END = DRAWGROUP_END;
    4861
    4962#if !FINAL_RELEASE
  • trunk/src/font.cpp

    r186 r210  
    5959        exit(1);
    6060    }
     61
     62    drawgroup = DRAWGROUP_BEFORE;
    6163}
    6264
     
    6466{
    6567    delete data;
    66 }
    67 
    68 Entity::Group Font::GetGroup()
    69 {
    70     return GROUP_BEFORE;
    7168}
    7269
  • trunk/src/font.h

    r154 r210  
    2525    /* Inherited from Entity */
    2626    virtual char const *GetName();
    27     virtual Group GetGroup();
    2827    virtual void TickDraw(float deltams);
    2928
  • trunk/src/game.cpp

    r154 r210  
    4848}
    4949
    50 Entity::Group Game::GetGroup()
    51 {
    52     return Entity::GetGroup();
    53 }
    54 
    5550void Game::TickGame(float deltams)
    5651{
  • trunk/src/game.h

    r154 r210  
    2525protected:
    2626    /* Inherited from Entity */
    27     virtual Group GetGroup();
    2827    virtual void TickGame(float deltams);
    2928    virtual void TickDraw(float deltams);
  • trunk/src/mapviewer.cpp

    r157 r210  
    4848}
    4949
    50 Entity::Group MapViewer::GetGroup()
    51 {
    52     return Entity::GetGroup();
    53 }
    54 
    5550void MapViewer::TickGame(float deltams)
    5651{
  • trunk/src/mapviewer.h

    r157 r210  
    2525protected:
    2626    /* Inherited from Entity */
    27     virtual Group GetGroup();
    2827    virtual void TickGame(float deltams);
    2928    virtual void TickDraw(float deltams);
  • trunk/src/sdlinput.cpp

    r170 r210  
    3535    data = new SdlInputData();
    3636    SDL_GetMouseState(&data->mx, &data->my);
    37 }
    3837
    39 Entity::Group SdlInput::GetGroup()
    40 {
    41     return GROUP_BEFORE;
     38    gamegroup = GAMEGROUP_BEFORE;
    4239}
    4340
  • trunk/src/sdlinput.h

    r170 r210  
    2424
    2525protected:
    26     virtual Group GetGroup();
    2726    virtual void TickGame(float deltams);
    2827
  • trunk/src/ticker.cpp

    r170 r210  
    2828        frame(0), deltams(0), bias(0)
    2929    {
    30         for (int i = 0; i < Entity::GROUP_COUNT; i++)
     30        for (int i = 0; i < Entity::ALLGROUP_END; i++)
    3131            list[i] = NULL;
    3232    }
     
    5252    /* Entity management */
    5353    Entity *todolist, *autolist;
    54     Entity *list[Entity::GROUP_COUNT];
     54    Entity *list[Entity::ALLGROUP_END];
    5555    int nentities;
    5656
     
    7373     * ready yet, so we do not know which group this entity belongs to. Wait
    7474     * until the first tick. */
    75     entity->next = data->todolist;
     75    entity->gamenext = data->todolist;
    7676    data->todolist = entity;
    7777    /* Objects are autoreleased by default. Put them in a circular list. */
     
    100100            if (e == entity)
    101101            {
    102                 if (prev)
    103                     prev->autonext = e->autonext;
    104                 else
    105                     data->autolist = e->autonext;
     102                (prev ? prev->autonext : data->autolist) = e->autonext;
    106103                break;
    107104            }
     
    133130#if 0
    134131    fprintf(stderr, "-------------------------------------\n");
    135     for (int i = 0; i < Entity::GROUP_COUNT; i++)
    136     {
    137         fprintf(stderr, "Group %i\n", i);
    138 
    139         for (Entity *e = data->list[i]; e; e = e->next)
     132    for (int i = 0; i < Entity::ALLGROUP_END; i++)
     133    {
     134        fprintf(stderr, "%s Group %i\n",
     135                (i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i);
     136
     137        for (Entity *e = data->list[i]; e; )
     138        {
    140139            fprintf(stderr, "  \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy);
     140            e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
     141        }
    141142    }
    142143#endif
     
    148149
    149150    /* Garbage collect objects that can be destroyed. We can do this
    150      * before inserting awaiting objects, because there is no way these
    151      * are already marked for destruction. */
    152     for (int i = 0; i < Entity::GROUP_COUNT; i++)
     151     * before inserting awaiting objects, because only objects already in
     152     * the tick lists can be marked for destruction. */
     153    for (int i = 0; i < Entity::ALLGROUP_END; i++)
    153154        for (Entity *e = data->list[i], *prev = NULL; e; )
    154155        {
    155             if (e->destroy)
    156             {
    157                 if (prev)
    158                     prev->next = e->next;
    159                 else
    160                     data->list[i] = e->next;
     156            if (e->destroy && i < Entity::GAMEGROUP_END)
     157            {
     158                /* If entity is to be destroyed, remove it from the
     159                 * game tick list. */
     160                (prev ? prev->gamenext : data->list[i]) = e->gamenext;
     161
     162                e = e->gamenext;
     163            }
     164            else if (e->destroy)
     165            {
     166                /* If entity is to be destroyed, remove it from the
     167                 * draw tick list and destroy it. */
     168                (prev ? prev->drawnext : data->list[i]) = e->drawnext;
    161169
    162170                Entity *tmp = e;
    163                 e = e->next;
     171                e = e->drawnext; /* Can only be in a draw group list */
    164172                delete tmp;
    165173
     
    168176            else
    169177            {
    170                 if (e->ref <= 0)
     178                if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN)
    171179                    e->destroy = 1;
    172180                prev = e;
    173                 e = e->next;
     181                e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
    174182            }
    175183        }
     
    179187    {
    180188        Entity *e = data->todolist;
    181         data->todolist = e->next;
    182 
    183         int i = e->GetGroup();
    184         e->next = data->list[i];
    185         data->list[i] = e;
     189        data->todolist = e->gamenext;
     190
     191        e->gamenext = data->list[e->gamegroup];
     192        data->list[e->gamegroup] = e;
     193        e->drawnext = data->list[e->drawgroup];
     194        data->list[e->drawgroup] = e;
    186195    }
    187196
    188197    /* Tick objects for the game loop */
    189     for (int i = 0; i < Entity::GROUP_COUNT; i++)
    190         for (Entity *e = data->list[i]; e; e = e->next)
     198    for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++)
     199        for (Entity *e = data->list[i]; e; e = e->gamenext)
    191200            if (!e->destroy)
    192201            {
     
    212221
    213222    /* Tick objects for the draw loop */
    214     for (int i = 0; i < Entity::GROUP_COUNT; i++)
    215         for (Entity *e = data->list[i]; e; e = e->next)
     223    for (int i = Entity::DRAWGROUP_BEGIN; i < Entity::DRAWGROUP_END; i++)
     224        for (Entity *e = data->list[i]; e; e = e->drawnext)
    216225            if (!e->destroy)
    217226            {
  • trunk/src/tileset.cpp

    r205 r210  
    7272    data->tx = 32.0f / data->img->w;
    7373    data->ty = 32.0f / data->img->h;
     74
     75    drawgroup = DRAWGROUP_BEFORE;
    7476}
    7577
     
    7981    free(data->name);
    8082    delete data;
    81 }
    82 
    83 Entity::Group TileSet::GetGroup()
    84 {
    85     return GROUP_BEFORE;
    8683}
    8784
  • trunk/src/tileset.h

    r154 r210  
    3030    /* Inherited from Entity */
    3131    virtual char const *GetName();
    32     virtual Group GetGroup();
    3332    virtual void TickDraw(float deltams);
    3433
  • trunk/src/world.cpp

    r183 r210  
    3636    data->width = 0;
    3737    data->height = 0;
     38
     39    drawgroup = DRAWGROUP_BEFORE;
    3840}
    3941
     
    4143{
    4244    delete data;
    43 }
    44 
    45 Entity::Group World::GetGroup()
    46 {
    47     return GROUP_BEFORE;
    4845}
    4946
  • trunk/src/world.h

    r183 r210  
    2525    /* Inherited from Entity */
    2626    virtual char const *GetName();
    27     virtual Group GetGroup();
    2827    virtual void TickGame(float deltams);
    2928    virtual void TickDraw(float deltams);
Note: See TracChangeset for help on using the changeset viewer.