Ignore:
Timestamp:
Apr 29, 2012, 11:55:32 PM (9 years ago)
Author:
sam
Message:

core: tick methods now use seconds, like any sane system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ticker.cpp

    r1309 r1310  
    22// Lol Engine
    33//
    4 // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
     4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
    55//   This program is free software; you can redistribute it and/or
    66//   modify it under the terms of the Do What The Fuck You Want To
     
    3333        todolist(0), autolist(0),
    3434        nentities(0),
    35         frame(0), recording(0), deltams(0), bias(0), fps(0),
     35        frame(0), recording(0), deltatime(0), bias(0), fps(0),
    3636        quit(0), quitframe(0), quitdelay(20), panic(0)
    3737    {
     
    6969    int frame, recording;
    7070    Timer timer;
    71     float deltams, bias, fps;
     71    float deltatime, bias, fps;
    7272
    7373    /* Background threads */
     
    182182        data->frame++;
    183183
    184         /* If recording with fixed framerate, set deltams to a fixed value */
     184        /* If recording with fixed framerate, set deltatime to a fixed value */
    185185        if (data->recording && data->fps)
    186186        {
    187             data->deltams = 1000.0f / data->fps;
     187            data->deltatime = 1.f / data->fps;
    188188        }
    189189        else
    190190        {
    191             data->deltams = 1000.0f * data->timer.Get();
    192             data->bias += data->deltams;
     191            data->deltatime = data->timer.Get();
     192            data->bias += data->deltatime;
    193193        }
    194194
     
    279279                    e->m_tickstate = Entity::STATE_PRETICK_GAME;
    280280#endif
    281                     e->TickGame(data->deltams);
     281                    e->TickGame(data->deltatime);
    282282#if !LOL_RELEASE
    283283                    if (e->m_tickstate != Entity::STATE_POSTTICK_GAME)
     
    369369                e->m_tickstate = Entity::STATE_PRETICK_DRAW;
    370370#endif
    371                 e->TickDraw(data->deltams);
     371                e->TickDraw(data->deltatime);
    372372#if !LOL_RELEASE
    373373                if (e->m_tickstate != Entity::STATE_POSTTICK_DRAW)
     
    392392    /* If framerate is fixed, force wait time to 1/FPS. Otherwise, set wait
    393393     * time to 0. */
    394     float framems = data->fps ? 1000.0f / data->fps : 0.0f;
    395 
    396     if (framems > data->bias + 200.0f)
    397         framems = data->bias + 200.0f; // Don't go below 5 fps
    398     if (framems > data->bias)
    399         data->timer.Wait(1e-3f * (framems - data->bias));
     394    float frametime = data->fps ? 1.f / data->fps : 0.f;
     395
     396    if (frametime > data->bias + .2f)
     397        frametime = data->bias + .2f; // Don't go below 5 fps
     398    if (frametime > data->bias)
     399        data->timer.Wait(frametime - data->bias);
    400400
    401401    /* If recording, do not try to compensate for lag. */
    402402    if (!data->recording)
    403         data->bias -= framems;
     403        data->bias -= frametime;
    404404}
    405405
Note: See TracChangeset for help on using the changeset viewer.