From f138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Wed, 20 Sep 2023 23:58:58 -0700 Subject: Copy from the PlasticSCM repo, replace vendored glm wtih conan --- source/30-game/Level.hpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 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..c030b8e --- /dev/null +++ b/source/30-game/Level.hpp @@ -0,0 +1,95 @@ +#pragma once + +#include "EditorCore.hpp" +#include "GameObject.hpp" + +#include +#include +#include + +#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; + Uid mUid; + std::vector mEntries; + +public: + Level(); + ~Level(); + + void Instanciate(GameObject* relRoot) const; + + LevelManager* GetLinkedLevelManager() const { return mMan; } + const Uid& GetUid() const { return mUid; } + + // Editor stuff + void ShowInstanciationEntries(IEditor& editor); +}; + +class LevelManager { +public: + static inline LevelManager* instance = nullptr; + +public: // NOTE: public for the editor; actual game components should not modify the map using this + // TODO maybe cut this struct to only the first RcPtr field in release mode? + 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; + + // Editor book keeping fields + bool edited = false; + }; + // 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); + + /// Create and add a new level object with the given uid. + /// Should only be used by the editor. + LoadableObject& AddLevel(const Uid& uid); + /// Should only be used by the editor. + void SaveLevel(const Uid& uid) const; + /// Should only be used by the editor. + void SaveLevel(const Uid& uid, const std::filesystem::path& path) const; + +private: + void SaveLevelImpl(const LoadableObject& obj, const std::filesystem::path& path) const; +}; + +class LevelWrapperObject : public GameObject { + BRUSSEL_CLASS() + +private: + RcPtr mLevel; + +public: + LevelWrapperObject(GameWorld* world); + ~LevelWrapperObject() override; + + Level* GetBoundLevel() const; + void SetBoundLevel(Level* level); +}; -- cgit v1.2.3-70-g09d2