Ignore:
Timestamp:
Jan 9, 2004, 10:51:53 AM (17 years ago)
Author:
Sam Hocevar
Message:
  • test/event.c: + Do not refresh after each event, but only when there is no event

pending.

+ If the pressed key is a printable character, display it.

  • src/time.c: + Moved _caca_getticks() to this file.
  • src/caca.c: + Set the escape delay to a very low value in the ncurses driver,

because I don't want escape sequences to be entered manually.

  • src/io.c: + Autorepeat emulation in the ncurses and slang drivers: do not

immediately send the key release event.

  • configure.ac: + Check for usleep. + Improvements in the win32 platform detection.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/graphics.c

    r330 r331  
    6464#include <unistd.h>
    6565#include <stdarg.h>
    66 #include <sys/time.h>
    67 #include <time.h>
    6866
    6967#include "caca.h"
     
    188186#endif
    189187
    190 static unsigned int _caca_getticks(void);
    191 
    192188/** \brief Set the default colour pair.
    193189 *
     
    829825}
    830826
    831 static unsigned int _caca_getticks(void)
    832 {
    833     static int last_sec = 0, last_usec = 0;
    834 
    835     struct timeval tv;
    836     unsigned int ticks = 0;
    837 
    838     gettimeofday(&tv, NULL);
    839 
    840     if(last_sec != 0)
    841     {
    842         /* If the delay was greater than 60 seconds, return 10 seconds
    843          * otherwise we may overflow our ticks counter. */
    844         if(tv.tv_sec >= last_sec + 60)
    845             ticks = 60 * 1000000;
    846         else
    847         {
    848             ticks = (tv.tv_sec - last_sec) * 1000000;
    849             ticks += tv.tv_usec;
    850             ticks -= last_usec;
    851         }
    852     }
    853 
    854     last_sec = tv.tv_sec;
    855     last_usec = tv.tv_usec;
    856 
    857     return ticks;
    858 }
    859 
    860827/** \brief Flush pending changes and redraw the screen.
    861828 *
    862829 *  This function flushes all graphical operations and prints them to the
    863  *  screen. Nothing will show on the screen caca_refresh() is not called.
     830 *  screen. Nothing will show on the screen until caca_refresh() is
     831 *  called.
    864832 *
    865833 *  If caca_set_delay() was called with a non-zero value, caca_refresh()
     
    874842#define IDLE_USEC 10000
    875843#endif
     844    static struct caca_timer timer = CACA_TIMER_INITIALIZER;
    876845    static int lastticks = 0;
    877     int ticks = lastticks + _caca_getticks();
     846    int ticks = lastticks + _caca_getticks(&timer);
    878847
    879848#if defined(USE_SLANG)
     
    959928
    960929    /* Wait until _caca_delay + time of last call */
    961     ticks += _caca_getticks();
    962     for(; ticks + IDLE_USEC < (int)_caca_delay; ticks += _caca_getticks())
     930    ticks += _caca_getticks(&timer);
     931    for(ticks += _caca_getticks(&timer);
     932        ticks + IDLE_USEC < (int)_caca_delay;
     933        ticks += _caca_getticks(&timer))
     934    {
     935#if defined(HAVE_USLEEP)
    963936        usleep(IDLE_USEC);
     937#elif defined(HAVE_SLEEP)
     938        Sleep(IDLE_USEC / 1000);
     939#else
     940        SLEEP
     941#endif
     942    }
    964943
    965944    /* Update the sliding mean of the render time */
Note: See TracChangeset for help on using the changeset viewer.