MCPcopy Create free account
hub / github.com/crownengine/crown / read_data_dependencies

Function read_data_dependencies

src/resource/data_compiler.cpp:405–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

403}
404
405static void read_data_dependencies(DataCompiler &dc
406 , FilesystemDisk &data_fs
407 , const HashMap<StringId64, DynamicString> &data_index
408 , const char *filename
409 )
410{
411 Buffer json(default_allocator());
412 File *file = data_fs.open(filename, FileOpenMode::READ);
413 if (file->is_open())
414 file->read_all(json);
415 data_fs.close(*file);
416
417 TempAllocator1024 ta;
418 JsonObject obj(ta);
419 sjson::parse(obj, json);
420
421 auto cur = json_object::begin(obj);
422 auto end = json_object::end(obj);
423 for (; cur != end; ++cur) {
424 JSON_OBJECT_SKIP_HOLE(obj, cur);
425
426 StringId64 id;
427 id.parse(cur->first.data());
428
429 // Skip reading data that belongs to non-existent source file.
430 if (!hash_map::has(data_index, id))
431 continue;
432
433 JsonArray dependency_array(ta);
434 sjson::parse_array(dependency_array, cur->second);
435 for (u32 i = 0; i < array::size(dependency_array); ++i) {
436 DynamicString path(ta);
437 sjson::parse_string(path, dependency_array[i]);
438 if (path.has_prefix("//r ")) {
439 add_dependency_internal(dc._data_requirements, id, path.c_str() + 4);
440 } else if (path.has_prefix("//- ")) {
441 add_dependency_internal(dc._data_dependencies, id, path.c_str() + 4);
442 } else if (path.has_prefix("//? ")) {
443 const char *dependency = path.c_str() + 4;
444 u32 flags = DependencyFlags::OPTIONAL;
445 if ((dependency[0] == '0' || dependency[0] == '1') && dependency[1] == ' ') {
446 if (dependency[0] == '1')
447 flags |= DependencyFlags::EXISTS;
448 dependency += 2;
449 }
450 add_dependency_internal(dc._data_dependencies, id, dependency, flags);
451 } else { // Assume regular dependency
452 add_dependency_internal(dc._data_dependencies, id, path.c_str());
453 }
454 }
455 }
456}
457
458static s32 write_data_index(FilesystemDisk &data_fs, const char *filename, const HashMap<StringId64, DynamicString> &index)
459{

Callers 1

scan_and_restoreMethod · 0.85

Calls 15

add_dependency_internalFunction · 0.85
read_allMethod · 0.80
parseFunction · 0.70
beginFunction · 0.50
endFunction · 0.50
hasFunction · 0.50
parse_arrayFunction · 0.50
sizeFunction · 0.50
parse_stringFunction · 0.50
openMethod · 0.45
is_openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected