Changeset 1106


Ignore:
Timestamp:
Dec 7, 2011, 2:06:19 AM (8 years ago)
Author:
sam
Message:

core: try to merge Ticker and Emcee. Still not very good.

Location:
trunk
Files:
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/deushax/gtk/glmapview.cpp

    r863 r1106  
    111111        ticking = TRUE;
    112112
     113        /* FIXME: shouldn't this be protected by a mutex? */
    113114        if (mapviewer)
    114115            mapviewer->SetPOV(gtk_adjustment_get_value(hadj),
    115116                              mapviewer->GetHeight() - glarea->allocation.height
    116117                               - gtk_adjustment_get_value(vadj));
    117 
    118         /* Tick the game */
    119         Ticker::TickGame();
    120118    }
    121119
     
    183181        while (g_main_context_iteration(NULL, FALSE))
    184182            ;
    185 
    186         /* FIXME: do some GTK stuff instead of waiting for so long */
    187         Ticker::ClampFps();
    188183    }
    189184
  • trunk/src/Makefile.am

    r1105 r1106  
    1212    worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \
    1313    platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \
    14     real.cpp real.h emcee.cpp emcee.h \
     14    real.cpp real.h \
    1515    \
    1616    lol/unit.h \
  • trunk/src/application/application.cpp

    r1105 r1106  
    6060Application::Application(char const *name, ivec2 resolution, float framerate)
    6161{
    62     Emcee::Setup();
    6362    data = new ApplicationData(name, resolution, framerate);
    6463}
     
    7776{
    7877    delete data;
    79     Emcee::Shutdown();
    8078}
    8179
  • trunk/src/core.h

    r1105 r1106  
    104104
    105105// Managers
    106 #include "emcee.h"
    107106#include "ticker.h"
    108107#include "forge.h"
  • trunk/src/eglapp.cpp

    r863 r1106  
    159159    while (!Ticker::Finished())
    160160    {
    161         /* Tick the game */
    162         Ticker::TickGame();
    163 
    164161        /* Tick the renderer, show the frame and clamp to desired framerate. */
    165162        Ticker::TickDraw();
     
    167164        eglSwapBuffers(data->egl_dpy, data->egl_surf);
    168165#endif
    169 
    170         Ticker::ClampFps();
    171166    }
    172167}
  • trunk/src/entity.cpp

    r1105 r1106  
    7171void Entity::SetState(uint32_t state)
    7272{
    73     Emcee::SetState(this, state);
     73    Ticker::SetState(this, state);
    7474}
    7575
     
    7777                               Entity *other_entity, uint32_t other_state)
    7878{
    79     Emcee::SetStateWhenMatch(this, state, other_entity, other_state);
     79    Ticker::SetStateWhenMatch(this, state, other_entity, other_state);
    8080}
    8181
  • trunk/src/entity.h

    r1105 r1106  
    3030    friend class TickerData;
    3131    friend class Dict;
     32    friend class Emcee;
    3233
    3334protected:
  • trunk/src/platform/android/androidapp.cpp

    r966 r1106  
    9797Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
    9898{
    99     Ticker::ClampFps();
    100     Ticker::TickGame();
    10199    Ticker::TickDraw();
    102100}
  • trunk/src/platform/nacl/nacl_instance.cpp

    r1087 r1106  
    127127        return;
    128128
    129     Ticker::ClampFps();
    130     Ticker::TickGame();
    131 
    132129    opengl_context_->MakeContextCurrent(this);
    133130    Ticker::TickDraw();
  • trunk/src/platform/nacl/naclapp.cpp

    r1084 r1106  
    5959    while (!Ticker::Finished())
    6060    {
    61         /* Tick the game */
    62         Ticker::TickGame();
    63 
    6461        /* Tick the renderer, show the frame and clamp to desired framerate. */
    6562        Ticker::TickDraw();
     
    6764#if defined __native_client__
    6865#endif
    69 
    70         Ticker::ClampFps();
    7166    }
    7267}
  • trunk/src/platform/ps3/ps3app.cpp

    r1063 r1106  
    119119    while (!Ticker::Finished())
    120120    {
    121         /* Tick the game */
    122         Ticker::TickGame();
    123 
    124121        /* Tick the renderer, show the frame and clamp to desired framerate. */
    125122        Ticker::TickDraw();
     
    131128        cellSysutilCheckCallback();
    132129#endif
    133 
    134         Ticker::ClampFps();
    135130    }
    136131}
  • trunk/src/platform/sdl/sdlapp.cpp

    r1069 r1106  
    8585    while (!Ticker::Finished())
    8686    {
    87         /* Tick the game */
    88         Ticker::TickGame();
    89 
    9087        /* Tick the renderer, show the frame and clamp to desired framerate. */
    9188        Ticker::TickDraw();
     
    9390        SDL_GL_SwapBuffers();
    9491#endif
    95         Ticker::ClampFps();
    9692    }
    9793}
  • trunk/src/ticker.cpp

    r735 r1106  
    6767    Timer timer;
    6868    float deltams, bias, fps;
     69
     70    /* Background threads */
     71    static void *GameThreadMain(void *p);
     72    static void *DrawThreadMain(void *p); /* unused */
     73    Thread *gamethread, *drawthread;
     74    Queue gametick, drawtick;
    6975
    7076    /* Shutdown management */
     
    142148}
    143149
    144 void Ticker::Setup(float fps)
    145 {
    146     data->fps = fps;
    147 }
    148 
    149 void Ticker::TickGame()
    150 {
    151     Profiler::Stop(Profiler::STAT_TICK_FRAME);
    152     Profiler::Start(Profiler::STAT_TICK_FRAME);
    153 
    154     Profiler::Start(Profiler::STAT_TICK_GAME);
     150void *TickerData::GameThreadMain(void *p)
     151{
     152    for (;;)
     153    {
     154        int tick = data->gametick.Pop();
     155        if (!tick)
     156            break;
     157
     158        Profiler::Stop(Profiler::STAT_TICK_FRAME);
     159        Profiler::Start(Profiler::STAT_TICK_FRAME);
     160
     161        Profiler::Start(Profiler::STAT_TICK_GAME);
    155162
    156163#if 0
    157     Log::Debug("-------------------------------------\n");
    158     for (int i = 0; i < Entity::ALLGROUP_END; i++)
    159     {
    160         Log::Debug("%s Group %i\n",
    161                    (i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i);
    162 
    163         for (Entity *e = data->list[i]; e; )
    164         {
    165             Log::Debug("  \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy);
    166             e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
    167         }
    168     }
    169 #endif
    170 
    171     data->frame++;
    172 
    173     /* If recording with fixed framerate, set deltams to a fixed value */
    174     if (data->recording && data->fps)
    175     {
    176         data->deltams = 1000.0f / data->fps;
    177     }
    178     else
    179     {
    180         data->deltams = data->timer.GetMs();
    181         data->bias += data->deltams;
    182     }
    183 
    184     /* If shutdown is stuck, kick the first entity we meet and see
    185      * whether it makes things better. Note that it is always a bug to
    186      * have referenced entities after 20 frames, but at least this
    187      * safeguard makes it possible to exit the program cleanly. */
    188     if (data->quit && !((data->frame - data->quitframe) % data->quitdelay))
    189     {
    190         int n = 0;
    191         data->panic = 2 * (data->panic + 1);
    192 
    193         for (int i = 0; i < Entity::ALLGROUP_END && n < data->panic; i++)
    194         for (Entity *e = data->list[i]; e && n < data->panic; e = e->gamenext)
    195             if (e->ref)
     164        Log::Debug("-------------------------------------\n");
     165        for (int i = 0; i < Entity::ALLGROUP_END; i++)
     166        {
     167            Log::Debug("%s Group %i\n",
     168                       (i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i);
     169
     170            for (Entity *e = data->list[i]; e; )
    196171            {
    197 #if !LOL_RELEASE
    198                 Log::Error("poking %s\n", e->GetName());
    199 #endif
    200                 e->ref--;
    201                 n++;
    202             }
    203 
    204 #if !LOL_RELEASE
    205         if (n)
    206             Log::Error("%i entities stuck after %i frames, poked %i\n",
    207                        data->nentities, data->quitdelay, n);
    208 #endif
    209 
    210         data->quitdelay = data->quitdelay > 1 ? data->quitdelay / 2 : 1;
    211     }
    212 
    213     /* Garbage collect objects that can be destroyed. We can do this
    214      * before inserting awaiting objects, because only objects already in
    215      * the tick lists can be marked for destruction. */
    216     for (int i = 0; i < Entity::ALLGROUP_END; i++)
    217         for (Entity *e = data->list[i], *prev = NULL; e; )
    218         {
    219             if (e->destroy && i < Entity::GAMEGROUP_END)
    220             {
    221                 /* If entity is to be destroyed, remove it from the
    222                  * game tick list. */
    223                 (prev ? prev->gamenext : data->list[i]) = e->gamenext;
    224 
    225                 e = e->gamenext;
    226             }
    227             else if (e->destroy)
    228             {
    229                 /* If entity is to be destroyed, remove it from the
    230                  * draw tick list and destroy it. */
    231                 (prev ? prev->drawnext : data->list[i]) = e->drawnext;
    232 
    233                 Entity *tmp = e;
    234                 e = e->drawnext; /* Can only be in a draw group list */
    235                 delete tmp;
    236 
    237                 data->nentities--;
    238             }
    239             else
    240             {
    241                 if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN)
    242                     e->destroy = 1;
    243                 prev = e;
     172                Log::Debug("  \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy);
    244173                e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
    245174            }
    246175        }
    247 
    248     /* Insert waiting objects into the appropriate lists */
    249     while (data->todolist)
    250     {
    251         Entity *e = data->todolist;
    252         data->todolist = e->gamenext;
    253 
    254         e->gamenext = data->list[e->gamegroup];
    255         data->list[e->gamegroup] = e;
    256         e->drawnext = data->list[e->drawgroup];
    257         data->list[e->drawgroup] = e;
    258     }
    259 
    260     /* Tick objects for the game loop */
    261     for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++)
    262         for (Entity *e = data->list[i]; e; e = e->gamenext)
    263             if (!e->destroy)
     176#endif
     177
     178        data->frame++;
     179
     180        /* If recording with fixed framerate, set deltams to a fixed value */
     181        if (data->recording && data->fps)
     182        {
     183            data->deltams = 1000.0f / data->fps;
     184        }
     185        else
     186        {
     187            data->deltams = data->timer.GetMs();
     188            data->bias += data->deltams;
     189        }
     190
     191        /* If shutdown is stuck, kick the first entity we meet and see
     192         * whether it makes things better. Note that it is always a bug to
     193         * have referenced entities after 20 frames, but at least this
     194         * safeguard makes it possible to exit the program cleanly. */
     195        if (data->quit && !((data->frame - data->quitframe) % data->quitdelay))
     196        {
     197            int n = 0;
     198            data->panic = 2 * (data->panic + 1);
     199
     200            for (int i = 0; i < Entity::ALLGROUP_END && n < data->panic; i++)
     201            for (Entity *e = data->list[i]; e && n < data->panic; e = e->gamenext)
     202                if (e->ref)
     203                {
     204#if !LOL_RELEASE
     205                    Log::Error("poking %s\n", e->GetName());
     206#endif
     207                    e->ref--;
     208                    n++;
     209                }
     210
     211#if !LOL_RELEASE
     212            if (n)
     213                Log::Error("%i entities stuck after %i frames, poked %i\n",
     214                           data->nentities, data->quitdelay, n);
     215#endif
     216
     217            data->quitdelay = data->quitdelay > 1 ? data->quitdelay / 2 : 1;
     218        }
     219
     220        /* Garbage collect objects that can be destroyed. We can do this
     221         * before inserting awaiting objects, because only objects already
     222         * inthe tick lists can be marked for destruction. */
     223        for (int i = 0; i < Entity::ALLGROUP_END; i++)
     224            for (Entity *e = data->list[i], *prev = NULL; e; )
    264225            {
    265 #if !LOL_RELEASE
    266                 if (e->state != Entity::STATE_IDLE)
    267                     Log::Error("entity not idle for game tick\n");
    268                 e->state = Entity::STATE_PRETICK_GAME;
    269 #endif
    270                 e->TickGame(data->deltams);
    271 #if !LOL_RELEASE
    272                 if (e->state != Entity::STATE_POSTTICK_GAME)
    273                     Log::Error("entity missed super game tick\n");
    274                 e->state = Entity::STATE_IDLE;
    275 #endif
     226                if (e->destroy && i < Entity::GAMEGROUP_END)
     227                {
     228                    /* If entity is to be destroyed, remove it from the
     229                     * game tick list. */
     230                    (prev ? prev->gamenext : data->list[i]) = e->gamenext;
     231
     232                    e = e->gamenext;
     233                }
     234                else if (e->destroy)
     235                {
     236                    /* If entity is to be destroyed, remove it from the
     237                     * draw tick list and destroy it. */
     238                    (prev ? prev->drawnext : data->list[i]) = e->drawnext;
     239
     240                    Entity *tmp = e;
     241                    e = e->drawnext; /* Can only be in a draw group list */
     242                    delete tmp;
     243
     244                    data->nentities--;
     245                }
     246                else
     247                {
     248                    if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN)
     249                        e->destroy = 1;
     250                    prev = e;
     251                    e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext;
     252                }
    276253            }
    277254
    278     Profiler::Stop(Profiler::STAT_TICK_GAME);
     255        /* Insert waiting objects into the appropriate lists */
     256        while (data->todolist)
     257        {
     258            Entity *e = data->todolist;
     259            data->todolist = e->gamenext;
     260
     261            e->gamenext = data->list[e->gamegroup];
     262            data->list[e->gamegroup] = e;
     263            e->drawnext = data->list[e->drawgroup];
     264            data->list[e->drawgroup] = e;
     265        }
     266
     267        /* Tick objects for the game loop */
     268        for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++)
     269            for (Entity *e = data->list[i]; e; e = e->gamenext)
     270                if (!e->destroy)
     271                {
     272#if !LOL_RELEASE
     273                    if (e->state != Entity::STATE_IDLE)
     274                        Log::Error("entity not idle for game tick\n");
     275                    e->state = Entity::STATE_PRETICK_GAME;
     276#endif
     277                    e->TickGame(data->deltams);
     278#if !LOL_RELEASE
     279                    if (e->state != Entity::STATE_POSTTICK_GAME)
     280                        Log::Error("entity missed super game tick\n");
     281                    e->state = Entity::STATE_IDLE;
     282#endif
     283                }
     284
     285        Profiler::Stop(Profiler::STAT_TICK_GAME);
     286
     287        data->drawtick.Push(1);
     288    }
     289
     290    data->drawtick.Push(0);
     291
     292    return NULL;
     293}
     294
     295void *TickerData::DrawThreadMain(void *p)
     296{
     297    for (;;)
     298    {
     299        int tick = data->drawtick.Pop();
     300        if (!tick)
     301            break;
     302
     303        data->gametick.Push(1);
     304    }
     305
     306    return NULL;
     307}
     308
     309void Ticker::SetState(Entity *entity, uint32_t state)
     310{
     311
     312}
     313
     314void Ticker::SetStateWhenMatch(Entity *entity, uint32_t state,
     315                               Entity *other_entity, uint32_t other_state)
     316{
     317
     318}
     319
     320void Ticker::Setup(float fps)
     321{
     322    data->fps = fps;
     323
     324    data->gamethread = new Thread(TickerData::GameThreadMain, NULL);
     325    data->gametick.Push(1);
    279326}
    280327
    281328void Ticker::TickDraw()
    282329{
     330    data->drawtick.Pop();
     331
    283332    Profiler::Start(Profiler::STAT_TICK_DRAW);
    284333
     
    323372    Profiler::Stop(Profiler::STAT_TICK_DRAW);
    324373    Profiler::Start(Profiler::STAT_TICK_BLIT);
    325 }
    326 
    327 void Ticker::ClampFps()
    328 {
     374
     375    /* Signal game thread that it can carry on */
     376    data->gametick.Push(1);
     377
     378    /* Clamp FPS */
    329379    Profiler::Stop(Profiler::STAT_TICK_BLIT);
    330380
     
    369419    data->quit = 1;
    370420    data->quitframe = data->frame;
     421
     422    data->gametick.Push(0);
     423    delete data->gamethread;
    371424}
    372425
  • trunk/src/ticker.h

    r748 r1106  
    3333
    3434    static void Setup(float fps);
    35     static void TickGame();
    3635    static void TickDraw();
    37     static void ClampFps();
    3836    static void StartBenchmark();
    3937    static void StopBenchmark();
     
    4139    static void StopRecording();
    4240    static int GetFrameNum();
     41
     42    static void SetState(Entity *entity, uint32_t state);
     43    static void SetStateWhenMatch(Entity *entity, uint32_t state,
     44                                  Entity *other_entity, uint32_t other_state);
    4345
    4446    static void Shutdown();
Note: See TracChangeset for help on using the changeset viewer.