20 return std::hash<std::string_view>{}(sv);
26 bool operator()(std::string_view lhs, std::string_view rhs)
const noexcept {
32 std::unordered_map<uint32_t, SceneHandle>
m_Handles;
37 if (!s_Data->m_Scenes.contains(name)) {
38 return std::unexpected(
Core::CoriError(std::format(
"No Scene with name '{}' exists.", name)));
45 if (!s_Data->m_Scenes.contains(name)) {
46 return std::unexpected(
Core::CoriError(std::format(
"No Scene with name '{}' exists.", name)));
49 return SceneHandle(s_Data->m_Scenes.find(name)->second);
53 if (s_Data->m_Handles.contains(sceneID)) {
54 return s_Data->m_Handles.at(sceneID);
57 return std::unexpected(
Core::CoriError(std::format(
"No scene with ID '{}' found.", sceneID)));
60 void SceneManager::Init() {
64 void SceneManager::Shutdown() {
73 if (s_Data->m_Scenes.contains(name)) {
74 return std::unexpected(
Core::CoriError(std::format(
"Scene with name '{}' already exists.", name)));
80 s_Data->m_Scenes.insert({ name, scene });
81 const uint32_t
id = s_Data->s_NextSceneID.fetch_add(1, std::memory_order_relaxed);
82 scene->m_SceneID = id;
84 s_Data->m_Handles.insert({ id, handle });
97 if (!s_Data->m_Scenes.contains(name)) {
98 return std::unexpected(
Core::CoriError(std::format(
"No Scene with name '{}' exists.", name)));
103 if (s_Data->m_Scenes.at(name).use_count() == 1) {
104 s_Data->m_Handles.erase(s_Data->m_Scenes.at(name)->m_SceneID);
105 s_Data->m_Scenes.erase(name);
109 return std::unexpected(
Core::CoriError(std::format(
"Failed to destroy Scene '{}', this scene is active in some layer. (ref count is > 1", name)));
#define CORI_CORE_INFO_TAGGED(...)
Custom error class mainly used in std::expected.
A handle for the scene, checks for scene validity before any call to the scene, if scene is invalid a...
static std::expected< SceneHandle, Core::CoriError<> > GetHandle(const uint32_t sceneID)
Allows you to get SceneHandle if all you know is scene id.
static std::expected< SceneHandle, Core::CoriError<> > GetScene(const std::string &name)
Retries the scene with the specified name from the cache.
static std::expected< void, Core::CoriError<> > DestroyScene(const std::string &name)
Destroys a scene with the specified name.
static std::expected< SceneHandle, Core::CoriError<> > CreateScene(const std::string &name)
Creates a scene with the specified name and adds it to the cache.
static std::shared_ptr< Scene > Create(std::string name)
System that is responsible for Animations, every Scene has it by default.
Anything connected to WorldSystem (ECS) is in this namespace.
bool operator()(std::string_view lhs, std::string_view rhs) const noexcept
size_t operator()(std::string_view sv) const noexcept
std::atomic< uint32_t > s_NextSceneID
std::unordered_map< uint32_t, SceneHandle > m_Handles
std::unordered_map< std::string, std::shared_ptr< Scene >, TransparentHash, TransparentEqual > m_Scenes