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

Function write_data_dependencies

src/resource/data_compiler.cpp:553–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

551}
552
553static s32 write_data_dependencies(FilesystemDisk &data_fs, const char *filename, const HashMap<StringId64, DynamicString> &index, const HashMap<StringId64, HashMap<DynamicString, u32>> &dependencies, const HashMap<StringId64, HashMap<DynamicString, u32>> &requirements)
554{
555 StringStream ss(default_allocator());
556 DynamicString temp_filename(default_allocator());
557
558 File *file = data_fs.open_temporary(temp_filename);
559 if (file->is_open()) {
560 auto cur = hash_map::begin(index);
561 auto end = hash_map::end(index);
562 for (; cur != end; ++cur) {
563 HASH_MAP_SKIP_HOLE(index, cur);
564
565 HashMap<DynamicString, u32> deps_deffault(default_allocator());
566 const HashMap<DynamicString, u32> &deps = hash_map::get(dependencies, cur->first, deps_deffault);
567 HashMap<DynamicString, u32> reqs_deffault(default_allocator());
568 const HashMap<DynamicString, u32> &reqs = hash_map::get(requirements, cur->first, reqs_deffault);
569
570 // Skip if data has no dependencies
571 if (hash_map::size(deps) == 0 && hash_map::size(reqs) == 0)
572 continue;
573
574 TempAllocator64 ta;
575 DynamicString key(ta);
576 key.from_string_id(cur->first);
577 ss << "\"" << key.c_str() << "\" = [\n";
578
579 // Write all dependencies
580 auto deps_cur = hash_map::begin(deps);
581 auto deps_end = hash_map::end(deps);
582 for (; deps_cur != deps_end; ++deps_cur) {
583 HASH_MAP_SKIP_HOLE(deps, deps_cur);
584
585 if (deps_cur->second & DependencyFlags::OPTIONAL)
586 ss << " \"//? " << ((deps_cur->second & DependencyFlags::EXISTS) ? '1' : '0') << " " << deps_cur->first.c_str() << "\"\n";
587 else
588 ss << " \"//- " << deps_cur->first.c_str() << "\"\n";
589 }
590
591 // Write all requirements
592 auto reqs_cur = hash_map::begin(reqs);
593 auto reqs_end = hash_map::end(reqs);
594 for (; reqs_cur != reqs_end; ++reqs_cur) {
595 HASH_MAP_SKIP_HOLE(reqs, reqs_cur);
596
597 ss << " \"//r " << reqs_cur->first.c_str() << "\"\n";
598 }
599
600 ss << "]\n";
601 }
602
603 u32 ss_len = strlen32(string_stream::c_str(ss));
604 if (ss_len != file->write(string_stream::c_str(ss), ss_len)) {
605 data_fs.close(*file);
606 return -1;
607 }
608 }
609 data_fs.close(*file);
610

Callers 1

compile_internalMethod · 0.85

Calls 11

getFunction · 0.85
open_temporaryMethod · 0.80
from_string_idMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
sizeFunction · 0.50
is_openMethod · 0.45
c_strMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected