Minor - Implements scene saving and loading - V12.10.0

Adds scene saving and loading functionality, using a component factory for dynamic component creation and serialization.
This allows users to save and load the state of entities, including their components and textures.

A new component factory is introduced to register and create different component types.
Each component implements serialization and deserialization methods, which are used to store and restore the component's state.

A new .ker scene file format is introduced to serialize entity data and to load it back into memory to restore the scene.

Also adds a DemoScene_V12.9.0.ker file to showcase the engine.
This commit is contained in:
2025-09-06 18:59:42 +02:00
parent 118e635415
commit defc1cb795
13 changed files with 518 additions and 374 deletions

View File

@@ -1,4 +1,6 @@
#pragma once
#include <sstream>
#include "../component.h"
#include <string>
@@ -94,13 +96,15 @@ public:
/**
* Serialize the component to a string.
* Format: "id:name:type"
* Format: "IdentityComponent:id:name:type"
* @return A string representation of the component.
*/
std::string Serialize() const override
{
std::string Serialize() const override {
std::stringstream ss;
ss << m_id << ":" << m_name << ":" << ObjectTypeToString(m_type);
ss << "IdentityComponent:"
<< GetId() << ":"
<< GetName() << ":"
<< ObjectTypeToString(GetType());
return ss.str();
}
@@ -110,31 +114,24 @@ public:
* @param data The string data to deserialize from.
* @return True if deserialization was successful, otherwise false.
*/
bool Deserialize(const std::string& data) override
{
bool Deserialize(const std::string& data) override {
std::stringstream ss(data);
std::string segment;
std::vector<std::string> segments;
while (std::getline(ss, segment, ':'))
{
segments.push_back(segment);
}
if (segments.empty()) return false;
if (segments.size() != 3) return false;
try
{
m_id = std::stoi(segments[0]);
m_name = segments[1];
m_type = StringToObjectType(segments[2]);
return true;
} catch (const std::exception&)
{
return false;
}
std::string type;
std::getline(ss, type, ':');
if (type != "IdentityComponent") return false;
std::string token, name, objectTypeStr;
int id;
std::getline(ss, token, ':'); id = std::stoi(token);
std::getline(ss, name, ':');
std::getline(ss, objectTypeStr);
SetId(id);
SetName(name);
SetType(StringToObjectType(objectTypeStr));
return true;
}