CoriEngine
Loading...
Searching...
No Matches
Layer.cpp
Go to the documentation of this file.
1#include "Layer.hpp"
3
4
5namespace Cori {
6 namespace Core {
7 Layer::Layer(std::string name) : m_Name(std::move(name)) {
8 if (m_Name.empty()) {
9 CORI_CORE_ERROR_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "Creating a Layer with an empty name. This WILL cause issues.");
10 }
12 }
13
17
20 }
21
24 }
25
26 std::expected<void, CoriError<>> Layer::BindScene(const std::string& name) {
27 if (name.empty()) {
28 return std::unexpected(CoriError("Scene name cannot be empty!"));
29 }
30
31 CORI_CORE_DEBUG_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "Binding Scene '{}' to Layer '{}'", name, m_Name);
32 auto result = World::SceneManager::GetScene(name);
33 if (!result) {
34 return std::unexpected(result.error());
35 }
36
37 const bool success = result.value().OnBind();
38 if (!success) {
39 return std::unexpected(CoriError(std::format("Failed to bind Scene '{}'", name)));
40 }
41
42 ActiveScene = result.value();
43 CORI_CORE_DEBUG_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "Scene '{}' bound to Layer '{}' successfully", name, m_Name);
44 return {};
45 }
46
47 std::expected<void, CoriError<>> Layer::UnbindScene() {
48 if (ActiveScene.IsValid()) {
49 CORI_CORE_WARN_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "No Scene is currently bound to Layer '{}', nothing to unbind.", m_Name);
50 return {};
51 }
52
53 CORI_CORE_DEBUG_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "Unbinding scene '{}' from Layer '{}'", ActiveScene.GetName(), m_Name);
54
55 const bool success = ActiveScene.OnUnbind();
56 if (!success) {
57 return std::unexpected(CoriError(std::format("Failed to unbind Scene '{}'", ActiveScene.GetName())));
58 }
59
60 CORI_CORE_DEBUG_TAGGED({ Logger::Tags::Core::Self, Logger::Tags::Core::Layer }, "Scene '{}' unbound from Layer '{}' successfully", ActiveScene.GetName(), m_Name);
61 ActiveScene.m_SceneRaw = std::shared_ptr<World::Scene>(nullptr);
62 return {};
63 }
64 }
65}
#define CORI_CORE_DEBUG_TAGGED(...)
Definition Logger.hpp:1026
#define CORI_CORE_WARN_TAGGED(...)
Definition Logger.hpp:1038
#define CORI_CORE_INFO_TAGGED(...)
Definition Logger.hpp:1027
Custom error class mainly used in std::expected.
Definition Error.hpp:27
virtual void OnDetach()
Method that runs when the layer gets detached to the LayerStack.
Definition Layer.cpp:22
std::expected< void, CoriError<> > BindScene(const std::string &name)
Binds the Scene to the Layer.
Definition Layer.cpp:26
World::SceneHandle ActiveScene
A SceneHandle to the Scene that is currently bound.
Definition Layer.hpp:90
virtual ~Layer()
Definition Layer.cpp:14
Layer(std::string name)
Definition Layer.cpp:7
std::expected< void, CoriError<> > UnbindScene()
Unbinds the Scene from the Layer.
Definition Layer.cpp:47
virtual void OnAttach()
Method that runs when the layer gets attached to the LayerStack.
Definition Layer.cpp:18
static std::expected< SceneHandle, Core::CoriError<> > GetScene(const std::string &name)
Retries the scene with the specified name from the cache.
Core systems of the engine are here.
Global engine namespace.
static constexpr char Self[]
Definition Logger.hpp:83
static constexpr char Layer[]
Definition Logger.hpp:94