Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Scene Class Reference

#include <Scene.h>

Inheritance diagram for Elevate::Scene:
Elevate::ISerializable

Public Member Functions

 Scene ()
 
 Scene (std::string name, SceneType type=SceneType::RuntimeScene)
 
 ~Scene ()=default
 
void UpdateScene ()
 
void RenderScene (Camera *cam=nullptr)
 
void Notify (Event &event)
 
void SubmitDrawCalls (RendererAPI &renderer)
 
const std::string & GetName () const
 
void AddObject (std::shared_ptr< GameObject > newObject, std::shared_ptr< GameObject > parent)
 
const std::set< std::shared_ptr< GameObject > > GetRootObjects () const
 
SceneType GetType ()
 
void SetSkybox (const std::string &skyboxFilePath)
 
std::weak_ptr< CubemapGetSkybox ()
 
void SetLighting (std::unique_ptr< SceneLighting > newLighting)
 
const SceneLightingGetSceneLighting ()
 
std::string Serialize () const override
 
- Public Member Functions inherited from Elevate::ISerializable
virtual void Deserialize (const std::string &data)
 

Static Public Member Functions

static ScenePtr Create (std::string name, SceneType type=SceneType::RuntimeScene)
 

Friends

class GameObject
 
class ComponentRegistry
 

Detailed Description

Definition at line 34 of file Scene.h.

Constructor & Destructor Documentation

◆ Scene() [1/2]

Elevate::Scene::Scene ( )

Definition at line 29 of file Scene.cpp.

29: Scene("DefaultScene", SceneType::RuntimeScene) { }
@ RuntimeScene
Definition Scene.h:29

◆ Scene() [2/2]

Elevate::Scene::Scene ( std::string  name,
SceneType  type = SceneType::RuntimeScene 
)

Definition at line 31 of file Scene.cpp.

31 : m_name(name), m_type(type)
32 {
33 m_registryId = s_nextRegistryId;
34 s_nextRegistryId++;
35 GetRegistryMap()[m_registryId] = std::make_unique<entt::registry>();
36
37 EE_TRACE("Created scene '{}' with registry id: {}", m_name.c_str(), m_registryId);
38 }
#define EE_TRACE(...)
Definition Log.h:66
std::unordered_map< uint32_t, std::unique_ptr< entt::registry > > & GetRegistryMap()

◆ ~Scene()

Elevate::Scene::~Scene ( )
default

Member Function Documentation

◆ AddObject()

void Elevate::Scene::AddObject ( std::shared_ptr< GameObject newObject,
std::shared_ptr< GameObject parent 
)

Definition at line 131 of file Scene.cpp.

132 {
133 if (!newObject)
134 return;
135
136 if (!parent)
137 {
138 AddRootObject(newObject);
139 }
140 else
141 {
142 if (newObject->GetScene() == parent->GetScene())
143 {
144 newObject->SetParent(parent);
145 }
146 else
147 {
148 EE_CORE_ERROR("Cannot add a child object from a different scene.");
149 }
150 }
151 }

◆ Create()

ScenePtr Elevate::Scene::Create ( std::string  name,
SceneType  type = SceneType::RuntimeScene 
)
static

Definition at line 153 of file Scene.cpp.

154 {
155 ScenePtr scene = std::make_shared<Scene>(name, type);
157 scene->Serialize();
158 return scene;
159 }
static void LoadScene(ScenePtr scene)
std::shared_ptr< Scene > ScenePtr
Definition Renderer.h:12

◆ GetName()

const std::string & Elevate::Scene::GetName ( ) const
inline

Definition at line 47 of file Scene.h.

47{ return m_name; };

◆ GetRootObjects()

const std::set< std::shared_ptr< GameObject > > Elevate::Scene::GetRootObjects ( ) const
inline

Definition at line 50 of file Scene.h.

50{ return m_rootObjects; }

◆ GetSceneLighting()

const SceneLighting * Elevate::Scene::GetSceneLighting ( )
inline

Definition at line 64 of file Scene.h.

65 {
66 return m_sceneLighting.get();
67 }

◆ GetSkybox()

std::weak_ptr< Cubemap > Elevate::Scene::GetSkybox ( )

