Improved servers resposiviness with better delay values

This commit is contained in:
Pauli Nieminen 2008-05-13 00:24:57 +00:00
parent 5745d05b91
commit 2b968add01
2 changed files with 9 additions and 2 deletions

View file

@ -541,7 +541,7 @@ namespace {
LOG_CS << "error in receiving data...\n";
}
SDL_Delay(500);
SDL_Delay(20);
}
}

View file

@ -449,8 +449,15 @@ void server::dump_stats(const time_t& now) {
void server::run() {
int graceful_counter = 0;
size_t current_ticks, start_ticks = 0;
const size_t ms_per_frame = 20;
for (int loop = 0;; ++loop) {
SDL_Delay(20);
// Try to run with 50 FPS all the time
// Server will respond a bit faster under heavy load
current_ticks = SDL_GetTicks();
if (current_ticks - start_ticks < ms_per_frame)
SDL_Delay(ms_per_frame - (current_ticks - start_ticks));
start_ticks = SDL_GetTicks();
try {
// We are going to waith 10 seconds before shutting down so users can get out of game.
if (graceful_restart && games_.size() == 0 && ++graceful_counter > 500 )