Probably for TU30

This commit is contained in:
GabsPuNs
2026-06-05 16:06:08 -04:00
parent 22a1aa3a74
commit 86b1da99ae
2 changed files with 108 additions and 236 deletions

View File

@@ -264,10 +264,6 @@ void DLCTexturePack::loadData()
}
}
wstring DLCTexturePack::getFilePath(DWORD packId, wstring filename, bool bAddDataFolder)
{
return app.getFilePath(packId,filename,bAddDataFolder);
@@ -277,6 +273,7 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
{
DLCTexturePack *texturePack = static_cast<DLCTexturePack *>(pParam);
texturePack->m_bLoadingData = false;
if(dwErr!=ERROR_SUCCESS)
{
// corrupt DLC
@@ -288,6 +285,7 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
texturePack->m_dlcDataPack = new DLCPack(texturePack->m_dlcInfoPack->getName(), dwLicenceMask);
texturePack->setHasAudio(false);
DWORD dwFilesProcessed = 0;
// Load the DLC textures
wstring dataFilePath = texturePack->m_dlcInfoPack->getFullDataPath();
if(!dataFilePath.empty())
@@ -301,41 +299,9 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
// Load the UI data
if(texturePack->m_dlcDataPack != nullptr)
{
#ifdef _XBOX
File xzpPath(getFilePath(texturePack->m_dlcInfoPack->GetPackID(), wstring(L"TexturePack.xzp") ) );
if(xzpPath.exists())
{
const char *pchFilename=wstringtofilename(xzpPath.getPath());
HANDLE fileHandle = CreateFile(
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share file? Probably not but...
nullptr, // Unused
OPEN_EXISTING , // how to create // TODO 4J Stu - Assuming that the file already exists if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
nullptr // Unsupported
);
if( fileHandle != INVALID_HANDLE_VALUE )
{
DWORD dwFileSize = xzpPath.length();
DWORD bytesRead;
PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
BOOL success = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,nullptr);
CloseHandle(fileHandle);
if(success)
{
DLCUIDataFile *uiDLCFile = (DLCUIDataFile *)texturePack->m_dlcDataPack->addFile(DLCManager::e_DLCType_UIData,L"TexturePack.xzp");
uiDLCFile->addData(pbData,bytesRead,true);
}
}
}
#else
File archivePath(getFilePath(texturePack->m_dlcInfoPack->GetPackID(), wstring(L"media.arc") ) );
if(archivePath.exists()) texturePack->m_archiveFile = new ArchiveFile(archivePath);
#endif
if(archivePath.exists())
texturePack->m_archiveFile = new ArchiveFile(archivePath);
/**
4J-JEV:
@@ -386,10 +352,10 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
DWORD bytesRead;
PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
app.FatalLoadError();
}
CloseHandle(fileHandle);
// 4J-PB - is it possible that we can get here after a read fail and it's not an error?
@@ -431,16 +397,15 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
nullptr // Unsupported
);
#endif
if( fileHandle != INVALID_HANDLE_VALUE )
{
DWORD bytesRead,dwFileSize = GetFileSize(fileHandle,nullptr);
PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
app.FatalLoadError();
}
CloseHandle(fileHandle);
// 4J-PB - is it possible that we can get here after a read fail and it's not an error?
@@ -449,104 +414,76 @@ int DLCTexturePack::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicen
}
}
}
// any audio data?
#ifdef _XBOX
File audioXSBPath(getFilePath(texturePack->m_dlcInfoPack->GetPackID(), wstring(L"MashUp.xsb") ) );
File audioXWBPath(getFilePath(texturePack->m_dlcInfoPack->GetPackID(), wstring(L"MashUp.xwb") ) );
if(audioXSBPath.exists() && audioXWBPath.exists())
{
texturePack->setHasAudio(true);
const char *pchXWBFilename=wstringtofilename(audioXWBPath.getPath());
Minecraft::GetInstance()->soundEngine->CreateStreamingWavebank(pchXWBFilename,&texturePack->m_pStreamedWaveBank);
const char *pchXSBFilename=wstringtofilename(audioXSBPath.getPath());
Minecraft::GetInstance()->soundEngine->CreateSoundbank(pchXSBFilename,&texturePack->m_pSoundBank);
}
#else
//DLCPack *pack = texturePack->m_dlcInfoPack->GetParentPack();
if(pack->getDLCItemsCount(DLCManager::e_DLCType_Audio)>0)
if(pack->getDLCItemsCount(DLCManager::e_DLCType_Audio) > 0)
{
DLCAudioFile *dlcFile = static_cast<DLCAudioFile *>(pack->getFile(DLCManager::e_DLCType_Audio, 0));
texturePack->setHasAudio(true);
// init the streaming sound ids for this texture pack
int iOverworldC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Overworld);
int iNetherC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Nether);
int iEndStart=iOverworldC+iNetherC;
int iEndC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_End);
int iAfterEnd=iOverworldC+iNetherC+iEndC;
int iCreativeC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Creative);
// init the streaming sound ids for this texture pack
int iOverworldC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Overworld);
int iNetherC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Nether);
int iEndC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_End);
int iCreativeC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Creative);
int iMenuC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Menu);
int iBattleC = dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Battle);
int iEndStart = iOverworldC + iNetherC;
int iAfterEnd = iEndStart + iEndC;
int iCreativeStart, iCreativeRange;
int iMenuStart, iMenuRange;
if(iCreativeC)
{
iCreativeStart=iAfterEnd;
iCreativeRange=iCreativeC;
iAfterEnd+=iCreativeC;
iCreativeStart = iAfterEnd;
iAfterEnd += iCreativeC;
}
else
{
iCreativeStart=0;
iCreativeRange=iOverworldC;
}
iCreativeStart = 0;
int iMenuC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Menu);
int iMenuStart, iMenuRange;
if(iMenuC)
{
iMenuStart=iAfterEnd;
iMenuRange=iMenuC;
iAfterEnd+=iMenuC;
iMenuStart = iAfterEnd;
iAfterEnd += iMenuC;
}
else
{
iMenuStart=0;
iMenuRange=iOverworldC;
}
iMenuStart = 0;
int iBattleC=dlcFile->GetCountofType(DLCAudioFile::e_AudioType_Battle);
if(iBattleC)
{
Minecraft::GetInstance()->soundEngine->SetStreamingSounds(
0,iOverworldC-1,
iOverworldC,iOverworldC+iNetherC-1,
iEndStart,iEndStart+iEndC-1,
iCreativeStart,iCreativeStart+iCreativeRange-1,
iMenuStart,iMenuStart+iMenuRange-1,
iAfterEnd,iAfterEnd+iBattleC-1,
iAfterEnd+iBattleC);
0, iOverworldC -1,
iOverworldC, iOverworldC + iNetherC -1,
iEndStart, iEndStart + iEndC -1,
iCreativeStart, iCreativeStart + iCreativeC -1,
iMenuStart, iMenuStart + iMenuRange -1,
iAfterEnd, iAfterEnd + iBattleC -1,
iAfterEnd + iBattleC);
}
else
{
Minecraft::GetInstance()->soundEngine->SetStreamingSounds(
0,iOverworldC-1,
iOverworldC,iOverworldC+iNetherC-1,
iEndStart,iEndStart+iEndC-1,
iCreativeStart,iCreativeStart+iCreativeRange-1,
iMenuStart,iMenuStart+iMenuRange-1,
0,iOverworldC-1,
0, iOverworldC -1,
iOverworldC, iOverworldC + iNetherC -1,
iEndStart, iEndStart + iEndC -1,
iCreativeStart, iCreativeStart + iCreativeC -1,
iMenuStart, iMenuStart + iMenuC -1,
0, iOverworldC -1,
iAfterEnd);
}
}
#endif
}
}
texturePack->loadColourTable();
}
// 4J-PB - we need to leave the texture pack mounted if it contained streaming audio
if(texturePack->hasAudio()==false)
{
#ifdef _XBOX
StorageManager.UnmountInstalledDLC("TPACK");
#endif
}
}
texturePack->m_bHasLoadedData = true;
if (app.getLevelGenerationOptions()) app.getLevelGenerationOptions()->setLoadedData();
if (app.getLevelGenerationOptions())
app.getLevelGenerationOptions()->setLoadedData();
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
return 0;

View File

@@ -91,14 +91,14 @@ DWORD Level::tlsIdxLightCache = TlsAlloc();
void Level::enableLightingCache()
{
// Allocate 16K (needs 32K for large worlds) for a 16x16x16x4 BYTE cache of results, plus 128K required for toCheck array. Rounding up to 256 to keep as multiple of alignement - aligning to 128K boundary for possible cache locking.
void *cache = static_cast<unsigned char *>(XPhysicalAlloc(256 * 1024, MAXULONG_PTR, 128 * 1024, PAGE_READWRITE | MEM_LARGE_PAGES));
void *cache = _aligned_malloc(256 * 1024, 128 * 1024);
TlsSetValue(tlsIdxLightCache,cache);
}
void Level::destroyLightingCache()
{
lightCache_t *cache = static_cast<lightCache_t *>(TlsGetValue(tlsIdxLightCache));
XPhysicalFree(cache);
_aligned_free(cache);
}
inline int GetIndex(int x, int y, int z)
@@ -588,7 +588,7 @@ void Level::_init()
villageSiege = new VillageSiege(this);
scoreboard = new Scoreboard();
toCheckLevel = new int[ 32 * 32 * 32]; // 4J - brought forward from 1.8.2
toCheckLevel = new int[32 * 32 * 32]; // - 4J - brought forward from 1.8.2
InitializeCriticalSectionAndSpinCount(&m_checkLightCS, 5120); // 4J - added for 1.8.2 lighting
// 4J Added
@@ -3444,71 +3444,47 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool f
// 4J - special mode added so we can do lava lighting updates without having all neighbouring chunks loaded in
if (!hasChunksAt(xc, yc, zc, 0)) return;
}
else
{
// 4J - this is normal java behaviour
if (!hasChunksAt(xc, yc, zc, 17)) return;
}
#if 0
/////////////////////////////////////////////////////////////////////////////////////////////
// Get the frequency of the timer
LARGE_INTEGER qwTicksPerSec, qwTime, qwNewTime, qwDeltaTime1, qwDeltaTime2;
float fElapsedTime1 = 0.0f;
float fElapsedTime2 = 0.0f;
QueryPerformanceFrequency( &qwTicksPerSec );
float fSecsPerTick = 1.0f / (float)qwTicksPerSec.QuadPart;
QueryPerformanceCounter( &qwTime );
/////////////////////////////////////////////////////////////////////////////////////////////
#endif
EnterCriticalSection(&m_checkLightCS);
initCachePartial(cache, xc, yc, zc);
// If we're in cached mode, then use memory allocated after the cached data itself for the toCheck array, in an attempt to make both that & the other cached data sit on the CPU L2 cache better.
int *toCheck;
if( cache == nullptr )
{
toCheck = toCheckLevel;
}
else
{
toCheck = reinterpret_cast<int *>(cache + (16 * 16 * 16));
}
int checkedPosition = 0;
int toCheckCount = 0;
//int darktcc = 0;
// 4J - added
int minXZ = - (dimension->getXZSize() * 16 ) / 2;
int maxXZ = (dimension->getXZSize() * 16 ) / 2 - 1;
if( ( xc > maxXZ ) || ( xc < minXZ ) || ( zc > maxXZ ) || ( zc < minXZ ) )
if( xc > maxXZ )
{
LeaveCriticalSection(&m_checkLightCS);
return;
}
// Lock 128K of cache (containing all the lighting cache + first 112K of toCheck array) on L2 to try and stop any cached data getting knocked out of L2 by other non-cached reads (or vice-versa)
// if( cache ) XLockL2(XLOCKL2_INDEX_TITLE, cache, 128 * 1024, XLOCKL2_LOCK_SIZE_1_WAY, 0 );
// If we're in cached mode, then use memory allocated after the cached data itself for the toCheck array, in an attempt to make both that & the other cached data sit on the CPU L2 cache better.
int *toCheck;
if( cache == nullptr )
toCheck = toCheckLevel;
else
toCheck = reinterpret_cast<int *>(cache + (16 * 16 * 16));
{
int checkedPosition = 0;
int toCheckCount = 0;
//int darktcc = 0;
if (xc >= minXZ && zc <= maxXZ && zc >= minXZ)
{
int centerCurrent = getBrightnessCached(cache, layer, xc, yc, zc);
int centerExpected = getExpectedLight(cache, xc, yc, zc, layer, false);
if( centerExpected != centerCurrent && cache )
{
initCacheComplete(cache, xc, yc, zc);
}
if (centerExpected > centerCurrent)
{
toCheck[toCheckCount++] = 32 | (32 << 6) | (32 << 12);
}
else if (centerExpected < centerCurrent)
{
// 4J - added tcn. This is the code that is run when checkLight has been called for a light source that has got darker / turned off.
@@ -3516,64 +3492,55 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool f
// stage of the function to potentially have their brightnesses put back up again. We shouldn't need to consider All these tiles as starting points for this process, now just
// considering the edge tiles (defined as a tile where we have a neighbour that is brightner than can be explained by the original light source we are turning off)
int tcn = 0;
if (layer == LightLayer::Block || true)
toCheck[toCheckCount++] = 32 | (32 << 6) | (32 << 12) | (centerCurrent << 18);
while (checkedPosition < toCheckCount)
{
toCheck[toCheckCount++] = 32 | (32 << 6) | (32 << 12) | (centerCurrent << 18);
while (checkedPosition < toCheckCount)
int p = toCheck[checkedPosition++];
int x = ((p) & 63) - 32 + xc;
int y = ((p >> 6) & 63) - 32 + yc;
int z = ((p >> 12) & 63) - 32 + zc;
int expected = ((p >> 18) & 15);
int current = getBrightnessCached(cache, layer, x, y, z);
if (current == expected)
{
int p = toCheck[checkedPosition++];
int x = ((p) & 63) - 32 + xc;
int y = ((p >> 6) & 63) - 32 + yc;
int z = ((p >> 12) & 63) - 32 + zc;
int expected = ((p >> 18) & 15);
int current = getBrightnessCached(cache, layer, x, y, z);
if (current == expected)
setBrightnessCached(cache, &cacheUse, layer, x, y, z, 0);
// cexp--; // 4J - removed, change from 1.2.3
if (expected > 0)
{
setBrightnessCached(cache, &cacheUse, layer, x, y, z, 0);
// cexp--; // 4J - removed, change from 1.2.3
if (expected > 0)
int xd = Mth::abs(x - xc);
int yd = Mth::abs(y - yc);
int zd = Mth::abs(z - zc);
if (xd + yd + zd < 17)
{
int xd = Mth::abs(x - xc);
int yd = Mth::abs(y - yc);
int zd = Mth::abs(z - zc);
if (xd + yd + zd < 17)
bool edge = false;
for (int face = 0; face < 6; face++)
{
bool edge = false;
for (int face = 0; face < 6; face++)
{
int xx = x + Facing::STEP_X[face];
int yy = y + Facing::STEP_Y[face];
int zz = z + Facing::STEP_Z[face];
int xx = x + Facing::STEP_X[face];
int yy = y + Facing::STEP_Y[face];
int zz = z + Facing::STEP_Z[face];
// 4J - added - don't let this lighting creep out of the normal fixed world and into the infinite water chunks beyond
if( ( xx > maxXZ ) || ( xx < minXZ ) || ( zz > maxXZ ) || ( zz < minXZ ) ) continue;
if( ( yy < 0 ) || ( yy >= maxBuildHeight ) ) continue;
// 4J - added - don't let this lighting creep out of the normal fixed world and into the infinite water chunks beyond
if( ( xx > maxXZ ) || ( xx < minXZ ) || ( zz > maxXZ ) || ( zz < minXZ ) ) continue;
if( ( yy < 0 ) || ( yy >= maxBuildHeight ) ) continue;
// 4J - some changes here brought forward from 1.2.3
int block = max(1, getBlockingCached(cache, layer, nullptr, xx, yy, zz) );
current = getBrightnessCached(cache, layer, xx, yy, zz);
if ((current == expected - block) && (toCheckCount < (32 * 32 * 32))) // 4J - 32 * 32 * 32 was toCheck.length
{
toCheck[toCheckCount++] = (xx - xc + 32) | ((yy - yc + 32) << 6) | ((zz - zc + 32) << 12) | ((expected - block) << 18);
}
else
{
// 4J - added - keep track of which tiles form the edge of the region we are zeroing
if( current > ( expected - block ) )
{
edge = true;
}
}
}
// 4J - added - keep track of which tiles form the edge of the region we are zeroing - can store over the original elements in the array because tcn must be <= tcp
if( edge == true )
// 4J - some changes here brought forward from 1.2.3
int block = max(1, getBlockingCached(cache, layer, nullptr, xx, yy, zz) );
current = getBrightnessCached(cache, layer, xx, yy, zz);
if ((current == expected - block) && (toCheckCount < (32 * 32 * 32))) // 4J - 32 * 32 * 32 was toCheck.length
toCheck[toCheckCount++] = (xx - xc + 32) | ((yy - yc + 32) << 6) | ((zz - zc + 32) << 12) | ((expected - block) << 18);
else if( current > ( expected - block ) )
{
toCheck[tcn++] = p;
// 4J - added - keep track of which tiles form the edge of the region we are zeroing
edge = true;
}
}
// 4J - added - keep track of which tiles form the edge of the region we are zeroing - can store over the original elements in the array because tcn must be <= tcp
if( edge == true )
toCheck[tcn++] = p;
}
}
}
}
checkedPosition = 0;
@@ -3591,35 +3558,26 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool f
// If force is set, then this is being used to in a special mode to try and light lava tiles as chunks are being loaded in. In this case, we
// don't want a lighting update to drag in any neighbouring chunks that aren't loaded yet.
if( force )
{
if( !hasChunkAt(x,y,z) )
{
continue;
}
}
if( force || (y < 0 && y > 256 && !hasChunkAt(x, y, z)) )
continue;
int current = getBrightnessCached(cache, layer, x, y, z);
// If rootOnlyEmissive flag is set, then only consider the starting tile to be possibly emissive.
bool propagatedOnly = false;
if (layer == LightLayer::Block)
{
if( rootOnlyEmissive )
{
propagatedOnly = ( x != xc ) || ( y != yc ) || ( z != zc );
}
}
int expected = getExpectedLight(cache, x, y, z, layer, propagatedOnly);
if (layer == LightLayer::Block && rootOnlyEmissive)
propagatedOnly = ( x != xc ) || ( y != yc ) || ( z != zc );
int expected = getExpectedLight(cache, x, y, z, layer, propagatedOnly);
if (expected != current)
{
setBrightnessCached(cache, &cacheUse, layer, x, y, z, expected);
if (expected > current)
{
int xd = abs(x - xc);
int yd = abs(y - yc);
int zd = abs(z - zc);
int xd = Mth::abs(x - xc);
int yd = Mth::abs(y - yc);
int zd = Mth::abs(z - zc);
bool withinBounds = toCheckCount < (32 * 32 * 32) - 6; // 4J - 32 * 32 * 32 was toCheck.length
if (xd + yd + zd < 17 && withinBounds)
{
@@ -3634,34 +3592,11 @@ void Level::checkLight(LightLayer::variety layer, int xc, int yc, int zc, bool f
}
}
}
// if( cache ) XUnlockL2(XLOCKL2_INDEX_TITLE);
#if 0
QueryPerformanceCounter( &qwNewTime );
qwDeltaTime1.QuadPart = qwNewTime.QuadPart - qwTime.QuadPart;
qwTime = qwNewTime;
#endif
flushCache(cache, cacheUse, layer);
#if 0
/////////////////////////////////////////////////////////////////
if( cache )
{
QueryPerformanceCounter( &qwNewTime );
qwDeltaTime2.QuadPart = qwNewTime.QuadPart - qwTime.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);
}
}
/////////////////////////////////////////////////////////////////
#endif
LeaveCriticalSection(&m_checkLightCS);
}
bool Level::tickPendingTicks(bool force)
{
return false;