Definition at line 166 of file Scene.cpp.

167 {
168 return m_cubemap;
169 }

◆ GetType()

SceneType Elevate::Scene::GetType ( )
inline

Definition at line 52 of file Scene.h.

52{ return m_type; }

◆ Notify()

void Elevate::Scene::Notify ( Event event)

Definition at line 123 of file Scene.cpp.

124 {
125 for (std::shared_ptr<GameObject> obj : m_rootObjects)
126 {
127 obj->Notify(e);
128 }
129 }

◆ RenderScene()

void Elevate::Scene::RenderScene ( Camera cam = nullptr)

Definition at line 63 of file Scene.cpp.

64 {
65 if (!cam)
66 {
68 }
69
70 // Render the cubemap / skybox
71 if (cam)
72 {
73 // Either do not calculate here or stop calculating it in the layer
74 glm::mat4 view = glm::mat4(glm::mat3(cam->GenViewMatrix()));
75
76 if (m_cubemap)
77 {
78 m_cubemap->SetProjectionMatrix(cam->GetProjectionMatrix());
79 m_cubemap->SetViewMatrix(view);
80 m_cubemap->Draw();
81 }
82 }
83
84 // todo remove
85 //for (std::shared_ptr<GameObject> obj : m_rootObjects)
86 //{
87 // obj->PreRender();
88 //}
89
90 // todo remove
91 //if (m_sceneLighting)
92 //{
93 // Renderer::SetupShaders(this);
94 //}
95
96 for (std::shared_ptr<GameObject> obj : m_rootObjects)
97 {
98 switch (m_type)
99 {
100 case EditorScene:
102 {
103 obj->Render();
104 }
105
106 break;
107 case RuntimeScene:
108 obj->Render();
109
111 {
112 obj->RenderInEditor();
113 }
114
115 break;
116 case DebugScene:
117 obj->Render();
118 break;
119 }
120 }
121 }
static const GameContextState & GetGameState()
static Camera * GetCurrent()
@ DebugScene
Definition Scene.h:31
@ EditorScene
Definition Scene.h:30
@ EditorMode
Definition GameContext.h:8

◆ Serialize()

std::string Elevate::Scene::Serialize ( ) const
overridevirtual

Reimplemented from Elevate::ISerializable.

Definition at line 183 of file Scene.cpp.

184 {
185 //rapidjson::Document doc;
186 //doc.SetObject();
187 //auto& allocator = doc.GetAllocator();
188
189 //doc.AddMember("name", rapidjson::Value(m_name.c_str(), allocator), allocator);
190 //doc.AddMember("type", rapidjson::Value().SetInt(m_type), allocator);
191
195
196 //rapidjson::StringBuffer buffer;
197 //rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
198 //doc.Accept(writer);
199
200 //EE_CORE_TRACE("{}", buffer.GetString());
201 //return buffer.GetString();
202 return "scene";
203 }

◆ SetLighting()

void Elevate::Scene::SetLighting ( std::unique_ptr< SceneLighting newLighting)
inline

Definition at line 60 of file Scene.h.

61 {
62 m_sceneLighting = std::move(newLighting);
63 }

◆ SetSkybox()

void Elevate::Scene::SetSkybox ( const std::string &  skyboxFilePath)

Definition at line 161 of file Scene.cpp.

162 {
163 m_cubemap.reset(Cubemap::CreateFromFile(skyboxFilePath));
164 }
static Cubemap * CreateFromFile(const std::string &filePath)
Definition Cubemap.cpp:70

◆ SubmitDrawCalls()

void Elevate::Scene::SubmitDrawCalls ( RendererAPI renderer)

◆ UpdateScene()

void Elevate::Scene::UpdateScene ( )

Definition at line 50 of file Scene.cpp.

51 {
53 {
54 return;
55 }
56
57 for (std::shared_ptr<GameObject> obj : m_rootObjects)
58 {
59 obj->Update();
60 }
61 }

Friends And Related Symbol Documentation

◆ ComponentRegistry

friend class ComponentRegistry
friend

Definition at line 90 of file Scene.h.

◆ GameObject

friend class GameObject
friend

Definition at line 89 of file Scene.h.


The documentation for this class was generated from the following files: