Skip to content

Commit

Permalink
Fix for frame rate below physics tick rate
Browse files Browse the repository at this point in the history
There was a bug in the dirty flag logic which could result in a 'double refresh' where frame rate fell below physics tick rate - effectively turning off smoothing in that situation.

This fix removes the dirty flag and simply refreshes on each physics tick. This will do as a sticky plaster as this should be in Godot core very soon anyway.
  • Loading branch information
lawnjelly authored Oct 19, 2021
1 parent b4821c9 commit 036278b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
18 changes: 2 additions & 16 deletions addons/smoothing/smoothing.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const SF_ENABLED = 1 << 0
const SF_TRANSLATE = 1 << 1
const SF_BASIS = 1 << 2
const SF_SLERP = 1 << 3
const SF_DIRTY = 1 << 4
const SF_INVISIBLE = 1 << 5
const SF_INVISIBLE = 1 << 4

export (int, FLAGS, "enabled", "translate", "basis", "slerp") var flags: int = SF_ENABLED | SF_TRANSLATE | SF_BASIS setget _set_flags, _get_flags

Expand Down Expand Up @@ -120,8 +119,6 @@ func _notification(what):


func _RefreshTransform():
_ClearFlags(SF_DIRTY)

if _HasTarget() == false:
return

Expand Down Expand Up @@ -186,11 +183,8 @@ func _HasTarget() -> bool:


func _process(_delta):
if _TestFlags(SF_DIRTY):
_RefreshTransform()

var f = Engine.get_physics_interpolation_fraction()

var tr: Transform = Transform()

# translate
Expand All @@ -207,17 +201,9 @@ func _process(_delta):

transform = tr

pass


func _physics_process(_delta):
# take care of the special case where multiple physics ticks
# occur before a frame .. the data must flow!
if _TestFlags(SF_DIRTY):
_RefreshTransform()

_SetFlags(SF_DIRTY)
pass
_RefreshTransform()


func _LerpBasis(from: Basis, to: Basis, f: float) -> Basis:
Expand Down
16 changes: 2 additions & 14 deletions addons/smoothing/smoothing_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const SF_ROTATE = 1 << 2
const SF_SCALE = 1 << 3
const SF_GLOBAL_IN = 1 << 4
const SF_GLOBAL_OUT = 1 << 5
const SF_DIRTY = 1 << 6
const SF_INVISIBLE = 1 << 7
const SF_INVISIBLE = 1 << 6

export (int, FLAGS, "enabled", "translate", "rotate", "scale", "global in", "global out") var flags: int = SF_ENABLED | SF_TRANSLATE setget _set_flags, _get_flags

Expand Down Expand Up @@ -112,13 +111,11 @@ func _SetProcessing():

set_process(bEnable)
set_physics_process(bEnable)
pass


func _enter_tree():
# might have been moved
_FindTarget()
pass


func _notification(what):
Expand All @@ -130,7 +127,6 @@ func _notification(what):


func _RefreshTransform():
_ClearFlags(SF_DIRTY)

if _HasTarget() == false:
return
Expand Down Expand Up @@ -222,8 +218,6 @@ func _HasTarget() -> bool:


func _process(_delta):
if _TestFlags(SF_DIRTY):
_RefreshTransform()

var f = Engine.get_physics_interpolation_fraction()

Expand Down Expand Up @@ -256,13 +250,7 @@ func _process(_delta):


func _physics_process(_delta):
# take care of the special case where multiple physics ticks
# occur before a frame .. the data must flow!
if _TestFlags(SF_DIRTY):
_RefreshTransform()

_SetFlags(SF_DIRTY)
pass
_RefreshTransform()


func _LerpAngle(from: float, to: float, weight: float) -> float:
Expand Down

2 comments on commit 036278b

@grenappels
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This will do as a sticky plaster as this should be in Godot core very soon anyway." - does this mean that this package will no longer be necessary at that point? It's been nice to use so far but I am happy to have interpolation in Godot without having to worry about building for it 😃

@Calinou
Copy link
Contributor

@Calinou Calinou commented on 036278b Oct 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This will do as a sticky plaster as this should be in Godot core very soon anyway." - does this mean that this package will no longer be necessary at that point? It's been nice to use so far but I am happy to have interpolation in Godot without having to worry about building for it smiley

Yes, see godotengine/godot-proposals#2753. Physics interpolation in core is planned for Godot 3.5 and 4.0.

Please sign in to comment.