Changeset 335


Ignore:
Timestamp:
Jan 11, 2004, 2:45:57 AM (16 years ago)
Author:
Sam Hocevar
Message:
  • configure.ac: + Check for gettimeofday().
  • src/time.c: + Created _caca_time(). + Ported _caca_getticks() to the Win32 API.
  • src/caca.c: + Properly builds on Win32.
  • test/event.c: + Added <stdlib.h> because we use malloc().
Location:
libcaca/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/configure.ac

    r333 r335  
    3030
    3131AC_CHECK_HEADERS(inttypes.h endian.h)
    32 AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp usleep Sleep)
     32AC_CHECK_FUNCS(vsnprintf getenv putenv strcasecmp usleep Sleep gettimeofday)
    3333AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm")
    3434
  • libcaca/trunk/src/caca.c

    r331 r335  
    4848#if defined(USE_X11)
    4949#   include <X11/Xlib.h>
     50#endif
     51#if defined(USE_WIN32)
     52#   include <windows.h>
    5053#endif
    5154
     
    157160#endif
    158161#if defined(USE_X11)
    159     /* Nothing to do */
     162    if(_caca_driver == CACA_DRIVER_X11)
     163    {
     164        /* Nothing to do */
     165    }
     166    else
     167#endif
     168#if defined(USE_WIN32)
     169    if(_caca_driver == CACA_DRIVER_WIN32)
     170    {
     171        /* Nothing to do */
     172        printf("initialising win32 driver\n");
     173    }
     174    else
    160175#endif
    161176    {
     
    374389    else
    375390#endif
     391#if defined(USE_WIN32)
     392    if(_caca_driver == CACA_DRIVER_WIN32)
     393    {
     394        /* Nothing to do */
     395    }
     396    else
     397#endif
    376398    {
    377399        /* Dummy */
     
    391413    if(var && *var)
    392414    {
     415#if defined(USE_WIN32)
     416        if(!strcasecmp(var, "win32"))
     417            _caca_driver = CACA_DRIVER_WIN32;
     418        else
     419#endif
    393420#if defined(USE_CONIO)
    394421        if(!strcasecmp(var, "conio"))
     
    417444#endif
    418445
     446#if defined(USE_WIN32)
     447    _caca_driver = CACA_DRIVER_WIN32;
     448    return;
     449#endif
    419450#if defined(USE_CONIO)
    420451    _caca_driver = CACA_DRIVER_CONIO;
     
    488519static void caca_init_terminal(void)
    489520{
    490 #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
     521#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) && \
     522     (defined(USE_SLANG) || defined(USE_NCURSES))
    491523    char *term, *colorterm, *other;
     524#endif
    492525
    493526#if defined(USE_SLANG)
     
    499532    return;
    500533
     534#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) && \
     535     (defined(USE_SLANG) || defined(USE_NCURSES))
    501536    term = getenv("TERM");
    502537    colorterm = getenv("COLORTERM");
  • libcaca/trunk/src/caca_internals.h

    r331 r335  
    4646    CACA_DRIVER_X11 = 4,
    4747#endif
     48#if defined(USE_WIN32)
     49    CACA_DRIVER_WIN32 = 5,
     50#endif
    4851    CACA_DRIVER_NONE = 0
    4952};
     
    6568
    6669/* Timer functions */
     70extern void _caca_sleep(unsigned int);
    6771extern unsigned int _caca_getticks(struct caca_timer *);
    6872
  • libcaca/trunk/src/graphics.c

    r332 r335  
    6262#include <string.h>
    6363#include <stdlib.h>
    64 #include <unistd.h>
    6564#include <stdarg.h>
    6665
     
    936935        ticks += _caca_getticks(&timer))
    937936    {
    938 #if defined(HAVE_USLEEP)
    939         usleep(IDLE_USEC);
    940 #elif defined(HAVE_SLEEP)
    941         Sleep(IDLE_USEC / 1000);
    942 #else
    943         SLEEP
    944 #endif
     937        _caca_sleep(IDLE_USEC);
    945938    }
    946939
  • libcaca/trunk/src/io.c

    r332 r335  
    4848#   include <X11/keysym.h>
    4949#endif
    50 
    51 #include <unistd.h>
     50#if defined(USE_WIN32)
     51#   include <windows.h>
     52#endif
    5253
    5354#include "caca.h"
     
    122123            return event;
    123124
    124 #if defined(HAVE_USLEEP)
    125         usleep(10000);
    126 #elif defined(HAVE_SLEEP)
    127         Sleep(10);
    128 #else
    129         SLEEP
    130 #endif
     125        _caca_sleep(10000);
    131126    }
    132127}
     
    543538    else
    544539#endif
     540#if defined(USE_WIN32)
     541    if(_caca_driver == CACA_DRIVER_WIN32)
     542    {
     543        return CACA_EVENT_NONE;
     544    }
     545    else
     546#endif
    545547    {
    546548        /* Dummy */
  • libcaca/trunk/src/time.c

    r331 r335  
    3434#include <time.h>
    3535
     36#if defined(USE_WIN32)
     37#   include <windows.h>
     38#endif
     39
     40#include <unistd.h>
     41
    3642#include "caca.h"
    3743#include "caca_internals.h"
    3844
     45void _caca_sleep(unsigned int usec)
     46{
     47#if defined(HAVE_USLEEP)
     48        usleep(usec);
     49#elif defined(HAVE_SLEEP)
     50        Sleep(usec / 1000);
     51#else
     52        SLEEP
     53#endif
     54}
     55
    3956unsigned int _caca_getticks(struct caca_timer *timer)
    4057{
     58#if defined(HAVE_GETTIMEOFDAY)
    4159    struct timeval tv;
     60#elif defined(USE_WIN32)
     61    static long long int freq = -1LL;
     62    long long int usec;
     63#endif
    4264    unsigned int ticks = 0;
     65    int new_sec, new_usec;
    4366
     67#if defined(HAVE_GETTIMEOFDAY)
    4468    gettimeofday(&tv, NULL);
     69    new_sec = tv.tv_sec;
     70    new_usec = tv.tv_usec;
     71#elif defined(USE_WIN32)
     72    if(freq == -1LL)
     73    {
     74        if(!QueryPerformanceFrequency((LARGE_INTEGER *)&freq))
     75            freq = 0;
     76    }
     77
     78    QueryPerformanceCounter((LARGE_INTEGER *)&usec);
     79    new_sec = usec / freq;
     80    new_usec = usec % freq;
     81#endif
    4582
    4683    if(timer->last_sec != 0)
     
    4885        /* If the delay was greater than 60 seconds, return 10 seconds
    4986         * otherwise we may overflow our ticks counter. */
    50         if(tv.tv_sec >= timer->last_sec + 60)
     87        if(new_sec >= timer->last_sec + 60)
    5188            ticks = 60 * 1000000;
    5289        else
    5390        {
    54             ticks = (tv.tv_sec - timer->last_sec) * 1000000;
    55             ticks += tv.tv_usec;
     91            ticks = (new_sec - timer->last_sec) * 1000000;
     92            ticks += new_usec;
    5693            ticks -= timer->last_usec;
    5794        }
    5895    }
    5996
    60     timer->last_sec = tv.tv_sec;
    61     timer->last_usec = tv.tv_usec;
     97    timer->last_sec = new_sec;
     98    timer->last_usec = new_usec;
    6299
    63100    return ticks;
  • libcaca/trunk/test/event.c

    r332 r335  
    2626#include <stdio.h>
    2727#include <string.h>
     28#include <stdlib.h>
    2829
    2930#include "caca.h"
Note: See TracChangeset for help on using the changeset viewer.