-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give each RigidBody its own DirectBodyState wrapper. #42928
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -968,19 +968,10 @@ int PhysicsServer2DSW::body_test_ray_separation(RID p_body, const Transform2D &p | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
PhysicsDirectBodyState2D *PhysicsServer2DSW::body_get_direct_state(RID p_body) { | ||||||||||||||||||
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); | ||||||||||||||||||
|
||||||||||||||||||
if (!body_owner.owns(p_body)) { | ||||||||||||||||||
return nullptr; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
Body2DSW *body = body_owner.getornull(p_body); | ||||||||||||||||||
ERR_FAIL_COND_V(!body, nullptr); | ||||||||||||||||||
ERR_FAIL_COND_V(!body->get_space(), nullptr); | ||||||||||||||||||
ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); | ||||||||||||||||||
|
||||||||||||||||||
direct_state->body = body; | ||||||||||||||||||
return direct_state; | ||||||||||||||||||
ERR_FAIL_COND_V_MSG(!body, nullptr, "Body with RID " + itos(p_body.get_id()) + " not owned by this server."); | ||||||||||||||||||
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || (body->get_space() && body->get_space()->is_locked()), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification."); | ||||||||||||||||||
return body->get_direct_state(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/* JOINT API */ | ||||||||||||||||||
|
@@ -1240,10 +1231,8 @@ void PhysicsServer2DSW::set_active(bool p_active) { | |||||||||||||||||
|
||||||||||||||||||
void PhysicsServer2DSW::init() { | ||||||||||||||||||
doing_sync = false; | ||||||||||||||||||
last_step = 0.001; | ||||||||||||||||||
iterations = 8; // 8? | ||||||||||||||||||
stepper = memnew(Step2DSW); | ||||||||||||||||||
direct_state = memnew(PhysicsDirectBodyState2DSW); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel it may be a better idea to create this on demand (when requested, if null, create and return) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used to sync the server state with the Godot scene every iteration; so I think there is little point in delaying its creation: godot/servers/physics_2d/body_2d_sw.cpp Lines 586 to 592 in a5fa919
BTW This PR simplifies this to simply use it's own copy: ![]() Note: godot/scene/2d/physics_body_2d.cpp Line 863 in a5fa919
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
void PhysicsServer2DSW::step(real_t p_step) { | ||||||||||||||||||
|
@@ -1253,8 +1242,6 @@ void PhysicsServer2DSW::step(real_t p_step) { | |||||||||||||||||
|
||||||||||||||||||
_update_shapes(); | ||||||||||||||||||
|
||||||||||||||||||
last_step = p_step; | ||||||||||||||||||
PhysicsDirectBodyState2DSW::singleton->step = p_step; | ||||||||||||||||||
island_count = 0; | ||||||||||||||||||
active_objects = 0; | ||||||||||||||||||
collision_pairs = 0; | ||||||||||||||||||
|
@@ -1326,7 +1313,6 @@ void PhysicsServer2DSW::end_sync() { | |||||||||||||||||
|
||||||||||||||||||
void PhysicsServer2DSW::finish() { | ||||||||||||||||||
memdelete(stepper); | ||||||||||||||||||
memdelete(direct_state); | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
void PhysicsServer2DSW::_update_shapes() { | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think this handles multi-threaded nicely. i.e. if someone uses this incorrectly they will know.