Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Oct 2, 2023
1 parent 7ef0635 commit bd17ea4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,10 +2693,14 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
inline void Game::step(f32 dtime)
{
if (server) {
float fps_max = (!device->isWindowFocused() || g_menumgr.pausesGame()) ?
g_settings->getFloat("fps_max_unfocused") :
g_settings->getFloat("fps_max");
fps_max = std::max(fps_max, 1.0f);
float steplen = 1.0f / fps_max;

server->setStepSettings(Server::StepSettings{
(!device->isWindowFocused() || g_menumgr.pausesGame()) ?
1.0f / std::max(g_settings->getFloat("fps_max_unfocused"), 1.0f) :
1.0f / std::max(g_settings->getFloat("fps_max"), 1.0f),
steplen,
m_is_paused
});

Expand Down
10 changes: 5 additions & 5 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void *ServerThread::run()
m_server->AsyncRunStep(step_settings.pause ? 0.0f : dtime);

const float remaining_time = step_settings.steplen
- 1.0e-6f * (float)(porting::getTimeUs() - t0);
- 1e-6f * (porting::getTimeUs() - t0);
m_server->Receive(remaining_time);

} catch (con::PeerNotFoundException &e) {
Expand All @@ -143,7 +143,7 @@ void *ServerThread::run()
m_server->setAsyncFatalError(e);
}

dtime = 1.0e-6f * (float)(porting::getTimeUs() - t0);
dtime = 1e-6f * (porting::getTimeUs() - t0);
}

END_DEBUG_EXCEPTION_HANDLER
Expand Down Expand Up @@ -1032,9 +1032,9 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
void Server::Receive(float timeout)
{
const u64 t0 = porting::getTimeUs();
const float timeout_us = timeout * 1.0e6f;
const float timeout_us = timeout * 1e6f;
auto remaining_time_us = [&]() -> float {
return timeout_us - (float)(porting::getTimeUs() - t0);
return std::max(0.0f, timeout_us - (porting::getTimeUs() - t0));
};

NetworkPacket pkt;
Expand All @@ -1044,7 +1044,7 @@ void Server::Receive(float timeout)
peer_id = 0;
try {
if (!m_con->ReceiveTimeoutMs(&pkt,
(u32)std::max(0.0f, remaining_time_us()) / 1000)) {
(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.
Expand Down

0 comments on commit bd17ea4

Please sign in to comment.