]> git.saurik.com Git - wxWidgets.git/blame - src/common/timercmn.cpp
drawing optimization fix
[wxWidgets.git] / src / common / timercmn.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: timercmn.cpp
3// Purpose: Common timer implementation
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13//#pragma implementation "timercmn.h"
14#pragma implementation
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/defs.h"
26#include "wx/list.h"
27#endif
28
29#include "wx/timer.h"
30
31#ifdef __SVR4__
32#define __SYSV__
33#endif
34
35#include <time.h>
36#include <sys/types.h>
37
38#if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__)) || defined(__MINGW32__)
39#include <sys/timeb.h>
40#endif
41
edaa81ae
RR
42#if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
43 defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__)
c801d85f
KB
44#include <sys/time.h>
45#endif
46
47#ifdef __MINGW32__
48#include "windows.h"
49#endif
50
51#if defined(__SUN__) || defined(__OSF__)
52// At least on Sun, ftime is undeclared.
53// Need to be verified on other platforms.
54extern "C" int ftime(struct timeb *tp);
55// extern "C" time_t time(time_t);
56// #include <sys/timeb.h>
57#if defined(__SVR4__) && !defined(__ALPHA__)
58// ditto for gettimeofday on Solaris 2.x.
59extern "C" int gettimeofday(struct timeval *tp, void *);
60#endif
61#endif
62
63/*
64 * Timer functions
65 *
66 */
67
68long wxStartTime = 0;
69void wxStartTimer(void)
70{
71#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
72 struct timeval tp;
f57fe24c 73#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
74 gettimeofday(&tp, (struct timezone *)NULL);
75#else
76 gettimeofday(&tp);
77#endif
78 wxStartTime = 1000*tp.tv_sec + tp.tv_usec/1000;
79#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
80 time_t t0;
81 struct tm *tp;
82 time(&t0);
83 tp = localtime(&t0);
84 wxStartTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
85#else
86 struct timeb tp;
87 ftime(&tp);
88 wxStartTime = 1000*tp.time + tp.millitm;
89#endif
90}
91
92// Returns elapsed time in milliseconds
93long wxGetElapsedTime(bool resetTimer)
94{
95#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
96 struct timeval tp;
f57fe24c 97#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
98 gettimeofday(&tp, (struct timezone *)NULL);
99#else
100 gettimeofday(&tp);
101#endif
102 long oldTime = wxStartTime;
103 long newTime = 1000*tp.tv_sec + tp.tv_usec / 1000;
104 if (resetTimer)
105 wxStartTime = newTime;
106#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
107 time_t t0;
108 struct tm *tp;
109 time(&t0);
110 tp = localtime(&t0);
111 long oldTime = wxStartTime;
112 long newTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
113 if (resetTimer)
114 wxStartTime = newTime;
115#else
116 struct timeb tp;
117 ftime(&tp);
118 long oldTime = wxStartTime;
119 long newTime = 1000*tp.time + tp.millitm;
120 if (resetTimer)
121 wxStartTime = newTime;
122#endif
123 return newTime - oldTime;
124}
125
126// EXPERIMENTAL: comment this out if it doesn't compile.
127#ifndef __VMS__
128bool wxGetLocalTime(long *timeZone, int *dstObserved)
129{
130#if defined(__MINGW32__) && defined(__EGCS__)
131 time_t t0;
132 struct tm *tp;
133 time(&t0);
134 tp = localtime(&t0);
135 *timeZone = timezone; // tp->tm_gmtoff; // ???
136 *dstObserved = tp->tm_isdst;
137#elif defined(__MINGW32__)
138 time_t t0;
139 struct tm *tp;
140 time(&t0);
141 tp = localtime(&t0);
142 timeb tz;
143 ftime(& tz);
144 *timeZone = tz._timezone;
145 *dstObserved = tp->tm_isdst;
146#else
147
2049ba38 148#if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) && !defined(__GNUWIN32__))
c801d85f
KB
149#ifdef __BORLANDC__
150 /* Borland uses underscores */
151 *timeZone = _timezone;
152 *dstObserved = _daylight;
153#else
154 *timeZone = timezone;
155 *dstObserved = daylight;
156#endif
157#elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
158 struct timeval tp;
159#if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
160 struct timezone tz;
161 gettimeofday(&tp, &tz);
162 *timeZone = 60*(tz.tz_minuteswest);
163 *dstObserved = tz.tz_dsttime;
164#else
165 time_t t0;
166 struct tm *tp;
167 time(&t0);
168 tp = localtime(&t0);
169 *timeZone = tp->tm_gmtoff; // ???
170 *dstObserved = tp->tm_isdst;
171#endif
34138703
JS
172#elif defined(__WXSTUBS__)
173 return FALSE;
c801d85f
KB
174#else
175// #error wxGetLocalTime not implemented.
176 struct timeval tp;
177 struct timezone tz;
178 gettimeofday(&tp, &tz);
179 *timeZone = 60*(tz.tz_minuteswest);
180 *dstObserved = tz.tz_dsttime;
181#endif
182#endif
183 // __MINGW32__
184 return TRUE;
185}
186#endif
187
188// Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
189long wxGetCurrentTime(void)
190{
191#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
192 struct timeval tp;
f57fe24c 193#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
194 gettimeofday(&tp, (struct timezone *)NULL);
195#else
196 gettimeofday(&tp);
197#endif
198 return tp.tv_sec;
199#else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))
200 return time(0);
201#endif
202/*
203#else
204 struct timeb tp;
205 ftime(&tp);
206 return tp.time;
207#endif
208*/
209}
210