diff options
author | rtk0c <[email protected]> | 2022-05-22 23:05:03 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-05-22 23:05:03 -0700 |
commit | 123f741e3f5374b93ac39887b62bfa0d66762ae2 (patch) | |
tree | cedbc4b2dd87e2caadfde48a0c12a0336672bdd3 /source/Level.hpp | |
parent | c568f0a8c9f0aef00c770b494ee1ff3a89ab48de (diff) |
Changeset: 36 Add basic machinery for levels (no saving/loading yet)
Diffstat (limited to 'source/Level.hpp')
-rw-r--r-- | source/Level.hpp | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/source/Level.hpp b/source/Level.hpp index 5c92333..c1170a3 100644 --- a/source/Level.hpp +++ b/source/Level.hpp @@ -1,13 +1,71 @@ #pragma once #include "GameObject.hpp" +#include "RcPtr.hpp" +#include "Uid.hpp" + +#include <robin_hood.h> +#include <filesystem> +#include <vector> + +// 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<InstanciationEntry> 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> 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<Uid, LoadableObject> 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<Level> mLevel; + public: LevelWrapperObject(GameWorld* world); ~LevelWrapperObject() override; -}; -/// Represents a seralized GameObject tree. -class Level { + Level* GetBoundLevel() const; + void SetBoundLevel(Level* level); }; |