Changeset 178 for ttyvaders


Ignore:
Timestamp:
Nov 14, 2003, 8:00:07 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • libee/ee.c: + Implemented correct framerate wait loop. + No framedropping yet.
  • test/demo.c src/main.c: + Set an arbitrary framerate for demos.
Location:
ttyvaders/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/libee/ee.c

    r168 r178  
    191191}
    192192
    193 void ee_set_delay(int usec)
    194 {
    195     _ee_delay = usec;
    196 }
    197 
    198193int ee_get_width(void)
    199194{
     
    218213}
    219214
    220 #if !defined(USE_CONIO)
    221 static int64_t local_time(void)
    222 {
     215void ee_set_delay(int usec)
     216{
     217    _ee_delay = usec;
     218}
     219
     220static unsigned int _ee_getticks(void)
     221{
     222    static unsigned int last_sec = 0, last_usec = 0;
     223
    223224    struct timeval tv;
    224     int64_t now;
     225    unsigned int ticks = 0;
    225226
    226227    gettimeofday(&tv, NULL);
    227     now = tv.tv_sec;
    228     now *= 1000000;
    229     now += tv.tv_usec;
    230     return now;
    231 }
    232 #endif
     228
     229    if(last_sec != 0)
     230    {
     231        ticks = (tv.tv_sec - last_sec) * 1000000 + (tv.tv_usec - last_usec);
     232    }
     233
     234    last_sec = tv.tv_sec;
     235    last_usec = tv.tv_usec;
     236
     237    return ticks;
     238}
    233239
    234240void ee_refresh(void)
    235241{
    236 #if !defined(USE_CONIO)
    237     static int64_t local_clock = 0;
    238     int64_t now;
    239 
    240     if(!local_clock)
    241     {
    242         /* Initialize local_clock */
    243         local_clock = local_time();
    244     }
    245 
    246     if(local_time() > local_clock + 10000)
    247     {
    248         /* If we are late, we shouldn't display anything */
    249     }
    250 #endif
     242    static int lastticks = 0;
     243    unsigned int ticks = lastticks + _ee_getticks();
    251244
    252245#if defined(USE_SLANG)
     
    262255#endif
    263256
    264 #if !defined(USE_CONIO)
    265     now = local_time();
    266 
    267     if(now < local_clock + _ee_delay - 10000)
    268     {
    269         usleep(local_clock + _ee_delay - 10000 - now);
    270     }
    271 
    272     local_clock += _ee_delay;
    273 #else
    274     delay(5);
    275 #endif
     257    /* Wait until _ee_delay + time of last call */
     258    for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks())
     259        usleep(10000);
     260
     261    lastticks = ticks - _ee_delay;
     262
     263    /* If we drifted too much, it's bad, bad, bad. */
     264    if(lastticks > _ee_delay)
     265        lastticks = 0;
    276266}
    277267
  • ttyvaders/trunk/src/main.c

    r174 r178  
    4646        return 1;
    4747    }
     48
     49    ee_set_delay(100000);
    4850
    4951    /* Initialize our program */
  • ttyvaders/trunk/test/demo.c

    r164 r178  
    5656    }
    5757
     58    ee_set_delay(40000);
     59
    5860    /* Initialize data */
    5961    sprite = ee_load_sprite("data/barboss.txt");
Note: See TracChangeset for help on using the changeset viewer.