1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "bladerunner/time.h"
24 
25 #include "bladerunner/bladerunner.h"
26 
27 #include "common/timer.h"
28 #include "common/system.h"
29 
30 namespace BladeRunner {
31 
Time(BladeRunnerEngine * vm)32 Time::Time(BladeRunnerEngine *vm) {
33 	_vm = vm;
34 
35 	_start = currentSystem();
36 	_pauseCount = 0;
37 	_offset = 0u;
38 	_pauseStart = 0u;
39 }
40 
currentSystem()41 uint32 Time::currentSystem() {
42 	return _vm->getTotalPlayTime();
43 }
44 
current()45 uint32 Time::current() {
46 	uint32 time = currentSystem() - _offset;
47 	return time - _start;
48 }
49 
pause()50 int Time::pause() {
51 	if (_pauseCount == 0) {
52 		_pauseStart = current();
53 	}
54 	return ++_pauseCount;
55 }
56 
getPauseStart()57 uint32 Time::getPauseStart() {
58 	return _pauseStart;
59 }
60 
resume()61 int Time::resume() {
62 	assert(_pauseCount > 0);
63 	if (--_pauseCount == 0) {
64 		_offset += current() - _pauseStart;
65 	}
66 	return _pauseCount;
67 }
68 
isLocked()69 bool Time::isLocked() {
70 	return _pauseCount > 0;
71 }
72 
73 // To be called before loading a new game, since
74 // the offset should be reset to zero and _pauseStart should be current() (ie currentSystem() - _start)
75 // TODO Explore if it would make sense to only use the Engine methods for time accounting (pauseEngine, get/setTotalPlatTime)
76 //      or do we need separated/independent time accounting and pausing?
resetPauseStart()77 void Time::resetPauseStart() {
78 	_offset = 0u;
79 	_pauseStart = current();
80 }
81 
82 } // End of namespace BladeRunner
83