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 #ifndef KYRA_TIMER_H
23 #define KYRA_TIMER_H
24 
25 #include "kyra/kyra_v1.h"
26 
27 #include "common/list.h"
28 #include "common/stream.h"
29 #include "common/func.h"
30 
31 namespace Kyra {
32 
33 typedef Common::Functor1<int, void> TimerFunc;
34 
35 struct TimerEntry {
36  uint8 id;
37  int32 countdown;
38  int8 enabled;
39 
40  int32 lastUpdate;
41  uint32 nextRun;
42 
43  TimerFunc *func;
44 
45  uint32 pauseStartTime;
46 };
47 
48 class TimerManager {
49 public:
50  TimerManager(KyraEngine_v1 *vm, OSystem *sys) : _vm(vm), _system(sys), _timers(), _nextRun(0), _isPaused(0), _pauseStart(0) {}
51  ~TimerManager() { reset(); }
52 
53  void pause(bool p);
54 
55  void reset();
56 
57  void addTimer(uint8 id, TimerFunc *func, int countdown, bool enabled);
58 
59  int count() const { return _timers.size(); }
60 
61  void update();
62 
63  void resetNextRun();
64 
65  void setCountdown(uint8 id, int32 countdown);
66  void setDelay(uint8 id, int32 countdown);
67  int32 getDelay(uint8 id) const;
68  void setNextRun(uint8 id, uint32 nextRun);
69  uint32 getNextRun(uint8 id) const;
70 
71  void pauseSingleTimer(uint8 id, bool p);
72 
73  bool isEnabled(uint8 id) const;
74  void enable(uint8 id);
75  void disable(uint8 id);
76 
77  void loadDataFromFile(Common::SeekableReadStream &file, int version);
78  void saveDataToFile(Common::WriteStream &file) const;
79 
80 private:
81  void resync();
82 
83  KyraEngine_v1 *_vm;
84  OSystem *_system;
86  uint32 _nextRun;
87 
88  uint _isPaused;
89  uint32 _pauseStart;
90 
93 };
94 
95 class PauseTimer {
96 public:
97  PauseTimer(TimerManager &timer) : _timer(timer) { _timer.pause(true); }
98  ~PauseTimer() { _timer.pause(false); }
99 private:
100  TimerManager &_timer;
101 };
102 
103 } // End of namespace Kyra
104 
105 #endif
Definition: stream.h:77
Definition: timer.h:95
Definition: list.h:44
Definition: kyra_v1.h:126
Definition: stream.h:745
Definition: timer.h:35
Definition: timer.h:48
Definition: func.h:437
Definition: detection.h:27
Definition: list_intern.h:48
Definition: list_intern.h:51
Definition: system.h:161