ScummVM API documentation
event_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  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_EVENTTIMER_H_INCLUDED
28 #define ICB_EVENTTIMER_H_INCLUDED
29 
30 #include "common/stream.h"
31 
32 #include "engines/icb/string_vest.h"
33 #include "engines/icb/common/px_string.h"
34 #include "engines/icb/event_list.h"
35 
36 namespace ICB {
37 
38 // class _event_timer
39 // This structure holds timing information for events that are posted into the future or have
40 // to happen repeatedly.
41 class _event_timer {
42 public:
43  // Default constructor and destructor.
44  inline _event_timer();
45  ~_event_timer() {}
46 
47  // Copy constructor.
48  inline _event_timer(const _event_timer &oX);
49 
50  // Operator '='.
51  inline const _event_timer &operator=(const _event_timer &oOpB);
52 
53  // Gets and sets.
54  void SetObjectID(int32 nObjectID) { m_nObjectID = nObjectID; }
55  void SetStart(uint32 nStart) { m_nStart = nStart; }
56  void SetEnd(uint32 nEnd) { m_nEnd = nEnd; }
57  void SetInterval(uint32 nInterval) { m_nInterval = nInterval; }
58  void SetEventTime(uint32 nTime) { m_nCurrentTime = nTime; }
59  inline void SetEventName(const char *pcEventName);
60 
61  int32 GetObjectID() const { return (m_nObjectID); }
62  uint32 GetStart() const { return (m_nStart); }
63  uint32 GetEnd() const { return (m_nEnd); }
64  uint32 GetInterval() const { return (m_nInterval); }
65  uint32 GetEventTime() const { return (m_nCurrentTime); }
66  const char *GetEventName() const { return (m_pcEventName); }
67 
68  void Save(Common::WriteStream *stream) const {
69  stream->writeSint32LE(m_nObjectID);
70  stream->writeUint32LE(m_nStart);
71  stream->writeUint32LE(m_nEnd);
72  stream->writeUint32LE(m_nInterval);
73  stream->writeUint32LE(m_nCurrentTime);
74  stream->write(m_pcEventName, MAXLEN_EVENT_NAME);
75  }
76  void Restore(Common::SeekableReadStream *stream) {
77  m_nObjectID = stream->readSint32LE();
78  m_nStart = stream->readUint32LE();
79  m_nEnd = stream->readUint32LE();
80  m_nInterval = stream->readUint32LE();
81  m_nCurrentTime = stream->readUint32LE();
82  stream->read(m_pcEventName, MAXLEN_EVENT_NAME);
83  }
84 
85 private:
86  int32 m_nObjectID; // ID of object initiating this timer.
87  uint32 m_nStart; // When the event should start, relative to the time the event was placed.
88  uint32 m_nEnd; // When the event should end, relative to the time the event was placed.
89  uint32 m_nInterval; // Interval between occurrences of the event.
90  uint32 m_nCurrentTime; // Relative to the reference time.
91  char m_pcEventName[MAXLEN_EVENT_NAME]; // Name of the event.
92 };
93 
94 inline _event_timer::_event_timer() {
95  m_nObjectID = EVENT_INVALID_SENDER_ID;
96  m_nStart = 0;
97  m_nEnd = 0;
98  m_nInterval = 0;
99  m_nCurrentTime = 0;
100  m_pcEventName[0] = '\0';
101 }
102 
103 inline _event_timer::_event_timer(const _event_timer &oX) {
104  m_nObjectID = oX.m_nObjectID;
105  m_nStart = oX.m_nStart;
106  m_nEnd = oX.m_nEnd;
107  m_nInterval = oX.m_nInterval;
108  m_nCurrentTime = oX.m_nCurrentTime;
109  Common::strcpy_s(m_pcEventName, oX.m_pcEventName);
110 }
111 
112 inline const _event_timer &_event_timer::operator=(const _event_timer &oOpB) {
113  m_nObjectID = oOpB.m_nObjectID;
114  m_nStart = oOpB.m_nStart;
115  m_nEnd = oOpB.m_nEnd;
116  m_nInterval = oOpB.m_nInterval;
117  m_nCurrentTime = oOpB.m_nCurrentTime;
118  Common::strcpy_s(m_pcEventName, oOpB.m_pcEventName);
119 
120  return (*this);
121 }
122 
123 inline void _event_timer::SetEventName(const char *pcEventName) {
124  if (strlen(pcEventName) >= MAXLEN_EVENT_NAME)
125  Fatal_error("Event name [%s] too long (max %d) in _event_timer::SetEventName()", pcEventName, MAXLEN_EVENT_NAME - 1);
126 
127  Common::strcpy_s(m_pcEventName, pcEventName);
128 }
129 
130 } // End of namespace ICB
131 
132 #endif // #if !defined( EVENTTIMER_H_INCLUDED )
void writeUint32LE(uint32 value)
Definition: stream.h:159
Definition: stream.h:77
FORCEINLINE int32 readSint32LE()
Definition: stream.h:555
uint32 readUint32LE()
Definition: stream.h:473
Definition: actor.h:32
Definition: stream.h:745
void strcpy_s(char *dst, size_t size, const char *src)
FORCEINLINE void writeSint32LE(int32 value)
Definition: stream.h:200
virtual uint32 write(const void *dataPtr, uint32 dataSize)=0
Definition: event_timer.h:41
virtual uint32 read(void *dataPtr, uint32 dataSize)=0