wren
Vulkan-based game engine
Loading...
Searching...
No Matches
entity.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <flecs.h>
4
5#include "scene.hpp"
6
7namespace wren::scene {
8
9class Scene;
10
11class Entity {
12 public:
13 Entity(flecs::entity entity, const std::shared_ptr<Scene>& scene)
14 : entity_(entity), scene_(scene) {}
15
16 template <typename T>
17 [[nodiscard]] auto has_component() const -> bool;
18
19 template <typename T>
20 auto get_component() -> T&;
21
22 template <typename T, typename... Args>
23 void add_component(Args&&... args);
24
25 private:
26 flecs::entity entity_;
27
28 std::shared_ptr<Scene> scene_;
29};
30
31template <typename T>
32auto Entity::has_component() const -> bool {
33 // return scene_->world().all_of<T>();
34}
35
36template <typename T>
38 return scene_->world().get<T>(entity_);
39}
40
41template <typename T, typename... Args>
42void Entity::add_component(Args&&... args) {
43 entity_.add<T>();
44 entity_.set<T>(T(std::forward<Args>(args)...));
45}
46
47} // namespace wren::scene
Definition entity.hpp:11
auto has_component() const -> bool
Definition entity.hpp:32
auto get_component() -> T &
Definition entity.hpp:37
std::shared_ptr< Scene > scene_
Definition entity.hpp:28
Entity(flecs::entity entity, const std::shared_ptr< Scene > &scene)
Definition entity.hpp:13
flecs::entity entity_
Definition entity.hpp:26
void add_component(Args &&... args)
Definition entity.hpp:42
Definition scene.hpp:11
Definition components.cpp:3