Skip to content

Commit

Permalink
Fix rapier math name clash. Fix shape disable not updating. (#270)
Browse files Browse the repository at this point in the history
- Partially fixes
#245
- Fix #271
  • Loading branch information
Ughuuu authored Oct 7, 2024
1 parent 1cb89e7 commit 49eed98
Show file tree
Hide file tree
Showing 181 changed files with 6,818 additions and 771 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/godot_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Update plugin.cfg
- name: Update plugin.info.cfg
shell: sh
run: |
sed -i "s/<flavour>/godot-rapier-2d-${{ matrix.precision }}-${{ matrix.features }}/g" bin2d/addons/godot-rapier2d/plugin.cfg
sed -i "s/<flavour>/godot-rapier-3d-${{ matrix.precision }}-${{ matrix.features }}/g" bin3d/addons/godot-rapier3d/plugin.cfg
sed -i "s/<flavour>/godot-rapier-2d-${{ matrix.precision }}-${{ matrix.features }}/g" bin2d/addons/godot-rapier2d/plugin.info.cfg
sed -i "s/<flavour>/godot-rapier-3d-${{ matrix.precision }}-${{ matrix.features }}/g" bin3d/addons/godot-rapier3d/plugin.info.cfg
- name: Upload
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## v0.8.6

## v0.8.5

- Remove some references to RID internally and use uid instead. Also fix Area issue. by @Ughuuu in #243
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
name="Godot Rapier 2D"
description="A 2D and 3D drop-in replacement for the Godot engine that adds stability and fluids."
author="appsinacup"
version="0.8.5"
version="0.8.6"
flavour="<flavour>"
script=""
26 changes: 10 additions & 16 deletions bin2d/addons/godot-rapier2d/rapier_state_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,16 @@ func save_state(save_json: bool = false) -> int:
for owner_id in node.get_shape_owners():
for owner_shape_id in node.shape_owner_get_shape_count(owner_id):
var shape_rid = node.shape_owner_get_shape(owner_id, owner_shape_id).get_rid()
state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)] = {
"state" : save_node(shape_rid, save_json),
"id": RapierPhysicsServer2D.get_rapier_id(shape_rid)
}
state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)] = save_node(shape_rid, save_json)
if node is Joint2D:
rid = node.get_rid()
state[node_path] = {
"state" : save_node(rid, save_json),
"id": RapierPhysicsServer2D.get_rapier_id(rid)
}
state[node_path] = save_node(rid, save_json)
var space_rid = get_viewport().world_2d.space
state["space"] = {
"state" : save_node(space_rid, save_json),
"id": RapierPhysicsServer2D.get_rapier_id(space_rid)
}
state["space"] = save_node(space_rid, save_json)
state["id"] = RapierPhysicsServer2D.get_global_id()
return hash(state)

func load_state():
func load_state() -> int:
var physics_nodes := get_all_physics_nodes(get_tree().current_scene)
for node_path in physics_nodes:
var node := get_node(node_path)
Expand All @@ -67,10 +59,12 @@ func load_state():
for owner_shape_id in node.shape_owner_get_shape_count(owner_id):
var shape_rid = node.shape_owner_get_shape(owner_id, owner_shape_id).get_rid()
var shape_state = state[node_path + "/" + str(owner_id) + "/" + str(owner_shape_id)]
load_node(shape_rid, JSON.parse_string(shape_state.state))
load_node(shape_rid, JSON.parse_string(shape_state))
if node is Joint2D:
rid = node.get_rid()
var node_state = state[node_path]
load_node(rid, JSON.parse_string(node_state.state))
load_node(rid, JSON.parse_string(node_state))
var space_rid = get_viewport().world_2d.space
load_node(space_rid, JSON.parse_string(state["space"].state))
load_node(space_rid, JSON.parse_string(state["space"]))
RapierPhysicsServer2D.set_global_id(int(state["id"]))
return hash(state)
2 changes: 2 additions & 0 deletions bin2d/start.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ func completed() -> void:
Global.print_summary(duration)

var error_code = 1 if Global.MONITOR_REGRESSION.size() != 0 else 0
await get_tree().create_timer(1.0).timeout
#get_tree().reload_current_scene()
Global.exit(error_code)
3 changes: 2 additions & 1 deletion bin2d/test/integration/scene_change.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ func _ready() -> void:
else:
var state = JSON.parse_string(FileAccess.open("user://save.json", FileAccess.READ).get_as_text())
rapier_state.state = state
rapier_state.load_state()
print(rapier_state.load_state())
print(rapier_state.save_state(false))
print("After")
print(RapierPhysicsServer2D.get_stats())
await get_tree().create_timer(1.0).timeout
Expand Down
16 changes: 7 additions & 9 deletions bin2d/test/unit/test_body.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func test_body_empty():
var body_rid = RID()

