mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-07 01:47:13 +00:00
refactor: remove aabb tls
This commit is contained in:
parent
7101d03c6a
commit
a0be2e2fb5
|
|
@ -726,7 +726,6 @@ void Minecraft::run()
|
|||
{
|
||||
// try { // 4J - removed try/catch
|
||||
// if (minecraftApplet != null && !minecraftApplet.isActive()) break; // 4J - removed
|
||||
AABB::resetPool();
|
||||
|
||||
// if (parent == NULL && Display.isCloseRequested()) { // 4J - removed
|
||||
// stop();
|
||||
|
|
@ -1282,7 +1281,6 @@ void Minecraft::run_middle() {
|
|||
// try { // 4J - removed try/catch
|
||||
// if (minecraftApplet != null &&
|
||||
// !minecraftApplet.isActive()) break; // 4J - removed
|
||||
AABB::resetPool();
|
||||
|
||||
// if (parent == NULL && Display.isCloseRequested()) {
|
||||
// // 4J - removed
|
||||
|
|
@ -2226,7 +2224,6 @@ void Minecraft::run_end() { destroy(); }
|
|||
void Minecraft::emergencySave() {
|
||||
// 4J - lots of try/catches removed here, and garbage collector things
|
||||
levelRenderer->clear();
|
||||
AABB::clearPool();
|
||||
setLevel(NULL);
|
||||
}
|
||||
|
||||
|
|
@ -2402,7 +2399,6 @@ void Minecraft::levelTickUpdateFunc(void* pParam) {
|
|||
}
|
||||
|
||||
void Minecraft::levelTickThreadInitFunc() {
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -316,7 +316,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
|
|||
MinecraftServer* server = (MinecraftServer*)lpParam;
|
||||
Entity::useSmallIds(); // This thread can end up spawning entities as
|
||||
// resources
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
Tile::CreateNewThreadStorage();
|
||||
|
|
@ -365,7 +364,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
|
|||
LeaveCriticalSection(&server->m_postProcessCS);
|
||||
// #endif //__PS3__
|
||||
Tile::ReleaseThreadStorage();
|
||||
AABB::ReleaseThreadStorage();
|
||||
Level::destroyLightingCache();
|
||||
|
||||
ShutdownManager::HasFinished(ShutdownManager::ePostProcessThread);
|
||||
|
|
@ -1650,8 +1648,6 @@ void MinecraftServer::tick() {
|
|||
ironTimers.erase(toRemove[i]);
|
||||
}
|
||||
|
||||
AABB::resetPool();
|
||||
|
||||
tickCount++;
|
||||
|
||||
// 4J We need to update client difficulty levels based on the servers
|
||||
|
|
|
|||
|
|
@ -4707,7 +4707,6 @@ int CMinecraftApp::EthernetDisconnectReturned(
|
|||
int CMinecraftApp::SignoutExitWorldThreadProc(void* lpParameter) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
// app.SetGameStarted(false);
|
||||
|
|
@ -7698,7 +7697,6 @@ void CMinecraftApp::LeaveSaveNotificationSection() {
|
|||
int CMinecraftApp::RemoteSaveThreadProc(void* lpParameter) {
|
||||
// The game should be stopped while we are doing this, but the connections
|
||||
// ticks may try to create some AABB's or Vec3's
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
// 4J-PB - Xbox 360 - 163153 - [CRASH] TU17: Code: Multiplayer: During the
|
||||
|
|
|
|||
|
|
@ -950,7 +950,6 @@ bool CGameNetworkManager::IsNetworkThreadRunning() {
|
|||
int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
Tile::CreateNewThreadStorage();
|
||||
|
||||
|
|
@ -1009,7 +1008,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
|
|||
}
|
||||
|
||||
SetThreadName(-1, "Minecraft Server thread");
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
OldChunkStorage::UseDefaultThreadStorage();
|
||||
Entity::useSmallIds();
|
||||
|
|
@ -1022,7 +1020,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
|
|||
lpParameter); // saveData, app.GetGameHostOption(eGameHostOption_All));
|
||||
|
||||
Tile::ReleaseThreadStorage();
|
||||
AABB::ReleaseThreadStorage();
|
||||
Level::destroyLightingCache();
|
||||
|
||||
if (lpParameter != NULL) delete (NetworkGameInitData*)lpParameter;
|
||||
|
|
@ -1033,7 +1030,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
|
|||
int CGameNetworkManager::ExitAndJoinFromInviteThreadProc(void* lpParam) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
// app.SetGameStarted(false);
|
||||
|
|
@ -1185,7 +1181,6 @@ void CGameNetworkManager::_LeaveGame() {
|
|||
int CGameNetworkManager::ChangeSessionTypeThreadProc(void* lpParam) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
|
|
|
|||
|
|
@ -383,7 +383,6 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) {
|
|||
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
|
|
@ -420,7 +419,6 @@ int IUIScene_PauseMenu::SaveWorldThreadProc(void* lpParameter) {
|
|||
int IUIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
// app.SetGameStarted(false);
|
||||
|
|
|
|||
|
|
@ -222,7 +222,6 @@ HRESULT CScene_Death::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) {
|
|||
}
|
||||
|
||||
int CScene_Death::RespawnThreadProc(void* lpParameter) {
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
size_t iPad = (size_t)lpParameter;
|
||||
|
||||
|
|
|
|||
|
|
@ -1075,7 +1075,6 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) {
|
|||
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
|
|
@ -1107,7 +1106,6 @@ int UIScene_PauseMenu::SaveWorldThreadProc(LPVOID lpParameter) {
|
|||
int UIScene_PauseMenu::ExitWorldThreadProc(void* lpParameter) {
|
||||
// Share AABB & Vec3 pools with default (main thread) - should be ok as long
|
||||
// as we don't tick the main thread whilst this thread is running
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Compression::UseDefaultThreadStorage();
|
||||
|
||||
// app.SetGameStarted(false);
|
||||
|
|
|
|||
|
|
@ -794,7 +794,6 @@ void oldWinMainInit() {
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
Tile::CreateNewThreadStorage();
|
||||
|
|
|
|||
|
|
@ -856,7 +856,6 @@ return -1;
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
|
|
|||
|
|
@ -1040,7 +1040,6 @@ void RegisterAwardsWithProfileManager() {
|
|||
}
|
||||
|
||||
int StartMinecraftThreadProc(void* lpParameter) {
|
||||
AABB::UseDefaultThreadStorage();
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
RenderManager.InitialiseContext();
|
||||
Minecraft::start(std::wstring(), std::wstring());
|
||||
|
|
@ -1376,7 +1375,6 @@ int main(int argc, const char* argv[]) {
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
|
|
|||
|
|
@ -1210,7 +1210,6 @@ int main() {
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
Tile::CreateNewThreadStorage();
|
||||
|
|
|
|||
|
|
@ -660,7 +660,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
||||
Minecraft::main();
|
||||
|
|
|
|||
|
|
@ -895,7 +895,6 @@ int main() {
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
|
|
|||
|
|
@ -940,7 +940,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
|
|
|||
|
|
@ -699,7 +699,6 @@ int __cdecl main() {
|
|||
// Initialise TLS for tesselator, for this main thread
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
// Initialise TLS for AABB and Vec3 pools, for this main thread
|
||||
AABB::CreateNewThreadStorage();
|
||||
Compression::CreateNewThreadStorage();
|
||||
OldChunkStorage::CreateNewThreadStorage();
|
||||
Level::enableLightingCache();
|
||||
|
|
|
|||
|
|
@ -1121,7 +1121,6 @@ void GameRenderer::FinishedReassigning() {
|
|||
|
||||
int GameRenderer::runUpdate(void* lpParam) {
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
AABB::CreateNewThreadStorage();
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
Compression::UseDefaultThreadStorage();
|
||||
RenderManager.InitialiseContext();
|
||||
|
|
@ -1200,7 +1199,6 @@ int GameRenderer::runUpdate(void* lpParam) {
|
|||
|
||||
// PIXEndNamedEvent();
|
||||
|
||||
AABB::resetPool();
|
||||
m_updateEvents->Set(eUpdateEventIsFinished);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4030,7 +4030,6 @@ void LevelRenderer::staticCtor() {
|
|||
}
|
||||
|
||||
int LevelRenderer::rebuildChunkThreadProc(void* lpParam) {
|
||||
AABB::CreateNewThreadStorage();
|
||||
Tesselator::CreateNewThreadStorage(1024 * 1024);
|
||||
RenderManager.InitialiseContext();
|
||||
Chunk::CreateNewThreadStorage();
|
||||
|
|
|
|||
|
|
@ -12,47 +12,6 @@
|
|||
#include "HitResult.h"
|
||||
#include "Util/Vec3.h"
|
||||
|
||||
thread_local AABB::ThreadStorage* AABB::m_tlsPool = nullptr;
|
||||
AABB::ThreadStorage* AABB::m_tlsPoolDefault = nullptr;
|
||||
|
||||
AABB::ThreadStorage::ThreadStorage() {
|
||||
pool = new AABB[POOL_SIZE]; // 4jcraft, needs to be deleted with delete[]
|
||||
poolPointer = 0;
|
||||
}
|
||||
|
||||
AABB::ThreadStorage::~ThreadStorage() {
|
||||
delete[] pool; // 4jcraft, changed to []
|
||||
}
|
||||
|
||||
void AABB::CreateNewThreadStorage() {
|
||||
ThreadStorage* tls = new ThreadStorage();
|
||||
if (m_tlsPoolDefault == nullptr) {
|
||||
m_tlsPoolDefault = tls;
|
||||
}
|
||||
m_tlsPool = tls;
|
||||
}
|
||||
|
||||
void AABB::UseDefaultThreadStorage() { m_tlsPool = m_tlsPoolDefault; }
|
||||
|
||||
void AABB::ReleaseThreadStorage() {
|
||||
if (m_tlsPool != m_tlsPoolDefault) {
|
||||
delete m_tlsPool;
|
||||
}
|
||||
}
|
||||
|
||||
void AABB::clearPool() {}
|
||||
|
||||
void AABB::resetPool() {}
|
||||
|
||||
AABB* AABB::newTemp(double x0, double y0, double z0, double x1, double y1,
|
||||
double z1) {
|
||||
ThreadStorage* tls = m_tlsPool;
|
||||
AABB* thisAABB = &tls->pool[tls->poolPointer];
|
||||
*thisAABB = {x0, y0, z0, x1, y1, z1};
|
||||
tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE;
|
||||
return thisAABB;
|
||||
}
|
||||
|
||||
AABB::AABB(double x0, double y0, double z0, double x1, double y1, double z1) {
|
||||
this->x0 = x0;
|
||||
this->y0 = y0;
|
||||
|
|
|
|||
|
|
@ -6,38 +6,13 @@
|
|||
class HitResult;
|
||||
|
||||
class AABB {
|
||||
// 4J added so we can have separate pools for different threads
|
||||
class ThreadStorage {
|
||||
public:
|
||||
static const int POOL_SIZE = 1024;
|
||||
AABB* pool;
|
||||
unsigned int poolPointer;
|
||||
ThreadStorage();
|
||||
~ThreadStorage();
|
||||
};
|
||||
static thread_local ThreadStorage* m_tlsPool;
|
||||
static ThreadStorage* m_tlsPoolDefault;
|
||||
|
||||
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
|
||||
static void CreateNewThreadStorage();
|
||||
static void UseDefaultThreadStorage();
|
||||
static void ReleaseThreadStorage();
|
||||
|
||||
static void clearPool();
|
||||
static void resetPool();
|
||||
static AABB* newTemp(double x0, double y0, double z0, double x1, double y1,
|
||||
double z1);
|
||||
|
||||
double x0, y0, z0;
|
||||
double x1, y1, z1;
|
||||
|
||||
AABB() {}
|
||||
AABB(double x0, double y0, double z0, double x1, double y1, double z1);
|
||||
|
||||
public:
|
||||
AABB expand(double xa, double ya, double za) const;
|
||||
AABB grow(double xa, double ya, double za) const;
|
||||
AABB minmax(const AABB& other) const;
|
||||
|
|
|
|||
Loading…
Reference in a new issue