133 lines
3.4 KiB
C++
133 lines
3.4 KiB
C++
#ifndef SCENE_H
|
|
#define SCENE_H
|
|
|
|
#include <functional>
|
|
|
|
#include <destrum/Event.h>
|
|
#include <destrum/ObjectModel/ObjectId.h>
|
|
#include <destrum/Scene/SceneManager.h>
|
|
|
|
#include "destrum/Physics/JoltPhysicsWorld.h"
|
|
#include "destrum/Physics/PhysicsSceneBridge.h"
|
|
|
|
class GameObject;
|
|
class SceneSerializer;
|
|
|
|
class Scene final {
|
|
friend Scene& SceneManager::CreateScene(const std::string& name);
|
|
friend class SceneSerializer;
|
|
|
|
public:
|
|
// void Add(std::shared_ptr<GameObject> object);
|
|
void Remove(GameObject* object);
|
|
void RemoveAll();
|
|
|
|
GameObject* CreateGameObject(std::string name);
|
|
|
|
void Load();
|
|
|
|
void Update(float dt);
|
|
void FixedUpdate(float dt);
|
|
void LateUpdate(float dt);
|
|
void Render(const RenderContext& ctx);
|
|
void RenderImgui();
|
|
|
|
void CleanupDestroyedGameObjects();
|
|
void Unload();
|
|
void DestroyGameObjects();
|
|
|
|
[[nodiscard]] bool IsBeingUnloaded() const { return m_BeingUnloaded; }
|
|
|
|
void CommitPendingAdditions();
|
|
void RefreshPhysics();
|
|
|
|
[[nodiscard]] bool IsIterating() const { return m_IterationDepth != 0; }
|
|
void BeginIteration();
|
|
void EndIteration();
|
|
|
|
[[nodiscard]] const std::vector<std::shared_ptr<GameObject>>& GetObjects() const {
|
|
return m_objects;
|
|
}
|
|
|
|
void SetRegisterBindings(std::function<void()> registerBindings) {
|
|
m_registerBindings = std::move(registerBindings);
|
|
}
|
|
|
|
void SetUnregisterBindings(std::function<void()> unregisterBindings) {
|
|
m_unregisterBindings = std::move(unregisterBindings);
|
|
}
|
|
|
|
void UnloadBindings() {
|
|
if (!m_bindingsLoaded) {
|
|
m_bindingsUnloaded = true;
|
|
return;
|
|
}
|
|
if (m_unregisterBindings) {
|
|
m_unregisterBindings();
|
|
}
|
|
m_bindingsLoaded = false;
|
|
m_bindingsUnloaded = true;
|
|
}
|
|
|
|
void LoadBindings() {
|
|
if (m_BeingUnloaded || m_bindingsLoaded) {
|
|
return;
|
|
}
|
|
m_bindingsLoaded = true;
|
|
m_bindingsUnloaded = false;
|
|
try {
|
|
OnSceneLoaded.Invoke();
|
|
if (m_registerBindings) {
|
|
m_registerBindings();
|
|
}
|
|
} catch (...) {
|
|
if (m_unregisterBindings) {
|
|
m_unregisterBindings();
|
|
}
|
|
m_bindingsLoaded = false;
|
|
m_bindingsUnloaded = true;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[[nodiscard]] const std::string& GetName() const { return m_name; }
|
|
[[nodiscard]] unsigned int GetId() const { return m_id; }
|
|
|
|
~Scene();
|
|
Scene(const Scene& other) = delete;
|
|
Scene(Scene&& other) = delete;
|
|
Scene& operator=(const Scene& other) = delete;
|
|
Scene& operator=(Scene&& other) = delete;
|
|
|
|
Event<> OnSceneLoaded;
|
|
|
|
PhysicsSceneBridge& GetPhysics() { return m_Physics; }
|
|
private:
|
|
explicit Scene(const std::string& name);
|
|
|
|
PhysicsSceneBridge m_Physics{std::make_unique<JoltPhysicsWorld>()};
|
|
|
|
|
|
std::string m_name;
|
|
std::vector<std::shared_ptr<GameObject>> m_objects{};
|
|
std::vector<std::shared_ptr<GameObject>> m_pendingAdditions{};
|
|
bool m_BeingUnloaded{false};
|
|
std::size_t m_IterationDepth{0};
|
|
|
|
static unsigned int m_idCounter;
|
|
unsigned int m_id{0};
|
|
|
|
bool m_renderImgui{false};
|
|
|
|
//Imgui vars
|
|
bool m_ShowDemoWindow{false};
|
|
ObjectId m_SelectedObjectId{InvalidObjectId};
|
|
|
|
std::function<void()> m_registerBindings;
|
|
std::function<void()> m_unregisterBindings;
|
|
bool m_bindingsUnloaded{false};
|
|
bool m_bindingsLoaded{false};
|
|
};
|
|
|
|
#endif // SCENE_H
|