ScummVM API documentation
timer.h
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 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.
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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 //=============================================================================
32 // Author: Arvind
33 // Purpose: Timer class
34 //=============================================================================
35 #ifndef CRAB_TIMER_H
36 #define CRAB_TIMER_H
37 
38 #include "crab/crab.h"
39 #include "crab/rapidxml/rapidxml.hpp"
40 
41 namespace Crab {
42 
43 class Timer {
44 private:
45  // The clock time when the timer started
46  uint32 _startTicks;
47 
48  // The ticks stored when the timer was paused
49  uint32 _pausedTicks;
50 
51  // Since most timers usually only check one value, we might as well as store it here
52  uint32 _targetTicks;
53 
54  // See if we have a target loaded or set
55  bool _targetValid;
56 
57  // The timer status
58  bool _paused;
59  bool _started;
60 
61 public:
62  // Initialize variables
63  Timer();
64 
65  void target(const uint32 &val) {
66  _targetValid = true;
67  _targetTicks = val;
68  }
69 
70  void load(rapidxml::xml_node<char> *node, const Common::String &name, const bool &echo = true);
71 
72  // The various clock actions
73  void start();
74  void stop();
75  void pause();
76  void resume();
77 
78  // Gets the timer's time
79  uint32 ticks();
80 
81  // Get the time remaining
82  uint32 remainingTicks() {
83  return _targetTicks - ticks();
84  }
85 
86  // Have we reached the target yet?
87  bool targetReached(const float &factor = 1.0f);
88 
89  // Checks the status of the timer
90  bool started() {
91  return _started;
92  }
93 
94  bool paused() {
95  return _paused;
96  }
97 
98  bool targetValid() {
99  return _targetValid;
100  }
101 };
102 
103 } // End of namespace Crab
104 
105 #endif // CRAB_TIMER_H
Definition: str.h:59
Definition: moveeffect.h:37
Definition: timer.h:43