Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
objectmanager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#define GLM_ENABLE_EXPERIMENTAL
6#include "glm/gtx/hash.hpp"
7
10#include "server/game/enemy.hpp"
14//#include "server/game/grid.hpp"
16
17// forward declarations to use pointers
18class Trap;
19class Projectile;
20class Item;
21class Exit;
22class Orb;
23class WeaponCollider;
24
25
27public:
30
31 /* Object CRUD methods */
32
49
56 bool removeObject(EntityID globalID);
57
66 bool removeObject(Object** object_dbl_ptr);
67
76 bool replaceObject(EntityID globalID, Object* object);
77
84 Object* getObject(EntityID globalID);
85
86 /* SpecificID object getters by type */
87
94 Object* getBaseObject(SpecificID base_objectID);
95
102 Item* getItem(SpecificID itemID);
103
111
118 Player* getPlayer(SpecificID playerID);
119
125
131 Enemy* getEnemy(SpecificID enemyID);
132
138 Torchlight* getTorchlight(SpecificID torchlightID);
139
145 Trap* getTrap(SpecificID trapID);
146
154
162
170
178
186
194
202
210
218
226
234
235 /* Object Movement */
236
247 bool moveObject(Object* object, glm::vec3 newCornerPosition);
248
258 std::vector<glm::ivec2> objectGridCells(Object* object);
259
264 std::unordered_map<glm::ivec2, std::vector<Object*>> cellToObjects;
265
266 /* SharedGameState generation */
267
274 std::vector<boost::optional<SharedObject>> toShared();
275
276private:
277
292 SpecificID _createObject(Object* object, boost::optional<EntityID> id = boost::none);
293
294 /*
295 * Note on how Objects are stored:
296 *
297 * The ObjectManager class maintains a SmartVector<Object *> objects vector
298 * that holds pointers to all Objects in the game instance at the current
299 * timestep.
300 *
301 * The global objects SmartVector is indexed by each object's global
302 * EntityID; that is, if an object's EntityID is x, then a pointer to that
303 * object is stored in index x of the objects SmartVector.
304 *
305 * The Objects are dynamically allocated on the heap when created, meaning
306 * there is no guaranteed contiguous object storage in memory.
307 *
308 * Type-specific vectors are available for convenience and contain duplicate
309 * pointers; e.g., a SmartVector<Item *> will contain Item * pointers to all
310 * objects whose types derive from Item.
311 *
312 * The type-specific vectors are indexed by their objects' type-specific
313 * SpecificID; that is, if an object is stored in SmartVector<Item *> items
314 * and its SpecificID is x, then at index x of items is a pointer to that
315 * object.
316 *
317 * As each object has only one type-specific SpecificID, each object may
318 * only be stored in one type-specific SmartVector.
319 */
320
329 SmartVector<Object *> objects;
330
339 SmartVector<Object*> movableObjects;
340
341 /* Type-specific object smart vectors */
342
347 SmartVector<Object *> base_objects;
348
353
357 SmartVector<SolidSurface *> solid_surfaces;
358
363 SmartVector<Player *> players;
364
369 SmartVector<Enemy *> enemies;
370
375 SmartVector<Torchlight *> torchlights;
376
382
387 SmartVector<Projectile *> projectiles;
388
393 SmartVector<WeaponCollider*> weaponColliders;
394
399 SmartVector<Exit*> exits;
400
404 DungeonMaster * dm;
405};
Definition: dungeonmaster.hpp:11
Definition: enemy.hpp:8
Definition: exit.hpp:7
Definition: item.hpp:20
Definition: objectmanager.hpp:26
~ObjectManager()
Definition: objectmanager.cpp:30
SmartVector< Object * > getObjects()
Get a list of all objects in this game instance at the current timestep.
Definition: objectmanager.cpp:271
Object * getBaseObject(SpecificID base_objectID)
Attempts to retrieve the Object with the given SpecificID.
Definition: objectmanager.cpp:280
SmartVector< Projectile * > getProjectiles()
Get a list of all Projectiles in this game instance at the current timestep.
Definition: objectmanager.cpp:332
Torchlight * getTorchlight(SpecificID torchlightID)
Attempts to retrieve the Torchlight with the given SpecificID.
Definition: objectmanager.cpp:304
SmartVector< Enemy * > getEnemies()
Get a list of all Enemies in this game instance at the current timestep.
Definition: objectmanager.cpp:324
SmartVector< Item * > getItems()
Get a list of all items in this game instance at the current timestep.
Definition: objectmanager.cpp:312
std::unordered_map< glm::ivec2, std::vector< Object * > > cellToObjects
Hashmap that maps GridCell (x, y) positions to a vector of Objects that occupy / overlap that GridCel...
Definition: objectmanager.hpp:264
SmartVector< SolidSurface * > getSolidSurfaces()
Get a list of all SolidSurfaces in this game instance at the current timestep.
Definition: objectmanager.cpp:316
ObjectManager()
Definition: objectmanager.cpp:20
std::vector< boost::optional< SharedObject > > toShared()
Generates a list of SharedObjects that corresponds to all objects in the game instance.
Definition: objectmanager.cpp:389
SmartVector< Torchlight * > getTorchlights()
Get a list of all Projectiles in this game instance at the current timestep.
Definition: objectmanager.cpp:340
SmartVector< Player * > getPlayers()
Get a list of all Players in this game instance at the current timestep.
Definition: objectmanager.cpp:320
Enemy * getEnemy(SpecificID enemyID)
Attempts to retrieve the Enemy with the given SpecificID.
Definition: objectmanager.cpp:300
Object * getObject(EntityID globalID)
Attempts to retrieve the object with the given EntityID.
Definition: objectmanager.cpp:267
SmartVector< WeaponCollider * > getWeaponColliders()
Get a list of all WeaponCollider in this game instance at the current timestep.
Definition: objectmanager.cpp:336
Item * getItem(SpecificID itemID)
Attempts to retrieve the Item with the given SpecificID.
Definition: objectmanager.cpp:288
bool replaceObject(EntityID globalID, Object *object)
Replaces the object with the given EntityID with the given Object, if there currently exists an objec...
Definition: objectmanager.cpp:249
bool removeObject(EntityID globalID)
Attempts to remove an object with the given EntityID.
Definition: objectmanager.cpp:134
SmartVector< Trap * > getTraps()
Get a list of all Traps in this game instance at the current timestep.
Definition: objectmanager.cpp:328
Player * getPlayer(SpecificID playerID)
Attempts to retrieve the Player with the given SpecificID.
Definition: objectmanager.cpp:296
SolidSurface * getSolidSurface(SpecificID surfaceID)
Attempts to retrieve the SolidSurface with the given SpecificID.
Definition: objectmanager.cpp:292
SpecificID createObject(Object *object)
Creates a new object with the specified type.
Definition: objectmanager.cpp:36
std::vector< glm::ivec2 > objectGridCells(Object *object)
Given an object, his function will return a vector of positions of GridCells that are currently occup...
Definition: objectmanager.cpp:382
SmartVector< Object * > getMovableObjects()
Get a list of all objects in this game instance at the current timestep that are MOVABLE.
Definition: objectmanager.cpp:275
SmartVector< Exit * > getExits()
Get a list of all Exits in this game instance at the current timestep.
Definition: objectmanager.cpp:344
Trap * getTrap(SpecificID trapID)
Attempts to retrieve the Trap with the given SpecificID.
Definition: objectmanager.cpp:308
DungeonMaster * getDM()
Get the Dungeon Master pointer.
Definition: objectmanager.cpp:284
bool moveObject(Object *object, glm::vec3 newCornerPosition)
Attempts to move the given Object to the given corner position, updating its GridCell position vector...
Definition: objectmanager.cpp:349
Definition: object.hpp:95
Definition: orb.hpp:10
Definition: player.hpp:9
Definition: projectile.hpp:20
SmartVector is a wrapper for the std::vector class that adds objects either to the end of the wrapped...
Definition: smartvector.hpp:16
Definition: solidsurface.hpp:5
Definition: torchlight.hpp:8
Definition: trap.hpp:9
Definition: weaponcollider.hpp:12
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9
uint32_t SpecificID
Object ID within an object type-specific SmartVector (used by ServerGameState's ObjectManager)
Definition: typedefs.hpp:16