diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-02 20:46:41 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-02 20:46:41 -0400 |
| commit | a02c7589c6c9e902c59a632aa650635336fe648c (patch) | |
| tree | 8ec4800ff9f9effbd9141e02131123448679bc93 /src/serialization.cpp | |
| parent | fad302f7db146a78900f9b21dbbcd97761093c1b (diff) | |
pke: checkpoint: major serialization refactor
Diffstat (limited to 'src/serialization.cpp')
| -rw-r--r-- | src/serialization.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/serialization.cpp b/src/serialization.cpp new file mode 100644 index 0000000..d7dd312 --- /dev/null +++ b/src/serialization.cpp @@ -0,0 +1,102 @@ + +#include "serialization.hpp" +#include "serialization-component.hpp" +#include "serialization-camera.hpp" +#include "camera.hpp" +#include "ecs.hpp" + +srlztn_serialize_helper *pke_serialize_init(pk_membucket *bkt) { + srlztn_serialize_helper *helper = pk_new<srlztn_serialize_helper>(bkt); + // TODO custom allocator + helper->o = {}; + helper->bkt = bkt; + return helper; +} + +srlztn_deserialize_helper *pke_deserialize_init(pk_membucket *bkt) { + srlztn_deserialize_helper *helper = pk_new<srlztn_deserialize_helper>(bkt); + helper->bkt = bkt; + helper->read_line = nullptr; + // TODO custom allocator + helper->i = {}; + helper->mapping = {bkt}; + return helper; +} + +void pke_serialize_teardown(srlztn_serialize_helper *helper) { + (void)helper; +} + +void pke_deserialize_teardown(srlztn_deserialize_helper *helper) { + (void)helper; +} + +void pke_serialize_file_project(srlztn_serialize_helper *h) { + (void)h; +} + +void pke_deserialize_file_project(srlztn_deserialize_helper *h) { + (void)h; +} + +void pke_serialize_file_scene(srlztn_serialize_helper *h) { + h->o << SRLZTN_FILE_BEGIN << std::endl; + h->o << SRLZTN_FILE_VERSION << std::endl; + h->o << "" << std::endl; + + pk_handle_bucket_index_T instanceBucketCount = ECS_GetInstances_BucketCount(); + for (pk_handle_bucket_index_T b = 0; b < instanceBucketCount; ++b) { + pk_handle_item_index_T count; + auto *instances = ECS_GetInstances(b, count); + for (pk_handle_item_index_T i = 0; i < count; ++i) { + const auto &instance = instances[i]; + if (instance.entHandle == EntityHandle_MAX) + continue; + if (instance.flags & COMPONENT_INSTANCE_FLAG_DO_NOT_SERIALIZE) { + continue; + } + h->o << SRLZTN_OBJ_INSTANCE << std::endl; + pke_serialize_instance(h, &instance); + h->o << SRLZTN_OBJ_END << std::endl; + } + } + + pk_handle_bucket_index_T cameraBucketCount = PkeCamera_GetBucketCount(); + for (pk_handle_bucket_index_T b = 0; b < cameraBucketCount; ++b) { + pk_handle_item_index_T count; + auto *cameras = PkeCamera_GetCameras(b, count); + for (pk_handle_item_index_T i = 0; i < count; ++i) { + const auto &cam = cameras[i]; + if (cam.handle == CameraHandle_MAX) + continue; + h->o << SRLZTN_OBJ_CAMERA << std::endl; + pke_serialize_camera(h, &cam); + h->o << SRLZTN_OBJ_END << std::endl; + } + } + + h->o << SRLZTN_FILE_END << std::endl; +} +void pke_deserialize_file_scene(srlztn_deserialize_helper *h) { + h->read_line = pk_new<char>(h->read_line_len, h->bkt); + memset(h->read_line, '\0', h->read_line_len); + + while (h->i.getline(h->read_line, h->read_line_len)) { + if (strcmp(SRLZTN_OBJ_INSTANCE, h->read_line) == 0) { + pke_deserialize_instance(h); + continue; + } + if (strcmp(SRLZTN_OBJ_CAMERA, h->read_line) == 0) { + pke_deserialize_camera(h); + continue; + } + } +} + +void pke_serialize_file_level(srlztn_serialize_helper *h) { + (void)h; +} +void pke_deserialize_file_level(srlztn_deserialize_helper *h) { + (void)h; +} + |
