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