Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/variant/variant.hpp>
4#include <iostream>
5
13
14
15/****************************************************
16 *
17 * Important notes for adding new events:
18 *
19 * 1. Make sure you correctly define the serialization function for all data members
20 * 2. Make sure you define two constructors: one "dummy" default constructor which
21 * does nothing, and one constructor to actually make the Events. The dummy constructor
22 * is needed to make everything compile.
23 * 3. Make sure you add the new struct you make to the EventData boost::variant typedef
24 * further down.
25 *
26 ***************************************************/
27
31enum class EventType {
42 UseItem,
47};
48
49enum class ActionType {
50 MoveCam,
51 Jump,
52 Sprint,
53 Zoom
54};
55
59std::ostream& operator<<(std::ostream& os, const EventType& type);
60
67
68 glm::vec3 facing;
71
72 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
74 }
75};
76
77
82enum class PlayerRole {
83 Player,
86};
87
95 enum class Action {
96 Ready,
98 };
99
102 role(role) {}
103
106
107 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
108 ar& action & role;
109 }
110};
111
116 // Dummy value doesn't matter because will be overridden with whatever you deserialize
119
121
122 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
123 ar& state;
124 }
125};
126
131 // Dummy value doesn't matter because will be overridden with whatever you deserialize
133 explicit LoadSoundCommandsEvent(const std::vector<SoundCommand>& commands) : commands(commands) {}
134
135 std::vector<SoundCommand> commands;
136
137 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
138 ar & commands;
139 }
140};
141
148
150 glm::vec3 movement;
152
153 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
155 }
156};
157
164
167 glm::vec3 world_pos;
169
170 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
172 }
173};
174
181
183 glm::vec3 movement;
185
186 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
188 }
189};
190
197
198 glm::vec3 movement;
201
202 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
204 }
205};
206
213
216
217 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
218 // TODO:
219 }
220};
221
228
232 int entity_type; // replace with enum
233
234 // location information about the spawning...
235 // maybe literally embed an Object here? idk
236
237 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
238 // TODO:
239 }
240};
241
248
251
252 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
253 ar& playerEID& itemNum;
254 }
255
256};
257
264
266
267 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
268 ar& playerEID;
269 }
270};
271
278
280
281 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
282 ar& playerEID;
283 }
284
285};
286
291 bool is_cut;
292 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
293 ar & eid & intensity & is_cut;
294 }
295 };
296 std::array<boost::optional<UpdatedLightSource>, MAX_POINT_LIGHTS> lightSources;
297
298 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
299 ar & lightSources;
300 }
301};
302
305
307 const SharedGameState& state,
310 const std::array<boost::optional<SharedObject>, MAX_POINT_LIGHTS>& lights
312
316 std::array<boost::optional<SharedObject>, MAX_POINT_LIGHTS> lights;
317
318 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
319 ar & state & lights & pov_eid & dm_eid;
320 }
321};
322
327using EventData = boost::variant<
343>;
344
348struct Event {
349 Event() {}
352
362
363 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
364 ar& evt_source& type& data;
365 }
366};
367
373std::ostream& operator<<(std::ostream& os, const Event& evt);
CellType
Definition: celltype.hpp:3
ActionType
Definition: event.hpp:49
EventType
Definition: event.hpp:31
@ LoadSoundCommands
@ LoadIntroCutscene
@ UpdateLightSources
boost::variant< ChangeFacingEvent, LobbyActionEvent, LoadGameStateEvent, LoadSoundCommandsEvent, StartActionEvent, StopActionEvent, MoveRelativeEvent, MoveAbsoluteEvent, SpawnEntityEvent, SelectItemEvent, UseItemEvent, UpdateLightSourcesEvent, DropItemEvent, TrapPlacementEvent, LoadIntroCutsceneEvent > EventData
Definition: event.hpp:343
std::ostream & operator<<(std::ostream &os, const EventType &type)
Definition: event.cpp:14
PlayerRole
Definition: event.hpp:82
GLboolean * data
Definition: glad.h:1600
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glad.h:1531
#define MAX_POINT_LIGHTS
Definition: constants.hpp:7
GamePhase
Definition: sharedgamestate.hpp:20
Definition: event.hpp:64
ChangeFacingEvent(EntityID entity_to_change_face, glm::vec3 facing)
Definition: event.hpp:66
EntityID entity_to_change_face
Definition: event.hpp:69
DEF_SERIALIZE(Archive &ar, const unsigned int version)
some velocity / movement information...
Definition: event.hpp:72
ChangeFacingEvent()
Definition: event.hpp:65
glm::vec3 facing
Definition: event.hpp:68
Definition: event.hpp:275
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:281
EntityID playerEID
Definition: event.hpp:279
DropItemEvent()
Definition: event.hpp:276
DropItemEvent(EntityID playerEID)
Definition: event.hpp:277
Definition: event.hpp:348
EntityID evt_source
who is attempting to trigger this event (if client -> server) or who is triggering this event (if ser...
Definition: event.hpp:355
Event()
Definition: event.hpp:349
Event(EntityID evt_source, EventType type, EventData data)
Definition: event.hpp:350
EventType type
The type of event. This actually might not be needed because I think boost::variant has a tag built i...
Definition: event.hpp:358
EventData data
All of the different kinds of event data that you might have. Depending on the value of type,...
Definition: event.hpp:361
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:363
Definition: config.hpp:12
Definition: event.hpp:115
SharedGameState state
Definition: event.hpp:120
LoadGameStateEvent()
Definition: event.hpp:117
LoadGameStateEvent(const SharedGameState &state)
Definition: event.hpp:118
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:122
Definition: event.hpp:303
LoadIntroCutsceneEvent()=default
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:318
EntityID pov_eid
Definition: event.hpp:314
std::array< boost::optional< SharedObject >, MAX_POINT_LIGHTS > lights
Definition: event.hpp:316
LoadIntroCutsceneEvent(const SharedGameState &state, EntityID pov_eid, EntityID dm_eid, const std::array< boost::optional< SharedObject >, MAX_POINT_LIGHTS > &lights)
Definition: event.hpp:306
EntityID dm_eid
Definition: event.hpp:315
SharedGameState state
Definition: event.hpp:313
Definition: event.hpp:130
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:137
LoadSoundCommandsEvent(const std::vector< SoundCommand > &commands)
Definition: event.hpp:133
std::vector< SoundCommand > commands
Definition: event.hpp:135
LoadSoundCommandsEvent()=default
Definition: event.hpp:94
Action action
Definition: event.hpp:104
Action
Definition: event.hpp:95
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:107
PlayerRole role
Definition: event.hpp:105
LobbyActionEvent(Action action, PlayerRole role)
Definition: event.hpp:101
LobbyActionEvent()
Definition: event.hpp:100
Definition: event.hpp:210
EntityID entity_to_move
Definition: event.hpp:214
MoveAbsoluteEvent(EntityID entity_to_move)
Definition: event.hpp:212
DEF_SERIALIZE(Archive &ar, const unsigned int version)
some velocity / movement information...
Definition: event.hpp:217
MoveAbsoluteEvent()
Definition: event.hpp:211
Definition: event.hpp:194
MoveRelativeEvent(EntityID entity_to_move, glm::vec3 movement)
Definition: event.hpp:196
EntityID entity_to_move
Definition: event.hpp:199
glm::vec3 movement
Definition: event.hpp:198
MoveRelativeEvent()
Definition: event.hpp:195
DEF_SERIALIZE(Archive &ar, const unsigned int version)
some velocity / movement information...
Definition: event.hpp:202
Definition: event.hpp:245
SelectItemEvent(EntityID playerEID, int itemNum)
Definition: event.hpp:247
EntityID playerEID
Definition: event.hpp:249
SelectItemEvent()
Definition: event.hpp:246
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:252
int itemNum
Definition: event.hpp:250
The SharedGameState is a representation of the ServerGameState instance maintained by the server and ...
Definition: sharedgamestate.hpp:167
Definition: event.hpp:225
SpawnEntityEvent(EntityID new_id, int entity_type)
Definition: event.hpp:227
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:237
int entity_type
What kind of entity to spawn.
Definition: event.hpp:232
SpawnEntityEvent()
Definition: event.hpp:226
EntityID new_id
Id of the new entity, if the server is sending this down. Ignored, if this is a client request.
Definition: event.hpp:230
Definition: event.hpp:145
ActionType action
Definition: event.hpp:151
glm::vec3 movement
Definition: event.hpp:150
StartActionEvent(EntityID entity_to_act, glm::vec3 movement, ActionType action)
Definition: event.hpp:147
StartActionEvent()
Definition: event.hpp:146
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:153
EntityID entity_to_act
Definition: event.hpp:149
Definition: event.hpp:178
ActionType action
Definition: event.hpp:184
StopActionEvent()
Definition: event.hpp:179
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:186
glm::vec3 movement
Definition: event.hpp:183
StopActionEvent(EntityID entity_to_act, glm::vec3 movement, ActionType action)
Definition: event.hpp:180
EntityID entity_to_act
Definition: event.hpp:182
Definition: event.hpp:161
TrapPlacementEvent()
Definition: event.hpp:162
bool place
Definition: event.hpp:168
bool hover
Definition: event.hpp:168
TrapPlacementEvent(EntityID entity_to_act, glm::vec3 world_pos, CellType cell, bool hover, bool place)
Definition: event.hpp:163
glm::vec3 world_pos
Definition: event.hpp:167
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:170
CellType cell
Definition: event.hpp:166
EntityID entity_to_act
Definition: event.hpp:165
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:292
bool is_cut
Definition: event.hpp:291
float intensity
Definition: event.hpp:290
EntityID eid
Definition: event.hpp:289
Definition: event.hpp:287
std::array< boost::optional< UpdatedLightSource >, MAX_POINT_LIGHTS > lightSources
Definition: event.hpp:296
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:298
Definition: event.hpp:261
EntityID playerEID
Definition: event.hpp:265
UseItemEvent()
Definition: event.hpp:262
UseItemEvent(EntityID playerEID)
Definition: event.hpp:263
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: event.hpp:267
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9