| 854 | }; |
| 855 | |
| 856 | s32 compile(CompileOptions &opts) |
| 857 | { |
| 858 | Buffer buf = opts.read(); |
| 859 | TempAllocator4096 ta; |
| 860 | JsonObject obj(ta); |
| 861 | RETURN_IF_ERROR(sjson::parse(obj, buf)); |
| 862 | |
| 863 | Array<PhysicsMaterial> materials(default_allocator()); |
| 864 | Array<PhysicsActor> actors(default_allocator()); |
| 865 | CollisionFilterCompiler cfc(opts); |
| 866 | PhysicsConfigResource pcr; |
| 867 | |
| 868 | // Parse materials |
| 869 | s32 err = 0; |
| 870 | if (json_object::has(obj, "collision_filters")) { |
| 871 | err = cfc.parse(obj["collision_filters"]); |
| 872 | ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts); |
| 873 | } |
| 874 | if (json_object::has(obj, "materials")) { |
| 875 | err = parse_materials(obj["materials"], materials, opts); |
| 876 | ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts); |
| 877 | } |
| 878 | if (json_object::has(obj, "actors")) { |
| 879 | err = parse_actors(obj["actors"], actors, opts); |
| 880 | ENSURE_OR_RETURN(PHYSICS_RESOURCE, err == 0, opts); |
| 881 | } |
| 882 | if (json_object::has(obj, "gravity")) { |
| 883 | pcr.gravity = RETURN_IF_ERROR(sjson::parse_vector3(obj["gravity"])); |
| 884 | } else { |
| 885 | pcr.gravity = { 0.0f, 0.0f, -10.0f }; |
| 886 | } |
| 887 | |
| 888 | // Setup struct for writing |
| 889 | pcr.version = RESOURCE_HEADER(RESOURCE_VERSION_PHYSICS_CONFIG); |
| 890 | pcr.num_materials = array::size(materials); |
| 891 | pcr.num_actors = array::size(actors); |
| 892 | pcr.num_filters = array::size(cfc._filters); |
| 893 | |
| 894 | u32 offt = sizeof(PhysicsConfigResource); |
| 895 | pcr.materials_offset = offt; |
| 896 | offt += sizeof(PhysicsMaterial) * pcr.num_materials; |
| 897 | |
| 898 | pcr.actors_offset = offt; |
| 899 | offt += sizeof(PhysicsActor) * pcr.num_actors; |
| 900 | |
| 901 | pcr.filters_offset = offt; |
| 902 | |
| 903 | // Write all |
| 904 | opts.write(pcr.version); |
| 905 | opts.write(pcr.num_materials); |
| 906 | opts.write(pcr.materials_offset); |
| 907 | opts.write(pcr.num_actors); |
| 908 | opts.write(pcr.actors_offset); |
| 909 | opts.write(pcr.num_filters); |
| 910 | opts.write(pcr.filters_offset); |
| 911 | opts.write(pcr.gravity); |
| 912 | |
| 913 | // Write materials |
nothing calls this directly
no test coverage detected