var shape_rid = RID()
var transform = Transform2D()
var new_transform = Transform2D()
var force = Vector2(0, 0)
var impulse = Vector2(0, 0)
var callback = Callable()
Expand All @@ -47,7 +47,7 @@ func test_body_empty():
PhysicsServer2D.body_add_constant_central_force(body_rid, force)
PhysicsServer2D.body_add_constant_force(body_rid, force)
PhysicsServer2D.body_add_constant_torque(body_rid, torque)
PhysicsServer2D.body_add_shape(body_rid, shape_rid, transform)
PhysicsServer2D.body_add_shape(body_rid, shape_rid, new_transform)
PhysicsServer2D.body_apply_central_force(body_rid, force)
PhysicsServer2D.body_apply_central_impulse(body_rid, impulse)
PhysicsServer2D.body_apply_force(body_rid, force, impulse)
Expand Down Expand Up @@ -91,8 +91,7 @@ func test_body_empty():
var object_instance_id = PhysicsServer2D.body_get_object_instance_id(body_rid)
assert(object_instance_id == 0)

var param_value = PhysicsServer2D.body_get_param(body_rid, PhysicsServer2D.BodyParameter.BODY_PARAM_ANGULAR_DAMP)
#assert(param_value == null)
PhysicsServer2D.body_get_param(body_rid, PhysicsServer2D.BodyParameter.BODY_PARAM_ANGULAR_DAMP)

shape_rid = PhysicsServer2D.body_get_shape(body_rid, 0)
assert(shape_rid == RID())
Expand Down Expand Up @@ -131,7 +130,7 @@ func test_body_empty():
PhysicsServer2D.body_set_shape(body_rid, 0, shape_rid)
PhysicsServer2D.body_set_shape_as_one_way_collision(body_rid, 0, true, 0.0)
PhysicsServer2D.body_set_shape_disabled(body_rid, 0, true)
PhysicsServer2D.body_set_shape_transform(body_rid, 0, transform)
PhysicsServer2D.body_set_shape_transform(body_rid, 0, new_transform)
PhysicsServer2D.body_set_space(body_rid, space_rid)
PhysicsServer2D.body_set_state(body_rid, PhysicsServer2D.BodyState.BODY_STATE_ANGULAR_VELOCITY, 2.3)

Expand All @@ -143,18 +142,17 @@ func test_body():
var shape_rid = RID()
PhysicsServer2D.body_set_space(body_rid, space_rid)

var transform = Transform2D()
var new_transform = Transform2D()
var force = Vector2(1, 2)
var impulse = Vector2(1, 2)
var callback = Callable()
var excepted_body_rid = RID()
var axis_velocity = Vector2(1, 2)
var torque = 10.0

PhysicsServer2D.body_add_constant_central_force(body_rid, force)
PhysicsServer2D.body_add_constant_force(body_rid, force)
PhysicsServer2D.body_add_constant_torque(body_rid, torque)
PhysicsServer2D.body_add_shape(body_rid, shape_rid, transform)
PhysicsServer2D.body_add_shape(body_rid, shape_rid, new_transform)
PhysicsServer2D.body_apply_central_force(body_rid, force)
PhysicsServer2D.body_apply_central_impulse(body_rid, impulse)
PhysicsServer2D.body_apply_force(body_rid, force, impulse)
Expand Down Expand Up @@ -183,7 +181,7 @@ func test_body():
PhysicsServer2D.body_set_shape(body_rid, 0, shape_rid)
PhysicsServer2D.body_set_shape_as_one_way_collision(body_rid, 0, true, 0.0)
PhysicsServer2D.body_set_shape_disabled(body_rid, 0, true)
PhysicsServer2D.body_set_shape_transform(body_rid, 0, transform)
PhysicsServer2D.body_set_shape_transform(body_rid, 0, new_transform)
PhysicsServer2D.body_set_state(body_rid, PhysicsServer2D.BodyState.BODY_STATE_ANGULAR_VELOCITY, 4.0)

var canvas_instance_id = PhysicsServer2D.body_get_canvas_instance_id(body_rid)
Expand Down
1 change: 1 addition & 0 deletions bin2d/tests/nodes/DirectSpaceState/tests/2d/cast_motion.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func test_start() -> void:
body_query.transform = Transform2D(0, CENTER_RIGHT)
body_query.motion = Vector2(mid_screen_width / 0.016, 0)
var result = d_space.cast_motion(body_query)
print(d_space.get_rest_info(body_query))
p_monitor.add_test_result(!result.is_empty() and is_eq(result, [1,1]))

if true: # limit the scope
Expand Down
Loading

0 comments on commit 49eed98

Please sign in to comment.