summaryrefslogtreecommitdiff
path: root/src/serialization-component.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-04-07 14:12:28 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-04-07 14:30:50 -0400
commit7b43a9b51d9df0bc0e18102415f877772031f440 (patch)
treebbbdc15d8972ee4ca4d4a8379ffddb0be62752e3 /src/serialization-component.cpp
parentff63a4b2bf9f096f8cf8c6824e826b3b4d79e747 (diff)
pke: save and load camera target in scenes
Diffstat (limited to 'src/serialization-component.cpp')
-rw-r--r--src/serialization-component.cpp47
1 files changed, 16 insertions, 31 deletions
diff --git a/src/serialization-component.cpp b/src/serialization-component.cpp
index 9a29e67..8867339 100644
--- a/src/serialization-component.cpp
+++ b/src/serialization-component.cpp
@@ -88,8 +88,6 @@ bool pke_deserialize_inst_pos(srlztn_deserialize_helper *h, glm::vec3 &pos, glm:
}
bool pke_serialize_instance(srlztn_serialize_helper *h, const CompInstance *comp) {
- NULL_CHAR_ARR(handle_str, 23);
-
EntityType *et = nullptr;
if (comp->grBindsHandle != GrBindsHandle_MAX) {
et = EntityType_FindByEntityHandle(ECS_GetGrBinds(comp->grBindsHandle)->entHandle);
@@ -115,14 +113,6 @@ bool pke_serialize_instance(srlztn_serialize_helper *h, const CompInstance *comp
BulletToGlm(comp->bt.rigidBody->getCollisionShape()->getLocalScaling(), scale);
}
- if (comp->instanceHandle != InstanceHandle_MAX) {
- snprintf(handle_str, 22, "0x%08X 0x%08X", comp->instanceHandle.bucketIndex, comp->instanceHandle.itemIndex);
- h->o << SRLZTN_INSTANCE_COMPONENT_ENTITY_HANDLE << handle_str << std::endl;
- }
- if (comp->entHandle != InstanceHandle_MAX) {
- snprintf(handle_str, 22, "0x%08X 0x%08X", comp->entHandle.bucketIndex, comp->entHandle.itemIndex);
- h->o << SRLZTN_INSTANCE_COMPONENT_HANDLE << handle_str << std::endl;
- }
if (comp->uuid != pk_uuid_zed && comp->uuid != pk_uuid_max) {
h->o << SRLZTN_INSTANCE_COMPONENT_UUID << comp->uuid << std::endl;
}
@@ -151,7 +141,6 @@ bool pke_serialize_instance(srlztn_serialize_helper *h, const CompInstance *comp
bool pke_deserialize_instance(srlztn_deserialize_helper *h) {
uint64_t prefix_len;
PK_STN_RES stn_res;
- NULL_CHAR_ARR(handle_str, 21);
EntityType *et_ptr = nullptr;
float mass;
InstPos inst_pos;
@@ -190,29 +179,25 @@ bool pke_deserialize_instance(srlztn_deserialize_helper *h) {
// entity = reinterpret_cast<CreateInst*>(et_ptr->createInstanceCallback.func)();
fprintf(stderr, "[%s] Attempted to call EntityType::createInstanceCallback and we have not yet defined a valid function signature", __FILE__);
} else {
- EntityType_CreateGenericInstance(et_ptr, h->scene, &comp, &inst_pos);
- // fprintf(stdout ,"[Game::DeserializeInstance] Debug: entTypeCode '%s' does not have a registered callback func to handle instance creation.\n", entTypeCode);
+ srlztn_instance_mapping map{};
+ map.serialized_uuid = comp.uuid;
+ map.created_entity = EntityType_CreateGenericInstance(et_ptr, h->scene, &comp, &inst_pos);
+ // TODO gross
+ pk_arr_t<CompInstance *> instances;
+ ECS_GetInstances(map.created_entity, instances);
+ for (uint32_t i = 0; i < instances.next; ++i) {
+ if (comp.uuid == instances[i]->uuid) {
+ map.created_instance = instances[i];
+ }
+ }
+ if (map.created_instance == nullptr) {
+ fprintf(stderr, "[pke_deserialize_instance] Failed to find created instance for creating mapping");
+ } else {
+ pk_arr_append(&h->mapping, &map);
+ }
}
return true;
}
- if (strstr(h->read_line, SRLZTN_INSTANCE_COMPONENT_ENTITY_HANDLE)) {
- prefix_len = strlen(SRLZTN_INSTANCE_COMPONENT_ENTITY_HANDLE);
- sprintf(handle_str, "%.10s%c%s", h->read_line + prefix_len, '\0', h->read_line + prefix_len + 10);
- stn_res = pk_stn(&comp.entHandle.bucketIndex, handle_str, nullptr, 16);
- if (stn_res != PK_STN_RES_SUCCESS) return false;
- stn_res = pk_stn(&comp.entHandle.itemIndex, handle_str + 11, nullptr, 16);
- if (stn_res != PK_STN_RES_SUCCESS) return false;
- continue;
- }
- if (strstr(h->read_line, SRLZTN_INSTANCE_COMPONENT_HANDLE)) {
- prefix_len = strlen(SRLZTN_INSTANCE_COMPONENT_HANDLE);
- sprintf(handle_str, "%.10s%c%s", h->read_line + prefix_len, '\0', h->read_line + prefix_len + 10);
- stn_res = pk_stn(&comp.instanceHandle.bucketIndex, handle_str, nullptr, 16);
- if (stn_res != PK_STN_RES_SUCCESS) return false;
- stn_res = pk_stn(&comp.instanceHandle.itemIndex, handle_str + 11, nullptr, 16);
- if (stn_res != PK_STN_RES_SUCCESS) return false;
- continue;
- }
if (strstr(h->read_line, SRLZTN_INSTANCE_COMPONENT_UUID)) {
prefix_len = strlen(SRLZTN_INSTANCE_COMPONENT_UUID);
(h->read_line + prefix_len) >> comp.uuid ;