Add threadlock and universal fs functions

This commit is contained in:
murdle 2026-03-01 23:19:08 +02:00
parent 5b984ad854
commit f0632c2364
92 changed files with 618 additions and 281 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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)
{

View File

@ -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()
{

View File

@ -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));
}

View File

@ -373,8 +373,8 @@ private:
unordered_map<wstring, PMEMDATA> m_MEM_Files;
// for storing texture pack data files
unordered_map<int, PMEMDATA> 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];

View File

@ -229,8 +229,8 @@ protected:
};
std::queue<StateChangeInfo> m_stateChangeQueue;
CRITICAL_SECTION m_csStateChangeQueue;
CRITICAL_SECTION m_csMatching;
ThreadLock m_csStateChangeQueue;
ThreadLock m_csMatching;
typedef enum
{

View File

@ -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<QueuedSendBlock> m_sendQueue;
};

View File

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "SonyCommerce.h"
#include "PS3Extras/ShutdownManager.h"
#include "Common/Shutdown/ShutdownManager.h"
#include <sys/event.h>
@ -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;

View File

@ -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

View File

@ -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
};

View File

@ -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
}

View File

@ -0,0 +1,24 @@
#pragma once
#ifdef _XBOX
#include <Windows.h>
#else
#include <mutex>
#endif
class ThreadLock
{
public:
ThreadLock();
~ThreadLock();
void lock();
void unlock();
private:
#ifdef _XBOX
CRITICAL_SECTION m_cs;
#else
std::mutex m_mutex;
#endif
};

View File

@ -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;

View File

@ -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<size_t, UIScene *> 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

View File

@ -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

View File

@ -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
};

View File

@ -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);

View File

@ -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);

View File

@ -31,7 +31,7 @@ unordered_map<uintptr_t, size_t> 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);
}

View File

@ -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)

View File

@ -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;

View File

@ -86,7 +86,7 @@ private:
wstring m_score;
} StatResult;
CRITICAL_SECTION m_retrievedStatsLock;
ThreadLock m_retrievedStatsLock;
vector<StatResult> m_retrievedStats;

View File

@ -52,7 +52,7 @@ public:
void EvaluateDevicesForUser(__in Windows::Xbox::System::IUser^ user );
vector<AddedUser *> m_addedUsers;
CRITICAL_SECTION m_csAddedUsers;
ThreadLock m_csAddedUsers;
private:
/// <summary>

View File

@ -327,13 +327,13 @@ protected:
};
std::queue<StateChangeInfo> 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<RTS_Message> m_RTSMessageQueueIncoming;
CRITICAL_SECTION m_csRTSMessageQueueIncoming;
ThreadLock m_csRTSMessageQueueIncoming;
std::queue<RTS_Message> 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<HostGamertagResolveDetails *> 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<int> m_vecChatPlayersJoined;
public:
void HandleNewPartyFoundForPlayer();

View File

@ -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<SparseLightStorage *> GameRenderer::m_deleteStackSparseLightStorage;
vector<CompressedTileStorage *> GameRenderer::m_deleteStackCompressedTileStorage;
vector<SparseDataStorage *> GameRenderer::m_deleteStackSparseDataStorage;
#endif
CRITICAL_SECTION GameRenderer::m_csDeleteStack;
ThreadLock GameRenderer::m_csDeleteStack;
GameRenderer::GameRenderer(Minecraft *mc)
{

View File

@ -160,7 +160,7 @@ public:
static vector<SparseLightStorage *> m_deleteStackSparseLightStorage;
static vector<CompressedTileStorage *> m_deleteStackCompressedTileStorage;
static vector<SparseDataStorage *> 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);

View File

@ -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<shared_ptr<TileEntity>, 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<Chunk *> *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<RecentTile *> 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();
};

View File

@ -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;

View File

@ -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;

View File

@ -205,7 +205,7 @@ private:
postProcessRequest(int x, int z, ChunkSource *chunkSource) : x(x), z(z), chunkSource(chunkSource) {}
};
vector<postProcessRequest> m_postProcessRequests;
CRITICAL_SECTION m_postProcessCS;
ThreadLock m_postProcessCS;
public:
void addPostProcessRequest(ChunkSource *chunkSource, int x, int z);

