ScummVM API documentation
timers.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 * aint32 with this program; if not, write to the Free Software
19 *
20 *
21 * Based on the original sources
22 * Faery Tale II -- The Halls of the Dead
23 * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24 */
25
26#ifndef SAGA2_TIMERS_H
27#define SAGA2_TIMERS_H
28
29#include "saga2/idtypes.h"
30#include "saga2/calendar.h"
31#include "saga2/objects.h"
32
33namespace Saga2 {
34
35class Timer;
36class TimerList;
37
38// Fetch a specified actor's TimerList
39TimerList *fetchTimerList(GameObject *obj);
40
41void deleteTimer(Timer *t);
42
43// Check all active Timers
44void checkTimers();
45
46// Initialize the Timers
47void initTimers();
48void saveTimers(Common::OutSaveFile *outS);
49void loadTimers(Common::InSaveFile *in);
50void cleanupTimer();
51// Cleanup the active Timers
52void cleanupTimers();
53
54/* ===================================================================== *
55 TimerList class
56 * ===================================================================== */
57
58class TimerList {
59 GameObject *_obj;
60
61public:
62 // Constructor -- initial construction
64
66
67 ~TimerList();
68
69 // Return the number of bytes needed to archive this object in
70 // a buffer
71 static int32 archiveSize() {
72 return sizeof(ObjectID);
73 }
74
75 void write(Common::MemoryWriteStreamDynamic *out);
76
77 GameObject *getObject() {
78 return _obj;
79 }
80
82};
83
84/* ===================================================================== *
85 Timer class
86 * ===================================================================== */
87
88class Timer {
89 GameObject *_obj;
90 TimerID _id;
91 int16 _interval;
92 FrameAlarm _alarm;
93
94public:
95 bool _active;
96
97 // Constructor -- initial construction
98 Timer(GameObject *o, TimerID timerID, int16 frameInterval) : _obj(o), _id(timerID), _interval(frameInterval), _active(true) {
99 _alarm.set(_interval);
100 debugC(1, kDebugTimers, "Creating timer %p for %p (%s)",
101 (void *)this, (void *)o, o->objName());
102
103 g_vm->_timers.push_back(this);
104 }
105
107
108 ~Timer();
109
110 // Return the number of bytes needed to archive this object in
111 // a buffer
112 static int32 archiveSize();
113
114 void write(Common::MemoryWriteStreamDynamic *out);
115
116 GameObject *getObject() {
117 return _obj;
118 }
119 TimerID thisID() {
120 return _id;
121 }
122 int16 getInterval() {
123 return _interval;
124 }
125
126 bool check() {
127 return _alarm.check();
128 }
129 void reset() {
130 _alarm.set(_interval);
131 }
132};
133
134} // end of namespace Saga2
135
136#endif
Definition: list.h:44
Definition: memstream.h:194
Definition: savefile.h:54
Definition: stream.h:745
Definition: calendar.h:86
Definition: objects.h:118
Definition: timers.h:88
Definition: timers.h:58
void void void void void debugC(int level, uint32 debugChannel, MSVC_PRINTF const char *s,...) GCC_PRINTF(3