mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-12 18:11:55 +00:00
Merge pull request #312 from 4jcraft/refactor/replace-sleep
refactor: replace win32 thread sleeping and yielding with `std::thread` primitives
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "../../Minecraft.World/Platform/stdafx.h"
|
||||
#include "../../Minecraft.World/Util/StringHelpers.h"
|
||||
#include "../../Minecraft.World/Util/AABB.h"
|
||||
@@ -344,7 +347,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
|
||||
// message I could find
|
||||
pMinecraft->progressRenderer->progressStagePercentage(
|
||||
g_NetworkManager.GetJoiningReadyPercentage());
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
if (changedMessage) {
|
||||
pMinecraft->progressRenderer->progressStagePercentage(100);
|
||||
@@ -367,7 +370,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
|
||||
// this
|
||||
while (!app.DLCInstallProcessCompleted() && app.DLCInstallPending() &&
|
||||
!g_NetworkManager.IsLeavingGame()) {
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
if (g_NetworkManager.IsLeavingGame()) {
|
||||
MinecraftServer::HaltServer();
|
||||
@@ -448,7 +451,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
|
||||
|
||||
// 4J Stu - We were ticking this way too fast which could cause the
|
||||
// connection to time out The connections should tick at 20 per second
|
||||
Sleep(50);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
} while ((IsInSession() && !connection->isStarted() &&
|
||||
!connection->isClosed() && !g_NetworkManager.IsLeavingGame()) ||
|
||||
tPack->isLoadingData() ||
|
||||
@@ -548,7 +551,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
|
||||
// 4J Stu - We were ticking this way too fast which could cause
|
||||
// the connection to time out The connections should tick at 20
|
||||
// per second
|
||||
Sleep(50);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
app.DebugPrintf("<***> %d %d %d %d %d\n", IsInSession(),
|
||||
!connection->isStarted(),
|
||||
!connection->isClosed(),
|
||||
@@ -959,7 +962,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
|
||||
while (tPack->isLoadingData() ||
|
||||
(Minecraft::GetInstance()->skins->needsUIUpdate() ||
|
||||
ui.IsReloadingSkin())) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
ui.CleanUpSkinReload();
|
||||
if (app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None) {
|
||||
@@ -977,7 +980,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
|
||||
#ifdef __PSVITA__
|
||||
// 4J-JEV: Wait for the loading/saving to finish.
|
||||
while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle)
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
#endif
|
||||
|
||||
Tile::ReleaseThreadStorage();
|
||||
@@ -999,7 +1002,7 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
|
||||
param->texturePackId)) {
|
||||
while ((Minecraft::GetInstance()->skins->needsUIUpdate() ||
|
||||
ui.IsReloadingSkin())) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
param->levelGen->loadBaseSaveData();
|
||||
}
|
||||
@@ -1037,7 +1040,7 @@ int CGameNetworkManager::ExitAndJoinFromInviteThreadProc(void* lpParam) {
|
||||
UIScene_PauseMenu::_ExitWorld(NULL);
|
||||
|
||||
while (g_NetworkManager.IsInSession()) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
// Xbox should always be online when receiving invites - on PS3 we need to
|
||||
@@ -1242,7 +1245,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) !=
|
||||
eXuiServerAction_Idle &&
|
||||
!MinecraftServer::serverHalted()) {
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),
|
||||
eXuiServerAction_PauseServer, (void*)TRUE);
|
||||
@@ -1282,7 +1285,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
// if we don't do this then there's an async thread running doing this,
|
||||
// which could then finish at any inappropriate time later
|
||||
while (s_pPlatformNetworkManager->IsAddingPlayer()) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1313,7 +1316,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
|
||||
// wait for the current session to end
|
||||
while (g_NetworkManager.IsInSession()) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
// Reset this flag as the we don't need to know that we only lost the room
|
||||
@@ -1343,7 +1346,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
|
||||
// Wait for all the local players to rejoin the session
|
||||
while (g_NetworkManager.GetPlayerCount() < numLocalPlayers) {
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
|
||||
// Restore the network player of all the server players that are local
|
||||
@@ -1393,7 +1396,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
// Make sure that we have transitioned through any joining/creating stages
|
||||
// so we're actually ready to set to play
|
||||
while (!s_pPlatformNetworkManager->IsReadyToPlayOrIdle()) {
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1402,7 +1405,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
#ifndef _XBOX
|
||||
// Wait until the message box has been closed
|
||||
while (ui.IsSceneInStack(XUSER_INDEX_ANY, eUIScene_MessageBox)) {
|
||||
Sleep(10);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1952,7 +1955,7 @@ void CGameNetworkManager::HandleInviteWhenInMenus(
|
||||
#if 0
|
||||
while( waitHere )
|
||||
{
|
||||
Sleep(1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user