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
ComponentSerializerRegistry.hpp
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <vector>
4#include <functional>
5#include <ostream>
6#include "ecs/Entity.hpp"
7#include "ecs/Registry.hpp"
9
10#include "core/EngineAPI.hpp"
11
12class VulkanRenderer;
13
19public:
21 using SerializerCallback = std::function<void(Registry& registry, Entity entity, std::ostream& out, int indentLevel)>;
23 using DeserializerCallback = std::function<void(Registry& registry, VulkanRenderer& renderer, Entity entity, const std::string& entityJson)>;
24
37
43
50 void registerComponent(const std::string& componentName, SerializerCallback serialize, DeserializerCallback deserialize) {
51 for (auto& existing : registrations) {
52 if (existing.componentName == componentName) {
53 existing.serialize = serialize;
54 existing.deserialize = deserialize;
55 return;
56 }
57 }
58 registrations.push_back({ componentName, serialize, deserialize });
59 }
60
61
66 const std::vector<Registration>& getRegistrations() const {
67 return registrations;
68 }
69
70private:
74 std::vector<Registration> registrations;
75};
#define ENGINE_API
Definition EngineAPI.hpp:10
std::function< void(Registry &registry, Entity entity, std::ostream &out, int indentLevel)> SerializerCallback
Signature for component serialization callbacks.
Definition ComponentSerializerRegistry.hpp:21
static ComponentSerializerRegistry & getInstance()
Retrieves singleton instance of the registry.
Definition ComponentSerializerRegistry.cpp:3
ComponentSerializerRegistry()=default
Default constructor for singleton.
void registerComponent(const std::string &componentName, SerializerCallback serialize, DeserializerCallback deserialize)
Registers serializer callbacks for a component type.
Definition ComponentSerializerRegistry.hpp:50
const std::vector< Registration > & getRegistrations() const
Retrieves all registered components.
Definition ComponentSerializerRegistry.hpp:66
std::function< void(Registry &registry, VulkanRenderer &renderer, Entity entity, const std::string &entityJson)> DeserializerCallback
Signature for component deserialization callbacks.
Definition ComponentSerializerRegistry.hpp:23
std::vector< Registration > registrations
Array of registered components.
Definition ComponentSerializerRegistry.hpp:74
Lightweight identifier representing a game object in the Entity Component System.
Definition Entity.hpp:11
Coordinates entities and components, providing creation, removal, lookup, and views.
Definition Registry.hpp:30
Manages core Vulkan pipeline states, device interaction, frames, buffers, and command submissions.
Definition VulkanRenderer.hpp:127
Links a component name to its serialization and deserialization functions.
Definition ComponentSerializerRegistry.hpp:29
DeserializerCallback deserialize
Function to deserialize the component.
Definition ComponentSerializerRegistry.hpp:35
std::string componentName
String identifier of the component type.
Definition ComponentSerializerRegistry.hpp:31
SerializerCallback serialize
Function to serialize the component.
Definition ComponentSerializerRegistry.hpp:33