Skip to content

Commit

Permalink
Fix server steps shorter than dedicated_server_step since luanti-org#…
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Oct 25, 2024
1 parent 3f306a4 commit 498baab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,8 @@ ask_reconnect_on_crash (Ask to reconnect after crash) bool false
# Length of a server tick (the interval at which everything is generally updated),
# stated in seconds.
# Does not apply to sessions hosted from the client menu.
# This is a lower bound, i.e. server steps may not be shorter than this, but
# they are often longer.
dedicated_server_step (Dedicated server step) float 0.09 0.0 1.0

# Whether players are shown to clients without any range limit.
Expand Down
4 changes: 0 additions & 4 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6926,10 +6926,6 @@ Timing
* `time` is a lower bound. The job is executed in the first server-step that
started at least `time` seconds after the last time a server-step started,
measured with globalstep dtime.
* In particular this can result in relatively large delays if `time` is close
to the server-step dtime. For example, with a target server-step of 0.09 s,
`core.after(0.09, ...)` often waits two steps, resulting in a delay of about
0.18 s.
* If `time` is `0`, the job is executed in the next step.

* `job:cancel()`
Expand Down
8 changes: 3 additions & 5 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,12 +1104,10 @@ void Server::Receive(float timeout)
if (!m_con->ReceiveTimeoutMs(&pkt,
(u32)remaining_time_us() / 1000)) {
// No incoming data.
// Already break if there's 1ms left, as ReceiveTimeoutMs is too coarse
// and a faster server-step is better than busy waiting.
if (remaining_time_us() < 1000.0f)
break;
else
if (remaining_time_us() > 0.0f)
continue;
else
break;
}

peer_id = pkt.getPeerId();
Expand Down

0 comments on commit 498baab

Please sign in to comment.