8#ifndef GALAXY_STATE_SCENEMANAGER_HPP_
9#define GALAXY_STATE_SCENEMANAGER_HPP_
11#include <ankerl/unordered_dense.h>
23 class SceneManager final :
public fs::Serializable
25 using Map = ankerl::unordered_dense::map<std::uint64_t, std::unique_ptr<Scene>>;
46 [[maybe_unused]]
Scene*
add(
const std::string& name);
55 template<std::derived_from<Scene> Custom>
56 [[maybe_unused]] Custom*
add_custom(
const std::string& name);
65 [[nodiscard]]
Scene*
get(
const std::string& name);
74 void remove(
const std::string& name);
83 [[nodiscard]]
bool has(
const std::string& name);
112 void load_app(
const std::string& appdata_file);
119 void save_app(
const std::string& file);
153 [[nodiscard]]
const Map&
map()
const;
160 [[nodiscard]]
bool empty()
const;
167 [[nodiscard]] nlohmann::json
serialize()
override;
174 void deserialize(
const nlohmann::json& json)
override;
198 template<std::derived_from<Scene> Custom>
205 m_scenes[hash] = std::make_unique<Custom>(name);
209 GALAXY_LOG(GALAXY_WARNING,
"Tried to add a duplicate scene '{0}'.", name);
212 return static_cast<Custom*
>(
m_scenes[hash].get());
218 auto ptr = std::make_unique<System>(std::forward<Args>(args)...);
221 if constexpr (std::is_same<System, systems::RenderSystem>::value)
#define GALAXY_LOG(level, msg,...)
void create_system(Args &&... args)
Add a system to the manager.
void only_update_rendering()
Only update rendering.
void save_app(const std::string &file)
Save all active scenes and sub data within those scenes.
Custom * add_custom(const std::string &name)
Add a custom scene.
bool has(const std::string &name)
Does a scene exist.
scene::Scene * current() const
Get current scene.
virtual ~SceneManager()
Destructor.
std::size_t m_rendersystem_index
Rendersystem index.
SystemContainer m_systems
Stores systems.
void clear()
Deletes all scene data.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
void update()
Handle events and update logic.
void render()
Handle rendering.
nlohmann::json serialize() override
Serializes object.
void load_app(const std::string &appdata_file)
Load app data file into scene manager.
Scene * get(const std::string &name)
Get a specific scene.
Scene * add(const std::string &name)
Add a new scene.
ankerl::unordered_dense::map< std::uint64_t, std::unique_ptr< Scene > > Map
void set_scene(const std::string &name)
Scene to set to currently active.
SceneManager()
Constructor.
void remove(const std::string &name)
Remove a specific scene.
meta::vector< std::unique_ptr< systems::System > > SystemContainer
bool empty() const
Are there any scenes.
const Map & map() const
Get all scenes.
scene::Scene * m_current
Current scene.
Represents a scene in a game. Like the menu, game, etc. Does not share resources.
constexpr std::uint64_t fnv1a_64(const char *const str) noexcept
Convert string to 64bit hash.