11#include <nlohmann/json.hpp>
41 m_scenes[hash] = std::make_shared<Scene>(scene);
104 std::ifstream in(appdata_file, std::ifstream::in);
106 std::stringstream buffer;
107 buffer << in.rdbuf();
109 auto data = buffer.str();
112 if constexpr (!GALAXY_DEBUG_BUILD)
134 const auto parsed = nlohmann::json::parse(data);
156 if constexpr (!GALAXY_DEBUG_BUILD)
178 auto& fs = entt::locator<fs::VirtualFileSystem>::value();
179 if (!fs.write(data, file))
199 auto& em = entt::locator<meta::EntityFactory>::value();
201 nlohmann::json json =
"{\"scenes\":{}}"_json;
205 json[
"scenes"][scene->name()] = scene->serialize();
208 for (
auto i = 0; i <
m_stack.size(); i++)
210 json[
"stack"][std::to_string(i)] =
m_stack[i]->name();
213 json[
"entities"] = nlohmann::json::array();
214 for (
const auto& [entity] :
m_registry.
m_entt.view<entt::entity>(entt::exclude<flags::NotSerializable>).each())
224 auto& em = entt::locator<meta::EntityFactory>::value();
229 const auto& scenes = json.at(
"scenes");
231 for (
const auto& [name, data] : scenes.items())
233 auto scene =
create(name);
236 scene->deserialize(data);
240 const auto& stack = json.at(
"stack");
242 for (
const auto& [index, name] : stack.items())
244 const auto hash =
math::fnv1a(name.get<std::string>().c_str());
248 const auto& entity_json = json.at(
"entities");
249 for (
const auto& data : entity_json)
256 tag.
m_tag =
"Untagged";
#define GALAXY_LOG(level, msg,...)
void clear()
Clear any pending data.
entt::registry m_entt
Scene entities.
void save_app(const std::string &file)
Save all active scenes and sub data within those scenes.
bool empty() const noexcept
Are there any scenes.
std::shared_ptr< Scene > top() noexcept
Get top scene.
SceneManager() noexcept
Constructor.
void pop()
Remove scene on top of stack.
void set(const std::string &scene)
Clears all from stack and sets as active.
core::Registry m_registry
Entity data.
std::shared_ptr< Scene > create(const std::string &scene)
Create scene in engine.
void clear()
Deletes all scene data.
void deserialize(const nlohmann::json &json) override
Deserializes from object.
void update()
Process events and updates.
void render()
Render scenes.
ankerl::unordered_dense::map< std::uint64_t, std::shared_ptr< Scene > > m_scenes
Scene storage.
nlohmann::json serialize() override
Serializes object.
void pop_all()
Pop all scenes.
std::vector< std::shared_ptr< Scene > > m_stack
Active scenes.
void load_app(const std::string &appdata_file)
Load app data file into scene manager.
virtual ~SceneManager() noexcept
Destructor.
void push(const std::string &scene)
Push a scene onto the top of stack.
std::string dump(const nlohmann::json &json)
Dump json to string.
std::string encode_base64(const std::string &input)
Compresses string into Base64.
std::string decode_base64(const std::string &input)
Decompresses string into Base64.
constexpr bits fnv1a(const char *const str, const bits value=fnv_1a_params< bits >::offset) noexcept
Convert string to hash.
std::string encode_zlib(const std::string &input)
Compresses string into ZLib.
std::string decode_zlib(const std::string &input)
Decompresses string into ZLib.