ScummVM API documentation
event_list.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_EVENTLIST_H_INCLUDED
28#define ICB_EVENTLIST_H_INCLUDED
29
30#include "engines/icb/string_vest.h"
31#include "engines/icb/common/px_string.h"
32#include "engines/icb/string_vest.h"
33
34namespace ICB {
35
36// Use globals to save on rdata storage and having repeated strings therein
37extern const char *global_event_deleted_placeholder;
38extern const char *global_event_generic;
39extern const char *global_event_line_of_sight;
40extern const char *global_event_sound;
41extern const char *global_event_on_camera;
42extern const char *global_event_off_camera;
43extern const char *global_event_logic_rerun;
44extern const char *global_event_out_of_sight;
45extern const char *global_event_lift_ascend;
46extern const char *global_event_lift_descend;
47
48// This is used to mark deleted objects to save reallocating all the time.
49#define EVENT_DELETED_PLACEHOLDER global_event_deleted_placeholder
50
51// This string is used to identify a generic, anonymous event, which all objects respond to all the time.
52#define EVENT_LINE_OF_SIGHT global_event_line_of_sight
53#define EVENT_OUT_OF_SIGHT global_event_out_of_sight
54
55#define EVENT_ON_CAMERA global_event_on_camera
56#define EVENT_OFF_CAMERA global_event_off_camera
57
58#define EVENT_LIFT_ASCEND global_event_lift_ascend
59#define EVENT_LIFT_DESCEND global_event_lift_descend
60
61#define EVENT_LOGIC_RERUN global_event_logic_rerun
62
63// Primarily for PSX speed variable data structures are history.
64#define EVENT_MAX_EVENTS_REGISTERED 20
65
66// This marks an invalid object ID as the sender of an event.
67#define EVENT_INVALID_SENDER_ID (-1)
68
69struct _event {
70 const char *s_pcEventName;
71 int32 s_nLastSenderID;
72 bool8 s_bPending;
73 uint8 s_nPadding[3];
74
75 // Initialisation.
76 _event() {
77 s_pcEventName = EVENT_DELETED_PLACEHOLDER;
78 s_nLastSenderID = EVENT_INVALID_SENDER_ID;
79 s_bPending = FALSE8;
80 }
81
82 // Copy constructor and assignment.
83 _event(const _event &oX) {
84 s_pcEventName = oX.s_pcEventName;
85 s_nLastSenderID = oX.s_nLastSenderID;
86 s_bPending = oX.s_bPending;
87 }
88
89 const _event &operator=(const _event &oOpB) {
90 s_pcEventName = oOpB.s_pcEventName;
91 s_nLastSenderID = oOpB.s_nLastSenderID;
92 s_bPending = oOpB.s_bPending;
93 return (*this);
94 }
95};
96
97// class _event_list
98// Holds the list of events an object is currently interested in and counts of which ones are pending. Events
99// with handlers are held in a separate list and take precedence over generic events, which simply cause the
100// logic context for the object to be rerun.
102public:
103 // Default constructor and destructor.
104 inline _event_list();
105 ~_event_list() {}
106
107 // Copy constructor.
108 _event_list(const _event_list &oX);
109
110 // Operator '='.
111 const _event_list &operator=(const _event_list &oOpB);
112
113 // This sets a new object name for the event list, and resets everything else.
114 void SetNewObjectName(const char *pcObjectName);
115
116 // This gets the name of the object that the event list is for.
117 const char *GetObjectName() const { return (m_pcObjectName); }
118
119 // This determines whether or not an object requires any event processing.
120 inline bool8 HasEventPending();
121
122 // Checks if the named event is waiting for the object.
123 bool8 CheckEventWaiting(const char *pcEventName);
124
125 // This determines whether or not the named event is in the list of registered events.
126 bool8 IsEventInList(const char *pcEventName) const;
127
128 // These functions have direct script equivalents, but may also get used directly from the engine.
129 void AddEventForObject(const char *pcEventName);
130 void RemoveEventForObject(const char *pcEventName);
131 inline void RemoveAllEventsForObject();
132 bool8 DidObjectSendLastNamedEvent(uint32 nObjectID, const char *pcEventName) const;
133 int32 GetIDOfLastObjectToPostEvent(const char *pcEventName) const;
134 bool8 PostNamedEvent(const char *pcEventName, int32 nSenderID);
135 void ClearAllOutstandingEvents();
136
137private:
138 const char *m_pcObjectName; // Name of the object.
139 _event m_pNamedEventList[EVENT_MAX_EVENTS_REGISTERED]; // Named events this object is interested in.
140 uint8 m_nNumNamedEventsPending; // Number of named events pending.
141 uint8 m_nNumRegisteredEvents; // Number of events object is currently interested in.
142 bool8 m_bEventPending; // If true, at least one event is pending.
143 uint8 m_nPad1;
144
145 // Private functions used only inside this class.
146 void Initialise();
147};
148
149inline _event_list::_event_list() {
150 Initialise();
151 m_pcObjectName = EVENT_DELETED_PLACEHOLDER;
152}
153
154inline void _event_list::SetNewObjectName(const char *pcObjectName) {
155 Initialise();
156 m_pcObjectName = pcObjectName;
157}
158
159inline bool8 _event_list::HasEventPending() {
160 bool8 bRetVal;
161
162 // This function has no choice but to clear this flag, for two reasons: firstly, line-of-sight events don't
163 // get explicitly handled by a particular piece of code and so there is nowhere to clear the event if we
164 // don't do it here; secondly, even if named events are outstanding, I can't leave the event flag set because
165 // the script writer might not be making any calls to CheckEventWaiting(), in which case the event flag again
166 // would never get cleared.
167 bRetVal = m_bEventPending;
168 m_bEventPending = FALSE8;
169 return (bRetVal);
170}
171
172inline void _event_list::RemoveAllEventsForObject() { Initialise(); }
173
174} // End of namespace ICB
175
176#endif // #ifndef EVENTLIST_H_INCLUDED
Definition: event_list.h:101
Definition: event_list.h:69