Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
add missing todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Mar 1, 2024
1 parent 24aa449 commit ec78b59
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/bodies/box2d_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ void Box2DBody2D::_init_collider(box2d::FixtureHandle collider_handle) const {
if (mode >= PhysicsServer2D::BODY_MODE_KINEMATIC) {
// Only send contacts if contact monitor is enabled
bool send_contacts = can_report_contacts();
// TODO set contacts callback only if needed
//box2d::collider_set_contact_force_events_enabled(space_handle, collider_handle, send_contacts);
box2d::collider_set_contact_force_events_enabled(collider_handle, send_contacts);
}
}

Expand Down
33 changes: 0 additions & 33 deletions src/bodies/box2d_collision_object_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ void Box2DCollisionObject2D::add_shape(Box2DShape2D *p_shape, const Transform2D
shapes.push_back(shape);
p_shape->add_owner(this);

//if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
//}

if (space) {
_shapes_changed();
}
Expand All @@ -45,10 +41,6 @@ void Box2DCollisionObject2D::set_shape(int p_index, Box2DShape2D *p_shape) {
_update_shape_transform(shape);
}

//if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
//}

if (space) {
_shapes_changed();
}
Expand All @@ -62,10 +54,6 @@ void Box2DCollisionObject2D::set_shape_transform(int p_index, const Transform2D

_update_shape_transform(shape);

//if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
//}

if (space) {
_shapes_changed();
}
Expand All @@ -88,22 +76,6 @@ void Box2DCollisionObject2D::set_shape_disabled(int p_index, bool p_disabled) {
_update_shape_transform(shape);
}

// if (p_disabled && shape.bpid != 0) {
// space->get_broadphase()->remove(shape.bpid);
// shape.bpid = 0;
// if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
// }
// } else if (!p_disabled && shape.bpid == 0) {
// if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
// }
// }

//if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
//}

if (space) {
_shapes_changed();
}
Expand Down Expand Up @@ -132,10 +104,6 @@ void Box2DCollisionObject2D::remove_shape(int p_index) {
shape.shape->remove_owner(this);
shapes.remove_at(p_index);

//if (!pending_shape_update_list.in_list()) {
// Box2DPhysicsServer2D::singleton->pending_shape_update_list.add(&pending_shape_update_list);
//}

if (space) {
_shapes_changed();
}
Expand Down Expand Up @@ -350,6 +318,5 @@ void Box2DCollisionObject2D::_shape_changed(Box2DShape2D *p_shape) {
}

Box2DCollisionObject2D::Box2DCollisionObject2D(Type p_type) {
//: pending_shape_update_list(this) {
type = p_type;
}
6 changes: 6 additions & 0 deletions src/box2d-wrapper/box2d_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ FixtureHandle box2d::collider_create_solid(b2WorldId world_handle,
return fixture_handle;
}

void box2d::collider_set_contact_force_events_enabled(FixtureHandle collider_handle, bool send_contacts) {
for (int i = 0; i < collider_handle.handles.size(); i++) {
b2ShapeId shape_id = collider_handle.handles[i];
}
}

void box2d::collider_destroy(b2WorldId world_handle, FixtureHandle handle) {
for (b2ShapeId shapeId : handle.handles) {
b2DestroyShape(shapeId);
Expand Down
6 changes: 4 additions & 2 deletions src/box2d-wrapper/box2d_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct ShapeInfo {
struct QueryExcludedInfo {
uint32_t query_collision_layer_mask;
uint64_t query_canvas_instance_id;
//b2ShapeId *query_exclude;
b2ShapeId *query_exclude;
uint32_t query_exclude_size;
int64_t query_exclude_body;
};
Expand Down Expand Up @@ -127,7 +127,7 @@ struct ShapeCastResult {
b2Vec2 witness2;
b2Vec2 normal1;
b2Vec2 normal2;
//b2ShapeId collider;
b2ShapeId collider;
b2FixtureUserData user_data;
};

Expand Down Expand Up @@ -461,6 +461,8 @@ void world_set_active_body_callback(b2WorldId world_handle, ActiveBodyCallback c
void world_set_collision_filter_callback(b2WorldId world_handle,
b2ContactFilter *callback);

void collider_set_contact_force_events_enabled(FixtureHandle collider_handle, bool send_contacts);

void world_step(b2WorldId world_handle, const SimulationSettings settings);

} // namespace box2d
Expand Down
3 changes: 0 additions & 3 deletions src/servers/box2d_physics_server_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ RID Box2DPhysicsServer2D::_shape_create(ShapeType p_shape) {
case SHAPE_CONCAVE_POLYGON: {
shape = memnew(Box2DConcavePolygonShape2D);
} break;
case SHAPE_CUSTOM: {
ERR_FAIL_V_MSG(RID(), "Unsupported shape");
} break;
default:
ERR_FAIL_V_MSG(RID(), "Unsupported shape");
}
Expand Down
12 changes: 6 additions & 6 deletions src/spaces/box2d_direct_space_state_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool Box2DDirectSpaceState2D::_collide_shape(const RID &shape_rid, const Transfo
box2d::ShapeInfo shape_info = box2d::shape_info_from_body_shape(shape_handle, Transform2D(), transform);
box2d::QueryExcludedInfo query_excluded_info = box2d::default_query_excluded_info();
query_excluded_info.query_collision_layer_mask = collision_mask;
//query_excluded_info.query_exclude = (b2ShapeId *)memalloc((max_results) * sizeof(b2ShapeId));
query_excluded_info.query_exclude = (b2ShapeId *)memalloc((max_results) * sizeof(b2ShapeId));
query_excluded_info.query_exclude_size = 0;

int cpt = 0;
Expand All @@ -141,15 +141,15 @@ bool Box2DDirectSpaceState2D::_collide_shape(const RID &shape_rid, const Transfo
break;
}
(*result_count)++;
//query_excluded_info.query_exclude[query_excluded_info.query_exclude_size++] = result.collider;
query_excluded_info.query_exclude[query_excluded_info.query_exclude_size++] = result.collider;
if (results_out != nullptr) {
results_out[array_idx++] = Vector2(result.witness1.x, result.witness1.y);
results_out[array_idx++] = Vector2(result.witness2.x, result.witness2.y);
}

cpt++;
} while (cpt < max_results);
//memfree(query_excluded_info.query_exclude);
memfree(query_excluded_info.query_exclude);
return array_idx > 0;
}

Expand All @@ -164,7 +164,7 @@ int Box2DDirectSpaceState2D::_intersect_shape(const RID &shape_rid, const Transf

box2d::QueryExcludedInfo query_excluded_info = box2d::default_query_excluded_info();
query_excluded_info.query_collision_layer_mask = collision_mask;
//query_excluded_info.query_exclude = (b2ShapeId *)memalloc((p_result_max) * sizeof(b2ShapeId));
query_excluded_info.query_exclude = (b2ShapeId *)memalloc((p_result_max) * sizeof(b2ShapeId));
query_excluded_info.query_exclude_size = 0;

int cpt = 0;
Expand All @@ -173,7 +173,7 @@ int Box2DDirectSpaceState2D::_intersect_shape(const RID &shape_rid, const Transf
if (!result.collided) {
break;
}
//query_excluded_info.query_exclude[query_excluded_info.query_exclude_size++] = result.collider;
query_excluded_info.query_exclude[query_excluded_info.query_exclude_size++] = result.collider;

ERR_CONTINUE_MSG(!box2d::is_user_data_valid(result.user_data), "Invalid user data");
uint32_t shape_index = 0;
Expand All @@ -194,7 +194,7 @@ int Box2DDirectSpaceState2D::_intersect_shape(const RID &shape_rid, const Transf

} while (cpt < p_result_max);

//memfree(query_excluded_info.query_exclude);
memfree(query_excluded_info.query_exclude);
return cpt;
}

Expand Down
2 changes: 2 additions & 0 deletions src/spaces/box2d_space_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ bool Box2DSpace2D::ShouldCollide(b2ShapeId fixtureA, b2ShapeId fixtureB, b2Manif

return true;
}
// TODO
/*
box2d::CollisionEventInfo event_info_from_contact(b2Contact *contact) {
box2d::CollisionEventInfo event_info;
Expand Down Expand Up @@ -550,6 +551,7 @@ void Box2DSpace2D::step(real_t p_step) {
active_objects = box2d::world_get_active_objects_count(handle);
}

// TODO
// Returns true to ignore the collider
bool Box2DSpace2D::_is_handle_excluded_callback(b2WorldId world_handle, b2ShapeId collider_handle, b2FixtureUserData user_data, const box2d::QueryExcludedInfo *handle_excluded_info) {
/*
Expand Down

0 comments on commit ec78b59

Please sign in to comment.