| 87 | } |
| 88 | |
| 89 | void skr_load_scene(sugoi_storage_t* world, skr_json_reader_t* reader) |
| 90 | { |
| 91 | skr::json::value_t value = std::move(*(skr::json::value_t*)reader); |
| 92 | auto root = value.get_object(); |
| 93 | #define ERR(var) var.error() != simdjson::error_code::SUCCESS |
| 94 | if (ERR(root)) |
| 95 | return; |
| 96 | for (auto field : root.value_unsafe()) |
| 97 | { |
| 98 | auto key = field.unescaped_key(); |
| 99 | if(ERR(key)) |
| 100 | continue; |
| 101 | skr_guid_t guid; |
| 102 | auto keyStr = key.value_unsafe(); |
| 103 | if(!skr::guid::make_guid(skr::StringView((const char8_t*)keyStr.data(), (int32_t)keyStr.length()), guid)) |
| 104 | continue; |
| 105 | auto entity = field.value().get_object(); |
| 106 | if(entity.error() != simdjson::error_code::SUCCESS) |
| 107 | continue; |
| 108 | sugoi::type_builder_t entityType; |
| 109 | entityType.with(SUGOI_COMPONENT_GUID); |
| 110 | for (auto component : entity.value_unsafe()) |
| 111 | { |
| 112 | auto key = component.unescaped_key(); |
| 113 | if(ERR(key)) |
| 114 | continue; |
| 115 | auto keyStr = key.value_unsafe(); |
| 116 | auto typeId = sugoiT_get_type_by_name((const char8_t*)keyStr.data()); |
| 117 | if(typeId == sugoi::kInvalidTypeIndex) |
| 118 | continue; |
| 119 | auto desc = sugoiT_get_desc(typeId); |
| 120 | if(!desc->callback.deserialize_text || !desc->callback.serialize_text) |
| 121 | continue; |
| 122 | entityType.with(typeId); |
| 123 | } |
| 124 | sugoi_entity_type_t type = make_zeroed<sugoi_entity_type_t>(); |
| 125 | type.type = entityType.build(); |
| 126 | auto setup = [&, entity](sugoi_chunk_view_t* view) mutable |
| 127 | { |
| 128 | auto cguids = (skr_guid_t*)sugoiV_get_owned_rw(view, SUGOI_COMPONENT_GUID); |
| 129 | cguids[0] = guid; |
| 130 | for(auto component : entity.value_unsafe()) |
| 131 | { |
| 132 | auto componentValue = component.value(); |
| 133 | if(ERR(componentValue)) |
| 134 | continue; |
| 135 | auto type = sugoiT_get_type_by_name((const char8_t*)component.unescaped_key().value_unsafe().data()); |
| 136 | auto desc = sugoiT_get_desc(type); |
| 137 | auto serde = desc->callback.deserialize_text; |
| 138 | if(!serde) |
| 139 | continue; |
| 140 | auto data = sugoiV_get_owned_ro(view, type); |
| 141 | serde(view->chunk, view->start, (char*)data, 1, &componentValue); |
| 142 | } |
| 143 | }; |
| 144 | sugoiS_allocate_type(world, &type, 1, SUGOI_LAMBDA(setup)); |
| 145 | } |
| 146 | } |
nothing calls this directly
no test coverage detected