diff --git a/src/client/Chunk.cpp b/src/client/Chunk.cpp index 78e2f40d..b22c6d70 100644 --- a/src/client/Chunk.cpp +++ b/src/client/Chunk.cpp @@ -46,7 +46,7 @@ Tesselator *Chunk::t = Tesselator::getInstance(); LevelRenderer *Chunk::levelRenderer; // TODO - 4J see how input entity vector is set up and decide what way is best to pass this to the function -Chunk::Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, CRITICAL_SECTION& globalRenderableTileEntities_cs, int x, int y, int z, ClipChunk *clipChunk) +Chunk::Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, ThreadLock& globalRenderableTileEntities_cs, int x, int y, int z, ClipChunk *clipChunk) : globalRenderableTileEntities( &globalRenderableTileEntities ), globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) { clipChunk->visible = false; diff --git a/src/client/Chunk.h b/src/client/Chunk.h index 497dd687..3d57ccb2 100644 --- a/src/client/Chunk.h +++ b/src/client/Chunk.h @@ -56,10 +56,10 @@ public: private: LevelRenderer::rteMap *globalRenderableTileEntities; - CRITICAL_SECTION *globalRenderableTileEntities_cs; + ThreadLock *globalRenderableTileEntities_cs; bool assigned; public: - Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, CRITICAL_SECTION &globalRenderableTileEntities_cs, int x, int y, int z, ClipChunk *clipChunk); + Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, ThreadLock &globalRenderableTileEntities_cs, int x, int y, int z, ClipChunk *clipChunk); Chunk(); void setPos(int x, int y, int z); diff --git a/src/client/Common/Audio/SoundEngine.cpp b/src/client/Common/Audio/SoundEngine.cpp index 7a9d7057..e52dd57a 100644 --- a/src/client/Common/Audio/SoundEngine.cpp +++ b/src/client/Common/Audio/SoundEngine.cpp @@ -176,7 +176,7 @@ void AILCALL ErrorCallback(S64 i_Id, char const* i_Details) // AP - this is the callback when the driver is about to mix. At this point the mutex is locked by Miles so we can now call all Miles functions without // the possibility of incurring a stall. static bool SoundEngine_Change = false; // has tick been called? -static CRITICAL_SECTION SoundEngine_MixerMutex; +static ThreadLock SoundEngine_MixerMutex; void AILCALL MilesMixerCB(HDIGDRIVER dig) { diff --git a/src/client/Common/C4JMemoryPool.h b/src/client/Common/C4JMemoryPool.h index e1e795ec..c5ee2d6f 100644 --- a/src/client/Common/C4JMemoryPool.h +++ b/src/client/Common/C4JMemoryPool.h @@ -28,7 +28,7 @@ class C4JMemoryPoolFixed : public C4JMemoryPool uchar* m_memStart; // Beginning of memory pool uchar* m_memEnd; // End of memory pool uchar* m_next; // Num of next free block -// CRITICAL_SECTION m_CS; +// ThreadLock m_CS; public: C4JMemoryPoolFixed() { diff --git a/src/client/Common/Consoles_App.cpp b/src/client/Common/Consoles_App.cpp index 0ad9c8d8..58d92f4d 100644 --- a/src/client/Common/Consoles_App.cpp +++ b/src/client/Common/Consoles_App.cpp @@ -5325,8 +5325,8 @@ int CMinecraftApp::DLCMountedCallback(void* pParam,int iPad,unsigned long dwErr, m_Time.qwAppTime.QuadPart += qwDeltaTime.QuadPart; m_Time.qwTime.QuadPart = qwNewTime.QuadPart; - m_Time.fElapsedTime = m_Time.fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); - m_Time.fAppTime = m_Time.fSecsPerTick * ((FLOAT)(m_Time.qwAppTime.QuadPart)); + m_Time.fElapsedTime = m_Time.fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); + m_Time.fAppTime = m_Time.fSecsPerTick * ((float)(m_Time.qwAppTime.QuadPart)); } diff --git a/src/client/Common/Consoles_App.h b/src/client/Common/Consoles_App.h index aea1eb75..2b24a44f 100644 --- a/src/client/Common/Consoles_App.h +++ b/src/client/Common/Consoles_App.h @@ -373,8 +373,8 @@ private: unordered_map m_MEM_Files; // for storing texture pack data files unordered_map m_MEM_TPD; - CRITICAL_SECTION csMemFilesLock; // For locking access to the above map - CRITICAL_SECTION csMemTPDLock; // For locking access to the above map + ThreadLock csMemFilesLock; // For locking access to the above map + ThreadLock csMemTPDLock; // For locking access to the above map VNOTIFICATIONS m_vNotifications; @@ -780,7 +780,7 @@ public: void EnterSaveNotificationSection(); void LeaveSaveNotificationSection(); private: - CRITICAL_SECTION m_saveNotificationCriticalSection; + ThreadLock m_saveNotificationCriticalSection; int m_saveNotificationDepth; // Download Status @@ -792,11 +792,11 @@ private: bool m_bAllDLCContentRetrieved; bool m_bAllTMSContentRetrieved; bool m_bTickTMSDLCFiles; - CRITICAL_SECTION csDLCDownloadQueue; - CRITICAL_SECTION csTMSPPDownloadQueue; - CRITICAL_SECTION csAdditionalModelParts; - CRITICAL_SECTION csAdditionalSkinBoxes; - CRITICAL_SECTION csAnimOverrideBitmask; + ThreadLock csDLCDownloadQueue; + ThreadLock csTMSPPDownloadQueue; + ThreadLock csAdditionalModelParts; + ThreadLock csAdditionalSkinBoxes; + ThreadLock csAnimOverrideBitmask; bool m_bCorruptSaveDeleted; unsigned long m_dwAdditionalModelParts[XUSER_MAX_COUNT]; diff --git a/src/client/Common/Network/Sony/SQRNetworkManager.h b/src/client/Common/Network/Sony/SQRNetworkManager.h index c93368d8..9f7e8f2d 100644 --- a/src/client/Common/Network/Sony/SQRNetworkManager.h +++ b/src/client/Common/Network/Sony/SQRNetworkManager.h @@ -229,8 +229,8 @@ protected: }; std::queue m_stateChangeQueue; - CRITICAL_SECTION m_csStateChangeQueue; - CRITICAL_SECTION m_csMatching; + ThreadLock m_csStateChangeQueue; + ThreadLock m_csMatching; typedef enum { diff --git a/src/client/Common/Network/Sony/SQRNetworkPlayer.h b/src/client/Common/Network/Sony/SQRNetworkPlayer.h index 0cd56e8d..ef083ef3 100644 --- a/src/client/Common/Network/Sony/SQRNetworkPlayer.h +++ b/src/client/Common/Network/Sony/SQRNetworkPlayer.h @@ -98,6 +98,6 @@ class SQRNetworkPlayer SQRNetworkManager *m_manager; // Pointer back to the manager that is managing this player wchar_t m_name[21]; uintptr_t m_customData; - CRITICAL_SECTION m_csQueue; + ThreadLock m_csQueue; std::queue m_sendQueue; }; diff --git a/src/client/Common/Network/Sony/SonyCommerce.cpp b/src/client/Common/Network/Sony/SonyCommerce.cpp index c6b76c7c..d4ac0fee 100644 --- a/src/client/Common/Network/Sony/SonyCommerce.cpp +++ b/src/client/Common/Network/Sony/SonyCommerce.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "SonyCommerce.h" -#include "PS3Extras/ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" #include @@ -31,7 +31,7 @@ bool SonyCommerce::m_bUpgradingTrial = false; SonyCommerce::CallbackFunc SonyCommerce::m_trialUpgradeCallbackFunc; void* SonyCommerce::m_trialUpgradeCallbackParam; -CRITICAL_SECTION SonyCommerce::m_queueLock; +ThreadLock SonyCommerce::m_queueLock; diff --git a/src/client/Common/Shutdown/ShutdownManager.cpp b/src/client/Common/Shutdown/ShutdownManager.cpp new file mode 100644 index 00000000..1cdf9979 --- /dev/null +++ b/src/client/Common/Shutdown/ShutdownManager.cpp @@ -0,0 +1,204 @@ +#include "stdafx.h" +#include "ShutdownManager.h" +#include "..\..\Common\Leaderboards\LeaderboardManager.h" +#include "..\..\MinecraftServer.h" +#ifdef __PS3__ +#include "C4JSpursJob.h" + + +bool ShutdownManager::s_threadShouldRun[ShutdownManager::eThreadIdCount]; +int ShutdownManager::s_threadRunning[ShutdownManager::eThreadIdCount]; +ThreadLock ShutdownManager::s_threadRunningCS; +C4JThread::EventArray *ShutdownManager::s_eventArray[eThreadIdCount]; +#endif + +// Initialises the shutdown manager - this needs to be called as soon as the game is started so it can respond as quickly as possible to shut down requests +void ShutdownManager::Initialise() +{ +#ifdef __PS3__ + cellSysutilRegisterCallback( 1, SysUtilCallback, NULL ); + for( int i = 0; i < eThreadIdCount; i++ ) + { + s_threadShouldRun[i] = true; + s_threadRunning[i] = 0; + s_eventArray[i] = NULL; + } + // Special case for storage manager, which we will manually set now to be considered as running - this will be unset by StorageManager.ExitRequest if required + s_threadRunning[eStorageManagerThreads] = true; + InitializeCriticalSection(&s_threadRunningCS); +#endif +} + +// Called in response to a system request to exit the game. This just requests that the main thread should stop, and then the main thread is responsible for calling MainThreadHandleShutdown which +// starts the rest of the shut down process, then waits until it is complete. +void ShutdownManager::StartShutdown() +{ +#ifdef __PS3__ + s_threadShouldRun[ eMainThread ] = false; +#endif +} + +// This should be called from the main thread after it has been requested to shut down (ShouldRun for main thread returns false), and before it returns control to the kernel. This is responsible for +// signalling to all other threads to stop, and wait until their completion before returning. +void ShutdownManager::MainThreadHandleShutdown() +{ +#ifdef __PS3__ + // Set flags for each thread which will be reset when they are complete + s_threadRunning[ eMainThread ] = false; + + // Second wave of things we would like to shut down (after main) + LeaderboardManager::Instance()->CancelOperation(); + RequestThreadToStop( eLeaderboardThread ); + RequestThreadToStop( eCommerceThread ); + RequestThreadToStop( ePostProcessThread ); + RequestThreadToStop( eRunUpdateThread ); + RequestThreadToStop( eRenderChunkUpdateThread ); + RequestThreadToStop( eConnectionReadThreads ); + RequestThreadToStop( eConnectionWriteThreads ); + RequestThreadToStop( eEventQueueThreads ); + app.DebugPrintf("Shutdown manager: waiting on first batch of threads requested to terminate...\n"); + WaitForSignalledToComplete(); + app.DebugPrintf("Shutdown manager: terminated.\n"); + + // Now shut down the server thread + MinecraftServer::HaltServer(); + RequestThreadToStop( eServerThread ); + app.DebugPrintf("Shutdown manager: waiting on server to terminate...\n"); + WaitForSignalledToComplete(); + app.DebugPrintf("Shutdown manager: terminated.\n"); + + //And shut down the storage manager + RequestThreadToStop( eStorageManagerThreads ); + StorageManager.ExitRequest(&StorageManagerCompleteFn); + app.DebugPrintf("Shutdown manager: waiting on storage manager to terminate...\n"); + WaitForSignalledToComplete(); + app.DebugPrintf("Shutdown manager: terminated.\n"); + + // Audio system shutdown + app.DebugPrintf("Shutdown manager: Audio shutdown.\n"); + AIL_shutdown(); + + // Trophy system shutdown + app.DebugPrintf("Shutdown manager: Trophy system shutdown.\n"); + ProfileManager.Terminate(); + + // Network manager shutdown + app.DebugPrintf("Shutdown manager: Network manager shutdown.\n"); + g_NetworkManager.Terminate(); + + // Finally shut down the spurs job queue - leaving until last so there should be nothing else dependent on this still running + app.DebugPrintf("Shutdown manager: SPURS shutdown.\n"); + C4JSpursJobQueue::getMainJobQueue().shutdown(); + app.DebugPrintf("Shutdown manager: Complete.\n"); +#endif +} + +void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId) +{ +#ifdef __PS3__ + EnterCriticalSection(&s_threadRunningCS); + s_threadRunning[threadId]++; + LeaveCriticalSection(&s_threadRunningCS); +#endif +} + +void ShutdownManager::HasStarted(ShutdownManager::EThreadId threadId, C4JThread::EventArray *eventArray) +{ +#ifdef __PS3__ + EnterCriticalSection(&s_threadRunningCS); + s_threadRunning[threadId]++; + LeaveCriticalSection(&s_threadRunningCS); + s_eventArray[threadId] = eventArray; +#endif +} + +bool ShutdownManager::ShouldRun(ShutdownManager::EThreadId threadId) +{ +#ifdef __PS3__ + return s_threadShouldRun[threadId]; +#else + return true; +#endif +} + +void ShutdownManager::HasFinished(ShutdownManager::EThreadId threadId) +{ +#ifdef __PS3__ + EnterCriticalSection(&s_threadRunningCS); + s_threadRunning[threadId]--; + LeaveCriticalSection(&s_threadRunningCS); +#endif +} + +#ifdef __PS3__ +void ShutdownManager::SysUtilCallback(uint64_t status, uint64_t param, void *userdata) +{ + Minecraft *minecraft = Minecraft::GetInstance(); + switch(status) + { + case CELL_SYSUTIL_REQUEST_EXITGAME: + app.DebugPrintf("CELL_SYSUTIL_REQUEST_EXITGAME\n"); + StartShutdown(); + break; + case CELL_SYSUTIL_SYSTEM_MENU_OPEN: + // Tell the game UI to stop processing + StorageManager.SetSystemUIDisplaying(true); + break; + case CELL_SYSUTIL_DRAWING_END: + StorageManager.SetSystemUIDisplaying(false); + break; + case CELL_SYSUTIL_DRAWING_BEGIN: + case CELL_SYSUTIL_SYSTEM_MENU_CLOSE: + break; + case CELL_SYSUTIL_BGMPLAYBACK_PLAY: + if( minecraft ) + { + minecraft->soundEngine->updateSystemMusicPlaying(true); + } + app.DebugPrintf("BGM playing\n"); + break; + case CELL_SYSUTIL_BGMPLAYBACK_STOP: + if( minecraft ) + { + minecraft->soundEngine->updateSystemMusicPlaying(false); + } + app.DebugPrintf("BGM stopped\n"); + break; + } +} +#endif + +#ifdef __PS3__ +void ShutdownManager::WaitForSignalledToComplete() +{ + bool allComplete; + do + { + cellSysutilCheckCallback(); + Sleep(10); + allComplete = true; + for( int i = 0; i < eThreadIdCount; i++ ) + { + if( !s_threadShouldRun[i] ) + { + if( s_threadRunning[i] != 0 ) allComplete = false; + } + } + } while( !allComplete); + +} + +void ShutdownManager::RequestThreadToStop(int i) +{ + s_threadShouldRun[i] = false; + if( s_eventArray[i] ) + { + s_eventArray[i]->Cancel(); + } +} + +void ShutdownManager::StorageManagerCompleteFn() +{ + HasFinished(eStorageManagerThreads); +} +#endif \ No newline at end of file diff --git a/src/client/Common/Shutdown/ShutdownManager.h b/src/client/Common/Shutdown/ShutdownManager.h new file mode 100644 index 00000000..889d40cb --- /dev/null +++ b/src/client/Common/Shutdown/ShutdownManager.h @@ -0,0 +1,47 @@ +#pragma once + +class ShutdownManager +{ +public: + typedef enum + { + eMainThread, + + eLeaderboardThread, + eCommerceThread, + ePostProcessThread, + eRunUpdateThread, + eRenderChunkUpdateThread, + eServerThread, + eStorageManagerThreads, + eConnectionReadThreads, + eConnectionWriteThreads, + eEventQueueThreads, + + eThreadIdCount + } EThreadId; + + static void Initialise(); + static void StartShutdown(); + static void MainThreadHandleShutdown(); +#ifdef __PS3__ + static void SysUtilCallback(uint64_t status, uint64_t param, void *userdata); +#endif + + static void HasStarted(EThreadId threadId); + static void HasStarted(EThreadId threadId, C4JThread::EventArray *eventArray); + static bool ShouldRun(EThreadId threadId); + static void HasFinished(EThreadId threadId); + +private: +#ifdef __PS3__ + static bool s_threadShouldRun[eThreadIdCount]; + static int s_threadRunning[eThreadIdCount]; + static ThreadLock s_threadRunningCS; + static C4JThread::EventArray *s_eventArray[eThreadIdCount]; + + static void RequestThreadToStop(int i); + static void WaitForSignalledToComplete(); + static void StorageManagerCompleteFn(); +#endif +}; diff --git a/src/client/Common/ThreadLock.cpp b/src/client/Common/ThreadLock.cpp new file mode 100644 index 00000000..f14a3612 --- /dev/null +++ b/src/client/Common/ThreadLock.cpp @@ -0,0 +1,33 @@ +#include "ThreadLock.h" + +ThreadLock::ThreadLock() +{ +#ifdef _XBOX + InitializeCriticalSection(&m_cs); +#endif +} + +ThreadLock::~ThreadLock() +{ +#ifdef _XBOX + DeleteCriticalSection(&m_cs); +#endif +} + +void ThreadLock::lock() +{ +#ifdef _XBOX + EnterCriticalSection(&m_cs); +#else + m_mutex.lock(); +#endif +} + +void ThreadLock::unlock() +{ +#ifdef _XBOX + LeaveCriticalSection(&m_cs); +#else + m_mutex.unlock(); +#endif +} \ No newline at end of file diff --git a/src/client/Common/ThreadLock.h b/src/client/Common/ThreadLock.h new file mode 100644 index 00000000..82695f18 --- /dev/null +++ b/src/client/Common/ThreadLock.h @@ -0,0 +1,24 @@ +#pragma once + +#ifdef _XBOX +#include +#else +#include +#endif + +class ThreadLock +{ +public: + ThreadLock(); + ~ThreadLock(); + + void lock(); + void unlock(); + +private: +#ifdef _XBOX + CRITICAL_SECTION m_cs; +#else + std::mutex m_mutex; +#endif +}; \ No newline at end of file diff --git a/src/client/Common/UI/UIController.cpp b/src/client/Common/UI/UIController.cpp index c0a303ec..3533b7fa 100644 --- a/src/client/Common/UI/UIController.cpp +++ b/src/client/Common/UI/UIController.cpp @@ -47,7 +47,7 @@ #endif -CRITICAL_SECTION UIController::ms_reloadSkinCS; +ThreadLock UIController::ms_reloadSkinCS; bool UIController::ms_bReloadSkinCSInitialised = false; unsigned long UIController::m_dwTrialTimerLimitSecs=DYNAMIC_CONFIG_DEFAULT_TRIAL_TIME; diff --git a/src/client/Common/UI/UIController.h b/src/client/Common/UI/UIController.h index 75ddd17b..fa2a9423 100644 --- a/src/client/Common/UI/UIController.h +++ b/src/client/Common/UI/UIController.h @@ -18,7 +18,7 @@ public: static int64_t iggyAllocCount; // MGH - added to prevent crash loading Iggy movies while the skins were being reloaded - static CRITICAL_SECTION ms_reloadSkinCS; + static ThreadLock ms_reloadSkinCS; static bool ms_bReloadSkinCSInitialised; protected: @@ -26,7 +26,7 @@ protected: UIComponent_DebugUIMarketingGuide *m_uiDebugMarketingGuide; private: - CRITICAL_SECTION m_navigationLock; + ThreadLock m_navigationLock; static const int UI_REPEAT_KEY_DELAY_MS = 300; // How long from press until the first repeat static const int UI_REPEAT_KEY_REPEAT_RATE_MS = 100; // How long in between repeats @@ -140,7 +140,7 @@ private: D3D11_RECT m_customRenderingClearRect; unordered_map m_registeredCallbackScenes; // A collection of scenes and unique id's that are used in async callbacks so we can safely handle when they get destroyed - CRITICAL_SECTION m_registeredCallbackScenesCS;; + ThreadLock m_registeredCallbackScenesCS;; public: UIController(); @@ -180,7 +180,7 @@ protected: public: - CRITICAL_SECTION m_Allocatorlock; + ThreadLock m_Allocatorlock; void SetupFont(); public: // TICKING diff --git a/src/client/Common/UI/UIScene.cpp b/src/client/Common/UI/UIScene.cpp index 6c37c50b..97debb5d 100644 --- a/src/client/Common/UI/UIScene.cpp +++ b/src/client/Common/UI/UIScene.cpp @@ -263,7 +263,7 @@ bool UIScene::mapElementsAndNames() return true; } -extern CRITICAL_SECTION s_loadSkinCS; +extern ThreadLock s_loadSkinCS; void UIScene::loadMovie() { EnterCriticalSection(&UIController::ms_reloadSkinCS); // MGH - added to prevent crash loading Iggy movies while the skins were being reloaded diff --git a/src/client/Common/UI/UIScene_SkinSelectMenu.h b/src/client/Common/UI/UIScene_SkinSelectMenu.h index a06fa848..67073051 100644 --- a/src/client/Common/UI/UIScene_SkinSelectMenu.h +++ b/src/client/Common/UI/UIScene_SkinSelectMenu.h @@ -184,6 +184,6 @@ private: #endif #ifdef __PSVITA__ - CRITICAL_SECTION m_DLCInstallCS; // to prevent a race condition between the install and the mounted callback + ThreadLock m_DLCInstallCS; // to prevent a race condition between the install and the mounted callback #endif }; diff --git a/src/client/Common/XUI/XUI_Ctrl_4JList.h b/src/client/Common/XUI/XUI_Ctrl_4JList.h index d7c62119..063d2157 100644 --- a/src/client/Common/XUI/XUI_Ctrl_4JList.h +++ b/src/client/Common/XUI/XUI_Ctrl_4JList.h @@ -67,7 +67,7 @@ protected: int OnNotifySelChanged( HXUIOBJ hObjSource, XUINotifySelChanged* pNotifySelChangedData, bool& bHandled ); LISTITEMINFOARRAY m_vListData; - CRITICAL_SECTION m_AccessListData; + ThreadLock m_AccessListData; private: static bool AlphabeticSortFn(const void *a, const void *b); diff --git a/src/client/Durango/4JLibs/inc/4J_Input.h b/src/client/Durango/4JLibs/inc/4J_Input.h index 916ae042..cf3174be 100644 --- a/src/client/Durango/4JLibs/inc/4J_Input.h +++ b/src/client/Durango/4JLibs/inc/4J_Input.h @@ -111,7 +111,7 @@ public: void SetJoypadStickTriggerMap(int iPad,unsigned int uiFrom, unsigned int uiTo); void SetKeyRepeatRate(float fRepeatDelaySecs,float fRepeatRateSecs); void SetDebugSequence( const char *chSequenceA,int( *Func)(void*),void* lpParam ); - FLOAT GetIdleSeconds(int iPad); + float GetIdleSeconds(int iPad); unsigned int GetConnectedGamepadCount(); bool IsPadConnected(int iPad); bool IsPadLocked(int iPad); diff --git a/src/client/Durango/ApplicationView.cpp b/src/client/Durango/ApplicationView.cpp index 775d4fab..d1ffe113 100644 --- a/src/client/Durango/ApplicationView.cpp +++ b/src/client/Durango/ApplicationView.cpp @@ -31,7 +31,7 @@ unordered_map tracker; static volatile bool memDump = false; static volatile bool memReset = false; static bool memDumpInit = false; -static CRITICAL_SECTION memTrackCS; +static ThreadLock memTrackCS; static volatile size_t memSizeComp = 0; static long long lastTrackTime = 0; @@ -275,7 +275,7 @@ void ApplicationView::OnSuspending(Platform::Object^ sender, SuspendingEventArgs QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Entire suspend process: Elapsed time %f\n", fElapsedTime); } diff --git a/src/client/Durango/Durango_Minecraft.cpp b/src/client/Durango/Durango_Minecraft.cpp index 83b657bb..5c6e3e99 100644 --- a/src/client/Durango/Durango_Minecraft.cpp +++ b/src/client/Durango/Durango_Minecraft.cpp @@ -990,7 +990,7 @@ bool trackStarted = false; volatile size_t sizeCheckMin = 1160; volatile size_t sizeCheckMax = 1160; volatile int sectCheck = 48; -CRITICAL_SECTION memCS; +ThreadLock memCS; unsigned long tlsIdx; void* XMemAlloc(size_t dwSize, unsigned long dwAllocAttributes) diff --git a/src/client/Durango/Leaderboards/DurangoLeaderboardManager.h b/src/client/Durango/Leaderboards/DurangoLeaderboardManager.h index 76c7447f..1e70f0a4 100644 --- a/src/client/Durango/Leaderboards/DurangoLeaderboardManager.h +++ b/src/client/Durango/Leaderboards/DurangoLeaderboardManager.h @@ -28,7 +28,7 @@ protected: private: unsigned short m_openSessions; - CRITICAL_SECTION m_csStatsState; + ThreadLock m_csStatsState; EStatsState m_eStatsState; //State of the stats read ReadScore *m_scores; diff --git a/src/client/Durango/Leaderboards/DurangoStatsDebugger.h b/src/client/Durango/Leaderboards/DurangoStatsDebugger.h index f2ac0383..4ff4293b 100644 --- a/src/client/Durango/Leaderboards/DurangoStatsDebugger.h +++ b/src/client/Durango/Leaderboards/DurangoStatsDebugger.h @@ -86,7 +86,7 @@ private: wstring m_score; } StatResult; - CRITICAL_SECTION m_retrievedStatsLock; + ThreadLock m_retrievedStatsLock; vector m_retrievedStats; diff --git a/src/client/Durango/Network/ChatIntegrationLayer.h b/src/client/Durango/Network/ChatIntegrationLayer.h index 80b4e10a..61d2d0c1 100644 --- a/src/client/Durango/Network/ChatIntegrationLayer.h +++ b/src/client/Durango/Network/ChatIntegrationLayer.h @@ -52,7 +52,7 @@ public: void EvaluateDevicesForUser(__in Windows::Xbox::System::IUser^ user ); vector m_addedUsers; - CRITICAL_SECTION m_csAddedUsers; + ThreadLock m_csAddedUsers; private: /// diff --git a/src/client/Durango/Network/DQRNetworkManager.h b/src/client/Durango/Network/DQRNetworkManager.h index 1d6bc005..660c2962 100644 --- a/src/client/Durango/Network/DQRNetworkManager.h +++ b/src/client/Durango/Network/DQRNetworkManager.h @@ -327,13 +327,13 @@ protected: }; std::queue m_stateChangeQueue; - CRITICAL_SECTION m_csStateChangeQueue; - CRITICAL_SECTION m_csSendBytes; - CRITICAL_SECTION m_csPartyViewVector; + ThreadLock m_csStateChangeQueue; + ThreadLock m_csSendBytes; + ThreadLock m_csPartyViewVector; std::queue m_RTSMessageQueueIncoming; - CRITICAL_SECTION m_csRTSMessageQueueIncoming; + ThreadLock m_csRTSMessageQueueIncoming; std::queue m_RTSMessageQueueOutgoing; - CRITICAL_SECTION m_csRTSMessageQueueOutgoing; + ThreadLock m_csRTSMessageQueueOutgoing; private: void SetState(DQRNetworkManager::eDQRNetworkManagerInternalState state); static const eDQRNetworkManagerState m_INTtoEXTStateMappings[DNM_INT_STATE_COUNT]; @@ -359,7 +359,7 @@ private: MXS::XboxLiveContext^ m_primaryUserXboxLiveContext; WXN::SecureDeviceAssociationTemplate^ m_associationTemplate; - CRITICAL_SECTION m_csRoomSyncData; + ThreadLock m_csRoomSyncData; RoomSyncData m_roomSyncData; DQRNetworkPlayer *m_players[MAX_ONLINE_PLAYER_COUNT]; @@ -403,7 +403,7 @@ private: DQRConnectionInfo m_connectionInfoClient; // For client unsigned int m_hostSessionAddress; // For client - CRITICAL_SECTION m_csHostGamertagResolveResults; + ThreadLock m_csHostGamertagResolveResults; queue m_hostGamertagResolveResults; void AddPlayerFailed(Platform::String ^xuid); @@ -460,7 +460,7 @@ private: static int _RTSDoWorkThread(void* lpParameter); int RTSDoWorkThread(); - CRITICAL_SECTION m_csVecChatPlayers; + ThreadLock m_csVecChatPlayers; vector m_vecChatPlayersJoined; public: void HandleNewPartyFoundForPlayer(); diff --git a/src/client/GameRenderer.cpp b/src/client/GameRenderer.cpp index d559f13e..42dfc063 100644 --- a/src/client/GameRenderer.cpp +++ b/src/client/GameRenderer.cpp @@ -44,7 +44,7 @@ #include "HumanoidModel.h" #include "Item.h" #include "compression.h" -#include "PS3\PS3Extras\ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" #include "TexturePackRepository.h" #include "TexturePack.h" @@ -62,7 +62,7 @@ vector GameRenderer::m_deleteStackSparseLightStorage; vector GameRenderer::m_deleteStackCompressedTileStorage; vector GameRenderer::m_deleteStackSparseDataStorage; #endif -CRITICAL_SECTION GameRenderer::m_csDeleteStack; +ThreadLock GameRenderer::m_csDeleteStack; GameRenderer::GameRenderer(Minecraft *mc) { diff --git a/src/client/GameRenderer.h b/src/client/GameRenderer.h index a6568b49..1ed5c833 100644 --- a/src/client/GameRenderer.h +++ b/src/client/GameRenderer.h @@ -160,7 +160,7 @@ public: static vector m_deleteStackSparseLightStorage; static vector m_deleteStackCompressedTileStorage; static vector m_deleteStackSparseDataStorage; - static CRITICAL_SECTION m_csDeleteStack; + static ThreadLock m_csDeleteStack; static void AddForDelete(byte *deleteThis); static void AddForDelete(SparseLightStorage *deleteThis); static void AddForDelete(CompressedTileStorage *deleteThis); diff --git a/src/client/LevelRenderer.h b/src/client/LevelRenderer.h index bb1dacf0..7b45a99e 100644 --- a/src/client/LevelRenderer.h +++ b/src/client/LevelRenderer.h @@ -126,7 +126,7 @@ private: // 4J - this block of declarations was scattered round the code but have gathered everything into one place rteMap renderableTileEntities; // 4J - changed - was vector, now hashed by chunk so we can find them - CRITICAL_SECTION m_csRenderableTileEntities; + ThreadLock m_csRenderableTileEntities; MultiPlayerLevel *level[4]; // 4J - now one per player Textures *textures; // vector *sortedChunks[4]; // 4J - removed - not sorting our chunks anymore @@ -164,7 +164,7 @@ private: public: void fullyFlagRenderableTileEntitiesToBeRemoved(); // 4J added - CRITICAL_SECTION m_csDirtyChunks; + ThreadLock m_csDirtyChunks; bool m_nearDirtyChunk; @@ -186,7 +186,7 @@ public: RecentTile(int x, int y, int z, Level *level); ~RecentTile(); }; - CRITICAL_SECTION m_csDestroyedTiles; + ThreadLock m_csDestroyedTiles; vector m_destroyedTiles; public: void destroyingTileAt( Level *level, int x, int y, int z ); // For game to let this manager know that a tile is about to be destroyed (must be called before it actually is) @@ -271,7 +271,7 @@ public: static void staticCtor(); static int rebuildChunkThreadProc(void* lpParam); - CRITICAL_SECTION m_csChunkFlags; + ThreadLock m_csChunkFlags; #endif void nonStackDirtyChunksAdded(); }; diff --git a/src/client/Minecraft.h b/src/client/Minecraft.h index 1f522798..a2996a0e 100644 --- a/src/client/Minecraft.h +++ b/src/client/Minecraft.h @@ -310,7 +310,7 @@ public: // 4J Stu void forceStatsSave(int idx); - CRITICAL_SECTION m_setLevelCS; + ThreadLock m_setLevelCS; private: // A bit field that store whether a particular quadrant is in the full tutorial or not uint8_t m_inFullTutorialBits; diff --git a/src/client/MinecraftServer.cpp b/src/client/MinecraftServer.cpp index 0ddd3518..0479a9b8 100644 --- a/src/client/MinecraftServer.cpp +++ b/src/client/MinecraftServer.cpp @@ -43,7 +43,7 @@ #ifdef _XBOX #include "Common/XUI\XUI_DebugSetCamera.h" #endif -#include "PS3\PS3Extras\ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" #include "ServerCommandDispatcher.h" #include "BiomeSource.h" #include "PlayerChunkMap.h" @@ -842,7 +842,7 @@ void MinecraftServer::Suspend() QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); // 4J-JEV: Flush stats and call PlayerSessionExit. for (int iPad = 0; iPad < XUSER_MAX_COUNT; iPad++) @@ -1233,7 +1233,7 @@ void MinecraftServer::run(int64_t seed, void *lpParameter) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Autosave: Elapsed time %f\n", fElapsedTime); } break; diff --git a/src/client/MinecraftServer.h b/src/client/MinecraftServer.h index 1e116122..4692537b 100644 --- a/src/client/MinecraftServer.h +++ b/src/client/MinecraftServer.h @@ -205,7 +205,7 @@ private: postProcessRequest(int x, int z, ChunkSource *chunkSource) : x(x), z(z), chunkSource(chunkSource) {} }; vector m_postProcessRequests; - CRITICAL_SECTION m_postProcessCS; + ThreadLock m_postProcessCS; public: void addPostProcessRequest(ChunkSource *chunkSource, int x, int z); diff --git a/src/client/MultiPlayerChunkCache.h b/src/client/MultiPlayerChunkCache.h index 198260cb..6f3dd7de 100644 --- a/src/client/MultiPlayerChunkCache.h +++ b/src/client/MultiPlayerChunkCache.h @@ -18,7 +18,7 @@ private: LevelChunk **cache; // 4J - added for multithreaded support - CRITICAL_SECTION m_csLoadCreate; + ThreadLock m_csLoadCreate; // 4J - size of cache is defined by size of one side - must be even int XZSIZE; int XZOFFSET; diff --git a/src/client/PlayerConnection.h b/src/client/PlayerConnection.h index 4997dff1..dc762d0b 100644 --- a/src/client/PlayerConnection.h +++ b/src/client/PlayerConnection.h @@ -16,7 +16,7 @@ class PlayerConnection : public PacketListener, public ConsoleInputSource public: Connection *connection; bool done; - CRITICAL_SECTION done_cs; + ThreadLock done_cs; // 4J Stu - Added this so that we can manage UGC privileges PlayerUID m_offlineXUID, m_onlineXUID; diff --git a/src/client/PlayerList.h b/src/client/PlayerList.h index fb819799..c8fefd34 100644 --- a/src/client/PlayerList.h +++ b/src/client/PlayerList.h @@ -31,9 +31,9 @@ private: // 4J Added vector m_bannedXuids; deque m_smallIdsToKick; - CRITICAL_SECTION m_kickPlayersCS; + ThreadLock m_kickPlayersCS; deque m_smallIdsToClose; - CRITICAL_SECTION m_closePlayersCS; + ThreadLock m_closePlayersCS; /* 4J - removed Set bans = new HashSet(); Set ipBans = new HashSet(); diff --git a/src/client/ProgressRenderer.cpp b/src/client/ProgressRenderer.cpp index ccf78b4b..84addc59 100644 --- a/src/client/ProgressRenderer.cpp +++ b/src/client/ProgressRenderer.cpp @@ -4,7 +4,7 @@ #include "ProgressRenderer.h" #include "System.h" -CRITICAL_SECTION ProgressRenderer::s_progress; +ThreadLock ProgressRenderer::s_progress; ProgressRenderer::ProgressRenderer(Minecraft *minecraft) { diff --git a/src/client/ProgressRenderer.h b/src/client/ProgressRenderer.h index e8c19647..8b7dc4d1 100644 --- a/src/client/ProgressRenderer.h +++ b/src/client/ProgressRenderer.h @@ -10,7 +10,7 @@ public: eProgressStringType_String, // 4J-PB added for updating the bytes read on a save transfer }; - static CRITICAL_SECTION s_progress; + static ThreadLock s_progress; int getCurrentPercent(); int getCurrentTitle(); diff --git a/src/client/SDL/4JLibs/4J_Input.cpp b/src/client/SDL/4JLibs/4J_Input.cpp index 31e71b40..31e30e3d 100644 --- a/src/client/SDL/4JLibs/4J_Input.cpp +++ b/src/client/SDL/4JLibs/4J_Input.cpp @@ -165,7 +165,7 @@ void C_4JInput::SetDebugSequence(const char* chSequenceA, int(*Func)(void*), voi { } -FLOAT C_4JInput::GetIdleSeconds(int iPad) +float C_4JInput::GetIdleSeconds(int iPad) { return 0.0f; } diff --git a/src/client/SDL/4JLibs/4J_Input.h b/src/client/SDL/4JLibs/4J_Input.h index 88164e1e..c2516fea 100644 --- a/src/client/SDL/4JLibs/4J_Input.h +++ b/src/client/SDL/4JLibs/4J_Input.h @@ -45,16 +45,25 @@ #define TRIGGER_MAP_0 0 #define TRIGGER_MAP_1 1 +enum EKeyboardResult +{ + EKeyboard_Pending, + EKeyboard_Cancelled, + EKeyboard_ResultAccept, + EKeyboard_ResultDecline, +}; + +typedef struct _STRING_VERIFY_RESPONSE +{ + uint16_t wNumStrings; + int *pStringResult; +} +STRING_VERIFY_RESPONSE; + class C_4JInput { public: - enum EKeyboardResult - { - EKeyboard_Pending, - EKeyboard_Cancelled, - EKeyboard_ResultAccept, - EKeyboard_ResultDecline, - }; + enum EKeyboardMode { @@ -98,8 +107,10 @@ public: void SetMenuDisplayed(int iPad, bool bVal); - EKeyboardResult RequestKeyboard(unsigned int uiTitle, unsigned int uiText, unsigned int uiDesc, unsigned long dwPad, wchar_t *pwchResult, unsigned int uiResultSize,int( *Func)(void*,const bool),void* lpParam,EKeyboardMode eMode,CXuiStringTable *pStringTable=NULL); - EKeyboardResult RequestKeyboard(unsigned int uiTitle, const wchar_t* pwchDefault, unsigned int uiDesc, unsigned long dwPad, wchar_t *pwchResult, unsigned int uiResultSize,int( *Func)(void*,const bool),void* lpParam, EKeyboardMode eMode,CXuiStringTable *pStringTable=NULL); +// EKeyboardResult RequestKeyboard(unsigned int uiTitle, unsigned int uiText, unsigned int uiDesc, unsigned long dwPad, wchar_t *pwchResult, unsigned int uiResultSize,int( *Func)(void*,const bool),void* lpParam,EKeyboardMode eMode,C4JStringTable *pStringTable=NULL); +// EKeyboardResult RequestKeyboard(unsigned int uiTitle, const wchar_t* pwchDefault, unsigned int uiDesc, unsigned long dwPad, wchar_t *pwchResult, unsigned int uiResultSize,int( *Func)(void*,const bool),void* lpParam, EKeyboardMode eMode,C4JStringTable *pStringTable=NULL); + EKeyboardResult RequestKeyboard(const wchar_t* Title, const wchar_t* Text, unsigned long dwPad, unsigned int uiMaxChars, int( *Func)(void*,const bool),void* lpParam,C_4JInput::EKeyboardMode eMode); + void GetText(uint16_t *UTF16String); // Online check strings against offensive list - TCR 92 // TCR # 092 CMTV Player Text String Verification @@ -115,11 +126,10 @@ public: // Exemption It is not required to use the Xbox LIVE service to verify real-time text communication. An example of real-time text communication is in-game text chat. // // Intent Protect players from inappropriate language. -/* -bool VerifyStrings(wchar_t **pwStringA,int iStringC,int( *Func)(void*,STRING_VERIFY_RESPONSE *),void* lpParam); + bool VerifyStrings(wchar_t **pwStringA,int iStringC,int( *Func)(void*,STRING_VERIFY_RESPONSE *),void* lpParam); void CancelQueuedVerifyStrings(int( *Func)(void*,STRING_VERIFY_RESPONSE *),void* lpParam); void CancelAllVerifyInProgress(void); -*/ + //bool InputDetected(unsigned long dwUserIndex,wchar_t *pwchInput); }; diff --git a/src/client/ServerChunkCache.h b/src/client/ServerChunkCache.h index 90a20213..fa8050de 100644 --- a/src/client/ServerChunkCache.h +++ b/src/client/ServerChunkCache.h @@ -30,7 +30,7 @@ private: #endif // 4J - added for multithreaded support - CRITICAL_SECTION m_csLoadCreate; + ThreadLock m_csLoadCreate; // 4J - size of cache is defined by size of one side - must be even int XZSIZE; int XZOFFSET; diff --git a/src/client/ServerConnection.h b/src/client/ServerConnection.h index 56c5d39e..ca0c6cc4 100644 --- a/src/client/ServerConnection.h +++ b/src/client/ServerConnection.h @@ -19,7 +19,7 @@ public: private: int connectionCounter; private: - CRITICAL_SECTION pending_cs; // 4J added + ThreadLock pending_cs; // 4J added vector< shared_ptr > pending; vector< shared_ptr > players; diff --git a/src/client/ServerLevel.cpp b/src/client/ServerLevel.cpp index a6fa2d1a..1aa90a96 100644 --- a/src/client/ServerLevel.cpp +++ b/src/client/ServerLevel.cpp @@ -32,14 +32,14 @@ #include "TexturePackRepository.h" #include "DLCTexturePack.h" #include "ProgressListener.h" -#include "PS3\PS3Extras\ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" #include "PlayerChunkMap.h" WeighedTreasureArray ServerLevel::RANDOM_BONUS_ITEMS; C4JThread* ServerLevel::m_updateThread = NULL; C4JThread::EventArray* ServerLevel::m_updateTrigger; -CRITICAL_SECTION ServerLevel::m_updateCS[3]; +ThreadLock ServerLevel::m_updateCS[3]; Level *ServerLevel::m_level[3]; int ServerLevel::m_updateChunkX[3][LEVEL_CHUNKS_TO_UPDATE_MAX]; diff --git a/src/client/ServerLevel.h b/src/client/ServerLevel.h index a9e3999b..eae45ad7 100644 --- a/src/client/ServerLevel.h +++ b/src/client/ServerLevel.h @@ -17,12 +17,12 @@ private: EntityTracker *tracker; PlayerChunkMap *chunkMap; - CRITICAL_SECTION m_tickNextTickCS; // 4J added + ThreadLock m_tickNextTickCS; // 4J added set tickNextTickList; // 4J Was TreeSet unordered_set tickNextTickSet; // 4J Was HashSet vector m_queuedSendTileUpdates; // 4J added - CRITICAL_SECTION m_csQueueSendTileUpdates; + ThreadLock m_csQueueSendTileUpdates; protected: int saveInterval; @@ -133,7 +133,7 @@ public: int m_primedTntCount; int m_fallingTileCount; - CRITICAL_SECTION m_limiterCS; + ThreadLock m_limiterCS; list< shared_ptr > m_itemEntities; list< shared_ptr > m_hangingEntities; list< shared_ptr > m_arrowEntities; @@ -163,7 +163,7 @@ public: static int m_randValue[3]; static C4JThread::EventArray* m_updateTrigger; - static CRITICAL_SECTION m_updateCS[3]; + static ThreadLock m_updateCS[3]; static C4JThread* m_updateThread; static int runUpdate(void* lpParam); diff --git a/src/client/Windows64/4JLibs/inc/4J_Input.h b/src/client/Windows64/4JLibs/inc/4J_Input.h index c80ee20d..c2516fea 100644 --- a/src/client/Windows64/4JLibs/inc/4J_Input.h +++ b/src/client/Windows64/4JLibs/inc/4J_Input.h @@ -94,7 +94,7 @@ public: void SetJoypadStickTriggerMap(int iPad,unsigned int uiFrom, unsigned int uiTo); void SetKeyRepeatRate(float fRepeatDelaySecs,float fRepeatRateSecs); void SetDebugSequence( const char *chSequenceA,int( *Func)(void*),void* lpParam ); - FLOAT GetIdleSeconds(int iPad); + float GetIdleSeconds(int iPad); bool IsPadConnected(int iPad); // In-Game values which may have been remapped due to Southpaw, swap triggers, etc diff --git a/src/client/Windows64/Windows64_Minecraft.cpp b/src/client/Windows64/Windows64_Minecraft.cpp index c16024fd..a81905d3 100644 --- a/src/client/Windows64/Windows64_Minecraft.cpp +++ b/src/client/Windows64/Windows64_Minecraft.cpp @@ -559,8 +559,8 @@ app.DebugPrintf("width: %d, height: %d\n", width, height); // Setup the viewport D3D11_VIEWPORT vp; - vp.Width = (FLOAT)width; - vp.Height = (FLOAT)height; + vp.Width = (float)width; + vp.Height = (float)height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; @@ -1174,7 +1174,7 @@ bool trackStarted = false; volatile size_t sizeCheckMin = 1160; volatile size_t sizeCheckMax = 1160; volatile int sectCheck = 48; -CRITICAL_SECTION memCS; +ThreadLock memCS; unsigned long tlsIdx; void* XMemAlloc(size_t dwSize, unsigned long dwAllocAttributes) diff --git a/src/client/Xbox/4JLibs/inc/4J_Input.h b/src/client/Xbox/4JLibs/inc/4J_Input.h index 30f0c4da..88164e1e 100644 --- a/src/client/Xbox/4JLibs/inc/4J_Input.h +++ b/src/client/Xbox/4JLibs/inc/4J_Input.h @@ -85,7 +85,7 @@ public: void SetJoypadStickTriggerMap(int iPad,unsigned int uiFrom, unsigned int uiTo); void SetKeyRepeatRate(float fRepeatDelaySecs,float fRepeatRateSecs); void SetDebugSequence( const char *chSequenceA,int( *Func)(void*),void* lpParam ); - FLOAT GetIdleSeconds(int iPad); + float GetIdleSeconds(int iPad); bool IsPadConnected(int iPad); // In-Game values which may have been remapped due to Southpaw, swap triggers, etc diff --git a/src/client/Xbox/Audio/SoundEngine.cpp b/src/client/Xbox/Audio/SoundEngine.cpp index 1786e2d9..57b74b00 100644 --- a/src/client/Xbox/Audio/SoundEngine.cpp +++ b/src/client/Xbox/Audio/SoundEngine.cpp @@ -22,7 +22,7 @@ IXACT3WaveBank *SoundEngine::m_pStreamedWaveBank = NULL; IXACT3WaveBank *SoundEngine::m_pStreamedWaveBankAdditional = NULL; IXACT3SoundBank *SoundEngine::m_pSoundBank = NULL; IXACT3SoundBank *SoundEngine::m_pSoundBank2 = NULL; -CRITICAL_SECTION SoundEngine::m_CS; +ThreadLock SoundEngine::m_CS; X3DAUDIO_HANDLE SoundEngine::m_xact3dInstance; vector SoundEngine::currentSounds; diff --git a/src/client/Xbox/Audio/SoundEngine.h b/src/client/Xbox/Audio/SoundEngine.h index bbb4cf07..fe535379 100644 --- a/src/client/Xbox/Audio/SoundEngine.h +++ b/src/client/Xbox/Audio/SoundEngine.h @@ -38,7 +38,7 @@ class SoundEngine : public ConsoleSoundEngine static IXACT3SoundBank *m_pSoundBank; static IXACT3SoundBank *m_pSoundBank2; - static CRITICAL_SECTION m_CS; + static ThreadLock m_CS; struct soundInfo { diff --git a/src/client/Xbox/Font/XUI_Font.cpp b/src/client/Xbox/Font/XUI_Font.cpp index ceeb0f72..bede7504 100644 --- a/src/client/Xbox/Font/XUI_Font.cpp +++ b/src/client/Xbox/Font/XUI_Font.cpp @@ -50,21 +50,21 @@ XUI_Font::~XUI_Font() // Desc: Get the dimensions of a text string //-------------------------------------------------------------------------------------- -void XUI_Font::GetTextExtent( const wchar_t* strText, FLOAT* pWidth, - FLOAT* pHeight, bool bFirstLineOnly ) const +void XUI_Font::GetTextExtent( const wchar_t* strText, float* pWidth, + float* pHeight, bool bFirstLineOnly ) const { assert( pWidth != NULL ); assert( pHeight != NULL ); // Set default text extent in output parameters int iWidth = 0; - FLOAT fHeight = 0.0f; + float fHeight = 0.0f; if( strText ) { // Initialize counters that keep track of text extent int ix = 0; - FLOAT fy = m_fontData->getFontHeight(); // One character high to start + float fy = m_fontData->getFontHeight(); // One character high to start if( fy > fHeight ) fHeight = fy; @@ -104,7 +104,7 @@ void XUI_Font::GetTextExtent( const wchar_t* strText, FLOAT* pWidth, } // Convert the width to a float here, load/hit/store. :( - FLOAT fWidth = static_cast(iWidth); // Delay the use if fWidth to reduce LHS pain + float fWidth = static_cast(iWidth); // Delay the use if fWidth to reduce LHS pain // Apply the scale factor to the result fHeight *= m_fYScaleFactor; // Store the final results @@ -118,10 +118,10 @@ void XUI_Font::GetTextExtent( const wchar_t* strText, FLOAT* pWidth, // Name: GetTextWidth() // Desc: Returns the width in pixels of a text string //-------------------------------------------------------------------------------------- -FLOAT XUI_Font::GetTextWidth( const wchar_t* strText ) const +float XUI_Font::GetTextWidth( const wchar_t* strText ) const { - FLOAT fTextWidth; - FLOAT fTextHeight; + float fTextWidth; + float fTextHeight; GetTextExtent( strText, &fTextWidth, &fTextHeight ); return fTextWidth; } @@ -157,7 +157,7 @@ void XUI_Font::Begin() } //// Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc() - //FLOAT vTexScale[4]; + //float vTexScale[4]; //vTexScale[0] = 1.0f / TextureDesc.Width; // LHS due to int->float conversion //vTexScale[1] = 1.0f / TextureDesc.Height; //vTexScale[2] = 0.0f; @@ -191,7 +191,7 @@ void XUI_Font::Begin() // Desc: Draws text as textured polygons //-------------------------------------------------------------------------------------- void XUI_Font::DrawText( unsigned long dwColor, const wchar_t* strText, unsigned long dwFlags, - FLOAT fMaxPixelWidth ) + float fMaxPixelWidth ) { DrawText( m_fCursorX, m_fCursorY, dwColor, strText, dwFlags, fMaxPixelWidth ); } @@ -200,8 +200,8 @@ void XUI_Font::DrawText( unsigned long dwColor, const wchar_t* strText, unsigned // Name: DrawShadowText() // Desc: Draws text as textured polygons //-------------------------------------------------------------------------------------- -void XUI_Font::DrawShadowText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, unsigned long dwShadowColor, - const wchar_t* strText, unsigned long dwFlags, FLOAT fMaxPixelWidth) +void XUI_Font::DrawShadowText( float fOriginX, float fOriginY, unsigned long dwColor, unsigned long dwShadowColor, + const wchar_t* strText, unsigned long dwFlags, float fMaxPixelWidth) { float fXShadow=1.0f, fYShadow=1.0f; // 4J Stu - Don't move the drop shadow as much @@ -233,8 +233,8 @@ void XUI_Font::DrawShadowText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwC // TODO: This function should use the Begin/SetVertexData/End() API when it // becomes available. //-------------------------------------------------------------------------------------- -void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, - const wchar_t* strText, unsigned long dwFlags, FLOAT fMaxPixelWidth, bool darken /*= false*/ ) +void XUI_Font::DrawText( float fOriginX, float fOriginY, unsigned long dwColor, + const wchar_t* strText, unsigned long dwFlags, float fMaxPixelWidth, bool darken /*= false*/ ) { if( NULL == strText ) return; if( L'\0' == strText[0] ) return; @@ -316,7 +316,7 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, fOriginY -= m_fontData->getFontTopPadding(); XUI_FontData::SChar sChar = m_fontData->getChar(L'.'); - FLOAT fEllipsesPixelWidth = m_fXScaleFactor * 3.0f * (sChar.getOffset() + sChar.getWAdvance()); + float fEllipsesPixelWidth = m_fXScaleFactor * 3.0f * (sChar.getOffset() + sChar.getWAdvance()); if( dwFlags & ATGFONT_TRUNCATED ) { @@ -327,7 +327,7 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, } else { - FLOAT w, h; + float w, h; GetTextExtent( strText, &w, &h, true ); // If not, then clear the flag @@ -339,14 +339,14 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, // If vertically centered, offset the starting m_fCursorY value if( dwFlags & ATGFONT_CENTER_Y ) { - FLOAT w, h; + float w, h; GetTextExtent( strText, &w, &h ); m_fCursorY = floorf( m_fCursorY - (h * 0.5f) ); } // Add window offsets - FLOAT Winx = static_cast(m_rcWindow.x1); - FLOAT Winy = static_cast(m_rcWindow.y1); + float Winx = static_cast(m_rcWindow.x1); + float Winy = static_cast(m_rcWindow.y1); fOriginX += Winx; fOriginY += Winy; m_fCursorX += Winx; @@ -381,7 +381,7 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, if( dwFlags & ( ATGFONT_RIGHT | ATGFONT_CENTER_X ) ) { // Get the extent of this line - FLOAT w, h; + float w, h; GetTextExtent( strText, &w, &h, true ); // Offset this line's starting m_fCursorX value @@ -415,11 +415,11 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, // Translate unprintable characters XUI_FontData::SChar sChar = m_fontData->getChar( letter ); - FLOAT fOffset = m_fXScaleFactor * ( FLOAT )sChar.getOffset(); - FLOAT fAdvance = m_fXScaleFactor * ( FLOAT )sChar.getWAdvance(); + float fOffset = m_fXScaleFactor * ( float )sChar.getOffset(); + float fAdvance = m_fXScaleFactor * ( float )sChar.getWAdvance(); // 4J Use the font max width otherwise scaling doesnt look right - FLOAT fWidth = m_fXScaleFactor * (sChar.tu2() - sChar.tu1());//( FLOAT )pGlyph->wWidth; - FLOAT fHeight = m_fYScaleFactor * m_fontData->getFontHeight(); + float fWidth = m_fXScaleFactor * (sChar.tu2() - sChar.tu1());//( float )pGlyph->wWidth; + float fHeight = m_fYScaleFactor * m_fontData->getFontHeight(); if( 0 == dwNumEllipsesToDraw ) { @@ -437,23 +437,23 @@ void XUI_Font::DrawText( FLOAT fOriginX, FLOAT fOriginY, unsigned long dwColor, // Setup the screen coordinates m_fCursorX += fOffset; - FLOAT X4 = m_fCursorX; - FLOAT X1 = X4 + m_fSlantFactor; - FLOAT X3 = X4 + fWidth; - FLOAT X2 = X1 + fWidth; - FLOAT Y1 = m_fCursorY; - FLOAT Y3 = Y1 + fHeight; - FLOAT Y2 = Y1; - FLOAT Y4 = Y3; + float X4 = m_fCursorX; + float X1 = X4 + m_fSlantFactor; + float X3 = X4 + fWidth; + float X2 = X1 + fWidth; + float Y1 = m_fCursorY; + float Y3 = Y1 + fHeight; + float Y2 = Y1; + float Y4 = Y3; m_fCursorX += fAdvance; // Add the vertices to draw this glyph - FLOAT tu1 = sChar.tu1() / (float)m_fontData->getImageWidth(); - FLOAT tv1 = sChar.tv1() / (float)m_fontData->getImageHeight(); - FLOAT tu2 = sChar.tu2() / (float)m_fontData->getImageWidth(); - FLOAT tv2 = sChar.tv2() / (float)m_fontData->getImageHeight(); + float tu1 = sChar.tu1() / (float)m_fontData->getImageWidth(); + float tv1 = sChar.tv1() / (float)m_fontData->getImageHeight(); + float tu2 = sChar.tu2() / (float)m_fontData->getImageWidth(); + float tv2 = sChar.tv2() / (float)m_fontData->getImageHeight(); Tesselator *t = Tesselator::getInstance(); t->begin(); diff --git a/src/client/Xbox/Font/XUI_Font.h b/src/client/Xbox/Font/XUI_Font.h index 4d660839..47931f87 100644 --- a/src/client/Xbox/Font/XUI_Font.h +++ b/src/client/Xbox/Font/XUI_Font.h @@ -22,15 +22,15 @@ public: const int m_iFontData; const float m_fScaleFactor; - FLOAT m_fXScaleFactor; // Scaling constants - FLOAT m_fYScaleFactor; - FLOAT m_fSlantFactor; // For italics + float m_fXScaleFactor; // Scaling constants + float m_fYScaleFactor; + float m_fSlantFactor; // For italics DOUBLE m_dRotCos; // Precalculated sine and cosine for italic like rotation DOUBLE m_dRotSin; D3DRECT m_rcWindow; // Bounds rect if the text window, modify via accessors only! - FLOAT m_fCursorX; // Current text cursor - FLOAT m_fCursorY; + float m_fCursorX; // Current text cursor + float m_fCursorY; bool m_bRotate; @@ -41,14 +41,14 @@ public: unsigned long refCount; public: float getScaleFactor() { return m_fScaleFactor; } - void GetScaleFactors(FLOAT *pfXScaleFactor, FLOAT *pfYScaleFactor) { *pfXScaleFactor = m_fScaleFactor; *pfYScaleFactor = m_fScaleFactor; } + void GetScaleFactors(float *pfXScaleFactor, float *pfYScaleFactor) { *pfXScaleFactor = m_fScaleFactor; *pfYScaleFactor = m_fScaleFactor; } // Accessor functions - inline void SetSlantFactor( FLOAT fSlantFactor ) + inline void SetSlantFactor( float fSlantFactor ) { m_fSlantFactor = fSlantFactor; } - inline void SetScaleFactors( FLOAT fXScaleFactor, FLOAT fYScaleFactor ) + inline void SetScaleFactors( float fXScaleFactor, float fYScaleFactor ) { // m_fXScaleFactor = m_fYScaleFactor = m_fScaleFactor; } @@ -62,16 +62,16 @@ public: ~XUI_Font(); // Returns the dimensions of a text string - void GetTextExtent( const wchar_t* strText, FLOAT* pWidth, - FLOAT* pHeight, bool bFirstLineOnly=false ) const; - FLOAT GetTextWidth( const wchar_t* strText ) const; - FLOAT GetCharAdvance( const wchar_t* strChar ) const; + void GetTextExtent( const wchar_t* strText, float* pWidth, + float* pHeight, bool bFirstLineOnly=false ) const; + float GetTextWidth( const wchar_t* strText ) const; + float GetCharAdvance( const wchar_t* strChar ) const; void SetWindow(const D3DRECT &rcWindow ); void SetWindow( int32_t x1, int32_t y1, int32_t x2, int32_t y2 ); void GetWindow(D3DRECT &rcWindow) const; - void SetCursorPosition( FLOAT fCursorX, FLOAT fCursorY ); - void SetRotationFactor( FLOAT fRotationFactor ); + void SetCursorPosition( float fCursorX, float fCursorY ); + void SetRotationFactor( float fRotationFactor ); // Function to create a texture containing rendered text D3DTexture* CreateTexture( const wchar_t* strText, @@ -84,10 +84,10 @@ public: // Begin() and End(). void Begin(); void DrawText( unsigned long dwColor, const wchar_t* strText, unsigned long dwFlags=0L, - FLOAT fMaxPixelWidth = 0.0f ); - void DrawText( FLOAT sx, FLOAT sy, unsigned long dwColor, const wchar_t* strText, - unsigned long dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f, bool darken = false ); - void DrawShadowText( FLOAT sx, FLOAT sy, unsigned long dwColor, unsigned long dwShadowColor, const wchar_t* strText, - unsigned long dwFlags=0L, FLOAT fMaxPixelWidth = 0.0f ); + float fMaxPixelWidth = 0.0f ); + void DrawText( float sx, float sy, unsigned long dwColor, const wchar_t* strText, + unsigned long dwFlags=0L, float fMaxPixelWidth = 0.0f, bool darken = false ); + void DrawShadowText( float sx, float sy, unsigned long dwColor, unsigned long dwShadowColor, const wchar_t* strText, + unsigned long dwFlags=0L, float fMaxPixelWidth = 0.0f ); void End(); }; \ No newline at end of file diff --git a/src/client/Xbox/Font/XUI_FontData.cpp b/src/client/Xbox/Font/XUI_FontData.cpp index 74962305..b4617c91 100644 --- a/src/client/Xbox/Font/XUI_FontData.cpp +++ b/src/client/Xbox/Font/XUI_FontData.cpp @@ -365,13 +365,13 @@ void XUI_FontData::Destroy() } /* -FLOAT XUI_FontData::GetCharAdvance( const wchar_t* strChar ) +float XUI_FontData::GetCharAdvance( const wchar_t* strChar ) { unsigned int uiChar = (unsigned int) *strChar; return 0.0f;// m_fontData.getAdvance(m_fontData.getGlyphId(uiChar)); } -FLOAT XUI_FontData::GetCharWidth( const wchar_t* strChar ) +float XUI_FontData::GetCharWidth( const wchar_t* strChar ) { return 0.0f; } diff --git a/src/client/Xbox/Font/XUI_FontData.h b/src/client/Xbox/Font/XUI_FontData.h index 369df372..56ebbf0e 100644 --- a/src/client/Xbox/Font/XUI_FontData.h +++ b/src/client/Xbox/Font/XUI_FontData.h @@ -26,15 +26,15 @@ typedef struct GLYPH_ATTR // Font description -#define ATGCALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(FLOAT)*4) + sizeof(uint16_t) + (sizeof(wchar_t)*(x)) ) +#define ATGCALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)*4) + sizeof(uint16_t) + (sizeof(wchar_t)*(x)) ) #define ATGFONTFILEVERSION 5 typedef struct FontFileHeaderImage_t { unsigned long m_dwFileVersion; // Version of the font file (Must match FONTFILEVERSION) - FLOAT m_fFontHeight; // Height of the font strike in pixels - FLOAT m_fFontTopPadding; // Padding above the strike zone - FLOAT m_fFontBottomPadding; // Padding below the strike zone - FLOAT m_fFontYAdvance; // Number of pixels to move the cursor for a line feed + float m_fFontHeight; // Height of the font strike in pixels + float m_fFontTopPadding; // Padding above the strike zone + float m_fFontBottomPadding; // Padding below the strike zone + float m_fFontYAdvance; // Number of pixels to move the cursor for a line feed uint16_t m_cMaxGlyph; // Number of font characters (Should be an odd number to maintain unsigned long Alignment) wchar_t m_TranslatorTable[1]; // ASCII to Glyph lookup table, NOTE: It's m_cMaxGlyph+1 in size. // Entry 0 maps to the "Unknown" glyph. @@ -140,8 +140,8 @@ public: int Create( int iFontTexture, const void* pFontData ); void Destroy(); - //FLOAT GetCharAdvance( const wchar_t* strChar ); - //FLOAT GetCharWidth( const wchar_t* strChar ); + //float GetCharAdvance( const wchar_t* strChar ); + //float GetCharWidth( const wchar_t* strChar ); //void GetCharMetrics( const wchar_t* strChar, XUICharMetrics *xuiMetrics); //unsigned short getGlyphId(wchar_t character); }; \ No newline at end of file diff --git a/src/client/Xbox/Font/XUI_FontRenderer.cpp b/src/client/Xbox/Font/XUI_FontRenderer.cpp index c022bdd0..e6eb2421 100644 --- a/src/client/Xbox/Font/XUI_FontRenderer.cpp +++ b/src/client/Xbox/Font/XUI_FontRenderer.cpp @@ -62,7 +62,7 @@ int XUI_FontRenderer::CreateFont( const TypefaceDescriptor * pTypefaceDescriptor XUI_Font *font = NULL; XUI_FontData *fontData = NULL; - FLOAT scale = 1; + float scale = 1; eFontData efontdata; if( xuiSize%12==0 ) diff --git a/src/client/Xbox/Xbox_Minecraft.cpp b/src/client/Xbox/Xbox_Minecraft.cpp index 7ca5c3d8..b24e6846 100644 --- a/src/client/Xbox/Xbox_Minecraft.cpp +++ b/src/client/Xbox/Xbox_Minecraft.cpp @@ -894,7 +894,7 @@ bool trackStarted = false; volatile size_t sizeCheckMin = 1160; volatile size_t sizeCheckMax = 1160; volatile int sectCheck = 48; -CRITICAL_SECTION memCS; +ThreadLock memCS; unsigned long tlsIdx; void* XMemAlloc(size_t dwSize, unsigned long dwAllocAttributes) diff --git a/src/world/ArmorItem.cpp b/src/world/ArmorItem.cpp index 263dd5c8..e0c3ff50 100644 --- a/src/world/ArmorItem.cpp +++ b/src/world/ArmorItem.cpp @@ -170,8 +170,9 @@ void ArmorItem::setColor(shared_ptr item, int color) { #ifndef _CONTENT_PACKAGE printf("Can't dye non-leather!"); - throw new UnsupportedOperationException("Can't dye non-leather!"); + __debugbreak(); #endif + //throw new UnsupportedOperationException("Can't dye non-leather!"); } CompoundTag *tag = item->getTag(); diff --git a/src/world/BiomeCache.h b/src/world/BiomeCache.h index 0fb3d7ac..cb000baf 100644 --- a/src/world/BiomeCache.h +++ b/src/world/BiomeCache.h @@ -48,5 +48,5 @@ public: byteArray getBiomeIndexBlockAt(int x, int z); private: - CRITICAL_SECTION m_CS; + ThreadLock m_CS; }; \ No newline at end of file diff --git a/src/world/BiomeDecorator.cpp b/src/world/BiomeDecorator.cpp index cf4a5b32..6ca7386c 100644 --- a/src/world/BiomeDecorator.cpp +++ b/src/world/BiomeDecorator.cpp @@ -23,7 +23,8 @@ void BiomeDecorator::decorate(Level *level, Random *random, int xo, int zo) { app.DebugPrintf("BiomeDecorator::decorate - Already decorating!!\n"); #ifndef _CONTENT_PACKAGE - throw new RuntimeException("Already decorating!!"); + __debugbreak(); + //throw new RuntimeException("Already decorating!!"); #endif } this->level = level; diff --git a/src/world/BiomeOverrideLayer.cpp b/src/world/BiomeOverrideLayer.cpp index d7f1155a..dbecf1f4 100644 --- a/src/world/BiomeOverrideLayer.cpp +++ b/src/world/BiomeOverrideLayer.cpp @@ -3,53 +3,47 @@ #include "net.minecraft.world.level.newbiome.layer.h" #include "net.minecraft.world.level.h" #include "BiomeOverrideLayer.h" - +#include +#include +#include BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) { m_biomeOverride = byteArray( width * height ); -#ifdef _UNICODE - wstring path = L"GAME:\\GameRules\\biomemap.bin"; - void* file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#else -#ifdef _WINDOWS64 - string path = "GameRules\\biomemap.bin"; -#else - string path = "GAME:\\GameRules\\biomemap.bin"; -#endif - void* file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -#endif - if( file == INVALID_HANDLE_VALUE ) - { - unsigned long error = GetLastError(); - //assert(false); - app.DebugPrintf("Biome override not found, using plains as default\n"); + std::string path; - memset(m_biomeOverride.data,Biome::plains->id,m_biomeOverride.length); + #if defined(__ORBIS__) || defined(_DURANGO) || defined(_XBOX) + path = "GAME:/GameRules/biomemap.bin"; + #else + path = "GameRules/biomemap.bin"; + #endif + + std::ifstream file(path, std::ios::binary); + + if (!file.is_open()) + { + app.DebugPrintf("Biome override not found, using plains as default\n"); + std::memset(m_biomeOverride.data, Biome::plains->id, m_biomeOverride.length); } else { + file.seekg(0, std::ios::end); + std::size_t fileSize = static_cast(file.tellg()); + file.seekg(0, std::ios::beg); -#ifdef _DURANGO - __debugbreak(); // TODO - unsigned long bytesRead,dwFileSize = 0; -#else - unsigned long bytesRead,dwFileSize = GetFileSize(file,NULL); -#endif - if(dwFileSize > m_biomeOverride.length) + if (fileSize > m_biomeOverride.length) { app.DebugPrintf("Biomemap binary is too large!!\n"); __debugbreak(); } - bool bSuccess = ReadFile(file,m_biomeOverride.data,dwFileSize,&bytesRead,NULL); - if(bSuccess==false) + file.read(reinterpret_cast(m_biomeOverride.data), fileSize); + + if (!file.good()) { app.FatalLoadError(); } - - CloseHandle(file); } } diff --git a/src/world/BoundingBox.cpp b/src/world/BoundingBox.cpp index eb828ed0..25a62cef 100644 --- a/src/world/BoundingBox.cpp +++ b/src/world/BoundingBox.cpp @@ -2,6 +2,7 @@ #include "BoundingBox.h" #include "Direction.h" #include "JavaMath.h" +#include BoundingBox::BoundingBox() { diff --git a/src/world/ButtonTile.cpp b/src/world/ButtonTile.cpp index 16055a7e..bb75ce99 100644 --- a/src/world/ButtonTile.cpp +++ b/src/world/ButtonTile.cpp @@ -300,7 +300,7 @@ void ButtonTile::checkPressed(Level *level, int x, int y, int z) bool shouldBePressed; updateShape(data); - Tile::ThreadStorage *tls = (Tile::ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; vector > *entities = level->getEntitiesOfClass(typeid(Arrow), AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1)); shouldBePressed = !entities->empty(); delete entities; diff --git a/src/world/C4JThread.cpp b/src/world/C4JThread.cpp index 4017eb59..ae4b4953 100644 --- a/src/world/C4JThread.cpp +++ b/src/world/C4JThread.cpp @@ -1,7 +1,8 @@ #include "C4JThread.h" std::vector C4JThread::ms_threadList; -std::mutex C4JThread::ms_threadListMutex; +ThreadLock C4JThread::ms_threadListLock; + thread_local C4JThread* C4JThread::tls_currentThread = nullptr; C4JThread C4JThread::m_mainThread("MainThread"); @@ -12,20 +13,22 @@ C4JThread::Event::Event(EMode mode) void C4JThread::Event::Set() { - std::lock_guard lock(m_mutex); + m_lock.lock(); m_signaled = true; m_cv.notify_all(); + m_lock.unlock(); } void C4JThread::Event::Clear() { - std::lock_guard lock(m_mutex); + m_lock.lock(); m_signaled = false; + m_lock.unlock(); } unsigned long C4JThread::Event::WaitForSignal(int timeoutMs) { - std::unique_lock lock(m_mutex); + m_lock.lock(); if (timeoutMs < 0) { @@ -40,6 +43,7 @@ unsigned long C4JThread::Event::WaitForSignal(int timeoutMs) if (m_mode == e_modeAutoClear) m_signaled = false; + m_lock.unlock(); return 0; } @@ -47,31 +51,40 @@ C4JThread::EventArray::EventArray(int size, Event::EMode mode) { m_events.reserve(size); for (int i = 0; i < size; ++i) - m_events.emplace_back(mode); + { + m_events.push_back(std::unique_ptr(new Event(mode))); + } } -void C4JThread::EventArray::Set(int i) { m_events[i].Set(); } -void C4JThread::EventArray::Clear(int i) { m_events[i].Clear(); } +void C4JThread::EventArray::Set(int i) +{ + m_events[i]->Set(); +} + +void C4JThread::EventArray::Clear(int i) +{ + m_events[i]->Clear(); +} void C4JThread::EventArray::SetAll() { - for (auto& e : m_events) e.Set(); + for (auto& e : m_events) e->Set(); } void C4JThread::EventArray::ClearAll() { - for (auto& e : m_events) e.Clear(); + for (auto& e : m_events) e->Clear(); } unsigned long C4JThread::EventArray::WaitForSingle(int index, int timeoutMs) { - return m_events[index].WaitForSignal(timeoutMs); + return m_events[index]->WaitForSignal(timeoutMs); } unsigned long C4JThread::EventArray::WaitForAll(int timeoutMs) { for (auto& e : m_events) - e.WaitForSignal(timeoutMs); + e->WaitForSignal(timeoutMs); return 0; } @@ -81,7 +94,7 @@ unsigned long C4JThread::EventArray::WaitForAny(int timeoutMs) { for (auto& e : m_events) { - if (e.WaitForSignal(0) == 0) + if (e->WaitForSignal(0) == 0) return 0; } std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -92,9 +105,9 @@ C4JThread::C4JThread(C4JThreadStartFunc* startFunc, void* param, const char* nam : m_threadParam(param), m_startFunc(startFunc) { std::strncpy(m_threadName, name, sizeof(m_threadName)); - - std::lock_guard lock(ms_threadListMutex); + ms_threadListLock.lock(); ms_threadList.push_back(this); + ms_threadListLock.unlock(); } C4JThread::C4JThread(const char* mainThreadName) diff --git a/src/world/C4JThread.h b/src/world/C4JThread.h index b523ef71..d63299a3 100644 --- a/src/world/C4JThread.h +++ b/src/world/C4JThread.h @@ -33,7 +33,7 @@ public: private: EMode m_mode; - std::mutex m_mutex; + ThreadLock m_lock; std::condition_variable m_cv; bool m_signaled = false; }; @@ -53,7 +53,7 @@ public: unsigned long WaitForSingle(int index, int timeoutMs); private: - std::vector m_events; + std::vector> m_events; }; class EventQueue @@ -72,7 +72,7 @@ public: void threadPoll(); std::queue m_queue; - std::mutex m_mutex; + ThreadLock m_lock; EventArray m_startEvent; Event m_finishedEvent; @@ -115,7 +115,7 @@ private: char m_threadName[64]{}; static std::vector ms_threadList; - static std::mutex ms_threadListMutex; + static ThreadLock ms_threadListLock; static thread_local C4JThread* tls_currentThread; static C4JThread m_mainThread; diff --git a/src/world/ClothDyeRecipes.cpp b/src/world/ClothDyeRecipes.cpp index 5ad38d82..d234c0d3 100644 --- a/src/world/ClothDyeRecipes.cpp +++ b/src/world/ClothDyeRecipes.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "net.minecraft.world.Item.h" +#include "net.minecraft.world.item.h" #include "DyePowderItem.h" #include "Tile.h" #include "ClothTile.h" diff --git a/src/world/CompressedTileStorage.cpp b/src/world/CompressedTileStorage.cpp index ed7e7671..f7d19fb0 100644 --- a/src/world/CompressedTileStorage.cpp +++ b/src/world/CompressedTileStorage.cpp @@ -18,7 +18,7 @@ static int g_currentCompressTiles = 0; int CompressedTileStorage::deleteQueueIndex; XLockFreeStack CompressedTileStorage::deleteQueue[3]; -CRITICAL_SECTION CompressedTileStorage::cs_write; +ThreadLock CompressedTileStorage::cs_write; #ifdef PSVITA_PRECOMPUTED_TABLE // AP - this will create a precomputed table to speed up getData diff --git a/src/world/CompressedTileStorage.h b/src/world/CompressedTileStorage.h index 3d433547..043b3ea1 100644 --- a/src/world/CompressedTileStorage.h +++ b/src/world/CompressedTileStorage.h @@ -98,7 +98,7 @@ public: static unsigned char compressBuffer[32768 + 256]; - static CRITICAL_SECTION cs_write; + static ThreadLock cs_write; int getAllocatedSize(int *count0, int *count1, int *count2, int *count4, int *count8); int getHighestNonEmptyY(); diff --git a/src/world/Connection.cpp b/src/world/Connection.cpp index a178543d..7bf5068e 100644 --- a/src/world/Connection.cpp +++ b/src/world/Connection.cpp @@ -4,7 +4,7 @@ #include "Connection.h" #include "ThreadName.h" #include "compression.h" -#include "PS3\PS3Extras\ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" // This should always be enabled, except for debugging use #ifndef _DEBUG @@ -544,7 +544,7 @@ int Connection::runRead(void* lpParam) Compression::UseDefaultThreadStorage(); - CRITICAL_SECTION *cs = &con->threadCounterLock; + ThreadLock *cs = &con->threadCounterLock; EnterCriticalSection(cs); con->readThreads++; @@ -559,7 +559,7 @@ int Connection::runRead(void* lpParam) ; // try { - //Sleep(100L); + //sleep(100L); // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well con->m_hWakeReadThread->WaitForSignal(100L); } @@ -592,7 +592,7 @@ int Connection::runWrite(void* lpParam) Compression::UseDefaultThreadStorage(); - CRITICAL_SECTION *cs = &con->threadCounterLock; + ThreadLock *cs = &con->threadCounterLock; EnterCriticalSection(cs); con->writeThreads++; @@ -607,7 +607,7 @@ int Connection::runWrite(void* lpParam) while (con->writeTick()) ; - //Sleep(100L); + //sleep(100L); // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well waitResult = con->m_hWakeWriteThread->WaitForSignal(100L); @@ -633,7 +633,7 @@ int Connection::runClose(void* lpParam) //try { - Sleep(2000); + sleep(2000); if (con->running) { // 4J TODO writeThread.interrupt(); @@ -657,7 +657,7 @@ int Connection::runSendAndQuit(void* lpParam) //try { - Sleep(2000); + sleep(2000); if (con->running) { // 4J TODO writeThread.interrupt(); diff --git a/src/world/Connection.h b/src/world/Connection.h index badd42e7..620a3293 100644 --- a/src/world/Connection.h +++ b/src/world/Connection.h @@ -53,7 +53,7 @@ private: bool running; queue > incoming; // 4J - was using synchronizedList... - CRITICAL_SECTION incoming_cs; // ... now has this critical section + ThreadLock incoming_cs; // ... now has this critical section queue > outgoing; // 4J - was using synchronizedList - but don't think it is required as usage is wrapped in writeLock critical section queue > outgoing_slow; // 4J - was using synchronizedList - but don't think it is required as usage is wrapped in writeLock critical section @@ -89,8 +89,8 @@ private: void _init(); // 4J Jev, these might be better of as private - CRITICAL_SECTION threadCounterLock; - CRITICAL_SECTION writeLock; + ThreadLock threadCounterLock; + ThreadLock writeLock; public: // 4J Jev, need to delete the critical section. diff --git a/src/world/ConsoleSaveFileOriginal.cpp b/src/world/ConsoleSaveFileOriginal.cpp index 150f1545..bf778e19 100644 --- a/src/world/ConsoleSaveFileOriginal.cpp +++ b/src/world/ConsoleSaveFileOriginal.cpp @@ -690,7 +690,7 @@ void ConsoleSaveFileOriginal::Flush(bool autosave, bool updateThumbnail ) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Check buffer size: Elapsed time %f\n", fElapsedTime); PIXEndNamedEvent(); @@ -721,7 +721,7 @@ void ConsoleSaveFileOriginal::Flush(bool autosave, bool updateThumbnail ) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Compress: Elapsed time %f\n", fElapsedTime); PIXEndNamedEvent(); @@ -938,12 +938,12 @@ int ConsoleSaveFileOriginal::getOriginalSaveVersion() void ConsoleSaveFileOriginal::LockSaveAccess() { - EnterCriticalSection(&m_lock); + m_lock.lock(); } void ConsoleSaveFileOriginal::ReleaseSaveAccess() { - LeaveCriticalSection(&m_lock); + m_lock.unlock(); } ESavePlatform ConsoleSaveFileOriginal::getSavePlatform() diff --git a/src/world/ConsoleSaveFileOriginal.h b/src/world/ConsoleSaveFileOriginal.h index 883305f5..2ce29e0d 100644 --- a/src/world/ConsoleSaveFileOriginal.h +++ b/src/world/ConsoleSaveFileOriginal.h @@ -26,7 +26,7 @@ private: #endif void* pvSaveMem; - CRITICAL_SECTION m_lock; + ThreadLock m_lock; void PrepareForWrite( FileEntry *file, unsigned long nNumberOfBytesToWrite ); void MoveDataBeyond(FileEntry *file, unsigned long nNumberOfBytesToWrite); diff --git a/src/world/ConsoleSaveFileSplit.cpp b/src/world/ConsoleSaveFileSplit.cpp index 6bb70c54..58abefc2 100644 --- a/src/world/ConsoleSaveFileSplit.cpp +++ b/src/world/ConsoleSaveFileSplit.cpp @@ -1369,7 +1369,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Check buffer size: Elapsed time %f\n", fElapsedTime); PIXEndNamedEvent(); @@ -1392,7 +1392,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime = fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + fElapsedTime = fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("Compress: Elapsed time %f\n", fElapsedTime); PIXEndNamedEvent(); diff --git a/src/world/ConsoleSaveFileSplit.h b/src/world/ConsoleSaveFileSplit.h index 054ef23d..161005dc 100644 --- a/src/world/ConsoleSaveFileSplit.h +++ b/src/world/ConsoleSaveFileSplit.h @@ -69,7 +69,7 @@ private: #endif void* pvSaveMem; - CRITICAL_SECTION m_lock; + ThreadLock m_lock; void PrepareForWrite( FileEntry *file, unsigned long nNumberOfBytesToWrite ); void MoveDataBeyond(FileEntry *file, unsigned long nNumberOfBytesToWrite); diff --git a/src/world/Level.cpp b/src/world/Level.cpp index 47e5aca9..471f2ce8 100644 --- a/src/world/Level.cpp +++ b/src/world/Level.cpp @@ -40,8 +40,7 @@ #include "TexturePackRepository.h" #include "DLCTexturePack.h" #include "Common/DLC/DLCPack.h" -#include "PS3\PS3Extras\ShutdownManager.h" - +#include "Common/Shutdown/ShutdownManager.h" unsigned long Level::tlsIdx = TlsAlloc(); unsigned long Level::tlsIdxLightCache = TlsAlloc(); @@ -3703,8 +3702,8 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool f { QueryPerformanceCounter( &qwNewTime ); qwDeltaTime2.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart; - fElapsedTime1 = fSecsPerTick * ((FLOAT)(qwDeltaTime1.QuadPart)); - fElapsedTime2 = fSecsPerTick * ((FLOAT)(qwDeltaTime2.QuadPart)); + fElapsedTime1 = fSecsPerTick * ((float)(qwDeltaTime1.QuadPart)); + fElapsedTime2 = fSecsPerTick * ((float)(qwDeltaTime2.QuadPart)); if( ( darktcc > 0 ) | ( tcc > 0 ) ) { printf("%d %d %d %f + %f = %f\n", darktcc, tcc, darktcc + tcc, fElapsedTime1 * 1000.0f, fElapsedTime2 * 1000.0f, ( fElapsedTime1 + fElapsedTime2 ) * 1000.0f); diff --git a/src/world/Level.h b/src/world/Level.h index 286da8dd..b11a7adf 100644 --- a/src/world/Level.h +++ b/src/world/Level.h @@ -90,7 +90,7 @@ public: static const int TICKS_PER_DAY = 20 * 60 * 20; // ORG:20*60*20 public: - CRITICAL_SECTION m_entitiesCS; // 4J added + ThreadLock m_entitiesCS; // 4J added vector > entities; @@ -99,7 +99,7 @@ protected: public: bool hasEntitiesToRemove(); // 4J added bool m_bDisableAddNewTileEntities; // 4J Added - CRITICAL_SECTION m_tileEntityListCS; // 4J added + ThreadLock m_tileEntityListCS; // 4J added vector > tileEntityList; private: vector > pendingTileEntities; @@ -508,7 +508,7 @@ public: virtual bool newFallingTileAllowed() { return true; } // 4J - added for new lighting from 1.8.2 - CRITICAL_SECTION m_checkLightCS; + ThreadLock m_checkLightCS; private: int m_iHighestY; // 4J-PB - for the end portal in The End diff --git a/src/world/LevelChunk.cpp b/src/world/LevelChunk.cpp index 76beb4af..8400b6d7 100644 --- a/src/world/LevelChunk.cpp +++ b/src/world/LevelChunk.cpp @@ -22,15 +22,15 @@ #ifdef SHARING_ENABLED -CRITICAL_SECTION LevelChunk::m_csSharing; +ThreadLock LevelChunk::m_csSharing; #endif #ifdef _ENTITIES_RW_SECTION // AP - use a RW critical section so we can have multiple threads reading the same data to avoid a clash CRITICAL_RW_SECTION LevelChunk::m_csEntities; #else - CRITICAL_SECTION LevelChunk::m_csEntities; + ThreadLock LevelChunk::m_csEntities; #endif -CRITICAL_SECTION LevelChunk::m_csTileEntities; +ThreadLock LevelChunk::m_csTileEntities; bool LevelChunk::touchedSky = false; void LevelChunk::staticCtor() diff --git a/src/world/LevelChunk.h b/src/world/LevelChunk.h index f9c4d8b3..73797f58 100644 --- a/src/world/LevelChunk.h +++ b/src/world/LevelChunk.h @@ -218,15 +218,15 @@ public: virtual void attemptCompression(); #ifdef SHARING_ENABLED - static CRITICAL_SECTION m_csSharing; // 4J added + static ThreadLock m_csSharing; // 4J added #endif // 4J added #ifdef _ENTITIES_RW_SECTION static CRITICAL_RW_SECTION m_csEntities; // AP - we're using a RW critical so we can do multiple reads without contention #else - static CRITICAL_SECTION m_csEntities; + static ThreadLock m_csEntities; #endif - static CRITICAL_SECTION m_csTileEntities; // 4J added + static ThreadLock m_csTileEntities; // 4J added static void staticCtor(); void checkPostProcess(ChunkSource *source, ChunkSource *parent, int x, int z); void checkChests(ChunkSource *source, int x, int z ); // 4J added diff --git a/src/world/LiquidTile.cpp b/src/world/LiquidTile.cpp index 466589a4..785688f1 100644 --- a/src/world/LiquidTile.cpp +++ b/src/world/LiquidTile.cpp @@ -306,7 +306,7 @@ void LiquidTile::animateTick(Level *level, int x, int y, int z, Random *random) { if (random->nextInt(100) == 0) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; double xx = x + random->nextFloat(); double yy = y + tls->yy1; double zz = z + random->nextFloat(); diff --git a/src/world/McRegionChunkStorage.cpp b/src/world/McRegionChunkStorage.cpp index 62b39bbb..2e56bdd9 100644 --- a/src/world/McRegionChunkStorage.cpp +++ b/src/world/McRegionChunkStorage.cpp @@ -4,7 +4,7 @@ #include "LevelData.h" #include "McRegionChunkStorage.h" -CRITICAL_SECTION McRegionChunkStorage::cs_memory; +ThreadLock McRegionChunkStorage::cs_memory; std::deque McRegionChunkStorage::s_chunkDataQueue; int McRegionChunkStorage::s_runningThreadCount = 0; diff --git a/src/world/McRegionChunkStorage.h b/src/world/McRegionChunkStorage.h index 83525589..00b88a2c 100644 --- a/src/world/McRegionChunkStorage.h +++ b/src/world/McRegionChunkStorage.h @@ -14,7 +14,7 @@ class McRegionChunkStorage : public ChunkStorage private: const wstring m_prefix; ConsoleSaveFile *m_saveFile; - static CRITICAL_SECTION cs_memory; + static ThreadLock cs_memory; unordered_map m_entityData; diff --git a/src/world/PerformanceTimer.cpp b/src/world/PerformanceTimer.cpp index 5ed7ee0c..dd31ed92 100644 --- a/src/world/PerformanceTimer.cpp +++ b/src/world/PerformanceTimer.cpp @@ -28,7 +28,7 @@ void PerformanceTimer::PrintElapsedTime(const wstring &description) QueryPerformanceCounter( &qwNewTime ); qwDeltaTime.QuadPart = qwNewTime.QuadPart - m_qwStartTime.QuadPart; - float fElapsedTime = m_fSecsPerTick * ((FLOAT)(qwDeltaTime.QuadPart)); + float fElapsedTime = m_fSecsPerTick * ((float)(qwDeltaTime.QuadPart)); app.DebugPrintf("TIMER: %ls: Elapsed time %f\n", description.c_str(), fElapsedTime); #endif diff --git a/src/world/PistonBaseTile.cpp b/src/world/PistonBaseTile.cpp index 8308465b..d7b39a02 100644 --- a/src/world/PistonBaseTile.cpp +++ b/src/world/PistonBaseTile.cpp @@ -75,7 +75,7 @@ Icon *PistonBaseTile::getTexture(int face, int data) // when the piston is extended, either normally // or because a piston arm animation, the top // texture is the furnace bottom - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; if (isExtended(data) || tls->xx0 > 0 || tls->yy0 > 0 || tls->zz0 > 0 || tls->xx1 < 1 || tls->yy1 < 1 || tls->zz1 < 1) { return iconInside; diff --git a/src/world/PistonMovingPiece.cpp b/src/world/PistonMovingPiece.cpp index e141cebe..07aabd10 100644 --- a/src/world/PistonMovingPiece.cpp +++ b/src/world/PistonMovingPiece.cpp @@ -137,7 +137,7 @@ void PistonMovingPiece::updateShape(LevelSource *level, int x, int y, int z, int progress = 1.0f - progress; } int facing = entity->getFacing(); - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; tls->xx0 = tile->getShapeX0() - Facing::STEP_X[facing] * progress; tls->yy0 = tile->getShapeY0() - Facing::STEP_Y[facing] * progress; tls->zz0 = tile->getShapeZ0() - Facing::STEP_Z[facing] * progress; diff --git a/src/world/Socket.cpp b/src/world/Socket.cpp index 109eb730..9afd70b0 100644 --- a/src/world/Socket.cpp +++ b/src/world/Socket.cpp @@ -5,12 +5,12 @@ #include "ThreadName.h" #include "ServerConnection.h" #include -#include "PS3\PS3Extras\ShutdownManager.h" +#include "Common/Shutdown/ShutdownManager.h" // This current socket implementation is for the creation of a single local link. 2 sockets can be created, one for either end of this local // link, the end (0 or 1) is passed as a parameter to the ctor. -CRITICAL_SECTION Socket::s_hostQueueLock[2]; +ThreadLock Socket::s_hostQueueLock[2]; std::queue Socket::s_hostQueue[2]; Socket::SocketOutputStreamLocal *Socket::s_hostOutStream[2]; Socket::SocketInputStreamLocal *Socket::s_hostInStream[2]; diff --git a/src/world/Socket.h b/src/world/Socket.h index 3bdf391a..82ffee88 100644 --- a/src/world/Socket.h +++ b/src/world/Socket.h @@ -92,14 +92,14 @@ private: int m_end; // 0 for client side or 1 for host side // For local connections between the host player and the server - static CRITICAL_SECTION s_hostQueueLock[2]; + static ThreadLock s_hostQueueLock[2]; static std::queue s_hostQueue[2]; static SocketOutputStreamLocal *s_hostOutStream[2]; static SocketInputStreamLocal *s_hostInStream[2]; // For network connections std::queue m_queueNetwork[2]; // For input data - CRITICAL_SECTION m_queueLockNetwork[2]; // For input data + ThreadLock m_queueLockNetwork[2]; // For input data SocketInputStreamNetwork *m_inputStream[2]; SocketOutputStreamNetwork *m_outputStream[2]; bool m_endClosed[2]; diff --git a/src/world/StemTile.cpp b/src/world/StemTile.cpp index 5b8a5e10..1ee6bd21 100644 --- a/src/world/StemTile.cpp +++ b/src/world/StemTile.cpp @@ -147,7 +147,7 @@ void StemTile::updateDefaultShape() void StemTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr forceEntity) // 4J added forceData, forceEntity param { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; tls->yy1 = (level->getData(x, y, z) * 2 + 2) / 16.0f; float ss = 0.125f; this->setShape(0.5f - ss, 0, 0.5f - ss, 0.5f + ss, (float) tls->yy1, 0.5f + ss); diff --git a/src/world/Tile.cpp b/src/world/Tile.cpp index 01f9bb90..2c3da7d3 100644 --- a/src/world/Tile.cpp +++ b/src/world/Tile.cpp @@ -217,7 +217,7 @@ void Tile::CreateNewThreadStorage() void Tile::ReleaseThreadStorage() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; delete tls; } @@ -650,7 +650,7 @@ Tile *Tile::disableMipmap() void Tile::setShape(float x0, float y0, float z0, float x1, float y1, float z1) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; tls->xx0 = x0; tls->yy0 = y0; tls->zz0 = z0; @@ -700,7 +700,7 @@ bool Tile::isFaceVisible(Level *level, int x, int y, int z, int f) bool Tile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); if (face == 0 && tls->yy0 > 0) return true; @@ -717,7 +717,7 @@ int Tile::getFaceFlags(LevelSource *level, int x, int y, int z) { int faceFlags = 0; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); @@ -792,7 +792,7 @@ Icon *Tile::getTexture(int face) AABB *Tile::getTileAABB(Level *level, int x, int y, int z) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1); @@ -806,7 +806,7 @@ void Tile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxe AABB *Tile::getAABB(Level *level, int x, int y, int z) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1); @@ -941,7 +941,7 @@ HitResult *Tile::clip(Level *level, int xt, int yt, int zt, Vec3 *a, Vec3 *b) a = a->add(-xt, -yt, -zt); b = b->add(-xt, -yt, -zt); - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; Vec3 *xh0 = a->clipX(b, tls->xx0); Vec3 *xh1 = a->clipX(b, tls->xx1); @@ -978,7 +978,7 @@ bool Tile::containsX(Vec3 *v) { if( v == NULL) return false; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return v->y >= tls->yy0 && v->y <= tls->yy1 && v->z >= tls->zz0 && v->z <= tls->zz1; @@ -988,7 +988,7 @@ bool Tile::containsY(Vec3 *v) { if( v == NULL) return false; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return v->x >= tls->xx0 && v->x <= tls->xx1 && v->z >= tls->zz0 && v->z <= tls->zz1; @@ -998,7 +998,7 @@ bool Tile::containsZ(Vec3 *v) { if( v == NULL) return false; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return v->x >= tls->xx0 && v->x <= tls->xx1 && v->y >= tls->yy0 && v->y <= tls->yy1; @@ -1063,14 +1063,14 @@ void Tile::handleEntityInside(Level *level, int x, int y, int z, shared_ptr forceEntity) // 4J added forceData, forceEntity param { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); } double Tile::getShapeX0() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->xx0; @@ -1078,7 +1078,7 @@ double Tile::getShapeX0() double Tile::getShapeX1() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->xx1; @@ -1086,7 +1086,7 @@ double Tile::getShapeX1() double Tile::getShapeY0() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->yy0; @@ -1094,7 +1094,7 @@ double Tile::getShapeY0() double Tile::getShapeY1() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->yy1; @@ -1102,7 +1102,7 @@ double Tile::getShapeY1() double Tile::getShapeZ0() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->zz0; @@ -1110,7 +1110,7 @@ double Tile::getShapeZ0() double Tile::getShapeZ1() { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return tls->zz1; diff --git a/src/world/Tile.h b/src/world/Tile.h index b5d67840..ec8b56dc 100644 --- a/src/world/Tile.h +++ b/src/world/Tile.h @@ -55,7 +55,7 @@ protected: int tileId; ThreadStorage(); }; - static unsigned long tlsIdxShape; + static thread_local ThreadStorage tlsShape; public: // Each new thread that needs to use Vec3 pools will need to call one of the following 2 functions, to either create its own // local storage, or share the default storage already allocated by the main thread diff --git a/src/world/TopSnowTile.cpp b/src/world/TopSnowTile.cpp index 9bcf5527..cae6522e 100644 --- a/src/world/TopSnowTile.cpp +++ b/src/world/TopSnowTile.cpp @@ -29,7 +29,7 @@ AABB *TopSnowTile::getAABB(Level *level, int x, int y, int z) int height = level->getData(x, y, z) & HEIGHT_MASK; if (height >= (MAX_HEIGHT / 2)) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + .5f, z + tls->zz1); } return NULL; diff --git a/src/world/TripWireTile.cpp b/src/world/TripWireTile.cpp index 40ad93f8..d84fbed5 100644 --- a/src/world/TripWireTile.cpp +++ b/src/world/TripWireTile.cpp @@ -165,7 +165,7 @@ void TripWireTile::checkPressed(Level *level, int x, int y, int z) bool wasPressed = (data & MASK_POWERED) == MASK_POWERED; bool shouldBePressed = false; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; vector > *entities = level->getEntities(nullptr, AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1)); if (!entities->empty()) { diff --git a/src/world/WaterLilyTile.cpp b/src/world/WaterLilyTile.cpp index 33cab1f5..5402bf23 100644 --- a/src/world/WaterLilyTile.cpp +++ b/src/world/WaterLilyTile.cpp @@ -33,7 +33,7 @@ void WaterlilyTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBL AABB *WaterlilyTile::getAABB(Level *level, int x, int y, int z) { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + tls->yy1, z + tls->zz1); diff --git a/src/world/WoolCarpetTile.cpp b/src/world/WoolCarpetTile.cpp index 16a3d0aa..71437255 100644 --- a/src/world/WoolCarpetTile.cpp +++ b/src/world/WoolCarpetTile.cpp @@ -20,7 +20,7 @@ AABB *WoolCarpetTile::getAABB(Level *level, int x, int y, int z) { int height = 0; float offset = 1.0f / SharedConstants::WORLD_RESOLUTION; - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + Tile::ThreadStorage* tls = &Tile::tlsShape; // 4J Stu - Added this so that the TLS shape is correct for this tile if(tls->tileId != this->id) updateDefaultShape(); return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + (height * offset), z + tls->zz1); diff --git a/src/world/compression.h b/src/world/compression.h index 44d0f93a..d469c839 100644 --- a/src/world/compression.h +++ b/src/world/compression.h @@ -64,8 +64,8 @@ private: XMEMCOMPRESSION_CONTEXT compressionContext; XMEMDECOMPRESSION_CONTEXT decompressionContext; #endif - CRITICAL_SECTION rleCompressLock; - CRITICAL_SECTION rleDecompressLock; + ThreadLock rleCompressLock; + ThreadLock rleDecompressLock; unsigned char rleCompressBuf[1024*100]; static const unsigned int staticRleSize = 1024*200; diff --git a/src/world/stdafx.h b/src/world/stdafx.h index e15b20e3..74dcb0bd 100644 --- a/src/world/stdafx.h +++ b/src/world/stdafx.h @@ -13,6 +13,8 @@ typedef unsigned int64_t uint64_t; #endif +#include "Common/ThreadLock.h" + #ifdef _WINDOWS64 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files: @@ -25,6 +27,8 @@ typedef unsigned int64_t uint64_t; #include #include #include +#include +#include struct LARGE_INTEGER { union { @@ -38,10 +42,14 @@ struct FILETIME { unsigned long dwHighDateTime; }; -#define CRITICAL_SECTION std::mutex - #define ZeroMemory(ptr, size) memset(ptr, 0, size) #define __stdcall + +#if defined(__GNUC__) || defined(__clang__) + #define __debugbreak() raise(SIGTRAP) +#else + #define __debugbreak() std::abort() +#endif #endif #ifdef _DURANGO diff --git a/src/world/x64headers/extraX64.h b/src/world/x64headers/extraX64.h index d48d3ccb..e321018b 100644 --- a/src/world/x64headers/extraX64.h +++ b/src/world/x64headers/extraX64.h @@ -6,7 +6,6 @@ #include "SkinBox.h" - #include #define MULTITHREAD_ENABLE @@ -93,7 +92,7 @@ template class XLockFreeStack { std::vector intStack; - mutable std::mutex m_mutex; + mutable ThreadLock m_lock; public: XLockFreeStack() = default; @@ -103,19 +102,22 @@ public: void Push(T* data) { - std::lock_guard lock(m_mutex); + m_lock.lock(); intStack.push_back(data); + m_lock.unlock(); } T* Pop() { - std::lock_guard lock(m_mutex); + m_lock.lock(); if (intStack.empty()) return nullptr; T* ret = intStack.back(); intStack.pop_back(); + + m_lock.unlock(); return ret; } };