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 compile(const char* path, CompileOptions& opts) { Buffer buf = opts.read(path); TempAllocator1024 ta; JsonObject boot(ta); sjson::parse(buf, boot); const char* boot_script_json = map::get(boot, FixedString("boot_script"), (const char*)NULL); const char* boot_package_json = map::get(boot, FixedString("boot_package"), (const char*)NULL); RESOURCE_COMPILER_ASSERT(boot_script_json != NULL, opts, "'boot_script' must be specified."); RESOURCE_COMPILER_ASSERT(boot_package_json != NULL, opts, "'boot_package' must be specified."); DynamicString boot_script(ta); DynamicString boot_package(ta); sjson::parse_string(boot_script_json, boot_script); sjson::parse_string(boot_package_json, boot_package); RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_SCRIPT, boot_script.c_str(), opts); RESOURCE_COMPILER_ASSERT_RESOURCE_EXISTS(RESOURCE_EXTENSION_PACKAGE, boot_package.c_str(), opts); opts.write(buf); }
Buffer compile_actor(const char* json, CompileOptions& opts) { TempAllocator4096 ta; JsonObject obj(ta); sjson::parse(json, obj); ActorResource ar; ar.actor_class = sjson::parse_string_id(obj["class"]); ar.mass = sjson::parse_float (obj["mass"]); ar.collision_filter = sjson::parse_string_id(obj["collision_filter"]); ar.flags = 0; ar.flags |= map::has(obj, FixedString("lock_translation_x")) ? sjson::parse_bool(obj["lock_translation_x"]) : 0; ar.flags |= map::has(obj, FixedString("lock_translation_y")) ? sjson::parse_bool(obj["lock_translation_y"]) : 0; ar.flags |= map::has(obj, FixedString("lock_translation_z")) ? sjson::parse_bool(obj["lock_translation_z"]) : 0; ar.flags |= map::has(obj, FixedString("lock_rotation_x")) ? sjson::parse_bool(obj["lock_rotation_x"]) : 0; ar.flags |= map::has(obj, FixedString("lock_rotation_y")) ? sjson::parse_bool(obj["lock_rotation_y"]) : 0; ar.flags |= map::has(obj, FixedString("lock_rotation_z")) ? sjson::parse_bool(obj["lock_rotation_z"]) : 0; Buffer buf(default_allocator()); array::push(buf, (char*)&ar, sizeof(ar)); return buf; }
void compile(const char* path, CompileOptions& opts) { Buffer buf = opts.read(path); TempAllocator4096 ta; JsonObject object(ta); sjson::parse(buf, object); Array<PhysicsConfigMaterial> materials(default_allocator()); Array<PhysicsConfigShape> shapes(default_allocator()); Array<PhysicsConfigActor> actors(default_allocator()); CollisionFilterCompiler cfc(opts); // Parse materials if (map::has(object, FixedString("collision_filters"))) cfc.parse(object["collision_filters"]); if (map::has(object, FixedString("materials"))) parse_materials(object["materials"], materials); if (map::has(object, FixedString("shapes"))) parse_shapes(object["shapes"], shapes); if (map::has(object, FixedString("actors"))) parse_actors(object["actors"], actors); // Setup struct for writing PhysicsConfigResource pcr; pcr.version = RESOURCE_VERSION_PHYSICS_CONFIG; pcr.num_materials = array::size(materials); pcr.num_shapes = array::size(shapes); pcr.num_actors = array::size(actors); pcr.num_filters = array::size(cfc._filters); u32 offt = sizeof(PhysicsConfigResource); pcr.materials_offset = offt; offt += sizeof(PhysicsConfigMaterial) * pcr.num_materials; pcr.shapes_offset = offt; offt += sizeof(PhysicsConfigShape) * pcr.num_shapes; pcr.actors_offset = offt; offt += sizeof(PhysicsConfigActor) * pcr.num_actors; pcr.filters_offset = offt; offt += sizeof(PhysicsCollisionFilter) * pcr.num_filters; // Write all opts.write(pcr.version); opts.write(pcr.num_materials); opts.write(pcr.materials_offset); opts.write(pcr.num_shapes); opts.write(pcr.shapes_offset); opts.write(pcr.num_actors); opts.write(pcr.actors_offset); opts.write(pcr.num_filters); opts.write(pcr.filters_offset); // Write material objects for (u32 i = 0; i < pcr.num_materials; ++i) { opts.write(materials[i].name._id); opts.write(materials[i].static_friction); opts.write(materials[i].dynamic_friction); opts.write(materials[i].restitution); } // Write material objects for (u32 i = 0; i < pcr.num_shapes; ++i) { opts.write(shapes[i].name._id); opts.write(shapes[i].trigger); opts.write(shapes[i]._pad[0]); opts.write(shapes[i]._pad[1]); opts.write(shapes[i]._pad[2]); } // Write actor objects for (u32 i = 0; i < pcr.num_actors; ++i) { opts.write(actors[i].name._id); opts.write(actors[i].linear_damping); opts.write(actors[i].angular_damping); opts.write(actors[i].flags); } for (u32 i = 0; i < array::size(cfc._filters); ++i) { opts.write(cfc._filters[i].name._id); opts.write(cfc._filters[i].me); opts.write(cfc._filters[i].mask); } }
he::FixedString FixedString::fromHandle(const char* const handle) { HE_ASSERT(GlobalStringTable::getInstance()->contains(handle), "Constructing fixedstring from handle but it is not in the fixedstring table! (%s)", handle); return FixedString(handle); }