Merge branch '4jcraft:dev' into dev

This commit is contained in:
ffqq 2026-03-28 03:48:04 +03:00 committed by GitHub
commit 016a3ebfb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 169 additions and 137 deletions

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "ServerLevel.h" #include "ServerLevel.h"
#include "../MinecraftServer.h" #include "../MinecraftServer.h"
@ -1570,7 +1573,7 @@ int ServerLevel::runUpdate(void* lpParam) {
} }
PIXEndNamedEvent(); PIXEndNamedEvent();
#ifdef __PS3__ #ifdef __PS3__
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
#endif //__PS3__ #endif //__PS3__
} }

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "Platform/stdafx.h" #include "Platform/stdafx.h"
#include "Minecraft.h" #include "Minecraft.h"
#include "GameState/GameMode.h" #include "GameState/GameMode.h"
@ -780,7 +783,7 @@ void Minecraft::run()
{ {
this->toggleFullScreen(); this->toggleFullScreen();
} }
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
*/ */
@ -795,7 +798,7 @@ void Minecraft::run()
achievementPopup->render(); achievementPopup->render();
Sleep(0); // 4J - was Thread.yield() std::this_thread::sleep_for(std::chrono::milliseconds(0)); // 4J - was Thread.yield())
// if (Keyboard::isKeyDown(Keyboard::KEY_F7)) Display.update(); // 4J - removed condition // if (Keyboard::isKeyDown(Keyboard::KEY_F7)) Display.update(); // 4J - removed condition
Display::update(); Display::update();
@ -2110,7 +2113,7 @@ void Minecraft::run_middle() {
{ {
this->toggleFullScreen(); this->toggleFullScreen();
} }
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
*/ */
@ -2139,7 +2142,10 @@ void Minecraft::run_middle() {
achievementPopup->render(); achievementPopup->render();
PIXBeginNamedEvent(0, "Sleeping"); PIXBeginNamedEvent(0, "Sleeping");
Sleep(0); // 4J - was Thread.yield() std::this_thread::yield(); // 4jcraft added now that we have
// portable thread yield.
// std::this_thread::sleep_for(
// std::chrono::milliseconds(0)); // 4J - was Thread.yield())
PIXEndNamedEvent(); PIXEndNamedEvent();
// if (Keyboard::isKeyDown(Keyboard::KEY_F7)) // if (Keyboard::isKeyDown(Keyboard::KEY_F7))

View file

@ -2,6 +2,8 @@
// #include "Minecraft.h" // #include "Minecraft.h"
#include <ctime> #include <ctime>
#include <thread>
#include <chrono>
#include "Input/ConsoleInput.h" #include "Input/ConsoleInput.h"
#include "Level/DerivedServerLevel.h" #include "Level/DerivedServerLevel.h"
@ -229,7 +231,7 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData* initData,
// 4J-JEV: Need to wait for levelGenerationOptions to load. // 4J-JEV: Need to wait for levelGenerationOptions to load.
while (app.getLevelGenerationOptions() != NULL && while (app.getLevelGenerationOptions() != NULL &&
!app.getLevelGenerationOptions()->hasLoadedData()) !app.getLevelGenerationOptions()->hasLoadedData())
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
if (app.getLevelGenerationOptions() != NULL && if (app.getLevelGenerationOptions() != NULL &&
!app.getLevelGenerationOptions()->ready()) { !app.getLevelGenerationOptions()->ready()) {
@ -335,7 +337,7 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
} else { } else {
LeaveCriticalSection(&server->m_postProcessCS); LeaveCriticalSection(&server->m_postProcessCS);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (!server->m_postUpdateTerminate && } while (!server->m_postUpdateTerminate &&
ShutdownManager::ShouldRun(ShutdownManager::ePostProcessThread)); ShutdownManager::ShouldRun(ShutdownManager::ePostProcessThread));
// #ifndef __PS3__ // #ifndef __PS3__
@ -356,7 +358,7 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
printf("processing request %00d\n", printf("processing request %00d\n",
server->m_postProcessRequests.size()); server->m_postProcessRequests.size());
#endif #endif
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
#endif #endif
EnterCriticalSection(&server->m_postProcessCS); EnterCriticalSection(&server->m_postProcessCS);
} }
@ -1078,7 +1080,7 @@ void MinecraftServer::stopServer(bool didInit) {
// files have completed saving. // files have completed saving.
#if defined(_DURANGO) || defined(__ORBIS__) || defined(__PSVITA__) #if defined(_DURANGO) || defined(__ORBIS__) || defined(__PSVITA__)
while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle) { while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
#endif #endif
@ -1580,7 +1582,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
app.SetXuiServerAction(i, eXuiServerAction_Idle); app.SetXuiServerAction(i, eXuiServerAction_Idle);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
} }
// else // else
@ -1588,7 +1590,7 @@ void MinecraftServer::run(int64_t seed, void* lpParameter) {
// while (running) // while (running)
// { // {
// handleConsoleInputs(); // handleConsoleInputs();
// Sleep(10); // std::this_thread::sleep_for(std::chrono::milliseconds(10));
// } // }
// } // }
#if 0 #if 0

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "ServerChunkCache.h" #include "ServerChunkCache.h"
#include "../Level/ServerLevel.h" #include "../Level/ServerLevel.h"
@ -277,7 +280,7 @@ LevelChunk* ServerChunkCache::create(
} }
#ifdef __PS3__ #ifdef __PS3__
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
#endif // __PS3__ #endif // __PS3__
return chunk; return chunk;
} }

View file

@ -1,5 +1,4 @@
 #include "../Minecraft.World/Platform/stdafx.h"
