Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions addons/netfox.extras/physics/rapier_driver_2d.gd.off
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@

extends PhysicsDriver

class_name RapierDriver2D

var _state: StateManager2D

var _stored_states: int = 0


func _init_physics_space() -> void:
physics_space = get_viewport().world_2d.space
PhysicsServer2D.space_set_active(physics_space, false)

_state = StateManager2D.new()
_state.root_node = self
_state.set_max_cache_length(ProjectSettings.get_setting("netfox/rollback/history_limit", 64))
_state.set_rolling_cache(true)
add_child(_state)


func _physics_step(delta) -> void:
RapierPhysicsServer2D.space_step(physics_space, delta)
RapierPhysicsServer2D.space_flush_queries(physics_space)



func _snapshot_space(tick: int) -> void:
snapshots[tick] = RapierPhysicsServer2D.export_binary(physics_space)
_state.cache_state(physics_space, tick)


func _rollback_space(tick: int) -> void:
# With rolling cache, tick states are ordered by age with the newest at 0
var offset = NetworkTime.tick - tick
if (offset >= _stored_states):
return

func _rollback_space(tick) -> void:
if snapshots.has(tick):
RapierPhysicsServer2D.import_binary(physics_space, snapshots[tick])
_stored_states = min(_stored_states + 1, _state.max_cache_length)
_state.load_cached_state(physics_space, offset)
29 changes: 24 additions & 5 deletions addons/netfox.extras/physics/rapier_driver_3d.gd.off
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@ extends PhysicsDriver

class_name RapierDriver3D

var _state: StateManager3D

var _stored_states: int = 0


func _init_physics_space() -> void:
physics_space = get_viewport().world_3d.space
PhysicsServer3D.space_set_active(physics_space, false)

_state = StateManager3D.new()
_state.root_node = self
_state.set_max_cache_length(ProjectSettings.get_setting("netfox/rollback/history_limit", 64))
_state.set_rolling_cache(true)
add_child(_state)


func _physics_step(delta) -> void:
RapierPhysicsServer3D.space_step(physics_space, delta)
RapierPhysicsServer3D.space_flush_queries(physics_space)



func _snapshot_space(tick: int) -> void:
snapshots[tick] = RapierPhysicsServer3D.export_binary(physics_space)
_state.cache_state(physics_space, tick)


func _rollback_space(tick: int) -> void:
# With rolling cache, tick states are ordered by age with the newest at 0
var offset = NetworkTime.tick - tick
if (offset >= _stored_states):
return

func _rollback_space(tick) -> void:
if snapshots.has(tick):
RapierPhysicsServer3D.import_binary(physics_space, snapshots[tick])
_stored_states = min(_stored_states + 1, _state.max_cache_length)
_state.load_cached_state(physics_space, offset)
2 changes: 1 addition & 1 deletion addons/netfox.extras/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.extras"
description="Game-specific utilities for Netfox"
author="Tamas Galffy and contributors"
version="1.40.1"
version="1.40.2"
script="netfox-extras.gd"
2 changes: 1 addition & 1 deletion addons/netfox.internals/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.internals"
description="Shared internals for netfox addons"
author="Tamas Galffy and contributors"
version="1.40.1"
version="1.40.2"
script="plugin.gd"
2 changes: 1 addition & 1 deletion addons/netfox.noray/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox.noray"
description="Bulletproof your connectivity with noray integration for netfox"
author="Tamas Galffy and contributors"
version="1.40.1"
version="1.40.2"
script="netfox-noray.gd"
2 changes: 1 addition & 1 deletion addons/netfox/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="netfox"
description="Shared internals for netfox addons"
author="Tamas Galffy and contributors"
version="1.40.1"
version="1.40.2"
script="netfox.gd"
4 changes: 4 additions & 0 deletions docs/netfox.extras/guides/physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ stepping or use an alternate physics addon that exposes stepping.
its builds are provided as-is, and are not associated with Godot nor the PR's
author.

!!!note
The current version of the Rapier drivers were tested against Godot Rapier
version **0.8.26**.

## Enabling Physics Engine Rollback

To enable physics rollback, add the appropriate physics driver node to the root
Expand Down
Loading