void parse_materials(const char* json, Array<PhysicsConfigMaterial>& objects) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = map::begin(object); auto end = map::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; JsonObject material(ta); sjson::parse_object(value, material); PhysicsConfigMaterial mat; mat.name = StringId32(key.data(), key.length()); mat.static_friction = sjson::parse_float(material["static_friction"]); mat.dynamic_friction = sjson::parse_float(material["dynamic_friction"]); mat.restitution = sjson::parse_float(material["restitution"]); array::push_back(objects, mat); } }
static void parse_textures(const char* json, Array<TextureData>& textures, Array<char>& names, Array<char>& dynamic, CompileOptions& opts) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = json_object::begin(object); auto end = json_object::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; DynamicString texture(ta); sjson::parse_string(value, texture); RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_TEXTURE, texture.c_str(), opts); TextureHandle th; th.sampler_handle = 0; th.texture_handle = 0; const u32 sampler_name_offset = array::size(names); array::push(names, key.data(), key.length()); array::push_back(names, '\0'); TextureData td; td.sampler_name_offset = sampler_name_offset; td.id = sjson::parse_resource_id(value); td.data_offset = reserve_dynamic_data(th, dynamic); array::push_back(textures, td); } }
void parse(const char* json) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = map::begin(object); auto end = map::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const StringId32 id = StringId32(key.data(), key.length()); map::set(_filter_map, id, new_filter_mask()); } begin = map::begin(object); end = map::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; const StringId32 id = StringId32(key.data(), key.length()); TempAllocator4096 ta; JsonObject filter(ta); sjson::parse_object(value, filter); JsonArray collides_with(ta); sjson::parse_array(filter["collides_with"], collides_with); u32 mask = 0; for (u32 i = 0; i < array::size(collides_with); ++i) { const StringId32 fi = sjson::parse_string_id(collides_with[i]); mask |= filter_to_mask(fi); } // Build mask PhysicsCollisionFilter pcf; pcf.name = id; pcf.me = filter_to_mask(id); pcf.mask = mask; array::push_back(_filters, pcf); } }
void parse_actors(const char* json, Array<PhysicsConfigActor>& objects) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = map::begin(object); auto end = map::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; JsonObject actor(ta); sjson::parse_object(value, actor); PhysicsConfigActor pa2; pa2.name = StringId32(key.data(), key.length()); // pa2.linear_damping = sjson::parse_float(actor["linear_damping"]); // 0.0f; // pa2.angular_damping = sjson::parse_float(actor["angular_damping"]); // 0.05f; const bool has_dynamic = map::has(actor, FixedString("dynamic")); const bool has_kinematic = map::has(actor, FixedString("kinematic")); const bool has_disable_gravity = map::has(actor, FixedString("disable_gravity")); pa2.flags = 0; if (has_dynamic) { pa2.flags |= (sjson::parse_bool(actor["dynamic"]) ? 1 : 0 ); } if (has_kinematic) { pa2.flags |= (sjson::parse_bool(actor["kinematic"]) ? PhysicsConfigActor::KINEMATIC : 0 ); } if (has_disable_gravity) { pa2.flags |= (sjson::parse_bool(actor["disable_gravity"]) ? PhysicsConfigActor::DISABLE_GRAVITY : 0 ); } array::push_back(objects, pa2); } }
void parse_shapes(const char* json, Array<PhysicsConfigShape>& objects) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = map::begin(object); auto end = map::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; JsonObject shape(ta); sjson::parse_object(value, shape); PhysicsConfigShape ps2; ps2.name = StringId32(key.data(), key.length()); ps2.trigger = sjson::parse_bool(shape["trigger"]); array::push_back(objects, ps2); } }
static void parse_uniforms(const char* json, Array<UniformData>& uniforms, Array<char>& names, Array<char>& dynamic, CompileOptions& opts) { TempAllocator4096 ta; JsonObject object(ta); sjson::parse(json, object); auto begin = json_object::begin(object); auto end = json_object::end(object); for (; begin != end; ++begin) { const FixedString key = begin->pair.first; const char* value = begin->pair.second; UniformHandle uh; uh.uniform_handle = 0; JsonObject uniform(ta); sjson::parse_object(value, uniform); DynamicString type(ta); sjson::parse_string(uniform["type"], type); const UniformType::Enum ut = name_to_uniform_type(type.c_str()); RESOURCE_COMPILER_ASSERT(ut != UniformType::COUNT , opts , "Unknown uniform type: '%s'" , type.c_str() ); const u32 name_offset = array::size(names); array::push(names, key.data(), key.length()); array::push_back(names, '\0'); UniformData ud; ud.type = ut; ud.name = StringId32(key.data(), key.length()); ud.name_offset = name_offset; ud.data_offset = reserve_dynamic_data(uh, dynamic); switch (ud.type) { case UniformType::FLOAT: reserve_dynamic_data(sjson::parse_float(uniform["value"]), dynamic); break; case UniformType::VECTOR2: reserve_dynamic_data(sjson::parse_vector2(uniform["value"]), dynamic); break; case UniformType::VECTOR3: reserve_dynamic_data(sjson::parse_vector3(uniform["value"]), dynamic); break; case UniformType::VECTOR4: reserve_dynamic_data(sjson::parse_vector4(uniform["value"]), dynamic); break; default: CE_FATAL("Unknown uniform type"); break; } array::push_back(uniforms, ud); } }