-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_object.hpp
65 lines (50 loc) · 1.59 KB
/
game_object.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "transform.hpp"
class component;
class game_object
{
public:
game_object();
void set_selected(bool selected = true);
bool is_selected() const;
void init();
void update();
void draw_gizmos();
void deinit();
void set_active(bool active_flag = true);
bool is_active() const;
void set_name(std::string_view name);
std::string_view get_name() const;
transform& get_transform();
const transform& get_transform() const;
component* get_component(std::string_view type_id);
template <typename T>
T* create_component()
{
return static_cast<T*>(_components.emplace_back(new T(this)));
}
template <typename T>
T* get_component()
{
// TODO: need to figure out a cleverer way of checking the component
// hierarchy to find matching component
auto iterator = std::find_if(_components.begin(),
_components.end(),
[](auto* component) -> bool
{ return dynamic_cast<T*>(component); });
return iterator == _components.end() ? nullptr
: static_cast<T*>(*iterator);
}
void add_child(game_object* child);
std::vector<game_object*>& get_children();
void set_parent(game_object* parent);
game_object* get_parent();
private:
transform _transformation;
bool _selected = false;
bool _is_active = true;
std::string _name;
std::vector<component*> _components;
game_object* _parent;
std::vector<game_object*> _children;
};