diff --git a/code/conquer.cpp b/code/conquer.cpp index 884efccaf..5d1292736 100644 --- a/code/conquer.cpp +++ b/code/conquer.cpp @@ -131,6 +131,7 @@ #include #include +#include #include #include #include @@ -141,6 +142,7 @@ #include #include #include +#include /**************************************** @@ -959,7 +961,7 @@ bool Map_Edit_Loop(void) Call_Back(); // maintains Theme.AI() for music // Color_Cycle(); - Sleep(1); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); return(!GameActive); } @@ -988,7 +990,7 @@ static void Resize_Tactical_View(bool flag) Rect view(0, 0, Options.ScreenWidth, Options.ScreenHeight); Map.Set_View_Dimensions(view); - Sleep(2); + std::this_thread::sleep_for(std::chrono::milliseconds(2)); } else { @@ -1001,7 +1003,7 @@ static void Resize_Tactical_View(bool flag) Rect view(0, _tab_height, Options.ScreenWidth-_sidebar_width, Options.ScreenHeight-_tab_height); Map.Set_View_Dimensions(view); - Sleep(2); + std::this_thread::sleep_for(std::chrono::milliseconds(2)); } } diff --git a/code/except.cpp b/code/except.cpp index eef6a2e37..7ea614006 100644 --- a/code/except.cpp +++ b/code/except.cpp @@ -60,6 +60,7 @@ #include #include +#include #include #include #include @@ -68,6 +69,7 @@ #include #include #include +#include #define MS_VC_THREAD_NAME_EXCEPTION 0x406D1388 #define MS_CPP_EXCEPTION 0xE06D7363 @@ -1679,7 +1681,7 @@ static void Save_Machine_State(EXCEPTION_POINTERS * e_info, DWORD self) // The artifacts are safe, and the dumper owns the dialog and the exit from here. for (;;) { SuspendThread(GetCurrentThread()); - Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } } diff --git a/code/mainloop.cpp b/code/mainloop.cpp index 083c8b89c..b8cc28733 100644 --- a/code/mainloop.cpp +++ b/code/mainloop.cpp @@ -71,6 +71,8 @@ #include "special.hh" #include +#include +#include // // Special module globals for recording and playback @@ -173,7 +175,7 @@ static void Check_For_Focus_Loss(void) Windows_Message_Handler(); break; } - Sleep(10); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); Windows_Message_Handler(); } } @@ -557,7 +559,7 @@ void Sync_Delay(void) TacticalMap->AI(); Map.Render(); } else { - Sleep(0); + std::this_thread::yield(); } if (!FrameTimer()) { break; @@ -567,7 +569,11 @@ void Sync_Delay(void) } // Out of focus nothing is drawn, so the wait gives the processor back. - Sleep(GameInFocus ? 0 : 1); + if (GameInFocus) { + std::this_thread::yield(); + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } } static CDTimerClass fps_timer; diff --git a/code/msengine.cpp b/code/msengine.cpp index f5f835255..e7477356d 100644 --- a/code/msengine.cpp +++ b/code/msengine.cpp @@ -28,7 +28,9 @@ #include "color.hh" #include +#include #include +#include /// @@ -377,7 +379,7 @@ void MSEngine::Wait_Delay(int delay) timer.Start(); } - Sleep(0); + std::this_thread::yield(); } while (timer.Value() > 0); @@ -406,7 +408,7 @@ void MSEngine::Wait_For_Focus(void) while (!GameInFocus) { DebugString("MSEngine - Sleeping\n"); - Sleep(500); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); Windows_Message_Handler(); } diff --git a/code/netdlg2.cpp b/code/netdlg2.cpp index 91c359214..7ac735b87 100644 --- a/code/netdlg2.cpp +++ b/code/netdlg2.cpp @@ -49,6 +49,7 @@ #include "wsproto.h" #include +#include /* @@ -390,7 +391,7 @@ bool Net2Can_Start(void) bool Net2_Service_Lobby(void) { Ipx.Service(); - Sleep(0); + std::this_thread::yield(); Call_Back(); Ipx.Service(); Title_Screen_Restore(); diff --git a/code/savemgr.cpp b/code/savemgr.cpp index 9de35b0e9..5bf2a12a0 100644 --- a/code/savemgr.cpp +++ b/code/savemgr.cpp @@ -42,8 +42,10 @@ #include "dialog.hh" #include +#include #include #include +#include #include @@ -602,7 +604,7 @@ void SaveManagerClass::Process_Pending_Load_Game(void) } UI_Service_Game(); UIShell.Tick(); - Sleep(10); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } box.Hide(); diff --git a/code/score.cpp b/code/score.cpp index 46b040ed9..16cb9f13d 100644 --- a/code/score.cpp +++ b/code/score.cpp @@ -75,6 +75,8 @@ #include "winstub.h" #include +#include +#include #define SIZEGBAR 140 @@ -1053,7 +1055,7 @@ void ScoreClass::Call_Back_Delay(int time) cd.Start(); } - Sleep(0); + std::this_thread::yield(); } while (cd > 0); @@ -1114,7 +1116,7 @@ void ScoreClass::Timing(void) } while (!GameInFocus) { - Sleep(500); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); Windows_Message_Handler(); } diff --git a/code/session.cpp b/code/session.cpp index 0a23d1ed8..970833984 100644 --- a/code/session.cpp +++ b/code/session.cpp @@ -78,8 +78,10 @@ #include "xstraw.h" #include +#include #include // for station ID computation #include // for station ID computation +#include #include // for ntohl @@ -1559,7 +1561,7 @@ void SessionClass::Update_Progress(int percent) Call_Back(); while (Ipx.Global_Num_Send() > 5 && timer > 0) { - Sleep(20); + std::this_thread::sleep_for(std::chrono::milliseconds(20)); Windows_Message_Handler(); Call_Back(); } diff --git a/code/startup.cpp b/code/startup.cpp index c0e51e5d9..bc6ac1fae 100644 --- a/code/startup.cpp +++ b/code/startup.cpp @@ -163,9 +163,11 @@ #include "zbuffer.h" #include +#include #include #include #include +#include #include extern HINSTANCE LanguageResources; @@ -411,7 +413,7 @@ static bool Claim_Single_Instance(void) if (GetLastError () == ERROR_ALREADY_EXISTS) { CloseHandle (AutoPlayMutex); AutoPlayMutex = NULL; - Sleep (2500); + std::this_thread::sleep_for(std::chrono::milliseconds(2500)); } else { DebugString("Create AutoPlayMutex.\n"); } diff --git a/code/taction.cpp b/code/taction.cpp index b4427474c..b938c4133 100644 --- a/code/taction.cpp +++ b/code/taction.cpp @@ -102,8 +102,10 @@ #include "draw.hh" #include "need.hh" +#include #include #include +#include DynamicVectorClass Actions; @@ -2058,7 +2060,7 @@ bool TActionClass::TAction_ZOOM_IN(HouseClass * , ObjectClass * , TriggerClass * Map.Flag_To_Redraw(); Map.Render(); - Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); return(true); } diff --git a/code/vqa.cpp b/code/vqa.cpp index 18a401c79..f9e1d95aa 100644 --- a/code/vqa.cpp +++ b/code/vqa.cpp @@ -33,6 +33,8 @@ // lib includes here. #include "audio/audiomovie.h" +#include +#include #include #include #include @@ -520,7 +522,7 @@ int VQAClass::Play_VQA(int last_frame_to_play, bool nobreakout) if (sleeping == true) { if (!GameInFocus) { - Sleep((1000/30)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 30)); continue; } else { sleeping = false;