refactor: eliminate app. calls from minecraft via Log, Strings, GameHostOptions, and service wiring

This commit is contained in:
MatthewBeshay
2026-04-04 14:47:39 +11:00
committed by Tropical
parent f28c722da4
commit 5f64818302
190 changed files with 2987 additions and 1165 deletions

View File

@@ -1,3 +1,7 @@
#include "minecraft/GameServices.h"
#include "minecraft/util/DebugSettings.h"
#include "minecraft/GameHostOptions.h"
#include "minecraft/util/Log.h"
#include "minecraft/world/level/storage/ConsoleSaveFileIO/ConsoleSaveFileSplit.h"
#include <assert.h>
@@ -197,7 +201,7 @@ void ConsoleSaveFileSplit::RegionFileReference::Compress() {
assert((dataOut - dataCompressed) == outputSize);
dataCompressedSize = outputSize;
// std::int64_t endTime = System::currentTimeMillis();
// app.DebugPrintf("Compressing region file 0x%.8x from %d to %d bytes -
// Log::info("Compressing region file 0x%.8x from %d to %d bytes -
//%dms\n", fileEntry->data.regionIndex, fileEntry->data.length,
// dataCompressedSize, endTime - startTime);
}
@@ -277,7 +281,7 @@ void ConsoleSaveFileSplit::RegionFileReference::Decompress() {
assert(0);
}
// std::int64_t endTime = System::currentTimeMillis();
// app.DebugPrintf("Decompressing region file from 0x%.8x %d to %d bytes -
// Log::info("Decompressing region file from 0x%.8x %d to %d bytes -
//%dms\n", fileEntry->data.regionIndex, dataCompressedSize,
// fileEntry->data.length, endTime - startTime);//
}
@@ -337,7 +341,7 @@ unsigned int ConsoleSaveFileSplit::RegionFileReference::GetCompressedSize() {
// Release dataCompressed
void ConsoleSaveFileSplit::RegionFileReference::ReleaseCompressed() {
// app.DebugPrintf("Releasing compressed data for region file from
// Log::info("Releasing compressed data for region file from
// 0x%.8x\n", fileEntry->data.regionIndex );
free(dataCompressed);
dataCompressed = nullptr;
@@ -367,7 +371,7 @@ ConsoleSaveFileSplit::ConsoleSaveFileSplit(
// Load a save from the game rules
bool bLevelGenBaseSave = false;
LevelGenerationOptions* levelGen = app.getLevelGenerationOptions();
LevelGenerationOptions* levelGen = GameServices::getLevelGenerationOptions();
if (pvSaveData == nullptr && levelGen != nullptr &&
levelGen->requiresBaseSave()) {
pvSaveData = levelGen->getBaseSaveData(fileSize);
@@ -491,7 +495,7 @@ void ConsoleSaveFileSplit::_init(const std::wstring& fileName, void* pvSaveData,
} else {
unsigned int storageLength;
PlatformStorage.GetSaveData(pvSaveMem, &storageLength);
app.DebugPrintf("Filesize - %d, Adjusted size - %d\n", fileSize,
Log::info("Filesize - %d, Adjusted size - %d\n", fileSize,
storageLength);
fileSize = storageLength;
}
@@ -504,7 +508,7 @@ void ConsoleSaveFileSplit::_init(const std::wstring& fileName, void* pvSaveData,
if (decompSize == 0) {
// 4J Stu - Saves created between 2/12/2011 and 7/12/2011 will
// have this problem
app.DebugPrintf("Invalid save data format\n");
Log::info("Invalid save data format\n");
memset(pvSaveMem, 0, fileSize);
// Clear the first 8 bytes that reference the header
header.WriteHeader(pvSaveMem);
@@ -538,7 +542,7 @@ void ConsoleSaveFileSplit::_init(const std::wstring& fileName, void* pvSaveData,
} else {
// Corrupt save, although most of the terrain should
// actually be ok
app.DebugPrintf("Failed to decompress save data!\n");
Log::info("Failed to decompress save data!\n");
#if !defined(_CONTENT_PACKAGE)
__debugbreak();
#endif
@@ -721,7 +725,7 @@ bool ConsoleSaveFileSplit::writeFile(FileEntry* file, const void* lpBuffer,
memcpy(fileRef->data + file->currentFilePointer, lpBuffer,
nNumberOfBytesToWrite);
// app.DebugPrintf(">>>>>>>>>>>>>> writing a region file's
// Log::info(">>>>>>>>>>>>>> writing a region file's
// data 0x%.8x, 0x%x offset %d of %d bytes (writing %d
// bytes)\n",file->data.regionIndex,fileRef->data,file->currentFilePointer,
// file->getFileSize(), nNumberOfBytesToWrite);
@@ -788,7 +792,7 @@ bool ConsoleSaveFileSplit::zeroFile(FileEntry* file,
memset(fileRef->data + file->currentFilePointer, 0,
nNumberOfBytesToWrite);
// app.DebugPrintf(">>>>>>>>>>>>>> writing a region file's
// Log::info(">>>>>>>>>>>>>> writing a region file's
// data 0x%.8x, 0x%x offset %d of %d bytes (writing %d
// bytes)\n",file->data.regionIndex,fileRef->data,file->currentFilePointer,
// file->getFileSize(), nNumberOfBytesToWrite);
@@ -966,7 +970,7 @@ void ConsoleSaveFileSplit::tick() {
writeHistory.push_back(writeEvent);
regionRef->Compress();
// app.DebugPrintf("Tick: Writing region 0x%.8x, compressed
// Log::info("Tick: Writing region 0x%.8x, compressed
// as %d bytes\n",regionRef->fileEntry->getRegionFileIndex(),
// regionRef->dataCompressedSize);
PlatformStorage.UpdateSubfile(regionRef->index,
@@ -1275,7 +1279,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
// The storage manage might potentially be busy doing a sub-file write
// initiated from the tick. Wait until this is totally processed.
while (PlatformStorage.GetSaveState() != IPlatformStorage::ESaveGame_Idle) {
app.DebugPrintf("Flush wait\n");
Log::info("Flush wait\n");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
@@ -1314,7 +1318,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
Compression::getCompression()->Compress(nullptr, &compLength, pvSaveMem,
fileSize);
app.DebugPrintf("Check buffer size: Elapsed time %f\n",
Log::info("Check buffer size: Elapsed time %f\n",
static_cast<float>(timer.elapsed_seconds()));
// We add 4 bytes to the start so that we can signal compressed data
@@ -1331,7 +1335,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
Compression::getCompression()->Compress(compData + 8, &compLength,
pvSaveMem, fileSize);
app.DebugPrintf("Compress: Elapsed time %f\n",
Log::info("Compress: Elapsed time %f\n",
static_cast<float>(timer.elapsed_seconds()));
memset(compData, 0, 8);
@@ -1339,7 +1343,7 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
memcpy(compData, &saveVer, sizeof(int));
memcpy(compData + 4, &fileSize, sizeof(int));
app.DebugPrintf("Save data compressed from %d to %d\n", fileSize,
Log::info("Save data compressed from %d to %d\n", fileSize,
compLength);
if (updateThumbnail) {
@@ -1363,16 +1367,16 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
hasSeed = true;
}
int iTextMetadataBytes = app.CreateImageTextData(
int iTextMetadataBytes = GameServices::createImageTextData(
bTextMetadata, seed, hasSeed,
app.GetGameHostOption(eGameHostOption_All),
GameHostOptions::get(eGameHostOption_All),
Minecraft::GetInstance()->getCurrentTexturePackId());
// set the icon and save image
PlatformStorage.SetSaveImages(pbThumbnailData, dwThumbnailDataSize,
pbDataSaveImage, dwDataSizeSaveImage,
bTextMetadata, iTextMetadataBytes);
app.DebugPrintf("Save thumbnail size %d\n", dwThumbnailDataSize);
Log::info("Save thumbnail size %d\n", dwThumbnailDataSize);
}
int32_t saveOrCheckpointId = 0;
@@ -1384,8 +1388,8 @@ void ConsoleSaveFileSplit::Flush(bool autosave, bool updateThumbnail) {
return SaveSaveDataCallback(this, bRes);
});
#if !defined(_CONTENT_PACKAGE)
if (app.DebugSettingsOn()) {
if (app.GetWriteSavesToFolderEnabled()) {
if (DebugSettings::isOn()) {
if (GameServices::getWriteSavesToFolderEnabled()) {
DebugFlushToFile(compData, compLength + 8);
}
}
@@ -1593,10 +1597,10 @@ void ConsoleSaveFileSplit::ConvertToLocalPlatform() {
std::wstring suffix(L".mcr");
if (fName.compare(fName.length() - suffix.length(), suffix.length(),
suffix) == 0) {
app.DebugPrintf("Processing a region file: %ls\n", fName.c_str());
Log::info("Processing a region file: %ls\n", fName.c_str());
ConvertRegionFile(File(fe->data.filename));
} else {
app.DebugPrintf("%ls is not a region file, ignoring\n",
Log::info("%ls is not a region file, ignoring\n",
fName.c_str());
}
}