TheAtlasEngine
 
Loading...
Searching...
No Matches
scene.hpp
1#pragma once
2#include <core/core.hpp>
3#include <string>
4#include <core/event/event_bus.hpp>
5#include <core/scene/game_object.hpp>
6
7namespace atlas {
8
24 class scene {
25 public:
31 scene(const std::string& p_name, event::event_bus& p_bus);
32
33 virtual ~scene() = default;
34
41 game_object entity(std::string_view p_name);
42
50 game_object entity(uint64_t p_id);
51
65 template<typename UEventType, typename UObject, typename UCallback>
66 void subscribe(UObject* p_instance, const UCallback& p_callback) {
67 m_bus->subscribe<UEventType>(p_instance, p_callback);
68 }
69
95 template<typename... Comps, typename... Args>
96 flecs::query_builder<Comps...> query_builder(Args&&... args) const {
97 return flecs::query_builder<Comps...>(m_registry,
98 std::forward(args)...);
99 }
100
126 uint32_t children_count(const game_object& p_parent);
127
139 bool defer_begin() { return m_registry.defer_begin(); }
140
150 bool defer_end() { return m_registry.defer_end(); }
151
153 [[nodiscard]] std::string name() const { return m_name; }
154
156 [[nodiscard]] event::event_bus* event_handle() const { return m_bus; }
157
162 operator flecs::world&() { return m_registry; }
163
164 private:
165 flecs::world m_registry;
166 std::string m_name;
167 event::event_bus* m_bus = nullptr;
168 };
169}; // namespace atlas
Event bus that holds the responsibility to reroute events to the subscribers of those particular even...
Definition event_bus.hpp:13
Creates a pointer wrapper which extends capabilities of flecs::entity.
Definition game_object.hpp:15
Constructs a scene that defines an area where game objects are part of contained within an atlas::wor...
Definition scene.hpp:24
event::event_bus * event_handle() const
Definition scene.hpp:156
bool defer_end()
Definition scene.hpp:150
bool defer_begin()
Defer operations until end of frame. When this operation is invoked while iterating,...
Definition scene.hpp:139
uint32_t children_count(const game_object &p_parent)
game_object entity(uint64_t p_id)
Retrieves if an entity already exists within the registry, create new entity otherwise.
void subscribe(UObject *p_instance, const UCallback &p_callback)
subscribes an event to the event::bus to get invoked when publishers notify all subscribers when an u...
Definition scene.hpp:66
game_object entity(std::string_view p_name)
Retrieves if an entity already exists within the registry, create new entity otherwise.
std::string name() const
Definition scene.hpp:153
flecs::query_builder< Comps... > query_builder(Args &&... args) const
queries components, returning entities (game objects) that contain those components queried with.
Definition scene.hpp:96
scene(const std::string &p_name, event::event_bus &p_bus)