Manual physics iteration extended#116510
Draft
ashtonmeuser wants to merge 8 commits intogodotengine:masterfrom
Draft
Manual physics iteration extended#116510ashtonmeuser wants to merge 8 commits intogodotengine:masterfrom
ashtonmeuser wants to merge 8 commits intogodotengine:masterfrom
Conversation
Added setting to disable default physics stepping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #116230.
After some playing around, I found that further exposure of the underlying main loop physics iteration is required to practically use
Engine.physics_iterationin a re-simulation context.This is a heavier-handed approach to manual physics stepping with a few more knobs to tweak. Specifically, this adds the following arguments:
increment_frames: BoolDefaults to
trueto retain current behaviour. Whentrue,Engine::_physics_framesis incremented during this physics iteration. This value is reflected inEngine.get_physics_frames(). Passingfalsedoes not increment_physics_frames. This argument is useful when re-simulating multiple physics frames during a single "game physics iteration" e.g. during rollback and re-simulation. If_physics_framesis incremented during each frame, input events will appear old despite being received during the current "game physics iteration", thus resulting in e.g.Input.is_action_just_pressedbeing unexpectedly false.flush_queries_order: Engine.FlushQueriesOrderDefaults to
Engine.FLUSH_QUERIES_BEFORE_STEPto maintain current behaviour. The main loop currently callsPhysicsServer2/3D.flush_queriesbefore callingphysics_processand thenPhysicsServer2/3D.step. PassingEngine.FLUSH_QUERIES_AFTER_STEPchanges this order tophysics_process→PhysicsServer2/3D.step→PhysicsServer2/3D.flush_queries. This is useful when resetting state between physics iterations as it avoids flushing stale queries. Finally, thePhysicsServer2/3D.flush_queriescall can be skipped entirely by passingEngine.FLUSH_QUERIES_NEVER.Additionally, this slightly tweaks the way in which the main loop invokes
PhysicsServer2/3D.step. It is now called betweenPhysicsServer2/3D.syncandPhysicsServer2/3D.end_sync.Godot's implementation of PhysicsServer uses the internal
doing_syncset and unset duringsyncandend_sync, respectively, to determine whenspace_get_direct_stateandbody_get_direct_statemay be called only when multithreaded physics is enabled.