2 Copyright 2007, 2008, 2009, 2010 Damian Stewart <damian@frey.co.nz>.
3 Distributed under the terms of the GNU General Public License v3.
5 This file is part of The Artvertiser.
7 The Artvertiser is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 The Artvertiser is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with The Artvertiser. If not, see <http://www.gnu.org/licenses/>.
33 double FTime::Update()
36 uint64_t now
= mach_absolute_time();
37 uint64_t diff
= now
- time
;
39 static double conversion
= 0.0;
40 if ( conversion
== 0.0 )
42 mach_timebase_info_data_t info
;
43 kern_return_t err
= mach_timebase_info( &info
);
46 conversion
= 1e-9*(double)info
.numer
/ (double) info
.denom
;
50 last_update_time
= (float)(conversion
* (double) diff
);
54 clock_gettime(CLOCK_REALTIME
, &now
);
57 double diff
= now
.tv_sec
- time
.tv_sec
;
58 diff
+= 1e-9*double(now
.tv_nsec
- time
.tv_nsec
);
61 last_update_time
= diff
;
64 return last_update_time
;
67 void FTime::SetSeconds( double seconds
)
70 assert( false && "implement me" );
73 time
.tv_sec
= (long long)seconds
;
75 time
.tv_nsec
= (seconds
- (long long)seconds
)*1e9
;
81 double FTime::ToMillis() const
84 static double conversion
= 0.0;
85 if ( conversion
== 0.0 )
87 mach_timebase_info_data_t info
;
88 kern_return_t err
= mach_timebase_info( &info
);
91 conversion
= 1e-6*(double)info
.numer
/ (double) info
.denom
;
94 return (conversion
* (double) time
);
98 double result
= 1e3
*double(time
.tv_sec
) + 1e-6*double(time
.tv_nsec
);