Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
SceneSerializer Class Reference

Serializes and deserializes ECS entities and their registered components to/from JSON files. More...

#include <SceneSerializer.hpp>

Public Member Functions

 SceneSerializer (Registry &registry, VulkanRenderer &renderer)
 Construct a new Scene Serializer object.
bool serialize (const std::string &path, const std::vector< Entity > &entities)
 Serializes a list of entities and their components to a JSON file.
bool deserialize (const std::string &path, std::vector< Entity > &outEntities)
 Deserializes entities and components from a JSON file.
bool deserializeFromString (const std::string &jsonContent, std::vector< Entity > &outEntities)
 Deserializes entities from a pre-loaded JSON string. Used by async loading: background thread reads the file, main thread calls this.
bool serializePrefab (const std::string &path, Entity rootEntity)
 Serializes a single entity and all its hierarchy children to a JSON prefab file.
Entity deserializePrefab (const std::string &path, std::vector< Entity > &loadedEntities, Entity parentEntity=Entity())
 Deserializes a prefab file, instantiates entities, and remaps hierarchical parent-child references.

Private Attributes

Registry & registry
 Reference to registry.
VulkanRenderer & renderer
 Reference to Vulkan renderer.

Detailed Description

Serializes and deserializes ECS entities and their registered components to/from JSON files.

Constructor & Destructor Documentation

◆ SceneSerializer()

SceneSerializer::SceneSerializer ( Registry & registry,
VulkanRenderer & renderer )

Construct a new Scene Serializer object.

Construct a new Scene Serializer:: Scene Serializer object.

Parameters
registryReference to the ECS Registry.
rendererReference to the Vulkan Renderer.
registryReference to ECS registry.
rendererReference to Vulkan renderer.

Member Function Documentation

◆ deserialize()

bool SceneSerializer::deserialize ( const std::string & path,
std::vector< Entity > & outEntities )

Deserializes entities and components from a JSON file.

Parameters
pathSource filepath.
outEntitiesTarget list to fill with loaded entities.
Returns
True if loading was successful, false otherwise.

◆ deserializeFromString()

bool SceneSerializer::deserializeFromString ( const std::string & jsonContent,
std::vector< Entity > & outEntities )

Deserializes entities from a pre-loaded JSON string. Used by async loading: background thread reads the file, main thread calls this.

Deserializes scene entities from a JSON file.

Parameters
jsonContentRaw JSON content string.
outEntitiesTarget list to fill with loaded entities.
Returns
True if loading was successful, false otherwise.
Parameters
pathSource file path.
outEntitiesVector to store deserialized entities.
Returns
True if successful, false otherwise.

Deserializes entities from a pre-loaded JSON string (no file I/O). Used by the async load pipeline: background thread pre-reads the file, main thread calls this to spawn entities and upload Vulkan resources.

◆ deserializePrefab()

Entity SceneSerializer::deserializePrefab ( const std::string & path,
std::vector< Entity > & loadedEntities,
Entity parentEntity = Entity() )

Deserializes a prefab file, instantiates entities, and remaps hierarchical parent-child references.

Parameters
pathSource prefab filepath.
loadedEntitiesTarget list to fill with the newly spawned entities.
parentEntityOptional parent entity to attach the newly created root under.
Returns
The newly spawned root entity, or invalid entity if failed.

◆ serialize()

bool SceneSerializer::serialize ( const std::string & path,
const std::vector< Entity > & entities )

Serializes a list of entities and their components to a JSON file.

Serializes a list of entities to a JSON file.

Parameters
pathTarget filepath.
entitiesList of entities to save.
Returns
True if saving was successful, false otherwise.
Parameters
pathTarget file path.
entitiesList of entities to save.
Returns
True if successful, false otherwise.

◆ serializePrefab()

bool SceneSerializer::serializePrefab ( const std::string & path,
Entity rootEntity )

Serializes a single entity and all its hierarchy children to a JSON prefab file.

Parameters
pathTarget filepath.
rootEntityThe root entity of the prefab hierarchy.
Returns
True if successful, false otherwise.

Member Data Documentation

◆ registry

Registry& SceneSerializer::registry
private

Reference to registry.

◆ renderer

VulkanRenderer& SceneSerializer::renderer
private

Reference to Vulkan renderer.


The documentation for this class was generated from the following files: