Potato Engine
Loading...
Searching...
No Matches
World.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <vector>
5#include <type_traits>
6
7#include "Util/Vector2.hpp"
9
11using ActorPool = std::vector<Actor*>;
12
13class Player;
14
18class World
19{
20public:
22 static constexpr int EXTENT_X = 1'000;
24 static constexpr int EXTENT_Y = 24;
25
30 World();
31 ~World();
32
38 template<typename ActorClass>
39 ActorClass* SpawnActor();
46 template<typename ActorClass>
47 ActorClass* SpawnActor(const Vector2& SpawnPosition);
48
53 void DestroyActor(Actor* actor);
60 Actor* AddtoPool(Actor* actor);
61
63 inline size_t ActorCount() const { return actorPool.size(); }
65 const ActorPool& GetAllActors() const;
66
67private:
68 Player* ActivePlayer;
69 ActorPool actorPool;
70
71};
72
73template<typename ActorClass>
74ActorClass* World::SpawnActor() {
75 static_assert(std::is_base_of_v<Actor, ActorClass>, "Illegal class spawn to world");
76
77 Actor* actor = new ActorClass();
78 AddtoPool(actor);
79
80 // post-spawn functionality here
81 actor->DispatchBeginPlay();
82
83 return static_cast<ActorClass*>(actor);
84}
85
86template<typename ActorClass>
87ActorClass* World::SpawnActor(const Vector2& SpawnPosition) {
89 actor->SetPosition(SpawnPosition);
90
91 return static_cast<ActorClass*>(actor);
92}
std::vector< Actor * > ActorPool
Collection of actors in world.
Definition World.hpp:11
Base actor class.
Definition Actor.hpp:14
void SetPosition(const Vector2 &position)
Sets position.
Definition Actor.cpp:41
void DispatchBeginPlay()
Internal function used to queue BeginPlay() on actor.
Definition Actor.cpp:22
User controllable character.
Definition Player.hpp:12
void DestroyActor(Actor *actor)
Destroys actor from world.
Definition World.cpp:23
ActorClass * SpawnActor()
Spawns Actor into world.
Definition World.hpp:74
Actor * AddtoPool(Actor *actor)
Attempts to add external actor object to world managing system.
Definition World.cpp:37
static constexpr int EXTENT_Y
y-height of game world
Definition World.hpp:24
static constexpr int EXTENT_X
x-width of game world
Definition World.hpp:22
const ActorPool & GetAllActors() const
Gets ActorPool.
Definition World.cpp:32
size_t ActorCount() const
Gets count of actors in world.
Definition World.hpp:63
Standard 2-dimensional vector.
Definition Vector2.hpp:11