From e66286ebe30afc9acc4531fc2bea29b7fb924f93 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Mon, 30 May 2022 17:03:20 -0700 Subject: Changeset: 56 Buildsystem cleanup: change to layered structure for different targets --- source/30-game/Level.hpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 source/30-game/Level.hpp (limited to 'source/30-game/Level.hpp') diff --git a/source/30-game/Level.hpp b/source/30-game/Level.hpp new file mode 100644 index 0000000..c1170a3 --- /dev/null +++ b/source/30-game/Level.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include "GameObject.hpp" +#include "RcPtr.hpp" +#include "Uid.hpp" + +#include +#include +#include + +// Forward declarations +class Level; +class LevelManager; + +/// Represents a seralized GameObject tree. +class Level : public RefCounted { + friend class LevelManager; + +private: + struct InstanciationEntry; + + LevelManager* mMan; + std::vector mEntries; + +public: + Level(); + ~Level(); + + void Instanciate(GameObject* relRoot) const; +}; + +class LevelManager { +public: + static inline LevelManager* instance = nullptr; + +public: // NOTE: public for the editor; actual game components should not modify the map using this + struct LoadableObject { + RcPtr level; // TODO make weak pointer + std::filesystem::path filePath; + // NOTE: these fields are only loaded in dev mode + std::string name; + std::string description; + }; + // We want pointer stability here for the editor (inspector object) + robin_hood::unordered_node_map mObjByUid; + +public: + void DiscoverFilesDesignatedLocation(); + void DiscoverFiles(const std::filesystem::path& dir); + + Level* FindLevel(const Uid& uid) const; + /// Get or load the given level + Level* LoadLevel(const Uid& uid); + /// Send the given level to be loaded on another thread + void PrepareLevel(const Uid& uid); + + // These should only be used by the editor + LoadableObject& AddLevel(const Uid& uid); +}; + +class LevelWrapperObject : public GameObject { +private: + RcPtr mLevel; + +public: + LevelWrapperObject(GameWorld* world); + ~LevelWrapperObject() override; + + Level* GetBoundLevel() const; + void SetBoundLevel(Level* level); +}; -- cgit v1.2.3-70-g09d2