Skip to content

Commit

Permalink
fxs
Browse files Browse the repository at this point in the history
  • Loading branch information
elementbound committed Nov 8, 2024
1 parent 66d870b commit 76baf05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
7 changes: 2 additions & 5 deletions addons/netfox/network-time-synchronizer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ signal on_initial_sync()
## Panic means that the difference between clocks is too large. The time sync
## will reset the clock to the remote clock's time and restart the time sync loop
## from there.
## [br]
## [br][br]
## Use this event in case you need to react to clock changes in your game.
signal on_panic(offset: float)

Expand Down Expand Up @@ -193,10 +193,7 @@ func _discipline_clock():
var w = log(1 + sorted_samples[i].get_rtt())
offset += offsets[i] * w
offset_weight += w

_logger.trace("Adding offset %.2fms * %.2f = %.2fms" % [offsets[i] * 1000., w, offsets[i] * 1000. * w])

_logger.trace("Normalizing weight %.2fms / %.4f => %.2fms" % [offset * 1000., offset_weight, offset / offset_weight * 1000.])

offset /= offset_weight

# Panic / Adjust
Expand Down
46 changes: 23 additions & 23 deletions addons/netfox/network-time.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ var tick: int:
## Time is continuously synced to the server. In case the time difference is
## excessive between local and the server, both [code]tick[/code] and
## [code]time[/code] will be reset to the estimated server values.
## [br]
## [br][br]
## This property determines the difference threshold in seconds for
## recalibration.
## [br]
## [br][br]
## [i]read-only[/i], you can change this in the project settings
## [br]
## [br][br]
## @deprecated: Use [member _NetworkTimeSynchronizer.panic_threshold] instead.
var recalibrate_threshold: float:
get:
Expand All @@ -108,9 +108,9 @@ var recalibrate_threshold: float:
##
## This is value is only an estimate, and is regularly updated. This means that
## this value can and probably will change depending on network conditions.
## [br]
## [br][br]
## [i]read-only[/i]
## [br]
## [br][br]
## @deprecated: Will return the same as [member tick].
var remote_tick: int:
get:
Expand All @@ -122,9 +122,9 @@ var remote_tick: int:
##
## This is value is only an estimate, and is regularly updated. This means that
## this value can and probably will change depending on network conditions.
## [br]
## [br][br]
## [i]read-only[/i]
## [br]
## [br][br]
## @deprecated: Will return the same as [member time].
var remote_time: float:
get:
Expand All @@ -137,9 +137,9 @@ var remote_time: float:
## This value is updated regularly, during server time sync. Latency can be
## estimated as half of the roundtrip time. Returns the same as [member
## _NetworkTimeSynchronizer.rtt].
## [br]
## [br][br]
## Will always be 0 on servers.
## [br]
## [br][br]
## [i]read-only[/i]
var remote_rtt: float:
get:
Expand All @@ -152,14 +152,14 @@ var remote_rtt: float:
## On clients, this value is synced to the server [i]only once[/i] when joining
## the game. After that, it will increase monotonically, incrementing every
## single tick.
## [br]
## [br][br]
## When hosting, this value is simply the number of ticks since game start.
## [br]
## [br][br]
## This property can be used for things that require a timer that is guaranteed
## to be linear, i.e. no jumps in time.
## [br]
## [br][br]
## [i]read-only[/i]
## [br]
## [br][br]
## @deprecated: Will return the same as [member tick].
var local_tick: int:
get:
Expand All @@ -172,14 +172,14 @@ var local_tick: int:
## On clients, this value is synced to the server [i]only once[/i] when joining
## the game. After that, it will increase monotonically, incrementing every
## single tick.
## [br]
## [br][br]
## When hosting, this value is simply the seconds elapsed since game start.
## [br]
## [br][br]
## This property can be used for things that require a timer that is guaranteed
## to be linear, i.e. no jumps in time.
## [br]
## [br][br]
## [i]read-only[/i]
## [br]
## [br][br]
## @deprecated: Will return the same as [member time].
var local_time: float:
get:
Expand Down Expand Up @@ -247,9 +247,9 @@ var physics_factor: float:
## minimum allowed clock stretch factor is derived as 1.0 / clock_stretch_max.
## Setting this to larger values will allow for quicker clock adjustment at the
## cost of bigger deviations in game speed.
## [br]
## [br][br]
## Make sure to adjust this value based on the game's needs.
## [br]
## [br][br]
## [i]read-only[/i], you can change this in the project settings
var clock_stretch_max: float:
get:
Expand Down Expand Up @@ -297,9 +297,9 @@ var clock_offset: float:
##
## Positive values mean the reference clock is behind the remote clock.
## Negative values mean the reference clock is ahead of the remote clock.
## [br]
## [br][br]
## Returns the same as [member _NetworkTimeSynchronizer.remote_offset].
## [br]
## [br][br]
## [i]read-only[/i]
var remote_clock_offset: float:
get:
Expand Down Expand Up @@ -355,9 +355,9 @@ static var _logger: _NetfoxLogger = _NetfoxLogger.for_netfox("NetworkTime")
##
## Once this is called, time will be synchronized and ticks will be consistently
## emitted.
## [br]
## [br][br]
## On clients, the initial time sync must complete before any ticks are emitted.
## [br]
## [br][br]
## To check if this initial sync is done, see [method is_initial_sync_done]. If
## you need a signal, see [signal after_sync].
func start():
Expand Down

0 comments on commit 76baf05

Please sign in to comment.