1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 // Code: Cyril Meynier
44 //
45 // Copyright (c) 1999-2000 ARKANE Studios SA. All rights reserved
46 
47 #include "core/GameTime.h"
48 
49 #include "platform/Time.h"
50 
51 arx::time arxtime;
52 
time()53 arx::time::time() {
54 
55 	// TODO can't call init from constructor Time::getUs() requires init
56 	// potential out-of-order construction resulting in a divide-by-zero
57 	start_time         = 0;
58 	pause_time         = 0;
59 	paused             = false;
60 	delta_time_us      = 0;
61 	frame_time_us      = 0;
62 	last_frame_time_us = 0;
63 	frame_delay_ms     = 0.0f;
64 }
65 
init()66 void arx::time::init() {
67 
68 	start_time         = Time::getUs();
69 	pause_time         = 0;
70 	paused             = false;
71 	delta_time_us      = 0;
72 	frame_time_us      = 0;
73 	last_frame_time_us = 0;
74 	frame_delay_ms     = 0.0f;
75 }
76 
pause()77 void arx::time::pause() {
78 	if(!is_paused()) {
79 		pause_time = Time::getUs();
80 		paused     = true;
81 	}
82 }
83 
resume()84 void arx::time::resume() {
85 	if(is_paused()) {
86 		start_time += Time::getElapsedUs(pause_time);
87 		pause_time = 0;
88 		paused     = false;
89 	}
90 }
91 
force_time_restore(const float & time)92 void arx::time::force_time_restore(const float &time) {
93 
94 	u64 requested_time = u64(time * 1000.0f);
95 
96 	start_time = Time::getElapsedUs(requested_time);
97 	delta_time_us = requested_time;
98 
99 	pause_time = 0;
100 	paused     = false;
101 }
102