Blender V2.61 - r43446

time.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "PIL_time.h"
00034 
00035 #ifdef WIN32
00036 #include <windows.h>
00037 
00038 double PIL_check_seconds_timer(void) 
00039 {
00040     static int hasperfcounter= -1; /* -1==unknown */
00041     static double perffreq;
00042 
00043     if (hasperfcounter==-1) {
00044         __int64 ifreq;
00045         hasperfcounter= QueryPerformanceFrequency((LARGE_INTEGER*) &ifreq);
00046         perffreq= (double) ifreq;
00047     } 
00048 
00049     if (hasperfcounter) {
00050         __int64 count;
00051 
00052         QueryPerformanceCounter((LARGE_INTEGER*) &count);
00053 
00054         return count/perffreq;
00055     } else {
00056         static double accum= 0.0;
00057         static int ltick= 0;
00058         int ntick= GetTickCount();
00059 
00060         if (ntick<ltick) {
00061             accum+= (0xFFFFFFFF-ltick+ntick)/1000.0;
00062         } else {
00063             accum+= (ntick-ltick)/1000.0;
00064         }
00065 
00066         ltick= ntick;
00067         return accum;
00068     }
00069 }
00070 
00071 void PIL_sleep_ms(int ms)
00072 {
00073     Sleep(ms);
00074 }
00075 
00076 #else
00077 
00078 #include <unistd.h>
00079 #include <sys/time.h>
00080 
00081 double PIL_check_seconds_timer(void) 
00082 {
00083     struct timeval tv;
00084     struct timezone tz;
00085 
00086     gettimeofday(&tv, &tz);
00087 
00088     return ((double) tv.tv_sec + tv.tv_usec/1000000.0);
00089 }
00090 
00091 void PIL_sleep_ms(int ms)
00092 {
00093     if (ms>=1000) {
00094         sleep(ms/1000);
00095         ms= (ms%1000);
00096     }
00097     
00098     usleep(ms*1000);
00099 }
00100 
00101 #endif