#include "../Minecraft.World/Platform/stdafx.h"
#include "../Minecraft.World/Recipes/Recipy.h" #include "../Minecraft.World/Recipes/Recipy.h"
#include "../Minecraft.Client/GameState/Options.h" #include "../Minecraft.Client/GameState/Options.h"
@ -69,6 +68,9 @@
#include <save_data_dialog.h> #include <save_data_dialog.h>
#endif #endif
#include <thread>
#include <chrono>
#include "Leaderboards/LeaderboardManager.h" #include "Leaderboards/LeaderboardManager.h"
// CMinecraftApp app; // CMinecraftApp app;
@ -4831,7 +4833,7 @@ int CMinecraftApp::SignoutExitWorldThreadProc(void* lpParameter) {
// We can't start/join a new game until the session is destroyed, so wait // We can't start/join a new game until the session is destroyed, so wait
// for it to be idle again // for it to be idle again
while (g_NetworkManager.IsInSession()) { while (g_NetworkManager.IsInSession()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
return S_OK; return S_OK;
@ -7724,7 +7726,7 @@ int CMinecraftApp::RemoteSaveThreadProc(void* lpParameter) {
eAppAction_WaitRemoteServerSaveComplete) { eAppAction_WaitRemoteServerSaveComplete) {
// Tick all the games connections // Tick all the games connections
pMinecraft->tickAllConnections(); pMinecraft->tickAllConnections();
Sleep(100); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
if (app.GetXuiAction(ProfileManager.GetPrimaryPad()) != if (app.GetXuiAction(ProfileManager.GetPrimaryPad()) !=
@ -9227,7 +9229,8 @@ bool CMinecraftApp::RetrieveNextTMSPPContent() {
C4JStorage::ETMSStatus_Fail_ReadInProgress) { C4JStorage::ETMSStatus_Fail_ReadInProgress) {
app.DebugPrintf( app.DebugPrintf(
"TMSPP_ReadFile failed - read in progress\n"); "TMSPP_ReadFile failed - read in progress\n");
Sleep(50); std::this_thread::sleep_for(
std::chrono::milliseconds(50));
LeaveCriticalSection(&csTMSPPDownloadQueue); LeaveCriticalSection(&csTMSPPDownloadQueue);
return false; return false;
} }
@ -9266,7 +9269,8 @@ bool CMinecraftApp::RetrieveNextTMSPPContent() {
app.DebugPrintf( app.DebugPrintf(
"@@@@@@@@@@@@@@@@@ TMSPP_ReadFile failed - busy " "@@@@@@@@@@@@@@@@@ TMSPP_ReadFile failed - busy "
"(probably reading already)\n"); "(probably reading already)\n");
Sleep(50); std::this_thread::sleep_for(
std::chrono::milliseconds(50));
LeaveCriticalSection(&csTMSPPDownloadQueue); LeaveCriticalSection(&csTMSPPDownloadQueue);
return false; return false;
} }

View file

@ -1,5 +1,7 @@
#include "../../stdafx.h" #include "../../stdafx.h"
#include <thread>
#include <chrono>
#include <cstdlib> #include <cstdlib>
#include <np.h> #include <np.h>
// #include <sys/ppu_thread.h> // #include <sys/ppu_thread.h>
@ -54,7 +56,7 @@ SonyLeaderboardManager::~SonyLeaderboardManager() {
// 4J-JEV: Wait for thread to stop and hope it doesn't take too long. // 4J-JEV: Wait for thread to stop and hope it doesn't take too long.
long long startShutdown = System::currentTimeMillis(); long long startShutdown = System::currentTimeMillis();
while (m_threadScoreboard->isRunning()) { while (m_threadScoreboard->isRunning()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
assert((System::currentTimeMillis() - startShutdown) < 16); assert((System::currentTimeMillis() - startShutdown) < 16);
} }
@ -87,7 +89,8 @@ int SonyLeaderboardManager::scoreboardThreadEntry(LPVOID lpParam) {
} }
if ((!needsWriting) && (self->m_eStatsState != eStatsState_Getting)) { if ((!needsWriting) && (self->m_eStatsState != eStatsState_Getting)) {
Sleep(50); // 4J-JEV: When we're not reading or writing. std::this_thread::sleep_for(std::chrono::milliseconds(
50)); // 4J-JEV: When we're not reading or writing.
} }
} while ((self->m_running || self->m_eStatsState == eStatsState_Getting || } while ((self->m_running || self->m_eStatsState == eStatsState_Getting ||

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/Util/AABB.h" #include "../../Minecraft.World/Util/AABB.h"
@ -344,7 +347,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
// message I could find // message I could find
pMinecraft->progressRenderer->progressStagePercentage( pMinecraft->progressRenderer->progressStagePercentage(
g_NetworkManager.GetJoiningReadyPercentage()); g_NetworkManager.GetJoiningReadyPercentage());
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
if (changedMessage) { if (changedMessage) {
pMinecraft->progressRenderer->progressStagePercentage(100); pMinecraft->progressRenderer->progressStagePercentage(100);
@ -367,7 +370,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
// this // this
while (!app.DLCInstallProcessCompleted() && app.DLCInstallPending() && while (!app.DLCInstallProcessCompleted() && app.DLCInstallPending() &&
!g_NetworkManager.IsLeavingGame()) { !g_NetworkManager.IsLeavingGame()) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
if (g_NetworkManager.IsLeavingGame()) { if (g_NetworkManager.IsLeavingGame()) {
MinecraftServer::HaltServer(); MinecraftServer::HaltServer();
@ -448,7 +451,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
// 4J Stu - We were ticking this way too fast which could cause the // 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 // 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() && } while ((IsInSession() && !connection->isStarted() &&
!connection->isClosed() && !g_NetworkManager.IsLeavingGame()) || !connection->isClosed() && !g_NetworkManager.IsLeavingGame()) ||
tPack->isLoadingData() || tPack->isLoadingData() ||
@ -548,7 +551,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft,
// 4J Stu - We were ticking this way too fast which could cause // 4J Stu - We were ticking this way too fast which could cause
// the connection to time out The connections should tick at 20 // the connection to time out The connections should tick at 20
// per second // per second
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
app.DebugPrintf("<***> %d %d %d %d %d\n", IsInSession(), app.DebugPrintf("<***> %d %d %d %d %d\n", IsInSession(),
!connection->isStarted(), !connection->isStarted(),
!connection->isClosed(), !connection->isClosed(),
@ -959,7 +962,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
while (tPack->isLoadingData() || while (tPack->isLoadingData() ||
(Minecraft::GetInstance()->skins->needsUIUpdate() || (Minecraft::GetInstance()->skins->needsUIUpdate() ||
ui.IsReloadingSkin())) { ui.IsReloadingSkin())) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
ui.CleanUpSkinReload(); ui.CleanUpSkinReload();
if (app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None) { if (app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None) {
@ -977,7 +980,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
#ifdef __PSVITA__ #ifdef __PSVITA__
// 4J-JEV: Wait for the loading/saving to finish. // 4J-JEV: Wait for the loading/saving to finish.
while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle) while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle)
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
#endif #endif
Tile::ReleaseThreadStorage(); Tile::ReleaseThreadStorage();
@ -999,7 +1002,7 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
param->texturePackId)) { param->texturePackId)) {
while ((Minecraft::GetInstance()->skins->needsUIUpdate() || while ((Minecraft::GetInstance()->skins->needsUIUpdate() ||
ui.IsReloadingSkin())) { ui.IsReloadingSkin())) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
param->levelGen->loadBaseSaveData(); param->levelGen->loadBaseSaveData();
} }
@ -1037,7 +1040,7 @@ int CGameNetworkManager::ExitAndJoinFromInviteThreadProc(void* lpParam) {
UIScene_PauseMenu::_ExitWorld(NULL); UIScene_PauseMenu::_ExitWorld(NULL);
while (g_NetworkManager.IsInSession()) { 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 // 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()) != while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) !=
eXuiServerAction_Idle && eXuiServerAction_Idle &&
!MinecraftServer::serverHalted()) { !MinecraftServer::serverHalted()) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),
eXuiServerAction_PauseServer, (void*)TRUE); 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, // if we don't do this then there's an async thread running doing this,
// which could then finish at any inappropriate time later // which could then finish at any inappropriate time later
while (s_pPlatformNetworkManager->IsAddingPlayer()) { while (s_pPlatformNetworkManager->IsAddingPlayer()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
#endif #endif
@ -1313,7 +1316,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
// wait for the current session to end // wait for the current session to end
while (g_NetworkManager.IsInSession()) { 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 // 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 // Wait for all the local players to rejoin the session
while (g_NetworkManager.GetPlayerCount() < numLocalPlayers) { 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 // 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 // Make sure that we have transitioned through any joining/creating stages
// so we're actually ready to set to play // so we're actually ready to set to play
while (!s_pPlatformNetworkManager->IsReadyToPlayOrIdle()) { while (!s_pPlatformNetworkManager->IsReadyToPlayOrIdle()) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
#endif #endif
@ -1402,7 +1405,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
#ifndef _XBOX #ifndef _XBOX
// Wait until the message box has been closed // Wait until the message box has been closed
while (ui.IsSceneInStack(XUSER_INDEX_ANY, eUIScene_MessageBox)) { while (ui.IsSceneInStack(XUSER_INDEX_ANY, eUIScene_MessageBox)) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
#endif #endif
@ -1952,7 +1955,7 @@ void CGameNetworkManager::HandleInviteWhenInMenus(
#if 0 #if 0
while( waitHere ) while( waitHere )
{ {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
#endif #endif

View file

@ -1,8 +1,11 @@
#include <thread>
#include <chrono>
#include <sys/event.h>
#include "../../../Minecraft.World/Platform/stdafx.h" #include "../../../Minecraft.World/Platform/stdafx.h"
#include "SonyCommerce.h" #include "SonyCommerce.h"
#include "../../../../Platform/PS3/PS3Extras/ShutdownManager.h" #include "../../../../Platform/PS3/PS3Extras/ShutdownManager.h"
#include <sys/event.h>
bool SonyCommerce::m_bCommerceInitialised = false; bool SonyCommerce::m_bCommerceInitialised = false;
SceNpCommerce2SessionInfo SonyCommerce::m_sessionInfo; SceNpCommerce2SessionInfo SonyCommerce::m_sessionInfo;
@ -122,7 +125,8 @@ int SonyCommerce::TickLoop(void* lpParam) {
ShutdownManager::ShouldRun(ShutdownManager::eCommerceThread)) { ShutdownManager::ShouldRun(ShutdownManager::eCommerceThread)) {
processEvent(); processEvent();
processMessage(); processMessage();
Sleep(16); // sleep for a frame std::this_thread::sleep_for(
std::chrono::milliseconds(16)); // sleep for a frame
} }
ShutdownManager::HasFinished(ShutdownManager::eCommerceThread); ShutdownManager::HasFinished(ShutdownManager::eCommerceThread);

View file

@ -1,4 +1,5 @@
#include <thread>
#include <chrono>
#include "../../../Minecraft.World/Platform/stdafx.h" #include "../../../Minecraft.World/Platform/stdafx.h"
#include "SonyRemoteStorage.h" #include "SonyRemoteStorage.h"
@ -286,7 +287,7 @@ bool SonyRemoteStorage::shutdown() {
void SonyRemoteStorage::waitForStorageManagerIdle() { void SonyRemoteStorage::waitForStorageManagerIdle() {
C4JStorage::ESaveGameState storageState = StorageManager.GetSaveState(); C4JStorage::ESaveGameState storageState = StorageManager.GetSaveState();
while (storageState != C4JStorage::ESaveGame_Idle) { while (storageState != C4JStorage::ESaveGame_Idle) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
// app.DebugPrintf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // app.DebugPrintf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// >>>>> storageState = %d\n", storageState); // >>>>> storageState = %d\n", storageState);
storageState = StorageManager.GetSaveState(); storageState = StorageManager.GetSaveState();

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "IUIScene_PauseMenu.h" #include "IUIScene_PauseMenu.h"
#include "UIScene.h" #include "UIScene.h"
@ -393,7 +396,7 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) {
while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) != while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) !=
eXuiServerAction_Idle && eXuiServerAction_Idle &&
!MinecraftServer::serverHalted()) { !MinecraftServer::serverHalted()) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
if (!MinecraftServer::serverHalted() && !app.GetChangingSessionType()) if (!MinecraftServer::serverHalted() && !app.GetChangingSessionType())
@ -661,7 +664,7 @@ void IUIScene_PauseMenu::_ExitWorld(void* lpParameter) {
// multiplayer client if host of the game will exit during the clients // multiplayer client if host of the game will exit during the clients
// loading to created world. // loading to created world.
while (g_NetworkManager.IsNetworkThreadRunning()) { while (g_NetworkManager.IsNetworkThreadRunning()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
pMinecraft->setLevel(NULL, exitReasonStringId, nullptr, saveStats); pMinecraft->setLevel(NULL, exitReasonStringId, nullptr, saveStats);
@ -681,7 +684,7 @@ void IUIScene_PauseMenu::_ExitWorld(void* lpParameter) {
// loads saved data We can't start/join a new game until the session is // loads saved data We can't start/join a new game until the session is
// destroyed, so wait for it to be idle again // destroyed, so wait for it to be idle again
while (g_NetworkManager.IsInSession()) { while (g_NetworkManager.IsInSession()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
app.SetChangingSessionType(false); app.SetChangingSessionType(false);

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "UI.h" #include "UI.h"
#include "UIScene_LoadOrJoinMenu.h" #include "UIScene_LoadOrJoinMenu.h"
@ -2229,7 +2232,7 @@ int UIScene_LoadOrJoinMenu::MustSignInReturnedTexturePack(void* pParam,
while (commerceState != CConsoleMinecraftApp::eCommerce_State_Offline && while (commerceState != CConsoleMinecraftApp::eCommerce_State_Offline &&
commerceState != CConsoleMinecraftApp::eCommerce_State_Online && commerceState != CConsoleMinecraftApp::eCommerce_State_Online &&
commerceState != CConsoleMinecraftApp::eCommerce_State_Error) { commerceState != CConsoleMinecraftApp::eCommerce_State_Error) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
commerceState = app.GetCommerceState(); commerceState = app.GetCommerceState();
} }
@ -2852,7 +2855,7 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) {
#if defined(_DURANGO) || defined(__ORBIS__) #if defined(_DURANGO) || defined(__ORBIS__)
while (StorageManager.GetSaveState() != while (StorageManager.GetSaveState() !=
C4JStorage::ESaveGame_Idle) { C4JStorage::ESaveGame_Idle) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
StorageManager.Tick(); StorageManager.Tick();
} }
#endif #endif
@ -2999,7 +3002,7 @@ int UIScene_LoadOrJoinMenu::DownloadSonyCrossSaveThreadProc(void* lpParameter) {
// waiting to dismiss the dialog // waiting to dismiss the dialog
break; break;
} }
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
m_bSaveTransferRunning = false; m_bSaveTransferRunning = false;
#ifdef __PS3__ #ifdef __PS3__
@ -3151,7 +3154,7 @@ int UIScene_LoadOrJoinMenu::UploadSonyCrossSaveThreadProc(void* lpParameter) {
// waiting for dialog to be dismissed // waiting for dialog to be dismissed
break; break;
} }
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
return 0; return 0;
@ -3247,7 +3250,7 @@ int UIScene_LoadOrJoinMenu::DownloadXbox360SaveThreadProc(void* lpParameter) {
while (StorageManager.SaveTransferClearState() != while (StorageManager.SaveTransferClearState() !=
C4JStorage::eSaveTransfer_Idle) { C4JStorage::eSaveTransfer_Idle) {
Sleep(5); std::this_thread::sleep_for(std::chrono::milliseconds(5));
} }
pStateContainer->m_bSaveTransferInProgress = true; pStateContainer->m_bSaveTransferInProgress = true;
@ -3432,7 +3435,7 @@ int UIScene_LoadOrJoinMenu::DownloadXbox360SaveThreadProc(void* lpParameter) {
while (StorageManager.GetSaveState() != while (StorageManager.GetSaveState() !=
C4JStorage::ESaveGame_Idle) { C4JStorage::ESaveGame_Idle) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
// 4J Stu - DO NOT tick this here. The main thread should be // 4J Stu - DO NOT tick this here. The main thread should be
// the only place ticking the StorageManager. You WILL get // the only place ticking the StorageManager. You WILL get
@ -3470,7 +3473,7 @@ int UIScene_LoadOrJoinMenu::DownloadXbox360SaveThreadProc(void* lpParameter) {
break; break;
} }
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
if (pStateContainer->m_bSaveTransferCancelled) { if (pStateContainer->m_bSaveTransferCancelled) {
@ -3517,7 +3520,7 @@ void UIScene_LoadOrJoinMenu::RequestFileSize(SaveTransferStateContainer* pClass,
IDS_SAVETRANSFER_TITLE_GET); IDS_SAVETRANSFER_TITLE_GET);
pMinecraft->progressRenderer->progressStage( pMinecraft->progressRenderer->progressStage(
IDS_SAVETRANSFER_STAGE_GET_DETAILS); IDS_SAVETRANSFER_STAGE_GET_DETAILS);
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
pClass->m_eSaveTransferState = pClass->m_eSaveTransferState =
StorageManager.SaveTransferGetDetails( StorageManager.SaveTransferGetDetails(
pClass->m_iPad, C4JStorage::eGlobalStorage_TitleUser, pClass->m_iPad, C4JStorage::eGlobalStorage_TitleUser,
@ -3573,7 +3576,7 @@ void UIScene_LoadOrJoinMenu::RequestFileData(SaveTransferStateContainer* pClass,
pMinecraft->progressRenderer->progressStart( pMinecraft->progressRenderer->progressStart(
IDS_SAVETRANSFER_TITLE_GET); IDS_SAVETRANSFER_TITLE_GET);
pMinecraft->progressRenderer->progressStage(-1); pMinecraft->progressRenderer->progressStage(-1);
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
pClass->m_eSaveTransferState = StorageManager.SaveTransferGetData( pClass->m_eSaveTransferState = StorageManager.SaveTransferGetData(
pClass->m_iPad, C4JStorage::eGlobalStorage_TitleUser, filename, pClass->m_iPad, C4JStorage::eGlobalStorage_TitleUser, filename,
&UIScene_LoadOrJoinMenu::SaveTransferReturned, &UIScene_LoadOrJoinMenu::SaveTransferReturned,
@ -3740,7 +3743,7 @@ int UIScene_LoadOrJoinMenu::CopySaveThreadProc(void* lpParameter) {
bool bContinue = true; bool bContinue = true;
do { do {
Sleep(100); std::this_thread::sleep_for(std::chrono::milliseconds(100));
ui.EnterCallbackIdCriticalSection(); ui.EnterCallbackIdCriticalSection();
pClass = (UIScene_LoadOrJoinMenu*)ui.GetSceneFromCallbackId( pClass = (UIScene_LoadOrJoinMenu*)ui.GetSceneFromCallbackId(
(size_t)lpParameter); (size_t)lpParameter);

View file

@ -1,9 +1,12 @@
// Minecraft.cpp : Defines the entry point for the application. // Minecraft.cpp : Defines the entry point for the application.
// //
#include <assert.h>
#include <thread>
#include <chrono>
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include "XUI_Death.h" #include "XUI_Death.h"
#include <assert.h>
#include "../../Minecraft.World/Util/AABB.h" #include "../../Minecraft.World/Util/AABB.h"
#include "../../Minecraft.World/Util/Vec3.h" #include "../../Minecraft.World/Util/Vec3.h"
#include "../../Minecraft.World/Headers/net.minecraft.stats.h" #include "../../Minecraft.World/Headers/net.minecraft.stats.h"
@ -234,7 +237,7 @@ int CScene_Death::RespawnThreadProc(void* lpParameter) {
// If we are offline, this should release straight away // If we are offline, this should release straight away
// WaitForSingleObject( pMinecraft->m_hPlayerRespawned, INFINITE ); // WaitForSingleObject( pMinecraft->m_hPlayerRespawned, INFINITE );
while (pMinecraft->localplayers[iPad]->GetPlayerRespawned() == false) { while (pMinecraft->localplayers[iPad]->GetPlayerRespawned() == false) {
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
return S_OK; return S_OK;

View file

@ -7,6 +7,9 @@
#include "XUI_Ctrl_CraftIngredientSlot.h" #include "XUI_Ctrl_CraftIngredientSlot.h"
#include "XUI_XZP_Icons.h" #include "XUI_XZP_Icons.h"
#include <thread>
#include <chrono>
LPCWSTR CScene_Leaderboards::m_TitleIconNameA[7] = { LPCWSTR CScene_Leaderboards::m_TitleIconNameA[7] = {
L"XuiHSlot1", L"XuiHSlot2", L"XuiHSlot3", L"XuiHSlot4", L"XuiHSlot1", L"XuiHSlot2", L"XuiHSlot3", L"XuiHSlot4",
L"XuiHSlot5", L"XuiHSlot6", L"XuiHSlot7", L"XuiHSlot5", L"XuiHSlot6", L"XuiHSlot7",
@ -283,7 +286,7 @@ HRESULT CScene_Leaderboards::OnDestroy() {
app.SetLiveLinkRequired(false); app.SetLiveLinkRequired(false);
while (m_isProcessingStatsRead) { while (m_isProcessingStatsRead) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
if (m_friends != NULL) delete[] m_friends; if (m_friends != NULL) delete[] m_friends;

View file

@ -1,6 +1,8 @@
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include <xuiresource.h> #include <xuiresource.h>
#include <xuiapp.h> #include <xuiapp.h>
#include <thread>
#include <chrono>
#include <assert.h> #include <assert.h>
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../Tutorial/TutorialMode.h" #include "../Tutorial/TutorialMode.h"
@ -2174,7 +2176,7 @@ bool CScene_MultiGameJoinLoad::WaitForTransferComplete(
// cancelled // cancelled
return false; return false;
} }
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
// update the progress // update the progress
pMinecraft->progressRenderer->progressStagePercentage( pMinecraft->progressRenderer->progressStagePercentage(
(unsigned int)(pClass->m_fProgress * 100.0f)); (unsigned int)(pClass->m_fProgress * 100.0f));

View file

@ -4,6 +4,8 @@
#include "../../Minecraft.World/Platform/stdafx.h" #include "../../Minecraft.World/Platform/stdafx.h"
#include <assert.h> #include <assert.h>
#include <thread>
#include <chrono>
#include "../../Minecraft.World/Util/AABB.h" #include "../../Minecraft.World/Util/AABB.h"
#include "../../Minecraft.World/Util/Vec3.h" #include "../../Minecraft.World/Util/Vec3.h"
#include "../../Minecraft.World/Headers/net.minecraft.stats.h" #include "../../Minecraft.World/Headers/net.minecraft.stats.h"
@ -1086,7 +1088,7 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) {
while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) != while (app.GetXuiServerAction(ProfileManager.GetPrimaryPad()) !=
eXuiServerAction_Idle && eXuiServerAction_Idle &&
!MinecraftServer::serverHalted()) { !MinecraftServer::serverHalted()) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
if (!MinecraftServer::serverHalted() && !app.GetChangingSessionType()) if (!MinecraftServer::serverHalted() && !app.GetChangingSessionType())
@ -1295,7 +1297,7 @@ void UIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) {
// multiplayer client if host of the game will exit during the clients // multiplayer client if host of the game will exit during the clients
// loading to created world. // loading to created world.
while (g_NetworkManager.IsNetworkThreadRunning()) { while (g_NetworkManager.IsNetworkThreadRunning()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
pMinecraft->setLevel(NULL, exitReasonStringId, nullptr, saveStats); pMinecraft->setLevel(NULL, exitReasonStringId, nullptr, saveStats);
@ -1315,7 +1317,7 @@ void UIScene_PauseMenu::_ExitWorld(LPVOID lpParameter) {
// loads saved data We can't start/join a new game until the session is // loads saved data We can't start/join a new game until the session is
// destroyed, so wait for it to be idle again // destroyed, so wait for it to be idle again
while (g_NetworkManager.IsInSession()) { while (g_NetworkManager.IsInSession()) {
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
app.SetChangingSessionType(false); app.SetChangingSessionType(false);

View file

@ -2,6 +2,8 @@
#include <xuiresource.h> #include <xuiresource.h>
#include <xuiapp.h> #include <xuiapp.h>
#include <assert.h> #include <assert.h>
#include <thread>
#include <chrono>
#include "XUI_Ctrl_4JList.h" #include "XUI_Ctrl_4JList.h"
#include "XUI_Ctrl_4JIcon.h" #include "XUI_Ctrl_4JIcon.h"
@ -363,7 +365,7 @@ int CScene_TransferToXboxOne::UploadSaveForXboxOneThreadProc(
// loop waiting for the write to complete // loop waiting for the write to complete
uiComplete = 0; uiComplete = 0;
while (pClass->m_bWaitingForWrite && (hr == S_OK)) { while (pClass->m_bWaitingForWrite && (hr == S_OK)) {
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
uiComplete++; uiComplete++;
if (uiComplete > 100) uiComplete = 100; if (uiComplete > 100) uiComplete = 100;
@ -380,7 +382,7 @@ int CScene_TransferToXboxOne::UploadSaveForXboxOneThreadProc(
// finish the bar // finish the bar
for (int i = uiComplete; i < 100; i++) { for (int i = uiComplete; i < 100; i++) {
Sleep(5); std::this_thread::sleep_for(std::chrono::milliseconds(5));
pMinecraft->progressRenderer->progressStagePercentage(i); pMinecraft->progressRenderer->progressStagePercentage(i);
} }
@ -396,7 +398,7 @@ int CScene_TransferToXboxOne::UploadSaveForXboxOneThreadProc(
// sleep until we have the data // sleep until we have the data
while (pClass->m_bSaveDataReceived == false) { while (pClass->m_bSaveDataReceived == false) {
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
// write the save to user TMS // write the save to user TMS
@ -443,7 +445,7 @@ int CScene_TransferToXboxOne::UploadSaveForXboxOneThreadProc(
} else { } else {
// loop waiting for the write to complete // loop waiting for the write to complete
while (pClass->m_bWaitingForWrite && (hr == S_OK)) { while (pClass->m_bWaitingForWrite && (hr == S_OK)) {
Sleep(50); std::this_thread::sleep_for(std::chrono::milliseconds(50));
} }
uiComplete += uiPercentageChunk; uiComplete += uiPercentageChunk;
if (uiComplete > 100) uiComplete = 100; if (uiComplete > 100) uiComplete = 100;

View file

@ -5,7 +5,6 @@
#include <assert.h> #include <assert.h>
// #include <system_service.h> // #include <system_service.h>
#include <codecvt>
#if defined(__linux__) && defined(__GLIBC__) #if defined(__linux__) && defined(__GLIBC__)
#include <signal.h> #include <signal.h>
#include <execinfo.h> #include <execinfo.h>
@ -710,15 +709,6 @@ void CleanupDevice() {
} }
#endif #endif
int StartMinecraftThreadProc(void* lpParameter) {
AABB::UseDefaultThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024);
RenderManager.InitialiseContext();
Minecraft::start(std::wstring(), std::wstring());
delete Tesselator::getInstance();
return 0;
}
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
#if defined(__linux__) && defined(__GLIBC__) #if defined(__linux__) && defined(__GLIBC__)
struct sigaction sa; struct sigaction sa;
@ -1197,7 +1187,7 @@ void FreeRichPresenceStrings() {
vRichPresenceStrings.clear(); vRichPresenceStrings.clear();
} }
#ifdef MEMORY_TRACKING #if 0 // #ifdef MEMORY_TRACKING
int totalAllocGen = 0; int totalAllocGen = 0;
std::unordered_map<int, int> allocCounts; std::unordered_map<int, int> allocCounts;

View file

@ -306,28 +306,6 @@ static inline ULONG TryEnterCriticalSection(
return pthread_mutex_trylock(CriticalSection) == 0; return pthread_mutex_trylock(CriticalSection) == 0;
} }
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsalloc
static inline DWORD TlsAlloc(VOID) {
pthread_key_t key;
if (pthread_key_create(&key, NULL) == 0) return key;
return TLS_OUT_OF_INDEXES;
}
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsfree
static inline BOOL TlsFree(DWORD dwTlsIndex) {
return pthread_key_delete(dwTlsIndex) == 0;
}
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsgetvalue
static inline LPVOID TlsGetValue(DWORD dwTlsIndex) {
return pthread_getspecific(dwTlsIndex);
}
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlssetvalue
static inline BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue) {
return pthread_setspecific(dwTlsIndex, lpTlsValue) == 0;
}
// https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalmemorystatus // https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalmemorystatus
static inline VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer) { static inline VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer) {
// TODO: Parse /proc/meminfo and set lpBuffer based on that. Probably will // TODO: Parse /proc/meminfo and set lpBuffer based on that. Probably will
@ -336,17 +314,7 @@ static inline VOID GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer) {
static inline DWORD GetLastError(VOID) { return errno; } static inline DWORD GetLastError(VOID) { return errno; }
static inline VOID Sleep(DWORD dwMilliseconds) { #ifdef __LP64__
struct timespec ts;
ts.tv_nsec = (dwMilliseconds * 1000000) % 1000000000;
ts.tv_sec = dwMilliseconds / 1000;
int ret;
do {
ret = nanosleep(&ts, &ts);
} while (ret == -1 && errno == EINTR);
}
static inline LONG64 InterlockedCompareExchangeRelease64( static inline LONG64 InterlockedCompareExchangeRelease64(
LONG64 volatile* Destination, LONG64 Exchange, LONG64 Comperand) { LONG64 volatile* Destination, LONG64 Exchange, LONG64 Comperand) {
LONG64 expected = Comperand; LONG64 expected = Comperand;
@ -354,6 +322,15 @@ static inline LONG64 InterlockedCompareExchangeRelease64(
__ATOMIC_RELEASE, __ATOMIC_RELAXED); __ATOMIC_RELEASE, __ATOMIC_RELAXED);
return expected; return expected;
} }
#else
static inline LONG64 InterlockedCompareExchangeRelease(
LONG volatile* Destination, LONG Exchange, LONG Comperand) {
LONG expected = Comperand;
__atomic_compare_exchange_n(Destination, &expected, Exchange, false,
__ATOMIC_RELEASE, __ATOMIC_RELAXED);
return expected;
}
#endif
// internal helper: convert time_t to FILETIME (100ns intervals since // internal helper: convert time_t to FILETIME (100ns intervals since
// 1601-01-01) // 1601-01-01)

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "LevelRenderer.h" #include "LevelRenderer.h"
#include <cmath> #include <cmath>
@ -2321,7 +2324,7 @@ bool LevelRenderer::updateDirtyChunks() {
} }
LeaveCriticalSection(&m_csDirtyChunks); LeaveCriticalSection(&m_csDirtyChunks);
#ifdef __PS3__ #ifdef __PS3__
Sleep(5); std::this_thread::sleep_for(std::chrono::milliseconds(5));
#endif // __PS3__ #endif // __PS3__
return false; return false;
} }

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "../../Util/StringHelpers.h" #include "../../Util/StringHelpers.h"
#include "../../Util/PortableFileIO.h" #include "../../Util/PortableFileIO.h"
@ -664,7 +667,7 @@ void ConsoleSaveFileOriginal::Flush(bool autosave, bool updateThumbnail) {
// save/save-exiting so seems prudent to wait for idle // save/save-exiting so seems prudent to wait for idle
while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle) { while (StorageManager.GetSaveState() != C4JStorage::ESaveGame_Idle) {
app.DebugPrintf("Flush wait\n"); app.DebugPrintf("Flush wait\n");
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
#endif #endif

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "../../Util/StringHelpers.h" #include "../../Util/StringHelpers.h"
#include "../../Util/PortableFileIO.h" #include "../../Util/PortableFileIO.h"
@ -1298,7 +1301,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
#endif #endif
app.DebugPrintf("Flush wait\n"); app.DebugPrintf("Flush wait\n");
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
finalizeWrite(); finalizeWrite();

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "../../Headers/net.minecraft.world.level.h" #include "../../Headers/net.minecraft.world.level.h"
#include "../../IO/Files/ConsoleSaveFileIO.h" #include "../../IO/Files/ConsoleSaveFileIO.h"
@ -388,9 +391,10 @@ int McRegionChunkStorage::runSaveThreadProc(void* lpParam) {
// If there was more than one thing in the queue last time we checked, // If there was more than one thing in the queue last time we checked,
// then we want to spin round again soon Otherwise wait a bit longer // then we want to spin round again soon Otherwise wait a bit longer
if ((lastQueueSize - 1) > 0) if ((lastQueueSize - 1) > 0)
Sleep(1); // Sleep 1 to yield std::this_thread::sleep_for(
std::chrono::milliseconds(1)); // Sleep 1 to yield
else else
Sleep(100); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
Compression::ReleaseThreadStorage(); Compression::ReleaseThreadStorage();
@ -410,7 +414,7 @@ void McRegionChunkStorage::WaitForAllSaves() {
LeaveCriticalSection(&cs_memory); LeaveCriticalSection(&cs_memory);
while (queueSize > 0) { while (queueSize > 0) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
EnterCriticalSection(&cs_memory); EnterCriticalSection(&cs_memory);
queueSize = s_chunkDataQueue.size(); queueSize = s_chunkDataQueue.size();
@ -424,7 +428,7 @@ void McRegionChunkStorage::WaitForAllSaves() {
LeaveCriticalSection(&cs_memory); LeaveCriticalSection(&cs_memory);
while (runningThreadCount > 0) { while (runningThreadCount > 0) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
EnterCriticalSection(&cs_memory); EnterCriticalSection(&cs_memory);
runningThreadCount = s_runningThreadCount; runningThreadCount = s_runningThreadCount;
@ -444,7 +448,7 @@ void McRegionChunkStorage::WaitForSaves() {
if (queueSize > MAX_QUEUE_SIZE) { if (queueSize > MAX_QUEUE_SIZE) {
while (queueSize > DESIRED_QUEUE_SIZE) { while (queueSize > DESIRED_QUEUE_SIZE) {
Sleep(10); std::this_thread::sleep_for(std::chrono::milliseconds(10));
EnterCriticalSection(&cs_memory); EnterCriticalSection(&cs_memory);
queueSize = s_chunkDataQueue.size(); queueSize = s_chunkDataQueue.size();

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "../IO/Streams/InputOutputStream.h" #include "../IO/Streams/InputOutputStream.h"
#include "Socket.h" #include "Socket.h"
@ -577,7 +580,7 @@ int Connection::runRead(void* lpParam) {
while (con->readTick()); while (con->readTick());
// try { // try {
// Sleep(100L); // std::this_thread::sleep_for(std::chrono::milliseconds(100L));
// TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure
// whether we should do that as well // whether we should do that as well
con->m_hWakeReadThread->WaitForSignal(100L); con->m_hWakeReadThread->WaitForSignal(100L);
@ -626,7 +629,7 @@ int Connection::runWrite(void* lpParam) {
ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads)) { ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads)) {
while (con->writeTick()); while (con->writeTick());
// Sleep(100L); // std::this_thread::sleep_for(std::chrono::milliseconds(100L));
// TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure
// whether we should do that as well // whether we should do that as well
waitResult = con->m_hWakeWriteThread->WaitForSignal(100L); waitResult = con->m_hWakeWriteThread->WaitForSignal(100L);

View file

@ -1,3 +1,6 @@
#include <thread>
#include <chrono>
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "../IO/Streams/InputOutputStream.h" #include "../IO/Streams/InputOutputStream.h"
#include "SocketAddress.h" #include "SocketAddress.h"
@ -250,7 +253,7 @@ int Socket::SocketInputStreamLocal::read() {
} }
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]); LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
return -1; return -1;
} }
@ -277,7 +280,7 @@ int Socket::SocketInputStreamLocal::read(byteArray b, unsigned int offset,
} }
LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]); LeaveCriticalSection(&s_hostQueueLock[m_queueIdx]);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
return -1; return -1;
} }
@ -356,7 +359,7 @@ int Socket::SocketInputStreamNetwork::read() {
} }
LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]); LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
return -1; return -1;
} }
@ -385,7 +388,7 @@ int Socket::SocketInputStreamNetwork::read(byteArray b, unsigned int offset,
} }
LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]); LeaveCriticalSection(&m_socket->m_queueLockNetwork[m_queueIdx]);
} }
Sleep(1); std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
return -1; return -1;
} }

View file

@ -9,8 +9,8 @@
#include "HitResult.h" #include "HitResult.h"
#include "Util/Vec3.h" #include "Util/Vec3.h"
unsigned int AABB::tlsIdx = 0; thread_local AABB::ThreadStorage* AABB::m_tlsPool = nullptr;
AABB::ThreadStorage* AABB::tlsDefault = NULL; AABB::ThreadStorage* AABB::m_tlsPoolDefault = nullptr;
AABB::ThreadStorage::ThreadStorage() { AABB::ThreadStorage::ThreadStorage() {
pool = new AABB[POOL_SIZE]; // 4jcraft, needs to be deleted with delete[] pool = new AABB[POOL_SIZE]; // 4jcraft, needs to be deleted with delete[]
@ -23,21 +23,18 @@ AABB::ThreadStorage::~ThreadStorage() {
void AABB::CreateNewThreadStorage() { void AABB::CreateNewThreadStorage() {
ThreadStorage* tls = new ThreadStorage(); ThreadStorage* tls = new ThreadStorage();
if (tlsDefault == NULL) { if (m_tlsPoolDefault == nullptr) {
tlsIdx = TlsAlloc(); m_tlsPoolDefault = tls;
tlsDefault = tls;
} }
m_tlsPool = tls;
TlsSetValue(tlsIdx, tls);
} }
void AABB::UseDefaultThreadStorage() { TlsSetValue(tlsIdx, tlsDefault); } void AABB::UseDefaultThreadStorage() { m_tlsPool = m_tlsPoolDefault; }
void AABB::ReleaseThreadStorage() { void AABB::ReleaseThreadStorage() {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx); if (m_tlsPool != m_tlsPoolDefault) {
if (tls == tlsDefault) return; delete m_tlsPool;
}
delete tls;
} }
AABB* AABB::newPermanent(double x0, double y0, double z0, double x1, double y1, AABB* AABB::newPermanent(double x0, double y0, double z0, double x1, double y1,
@ -51,7 +48,7 @@ void AABB::resetPool() {}
AABB* AABB::newTemp(double x0, double y0, double z0, double x1, double y1, AABB* AABB::newTemp(double x0, double y0, double z0, double x1, double y1,
double z1) { double z1) {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx); ThreadStorage* tls = m_tlsPool;
AABB* thisAABB = &tls->pool[tls->poolPointer]; AABB* thisAABB = &tls->pool[tls->poolPointer];
thisAABB->set(x0, y0, z0, x1, y1, z1); thisAABB->set(x0, y0, z0, x1, y1, z1);
tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE; tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE;

View file

@ -15,8 +15,8 @@ class AABB {
ThreadStorage(); ThreadStorage();
~ThreadStorage(); ~ThreadStorage();
}; };
static unsigned int tlsIdx; static thread_local ThreadStorage* m_tlsPool;
static ThreadStorage* tlsDefault; static ThreadStorage* m_tlsPoolDefault;
public: public:
// Each new thread that needs to use Vec3 pools will need to call one of the // Each new thread that needs to use Vec3 pools will need to call one of the

View file

@ -1,6 +1,8 @@
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "C4JThread.h" #include "C4JThread.h"
#include <thread>
#include <chrono>
#ifdef __PSVITA__ #ifdef __PSVITA__
#include "../../Minecraft.Client/Platform/PSVita/PSVitaExtras/ShutdownManager.h" #include "../../Minecraft.Client/Platform/PSVita/PSVitaExtras/ShutdownManager.h"
#include "../../Minecraft.Client/Platform/PSVita/PSVitaExtras/PSVitaTLSStorage.h" #include "../../Minecraft.Client/Platform/PSVita/PSVitaExtras/PSVitaTLSStorage.h"
@ -443,7 +445,7 @@ void C4JThread::Sleep(int millisecs) {
// 4J Stu - 0 is an error, so add a tiny sleep when we just want to yield // 4J Stu - 0 is an error, so add a tiny sleep when we just want to yield
sceKernelDelayThread(millisecs * 1000 + 1); sceKernelDelayThread(millisecs * 1000 + 1);
#else #else
::Sleep(millisecs); std::this_thread::sleep_for(std::chrono::milliseconds(millisecs));
#endif // __PS3__ #endif // __PS3__
} }