View File

@ -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;

View File

@ -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;

View File

@ -31,9 +31,9 @@ private:
// 4J Added
vector<PlayerUID> m_bannedXuids;
deque<uint8_t> m_smallIdsToKick;
CRITICAL_SECTION m_kickPlayersCS;
ThreadLock m_kickPlayersCS;
deque<uint8_t> m_smallIdsToClose;
CRITICAL_SECTION m_closePlayersCS;
ThreadLock m_closePlayersCS;
/* 4J - removed
Set<String> bans = new HashSet<String>();
Set<String> ipBans = new HashSet<String>();

View File

@ -4,7 +4,7 @@
#include "ProgressRenderer.h"
#include "System.h"
CRITICAL_SECTION ProgressRenderer::s_progress;
ThreadLock ProgressRenderer::s_progress;
ProgressRenderer::ProgressRenderer(Minecraft *minecraft)
{

View File

@ -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();

View File

@ -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;
}

View File

@ -45,16 +45,25 @@
#define TRIGGER_MAP_0 0
#define TRIGGER_MAP_1 1
class C_4JInput
enum EKeyboardResult
{
public:
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 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);
};

View File

@ -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;

View File

@ -19,7 +19,7 @@ public:
private:
int connectionCounter;
private:
CRITICAL_SECTION pending_cs; // 4J added
ThreadLock pending_cs; // 4J added
vector< shared_ptr<PendingConnection> > pending;
vector< shared_ptr<PlayerConnection> > players;

View File

@ -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];

View File

@ -17,12 +17,12 @@ private:
EntityTracker *tracker;
PlayerChunkMap *chunkMap;
CRITICAL_SECTION m_tickNextTickCS; // 4J added
ThreadLock m_tickNextTickCS; // 4J added
set<TickNextTickData, TickNextTickDataKeyCompare> tickNextTickList; // 4J Was TreeSet
unordered_set<TickNextTickData, TickNextTickDataKeyHash, TickNextTickDataKeyEq> tickNextTickSet; // 4J Was HashSet
vector<Pos *> 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<Entity> > m_itemEntities;
list< shared_ptr<Entity> > m_hangingEntities;
list< shared_ptr<Entity> > 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);

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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::soundInfo *> SoundEngine::currentSounds;

View File

@ -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
{

View File

@ -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<FLOAT>(iWidth); // Delay the use if fWidth to reduce LHS pain
float fWidth = static_cast<float>(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<FLOAT>(m_rcWindow.x1);
FLOAT Winy = static_cast<FLOAT>(m_rcWindow.y1);
float Winx = static_cast<float>(m_rcWindow.x1);
float Winy = static_cast<float>(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();

View File

@ -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();
};

View File

@ -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;
}

View File

@ -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);
};

View File

@ -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 )

View File

@ -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)

View File

@ -170,8 +170,9 @@ void ArmorItem::setColor(shared_ptr<ItemInstance> 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();

View File

@ -48,5 +48,5 @@ public:
byteArray getBiomeIndexBlockAt(int x, int z);
private:
CRITICAL_SECTION m_CS;
ThreadLock m_CS;
};

View File

@ -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;

View File

@ -3,53 +3,47 @@
#include "net.minecraft.world.level.newbiome.layer.h"
#include "net.minecraft.world.level.h"
#include "BiomeOverrideLayer.h"
#include <fstream>
#include <vector>
#include <cstring>
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<std::size_t>(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<char*>(m_biomeOverride.data), fileSize);
if (!file.good())
{
app.FatalLoadError();
}
CloseHandle(file);
}
}

View File

@ -2,6 +2,7 @@
#include "BoundingBox.h"
#include "Direction.h"
#include "JavaMath.h"
#include <climits>
BoundingBox::BoundingBox()
{

View File

@ -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<shared_ptr<Entity> > *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;

View File

@ -1,7 +1,8 @@
#include "C4JThread.h"
std::vector<C4JThread*> 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<std::mutex> lock(m_mutex);
m_lock.lock();
m_signaled = true;
m_cv.notify_all();
m_lock.unlock();
}
void C4JThread::Event::Clear()
{
std::lock_guard<std::mutex> lock(m_mutex);
m_lock.lock();
m_signaled = false;
m_lock.unlock();
}
unsigned long C4JThread::Event::WaitForSignal(int timeoutMs)
{
std::unique_lock<std::mutex> 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<Event>(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<std::mutex> lock(ms_threadListMutex);
ms_threadListLock.lock();
ms_threadList.push_back(this);
ms_threadListLock.unlock();
}
C4JThread::C4JThread(const char* mainThreadName)

View File

@ -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<Event> m_events;
std::vector<std::unique_ptr<Event>> m_events;
};
class EventQueue
@ -72,7 +72,7 @@ public:
void threadPoll();
std::queue<void*> 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<C4JThread*> ms_threadList;
static std::mutex ms_threadListMutex;
static ThreadLock ms_threadListLock;
static thread_local C4JThread* tls_currentThread;
static C4JThread m_mainThread;

View File

@ -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"

View File

@ -18,7 +18,7 @@ static int g_currentCompressTiles = 0;
int CompressedTileStorage::deleteQueueIndex;
XLockFreeStack <unsigned char> 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

View File

@ -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();

View File

@ -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();

View File

@ -53,7 +53,7 @@ private:
bool running;
queue<shared_ptr<Packet> > incoming; // 4J - was using synchronizedList...
CRITICAL_SECTION incoming_cs; // ... now has this critical section
ThreadLock incoming_cs; // ... now has this critical section
queue<shared_ptr<Packet> > outgoing; // 4J - was using synchronizedList - but don't think it is required as usage is wrapped in writeLock critical section
queue<shared_ptr<Packet> > 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.

View File

@ -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()

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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<shared_ptr<Entity> > 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<shared_ptr<TileEntity> > tileEntityList;
private:
vector<shared_ptr<TileEntity> > 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

View File

@ -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()

View File

@ -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

View File

@ -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();

View File

@ -4,7 +4,7 @@
#include "LevelData.h"
#include "McRegionChunkStorage.h"
CRITICAL_SECTION McRegionChunkStorage::cs_memory;
ThreadLock McRegionChunkStorage::cs_memory;
std::deque<DataOutputStream *> McRegionChunkStorage::s_chunkDataQueue;
int McRegionChunkStorage::s_runningThreadCount = 0;

View File

@ -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<int64_t, byteArray> m_entityData;

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -5,12 +5,12 @@
#include "ThreadName.h"
#include "ServerConnection.h"
#include <algorithm>
#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<byte> Socket::s_hostQueue[2];
Socket::SocketOutputStreamLocal *Socket::s_hostOutStream[2];
Socket::SocketInputStreamLocal *Socket::s_hostInStream[2];

View File

@ -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<byte> s_hostQueue[2];
static SocketOutputStreamLocal *s_hostOutStream[2];
static SocketInputStreamLocal *s_hostInStream[2];
// For network connections
std::queue<byte> 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];

View File

@ -147,7 +147,7 @@ void StemTile::updateDefaultShape()
void StemTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> 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);

View File

@ -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<Enti
void Tile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> 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;

View File

@ -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

View File

@ -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;

View File

@ -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<shared_ptr<Entity> > *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())
{

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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 <cstdint>
#include <cstring>
#include <mutex>
#include <csignal>
#include <cstdlib>
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

View File

@ -6,7 +6,6 @@
#include "SkinBox.h"
#include <vector>
#define MULTITHREAD_ENABLE
@ -93,7 +92,7 @@ template <typename T>
class XLockFreeStack
{
std::vector<T*> 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<std::mutex> lock(m_mutex);
m_lock.lock();
intStack.push_back(data);
m_lock.unlock();
}
T* Pop()
{
std::lock_guard<std::mutex> lock(m_mutex);
m_lock.lock();
if (intStack.empty())
return nullptr;
T* ret = intStack.back();
intStack.pop_back();
m_lock.unlock();
return ret;
}
};