-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat(scene): SceneSnapshot #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JeanPhilippeKernel
merged 11 commits into
JeanPhilippeKernel:develop
from
jnyfah:user/jnyfah/scene-1
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6542190
feat(scene): SceneSnapshot
jnyfah 0dcac85
feat(scene): ComponentSerializeFns
jnyfah 1102353
feat(scene): YAMLSceneSerializer
jnyfah c5ef571
feat(scene): clangformat
jnyfah de3d274
feat(scene): clangformat
jnyfah 353aaad
feat(scene): clangformat
jnyfah 9d0b68e
feat(scene): clangformat off
jnyfah 921c64d
feat(scene): clangformat off
jnyfah c527bf6
feat(scene): code-review
jnyfah 55eff5a
feat(scene): remove yaml test for now
jnyfah 94412b6
feat(scene): remove yaml test for now
jnyfah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include <ZEngine/ECS/ComponentSerializerRegistry.h> | ||
| #include <ZEngine/Logging/LoggerDefinition.h> | ||
| #include <ZEngine/ZEngineDef.h> | ||
|
|
||
| namespace ZEngine::ECS | ||
| { | ||
| ComponentSerializerRegistry& ComponentSerializerRegistry::Get() | ||
| { | ||
| static ComponentSerializerRegistry s_instance; | ||
| return s_instance; | ||
| } | ||
|
|
||
| bool ComponentSerializerRegistry::IsInitialized() const | ||
| { | ||
| return m_arena != nullptr; | ||
| } | ||
|
|
||
| void ComponentSerializerRegistry::Initialize(Core::Memory::ArenaAllocator* arena, uint32_t capacity) | ||
| { | ||
| ZENGINE_VALIDATE_ASSERT(arena != nullptr, "ComponentSerializerRegistry::Initialize: arena must not be null") | ||
| ZENGINE_VALIDATE_ASSERT(capacity > 0, "ComponentSerializerRegistry::Initialize: capacity must be > 0") | ||
|
|
||
| if (m_arena) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| m_arena = arena; | ||
| m_ids.init(arena, capacity); | ||
| m_fns.init(arena, capacity); | ||
| } | ||
|
|
||
| void ComponentSerializerRegistry::Register(ComponentTypeID type_id, ComponentSerializeFns fns) | ||
| { | ||
| ZENGINE_VALIDATE_ASSERT(m_arena != nullptr, "ComponentSerializerRegistry::Register: Initialize() must be called first") | ||
|
|
||
| if (Lookup(type_id)) | ||
| { | ||
| ZENGINE_CORE_WARN("ComponentSerializerRegistry: TypeID {} already registered, ignoring", type_id); | ||
| return; | ||
| } | ||
|
|
||
| ZENGINE_VALIDATE_ASSERT(m_ids.size() < m_ids.capacity(), "ComponentSerializerRegistry::Register: exceeded the capacity reserved by Initialize() — pass a larger capacity there") | ||
|
|
||
| m_ids.push(type_id); | ||
| m_fns.push(fns); | ||
| } | ||
|
|
||
| const ComponentSerializeFns* ComponentSerializerRegistry::Lookup(ComponentTypeID type_id) const | ||
| { | ||
| for (uint32_t i = 0; i < m_ids.size(); ++i) | ||
| { | ||
| if (m_ids[i] == type_id) | ||
| { | ||
| return &m_fns[i]; | ||
| } | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| void ComponentSerializerRegistry::ForEach(ForEachSerializerFn fn, void* ctx) const | ||
| { | ||
| if (!fn) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| for (uint32_t i = 0; i < m_ids.size(); ++i) | ||
| { | ||
| fn(ctx, m_ids[i], m_fns[i]); | ||
| } | ||
| } | ||
|
|
||
| uint32_t ComponentSerializerRegistry::Count() const | ||
| { | ||
| return static_cast<uint32_t>(m_ids.size()); | ||
| } | ||
| } // namespace ZEngine::ECS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #pragma once | ||
| #include <ZEngine/Core/Containers/Array.h> | ||
| #include <ZEngine/Core/Memory/Allocator.h> | ||
| #include <ZEngine/ECS/ComponentTypeID.h> | ||
| #include <ZEngine/ECS/EntityID.h> | ||
| #include <yaml-cpp/yaml.h> | ||
| #include <cstdint> | ||
|
|
||
| namespace ZEngine::ECS | ||
| { | ||
| class Scene; | ||
|
|
||
| using SerializeYAMLFn = void (*)(void* ctx, EntityID id, const Scene& scene, YAML::Node& out); | ||
| using DeserializeYAMLFn = void (*)(void* ctx, EntityID id, Scene& scene, const YAML::Node& in); | ||
| using SerializeBinaryFn = void (*)(void* ctx, EntityID id, const Scene& scene, Core::Containers::Array<uint8_t>& out); | ||
| using DeserializeBinaryFn = void (*)(void* ctx, EntityID id, Scene& scene, const uint8_t* data, uint32_t size); | ||
|
|
||
| struct ComponentSerializeFns | ||
| { | ||
| SerializeYAMLFn SerializeYAML = nullptr; | ||
| DeserializeYAMLFn DeserializeYAML = nullptr; | ||
| SerializeBinaryFn SerializeBinary = nullptr; | ||
| DeserializeBinaryFn DeserializeBinary = nullptr; | ||
| void* Context = nullptr; // first arg to every callback | ||
| }; | ||
|
|
||
| using ForEachSerializerFn = void (*)(void* ctx, ComponentTypeID type_id, const ComponentSerializeFns& fns); | ||
|
|
||
| class ComponentSerializerRegistry | ||
| { | ||
| public: | ||
| static ComponentSerializerRegistry& Get(); | ||
|
|
||
| void Initialize(Core::Memory::ArenaAllocator* arena, uint32_t capacity = 64); | ||
|
|
||
| [[nodiscard]] bool IsInitialized() const; | ||
|
|
||
| void Register(ComponentTypeID type_id, ComponentSerializeFns fns); | ||
|
|
||
| [[nodiscard]] const ComponentSerializeFns* Lookup(ComponentTypeID type_id) const; | ||
|
|
||
| // Iterates all registered type IDs in registration order. | ||
| void ForEach(ForEachSerializerFn fn, void* ctx) const; | ||
|
|
||
| [[nodiscard]] uint32_t Count() const; | ||
|
|
||
| private: | ||
| Core::Containers::Array<ComponentTypeID> m_ids; | ||
| Core::Containers::Array<ComponentSerializeFns> m_fns; | ||
| Core::Memory::ArenaAllocator* m_arena = nullptr; | ||
| }; | ||
| } // namespace ZEngine::ECS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #pragma once | ||
| #include <ZEngine/Core/VFS/IVFSContext.h> | ||
| #include <ZEngine/Core/VFS/VFSError.h> | ||
| #include <ZEngine/Core/VFS/VFSPath.h> | ||
| #include <ZEngine/ECS/SceneSnapshot.h> | ||
|
|
||
| namespace ZEngine::ECS | ||
| { | ||
| class ISceneSerializer | ||
| { | ||
| public: | ||
| virtual ~ISceneSerializer() = default; | ||
|
|
||
| virtual Core::VFS::VFSResult<void> Serialize(Core::VFS::IVFSContext& ctx, const Core::VFS::VFSPath& path, const SceneSnapshot& scene) = 0; | ||
|
|
||
| virtual Core::VFS::VFSResult<void> Deserialize(Core::VFS::IVFSContext& ctx, const Core::VFS::VFSPath& path, SceneSnapshot& out_scene) = 0; | ||
| }; | ||
| } // namespace ZEngine::ECS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
| #include <ZEngine/Core/Containers/Array.h> | ||
| #include <ZEngine/Core/Containers/Strings.h> | ||
| #include <ZEngine/Core/Memory/Allocator.h> | ||
| #include <ZEngine/ECS/EntityID.h> | ||
| #include <uuid.h> | ||
|
|
||
| namespace ZEngine::ECS | ||
| { | ||
| struct SceneSnapshot | ||
| { | ||
| uuids::uuid SceneUUID = {}; | ||
| Core::Containers::String Name = {}; | ||
|
|
||
| Core::Containers::Array<EntityID> Entities = {}; | ||
|
|
||
| static SceneSnapshot Create(Core::Memory::ArenaAllocator* arena, cstring name, uint32_t entity_capacity = 64) | ||
| { | ||
| SceneSnapshot snapshot{}; | ||
| snapshot.Name.init(arena, name ? name : ""); | ||
| snapshot.Entities.init(arena, entity_capacity ? entity_capacity : 1); | ||
| return snapshot; | ||
| } | ||
| }; | ||
| } // namespace ZEngine::ECS | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.