From 15131a1cc20e6e1715113f51c334b221f00c34a8 Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Mon, 23 Dec 2019 13:12:29 +0100 Subject: [PATCH] let the CPU sleep for 1 ms if there is no tic to proceed This brings CPU usage down from 100% to ~18% on my system - just like Chocolate Doom. --- Source/d_net.c | 1 + Source/i_system.c | 5 +++++ Source/i_video.h | 1 + 3 files changed, 7 insertions(+) diff --git a/Source/d_net.c b/Source/d_net.c index c9989998..48e78423 100644 --- a/Source/d_net.c +++ b/Source/d_net.c @@ -758,6 +758,7 @@ void TryRunTics (void) M_Ticker (); return; } + I_Sleep(1); } // run the count * ticdup dics diff --git a/Source/i_system.c b/Source/i_system.c index 952dabf6..c72b7689 100644 --- a/Source/i_system.c +++ b/Source/i_system.c @@ -59,6 +59,11 @@ void I_WaitVBL(int count) SDL_Delay((count*500)/TICRATE); } +void I_Sleep(int ms) +{ + SDL_Delay(ms); +} + // Most of the following has been rewritten by Lee Killough // // I_GetTime diff --git a/Source/i_video.h b/Source/i_video.h index 388267aa..1ec81d34 100644 --- a/Source/i_video.h +++ b/Source/i_video.h @@ -47,6 +47,7 @@ void I_FinishUpdate (void); // Wait for vertical retrace or pause a bit. void I_WaitVBL(int count); +void I_Sleep(int ms); void I_ReadScreen (byte* scr);