Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
servergamestate.hpp
Go to the documentation of this file.
1#pragma once
2
12#include "shared/game/event.hpp"
13#include "server/game/grid.hpp"
16
17#include <string>
18#include <vector>
19#include <chrono>
20#include <unordered_map>
21#include <queue>
22#include <boost/container_hash/hash.hpp>
23
25using EventList = std::vector<std::pair<EntityID, Event>>;
26
28 size_t operator()(const std::pair<int, int>& pair) const {
29 std::size_t c = 0;
30
31 boost::hash_combine(c, pair.first);
32 boost::hash_combine(c, pair.second);
33
34 return c;
35 }
36};
37
44public:
50
54 std::unique_ptr<Spawner> spawner;
55
61
68 explicit ServerGameState(GamePhase start_phase);
69
70 ServerGameState(GamePhase start_phase, const GameConfig& config);
71
78 explicit ServerGameState(GameConfig config);
79
81
86 void update(const EventList& events);
87
92
96 void markAsUpdated(EntityID id);
97
98 // TODO: Add specific update methods (E.g., updateMovement() to update
99 // object movement)
100
101 void updateMovement();
102
115 bool hasObjectCollided(Object* object, glm::vec3 newCornerPosition);
116
117 void updateItems();
118
119 void updateAttacks();
120
121 void updateEnemies();
122
123 void doProjectileTicks();
124
125 void doTorchlightTicks();
126
127 void updateTraps();
128
129 void handleDeaths();
130
131 void handleRespawns();
132
133 void handleDM();
134
135 void updateCompass();
136
137 void tickStatuses();
138
139 void spawnEnemies();
140
141 void handleTickVelocity();
142
143 void deleteEntities();
144
151
157
158 /* SharedGameState generation */
159
160 // TODO: Modify this function to dynamically allocate a SharedGameState
161 // instance and return a pointer (perhaps a unique pointer) to it
174 std::vector<SharedGameState> generateSharedGameState(bool send_all);
175
176 /* Audio Information */
178
179 /* Other getters and setters */
180
185 unsigned int getTimestep() const;
186
192 GamePhase getPhase() const;
193
197 void setPhase(GamePhase phase);
198
205
212
217 void setPlayerVictory(bool playerVictory);
218
235 void addPlayerToLobby(LobbyPlayer player);
236
243 void updateLobbyPlayer(EntityID id, LobbyPlayer player);
244
249
250 const Lobby& getLobby() const;
251
253
254 /* Maze initialization */
255
260 void loadMaze(const Grid& grid);
261
262 /* Maze getters */
263
268 Grid& getGrid();
269
270 /* Debugger Methods */
271
276 std::string to_string();
277
278private:
282 std::unordered_set<EntityID> entities_to_delete;
283
288 std::unordered_set<EntityID> updated_entities;
289
293 unsigned int timestep;
294
299 Lobby lobby;
300
304 GamePhase phase;
305
310 MatchPhase matchPhase;
311
317 time_t relay_finish_time;
318
323 bool playerVictory;
324
329 unsigned int numPlayerDeaths;
330
334 std::string maze_file;
335
339 std::string maps_directory;
340
344 Grid grid;
345
352 std::unordered_set<std::pair<Object*, Object*>, pair_hash> collidedObjects;
353
357 Trap* currentGhostTrap;
358
362 std::optional<glm::vec3> dmLightningCutLights;
363
367 std::optional<glm::vec3> dmActionCutLights;
368
372 unsigned int lastLightCut;
373
377 unsigned int lastLightningLightCut;
378
386 void spawnWall(GridCell* cell, int col, int row, bool is_internal);
387
401 void spawnTorch(GridCell *cell, glm::vec3 orb_pos, glm::vec3 exit_pos);
402
412 Trap* spawnFireballTrap(GridCell *cell);
413
414 Trap* spawnArrowTrap(GridCell* cell);
415
416 Trap* spawnFloorSpike(GridCell* cell);
417
418 Trap* spawnLava(GridCell* cell);
419
420 std::unordered_map<EntityID, std::array<std::optional<EntityID>, MAX_POINT_LIGHTS>> lightSourcesPerPlayer;
421
425 SoundTable sound_table;
426
427 GameConfig config;
428};
CellType
Definition: celltype.hpp:3
Definition: gridcell.hpp:23
Definition: grid.hpp:7
Definition: objectmanager.hpp:26
Definition: object.hpp:95
The ServerGameState class contains all abstract game state data and logic for a single game state ins...
Definition: servergamestate.hpp:43
void updateLobbyPlayer(EntityID id, LobbyPlayer player)
Updates the LobbyPlayer with the given EntityID to the given LobbyPlayer struct.
Definition: servergamestate.cpp:1640
void updateEnemies()
Definition: servergamestate.cpp:1137
void tickStatuses()
Definition: servergamestate.cpp:1374
~ServerGameState()
Definition: servergamestate.cpp:112
void update(const EventList &events)
Updates this ServerGameState from the current timestep to the next one.
Definition: servergamestate.cpp:187
MatchPhase getMatchPhase() const
Returns the match phase that this ServerGameState instance is currently in.
Definition: servergamestate.cpp:1581
Grid & getGrid()
Returns a reference to the Grid in use by this ServerGameState.
Definition: servergamestate.cpp:2408
void spawnEnemies()
Definition: servergamestate.cpp:1095
void handleRespawns()
Definition: servergamestate.cpp:1346
ObjectManager objects
ObjectManager instance that manages all objects in this game instance at the current timestep.
Definition: servergamestate.hpp:49
void updatePlayerLightningInvulnerabilityStatus()
Updates player's lightning invulnerability status (sets to false once the player's lightning invulner...
Definition: servergamestate.cpp:1525
void updateItems()
Definition: servergamestate.cpp:1099
void doProjectileTicks()
Definition: servergamestate.cpp:1150
void updateTraps()
Definition: servergamestate.cpp:1196
bool hasObjectCollided(Object *object, glm::vec3 newCornerPosition)
Detects whether a collision occurs with other objects when the given object moves to the given positi...
Definition: servergamestate.cpp:1028
void doTorchlightTicks()
Definition: servergamestate.cpp:1181
std::unique_ptr< Spawner > spawner
Controls the spawns for the enemies.
Definition: servergamestate.hpp:54
void transitionToRelayRace()
Transitions this ServerGameState's match phase to MatchPhase::RelayRace and updates all necessary dat...
Definition: servergamestate.cpp:1585
void handleTickVelocity()
Definition: servergamestate.cpp:1444
void updateDungeonMasterParalysis()
Updates the DungeonMaster's paralysis status (sets to false once the DungeonMaster's paralysis durati...
Definition: servergamestate.cpp:1553
void handleDM()
Definition: servergamestate.cpp:1391
void setPhase(GamePhase phase)
setter for game phase
Definition: servergamestate.cpp:1577
void updateAttacks()
Definition: servergamestate.cpp:1162
void updateMovement()
Definition: servergamestate.cpp:787
GamePhase getPhase() const
Returns the phase that this ServerGameState instance is currently in.
Definition: servergamestate.cpp:1573
SoundTable & soundTable()
Definition: servergamestate.cpp:181
void updateCompass()
Definition: servergamestate.cpp:1398
void setPlayerVictory(bool playerVictory)
Sets the playerVictory boolean.
Definition: servergamestate.cpp:1604
Trap * placeTrapInCell(GridCell *cell, CellType type)
Definition: servergamestate.cpp:1676
void deleteEntities()
Definition: servergamestate.cpp:1364
const Lobby & getLobby() const
Definition: servergamestate.cpp:1672
std::string to_string()
Creates a string representation of this ServerGameState object.
Definition: servergamestate.cpp:2414
unsigned int getTimestep() const
Returns the current timestep of this ServerGameState instance.
Definition: servergamestate.cpp:1569
void markForDeletion(EntityID id)
tell the gamestate to delete this entity at the end of the tick
Definition: servergamestate.cpp:778
void handleDeaths()
Definition: servergamestate.cpp:1257
void addPlayerToLobby(LobbyPlayer player)
Adds a new LobbyPlayer to this ServerGameState's Lobby struct. This method will assign the new player...
Definition: servergamestate.cpp:1608
void markAsUpdated(EntityID id)
mark an entity as updated
Definition: servergamestate.cpp:783
void removePlayerFromLobby(EntityID id)
Definition: servergamestate.cpp:1654
std::vector< SharedGameState > generateSharedGameState(bool send_all)
Generate a SharedGameState object from this ServerGameState instance.
Definition: servergamestate.cpp:115
ServerGameState()
Creates a ServerGameState instance. The intial GamePhase is set to Lobby.
Definition: servergamestate.cpp:42
void loadMaze(const Grid &grid)
Reads from maze file and initializes this ServerGameState's Grid instance, as well as creating all ne...
Definition: servergamestate.cpp:1829
Definition: soundtable.hpp:16
Definition: trap.hpp:9
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glad.h:1531
std::vector< std::pair< EntityID, Event > > EventList
Represents a list of events from a certain client with a specified ID.
Definition: servergamestate.hpp:25
#define MAX_POINT_LIGHTS
Definition: constants.hpp:7
GamePhase
Definition: sharedgamestate.hpp:20
MatchPhase
Definition: sharedgamestate.hpp:28
Definition: config.hpp:12
Definition: servergamestate.hpp:27
size_t operator()(const std::pair< int, int > &pair) const
Definition: servergamestate.hpp:28
Information about a player that has connected to the current lobby.
Definition: sharedgamestate.hpp:37
Information about the current lobby of players.
Definition: sharedgamestate.hpp:80
Definition: custom_hash.hpp:6
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9