source: libcaca/trunk/src/time.c @ 331

Last change on this file since 331 was 331, checked in by Sam Hocevar, 19 years ago
  • 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.
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/*
2 *  libcaca       ASCII-Art library
3 *  Copyright (c) 2002, 2003, 2004 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  This library is free software; you can redistribute it and/or
7 *  modify it under the terms of the GNU Lesser General Public
8 *  License as published by the Free Software Foundation; either
9 *  version 2 of the License, or (at your option) any later version.
10 *
11 *  This library is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 *  Lesser General Public License for more details.
15 *
16 *  You should have received a copy of the GNU Lesser General Public
17 *  License along with this library; if not, write to the Free Software
18 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 *  02111-1307  USA
20 */
21
22/** \file time.c
23 *  \version \$Id: time.c 331 2004-01-09 09:51:53Z sam $
24 *  \author Sam Hocevar <sam@zoy.org>
25 *  \brief Timer routines
26 *
27 *  This file contains simple timer routines.
28 */
29
30#include "config.h"
31
32#include <stdlib.h>
33#include <sys/time.h>
34#include <time.h>
35
36#include "caca.h"
37#include "caca_internals.h"
38
39unsigned int _caca_getticks(struct caca_timer *timer)
40{
41    struct timeval tv;
42    unsigned int ticks = 0;
43
44    gettimeofday(&tv, NULL);
45
46    if(timer->last_sec != 0)
47    {
48        /* If the delay was greater than 60 seconds, return 10 seconds
49         * otherwise we may overflow our ticks counter. */
50        if(tv.tv_sec >= timer->last_sec + 60)
51            ticks = 60 * 1000000;
52        else
53        {
54            ticks = (tv.tv_sec - timer->last_sec) * 1000000;
55            ticks += tv.tv_usec;
56            ticks -= timer->last_usec;
57        }
58    }
59
60    timer->last_sec = tv.tv_sec;
61    timer->last_usec = tv.tv_usec;
62
63    return ticks;
64}
65
Note: See TracBrowser for help on using the repository browser.