/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include #include #include double gr_get_current_time (void) { struct timeval time; gettimeofday (&time, NULL); return (double)(time.tv_sec) + 0.000001 * time.tv_usec; } void gr_time_add (struct timeval *dst, struct timeval *src) { int flag = 0; if (!dst || !src) return; dst->tv_usec += src->tv_usec; if (dst->tv_usec >= 1000000) { dst->tv_usec -= 1000000; flag = 1; } dst->tv_sec += src->tv_sec + (flag? 1:0); } void gr_time_sub (struct timeval *dst, struct timeval *src) { int flag = 0; if (!dst || !src) return; dst->tv_usec -= src->tv_usec; if (dst->tv_usec < 0) { flag = 1; dst->tv_usec += 1000000; } dst->tv_sec -= src->tv_sec + (flag? 1:0); } void gr_time_average (struct timeval *dst, struct timeval *src, double f) { double sec; if (!dst || !src) return; sec = (1.0 - f) * dst->tv_sec + f * src->tv_sec; dst->tv_sec = sec; dst->tv_usec = (1.0 - f) * dst->tv_usec + f * src->tv_usec + fmod (sec * 1000000, 1000000); } #if 0 GrLapRegion gr_lap_which_region (GrVertex *region, GrVertex *point) { } #endif