Potato Engine
Toggle main menu visibility
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
"
8
#include "
Game/Actors/Actor.hpp
"
9
11
using
ActorPool
= std::vector<Actor*>;
12
13
class
Player
;
14
18
class
World
19
{
20
public
:
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
67
private
:
68
Player
* ActivePlayer;
69
ActorPool
actorPool;
70
71
};
72
73
template
<
typename
ActorClass>
74
ActorClass*
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
86
template
<
typename
ActorClass>
87
ActorClass*
World::SpawnActor
(
const
Vector2
& SpawnPosition) {
88
Actor
* actor =
SpawnActor<ActorClass>
();
89
actor->
SetPosition
(SpawnPosition);
90
91
return
static_cast<
ActorClass*
>
(actor);
92
}
Actor.hpp
Vector2.hpp
ActorPool
std::vector< Actor * > ActorPool
Collection of actors in world.
Definition
World.hpp:11
Actor
Base actor class.
Definition
Actor.hpp:14
Actor::SetPosition
void SetPosition(const Vector2 &position)
Sets position.
Definition
Actor.cpp:41
Actor::DispatchBeginPlay
void DispatchBeginPlay()
Internal function used to queue BeginPlay() on actor.
Definition
Actor.cpp:22
Player
User controllable character.
Definition
Player.hpp:12
World::DestroyActor
void DestroyActor(Actor *actor)
Destroys actor from world.
Definition
World.cpp:23
World::SpawnActor
ActorClass * SpawnActor()
Spawns Actor into world.
Definition
World.hpp:74
World::AddtoPool
Actor * AddtoPool(Actor *actor)
Attempts to add external actor object to world managing system.
Definition
World.cpp:37
World::EXTENT_Y
static constexpr int EXTENT_Y
y-height of game world
Definition
World.hpp:24
World::EXTENT_X
static constexpr int EXTENT_X
x-width of game world
Definition
World.hpp:22
World::GetAllActors
const ActorPool & GetAllActors() const
Gets ActorPool.
Definition
World.cpp:32
World::ActorCount
size_t ActorCount() const
Gets count of actors in world.
Definition
World.hpp:63
Vector2
Standard 2-dimensional vector.
Definition
Vector2.hpp:11
Game
World.hpp
Generated by
1.17.0