-
Notifications
You must be signed in to change notification settings - Fork 235
Open
Description
The GameServer sleeps for 100 milliseconds in its executionThread. However, this is twice the tickInterval and six times the stepInterval, triggering many while loops. Changing the sleep duration to lower value (1 milliseconds) would trigger enough number of while loops.
void GameServer::executionThread()
{
setListening(true);
sf::Time stepInterval = sf::seconds(1.f / 60.f);
sf::Time stepTime = sf::Time::Zero;
sf::Time tickInterval = sf::seconds(1.f / 20.f);
sf::Time tickTime = sf::Time::Zero;
sf::Clock stepClock, tickClock;
while (!mWaitingThreadEnd)
{
handleIncomingPackets();
handleIncomingConnections();
stepTime += stepClock.getElapsedTime();
stepClock.restart();
tickTime += tickClock.getElapsedTime();
tickClock.restart();
// Fixed update step
while (stepTime >= stepInterval)
{
mBattleFieldRect.top += mBattleFieldScrollSpeed * stepInterval.asSeconds();
stepTime -= stepInterval;
}
// Fixed tick step
while (tickTime >= tickInterval)
{
tick();
tickTime -= tickInterval;
}
// Sleep to prevent server from consuming 100% CPU
// Changed to 1 milliseconds
sf::sleep(sf::milliseconds(1));
}
}
Metadata
Metadata
Assignees
Labels
No labels