Skip to content

File SceneManager.hpp

File List > Engine > include > Resources > SceneManager.hpp

Go to the documentation of this file

#ifndef ENGINE_RESOURCES_SCENEMANAGER_HPP_
#define ENGINE_RESOURCES_SCENEMANAGER_HPP_

#include "ECS/Registry.hpp"
#include <functional>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

namespace Engine {

class SceneManager {
  public:
    using Builder = std::function<void(Registry&)>;
    using FileLoader = std::function<bool(Registry&, const std::string&)>;
    using LoadedCallback = std::function<void(Registry&, const std::string&)>;

    void Register(const std::string& name, Builder builder);

    bool IsRegistered(const std::string& name) const;

    void SetFileLoader(FileLoader loader);

    bool HasFileLoader() const;

    void Load(const std::string& name);

    bool HasPendingLoad() const;

    const std::string& Current() const;

    void OnLoaded(LoadedCallback callback);

    bool ApplyPending(Registry& registry);

  private:
    std::unordered_map<std::string, Builder> m_CodeScenes;
    FileLoader m_FileLoader;
    std::vector<LoadedCallback> m_LoadedCallbacks;
    std::optional<std::string> m_Pending;
    std::string m_Current;
};

} // namespace Engine

#endif // ENGINE_RESOURCES_SCENEMANAGER_HPP_