wren
Vulkan-based game engine
Toggle main menu visibility
Loading...
Searching...
No Matches
entity.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <flecs.h>
4
5
#include "
components.hpp
"
6
#include "
scene.hpp
"
7
8
namespace
wren::scene
{
9
10
class
Scene
;
11
12
class
Entity
{
13
public
:
14
Entity
(flecs::entity entity,
const
std::shared_ptr<Scene>&
scene
)
15
:
entity_
(entity),
scene_
(
scene
) {}
16
17
template
<
typename
T>
18
[[nodiscard]]
auto
has_component
() const ->
bool
;
19
20
template <typename T>
21
auto
get_component
() -> T&;
22
23
template <typename T, typename... Args>
24
void
add_component
(Args&&... args);
25
26
private:
27
flecs::entity
entity_
;
28
29
std::shared_ptr<
Scene
>
scene_
;
30
};
31
32
template <typename T>
33
auto
Entity
::
has_component
() const ->
bool
{
34
return
entity_
.has<T>();
35
}
36
37
template
<
typename
T>
38
auto
Entity::get_component
() -> T& {
39
return
*
entity_
.get_mut<T>();
40
}
41
42
template
<
typename
T>
43
concept
HasInit
=
requires
() { T::init(); };
44
45
template
<
typename
T,
typename
... Args>
46
void
Entity::add_component
(Args&&... args) {
47
entity_
.add<T>();
48
if
(
sizeof
...(args) > 0) {
49
T t(std::forward<Args...>(args)...);
50
entity_
.set<T>(t);
51
}
52
53
if
constexpr
(
HasInit<T>
) {
54
T::init(
scene_
->world());
55
}
56
}
57
58
}
// namespace wren::scene
wren::scene::Entity::has_component
auto has_component() const -> bool
Definition
entity.hpp:33
wren::scene::Entity::get_component
auto get_component() -> T &
Definition
entity.hpp:38
wren::scene::Entity::scene_
std::shared_ptr< Scene > scene_
Definition
entity.hpp:29
wren::scene::Entity::Entity
Entity(flecs::entity entity, const std::shared_ptr< Scene > &scene)
Definition
entity.hpp:14
wren::scene::Entity::entity_
flecs::entity entity_
Definition
entity.hpp:27
wren::scene::Entity::add_component
void add_component(Args &&... args)
Definition
entity.hpp:46
wren::scene::Scene
Definition
scene.hpp:11
components.hpp
wren::scene::HasInit
Definition
entity.hpp:43
wren::scene
Definition
components.cpp:3
scene.hpp
wren
include
wren
scene
entity.hpp
Generated by
1.17.0