bool Entity::collides_with(Entity* other) { if (!can_collide || !other->can_collide) { return false; } int my_collision_level = get_collision_level(); int other_collision_level = other->get_collision_level(); bounding_box rwc_bounds; transform_into_world_coordinates(&rwc_bounds.lower, bounds.lower.x, bounds.lower.y, bounds.lower.z); transform_into_world_coordinates(&rwc_bounds.upper, bounds.upper.x, bounds.upper.y, bounds.upper.z); rwc_bounds.refit_for_rotation(); bounding_box other_rwc_bounds; other->transform_into_world_coordinates(&other_rwc_bounds.lower, other->bounds.lower.x, other->bounds.lower.y, other->bounds.lower.z); other->transform_into_world_coordinates(&other_rwc_bounds.upper, other->bounds.upper.x, other->bounds.upper.y, other->bounds.upper.z); other_rwc_bounds.refit_for_rotation(); if (!rwc_bounds.hits(other_rwc_bounds)) { // my big fat bounds doesn't even hit the other bounds return false; } if (my_collision_level >= other_collision_level) { return collides_with(other, &rwc_bounds, &other_rwc_bounds, my_collision_level, other_collision_level); } else { return other->collides_with(this, &other_rwc_bounds, &rwc_bounds, other_collision_level, my_collision_level); } }
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); } }