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

Method parse

src/resource/physics_resource.cpp:766–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764 }
765
766 s32 parse(const char *json)
767 {
768 TempAllocator4096 ta;
769 JsonObject obj(ta);
770 RETURN_IF_ERROR(sjson::parse(obj, json));
771
772 // Assign group to filter name.
773 auto cur = json_object::begin(obj);
774 auto end = json_object::end(obj);
775 for (; cur != end; ++cur) {
776 JSON_OBJECT_SKIP_HOLE(obj, cur);
777
778 const StringView key = cur->first;
779 const StringId32 id = StringId32(key.data(), key.length());
780
781 hash_map::set(_filter_map, id, new_filter_mask());
782 }
783
784 // Build masks.
785 cur = json_object::begin(obj);
786 end = json_object::end(obj);
787 for (; cur != end; ++cur) {
788 JSON_OBJECT_SKIP_HOLE(obj, cur);
789
790 const StringView key = cur->first;
791 const char *value = cur->second;
792 const StringId32 id = StringId32(key.data(), key.length());
793
794 TempAllocator4096 ta;
795 JsonObject filter(ta);
796 RETURN_IF_ERROR(sjson::parse_object(filter, value));
797
798 u32 mask = 0;
799
800 if (json_object::has(filter, "collides_with")) {
801 JsonArray include(ta);
802 RETURN_IF_ERROR(sjson::parse_array(include, filter["collides_with"]));
803
804 for (u32 i = 0; i < array::size(include); ++i) {
805 const StringId32 fi = RETURN_IF_ERROR(sjson::parse_string_id(include[i]));
806 mask |= filter_to_mask(fi);
807 }
808 }
809
810 if (json_object::has(filter, "collides_with_all_except")) {
811 mask = UINT32_MAX;
812
813 JsonArray exclude(ta);
814 RETURN_IF_ERROR(sjson::parse_array(exclude, filter["collides_with_all_except"]));
815
816 for (u32 i = 0; i < array::size(exclude); ++i) {
817 const StringId32 fi = RETURN_IF_ERROR(sjson::parse_string_id(exclude[i]));
818 mask &= ~filter_to_mask(fi);
819 }
820 }
821
822 PhysicsCollisionFilter pcf;
823 pcf.name = id;

Callers 1

compileFunction · 0.45

Calls 12

setClass · 0.85
parse_string_idFunction · 0.85
parseFunction · 0.70
beginFunction · 0.50
endFunction · 0.50
StringId32Class · 0.50
parse_objectFunction · 0.50
hasFunction · 0.50
parse_arrayFunction · 0.50
sizeFunction · 0.50
dataMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected