mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-18 17:22:55 +00:00
fix: harden Log::info, switch StringTable to span, consolidate getLocale
This commit is contained in:
parent
84140ae6d4
commit
80019158da
|
|
@ -12,7 +12,6 @@ DLCLocalisationFile::DLCLocalisationFile(const std::string& path)
|
|||
|
||||
void DLCLocalisationFile::addData(std::uint8_t* pbData,
|
||||
std::uint32_t dataBytes) {
|
||||
std::vector<std::string> locales;
|
||||
app.getLocale(locales);
|
||||
m_strings = new StringTable(pbData, dataBytes, locales);
|
||||
m_strings = new StringTable(
|
||||
std::span<const std::uint8_t>(pbData, dataBytes), app.getLocale());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,8 +351,6 @@ void DLCPack::UpdateLanguage() {
|
|||
DLCLocalisationFile* localisationFile = (DLCLocalisationFile*)getFile(
|
||||
DLCManager::e_DLCType_LocalisationData, "languages.loc");
|
||||
StringTable* strTable = localisationFile->getStringTable();
|
||||
std::vector<std::string> locales;
|
||||
app.getLocale(locales);
|
||||
strTable->ReloadStringTable(locales);
|
||||
strTable->ReloadStringTable(app.getLocale());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1177,6 +1177,11 @@ public:
|
|||
void getLocale(std::vector<std::string>& vecWstrLocales) {
|
||||
m_localizationManager.getLocale(vecWstrLocales);
|
||||
}
|
||||
[[nodiscard]] std::vector<std::string> getLocale() {
|
||||
std::vector<std::string> v;
|
||||
m_localizationManager.getLocale(v);
|
||||
return v;
|
||||
}
|
||||
int get_eMCLang(char* pwchLocale) {
|
||||
return m_localizationManager.get_eMCLang(pwchLocale);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,10 +223,7 @@ void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn,
|
|||
unsigned int bStringTableSize = dis2.readInt();
|
||||
std::vector<uint8_t> bStringTable(bStringTableSize);
|
||||
dis2.read(bStringTable);
|
||||
std::vector<std::string> locales;
|
||||
app.getLocale(locales);
|
||||
StringTable* strings =
|
||||
new StringTable(bStringTable.data(), bStringTable.size(), locales);
|
||||
StringTable* strings = new StringTable(bStringTable, app.getLocale());
|
||||
|
||||
// Read RuleFile.
|
||||
std::vector<uint8_t> bRuleFile(content.size() - bStringTable.size());
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@ void LocalizationManager::loadStringTable(ArchiveFile* mediaArchive) {
|
|||
std::vector<uint8_t> locFile = mediaArchive->getFile(localisationFile);
|
||||
std::vector<std::string> locales;
|
||||
getLocale(locales);
|
||||
m_stringTable =
|
||||
new StringTable(locFile.data(), locFile.size(), locales);
|
||||
m_stringTable = new StringTable(locFile, locales);
|
||||
} else {
|
||||
m_stringTable = nullptr;
|
||||
assert(false);
|
||||
|
|
|
|||
|
|
@ -145,10 +145,9 @@ void IUIScene_StartGame::UpdateTexturePackDescription(int index) {
|
|||
app.GetFileFromTPD(eTPDFileType_Loc, pbData, dwBytes, &pbFileData,
|
||||
&dwFileBytes);
|
||||
if (dwFileBytes > 0 && pbFileData) {
|
||||
std::vector<std::string> locales;
|
||||
app.getLocale(locales);
|
||||
StringTable* pStringTable =
|
||||
new StringTable(pbFileData, dwFileBytes, locales);
|
||||
StringTable* pStringTable = new StringTable(
|
||||
std::span<const std::uint8_t>(pbFileData, dwFileBytes),
|
||||
app.getLocale());
|
||||
m_texturePackTitle.SetText(
|
||||
pStringTable->getString("IDS_DISPLAY_NAME"));
|
||||
m_texturePackDescription.SetText(
|
||||
|
|
|
|||
|
|
@ -13,14 +13,13 @@ StringTable::StringTable(void) {}
|
|||
// localisation data only. The caller passes the locale list it wants
|
||||
// matched (typically obtained from the LocalizationManager) so that
|
||||
// StringTable does not have to know about app-side singletons.
|
||||
StringTable::StringTable(std::uint8_t* pbData, unsigned int dataSize,
|
||||
const std::vector<std::string>& locales) {
|
||||
src = std::vector<uint8_t>(pbData, pbData + dataSize);
|
||||
|
||||
StringTable::StringTable(std::span<const std::uint8_t> data,
|
||||
std::span<const std::string> locales)
|
||||
: src(data.begin(), data.end()) {
|
||||
ProcessStringTableData(locales);
|
||||
}
|
||||
|
||||
void StringTable::ReloadStringTable(const std::vector<std::string>& locales) {
|
||||
void StringTable::ReloadStringTable(std::span<const std::string> locales) {
|
||||
m_stringsMap.clear();
|
||||
m_stringsVec.clear();
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ void StringTable::ReloadStringTable(const std::vector<std::string>& locales) {
|
|||
}
|
||||
|
||||
void StringTable::ProcessStringTableData(
|
||||
const std::vector<std::string>& locales) {
|
||||
std::span<const std::string> locales) {
|
||||
ByteArrayInputStream bais(src);
|
||||
DataInputStream dis(&bais);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#define LOCALE_COUNT 11
|
||||
inline constexpr int kLocaleCount = 11;
|
||||
|
||||
class StringTable {
|
||||
private:
|
||||
|
|
@ -54,19 +55,17 @@ public:
|
|||
// };
|
||||
|
||||
StringTable(void);
|
||||
StringTable(std::uint8_t* pbData, unsigned int dataSize,
|
||||
const std::vector<std::string>& locales);
|
||||
StringTable(std::span<const std::uint8_t> data,
|
||||
std::span<const std::string> locales);
|
||||
~StringTable(void);
|
||||
void ReloadStringTable(const std::vector<std::string>& locales);
|
||||
void ReloadStringTable(std::span<const std::string> locales);
|
||||
|
||||
void getData(std::uint8_t** ppData, unsigned int* pSize);
|
||||
|
||||
const char* getString(const std::string& id);
|
||||
const char* getString(int id);
|
||||
|
||||
// static const char* m_wchLocaleCode[LOCALE_COUNT];
|
||||
|
||||
private:
|
||||
// std::string getLangId(uint32_t dwLanguage=0);
|
||||
void ProcessStringTableData(const std::vector<std::string>& locales);
|
||||
void ProcessStringTableData(std::span<const std::string> locales);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ std::vector<TickNextTickData>* ServerLevel::fetchTicksInChunk(LevelChunk* chunk,
|
|||
}
|
||||
} else {
|
||||
if (!toBeTicked.empty()) {
|
||||
Log::info("To be ticked size: %d\n", toBeTicked.size());
|
||||
Log::info("To be ticked size: %zu\n", toBeTicked.size());
|
||||
}
|
||||
for (auto it = toBeTicked.begin(); it != toBeTicked.end();) {
|
||||
TickNextTickData td = *it;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,22 @@
|
|||
|
||||
namespace Log {
|
||||
|
||||
#if defined(_FINAL_BUILD)
|
||||
// In shipping builds, info traces compile to nothing - matches the
|
||||
// historical Game::DebugPrintf behaviour. The varargs path is
|
||||
// completely elided so format strings and their arguments are not
|
||||
// even constructed.
|
||||
inline void info(const char* /*fmt*/, ...) {}
|
||||
#else
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
[[gnu::format(printf, 1, 2)]]
|
||||
#endif
|
||||
inline void info(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Log
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ void Arrow::lerpMotion(double xd, double yd, double zd) {
|
|||
xRotO = xRot = (float)(atan2(yd, sd) * 180 / std::numbers::pi);
|
||||
xRotO = xRot;
|
||||
yRotO = yRot;
|
||||
Log::info("%f %f : 0x%x\n", xRot, yRot, &yRot);
|
||||
Log::info("%f %f : %p\n", xRot, yRot, static_cast<void*>(&yRot));
|
||||
moveTo(x, y, z, yRot, xRot);
|
||||
life = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ void Explosion::finalizeExplosion(
|
|||
if (destroyBlocks) {
|
||||
// toBlowArray.addAll(toBlow);
|
||||
// TODO 4J Stu - Reverse iterator
|
||||
Log::info("Finalizing explosion size %d\n", toBlow.size());
|
||||
Log::info("Finalizing explosion size %zu\n", toBlow.size());
|
||||
static const int MAX_EXPLODE_PARTICLES = 50;
|
||||
// 4J - try and make at most MAX_EXPLODE_PARTICLES pairs of particles
|
||||
int fraction = (int)toBlowArray->size() / MAX_EXPLODE_PARTICLES;
|
||||
|
|
|
|||
|
|
@ -3872,8 +3872,8 @@ void Level::setGameTime(int64_t time) {
|
|||
// time passing so ignore (moving dimensions does this)
|
||||
Log::info(
|
||||
"Level::setTime: Massive time difference, ignoring for time "
|
||||
"passed stat (%lli)\n",
|
||||
timeDiff);
|
||||
"passed stat (%lld)\n",
|
||||
static_cast<long long>(timeDiff));
|
||||
timeDiff = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void ChunkStorageProfilerDecorator::tick() {
|
|||
0.000001 * (double)timeSpentLoading / (double)loadCount,
|
||||
loadCount);
|
||||
#endif
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
#endif
|
||||
}
|
||||
if (saveCount > 0) {
|
||||
|
|
@ -68,7 +68,7 @@ void ChunkStorageProfilerDecorator::tick() {
|
|||
0.000001 * (double)timeSpentSaving / (double)loadCount,
|
||||
loadCount);
|
||||
#endif
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
#endif
|
||||
}
|
||||
counter = 0;
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
|
|||
sprintf(buf,
|
||||
"Chunk file at %d, %d is missing level data, skipping\n", x,
|
||||
z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
delete chunkData;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
|
|||
sprintf(buf,
|
||||
"Chunk file at %d, %d is missing block data, skipping\n", x,
|
||||
z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
delete chunkData;
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
|
|||
"Chunk file at %d, %d is in the wrong location; "
|
||||
"relocating. Expected %d, %d, got %d, %d\n",
|
||||
x, z, x, z, levelChunk->x, levelChunk->z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
delete levelChunk;
|
||||
delete chunkData;
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ LevelChunk* OldChunkStorage::load(Level* level, int x, int z) {
|
|||
sprintf(buf,
|
||||
"Chunk file at %d, %d is missing level data, skipping\n", x,
|
||||
z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
return nullptr;
|
||||
}
|
||||
if (!tag->getCompound("Level")->contains("Blocks")) {
|
||||
|
|
@ -142,7 +142,7 @@ LevelChunk* OldChunkStorage::load(Level* level, int x, int z) {
|
|||
sprintf(buf,
|
||||
"Chunk file at %d, %d is missing block data, skipping\n", x,
|
||||
z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
return nullptr;
|
||||
}
|
||||
LevelChunk* levelChunk =
|
||||
|
|
@ -153,7 +153,7 @@ LevelChunk* OldChunkStorage::load(Level* level, int x, int z) {
|
|||
"Chunk fileat %d, %d is in the wrong location; relocating. "
|
||||
"Expected %d, %d, got %d, %d\n",
|
||||
x, z, x, z, levelChunk->x, levelChunk->z);
|
||||
Log::info(buf);
|
||||
Log::info("%s", buf);
|
||||
tag->putInt("xPos", x);
|
||||
tag->putInt("zPos", z);
|
||||
levelChunk =
|
||||
|
|
|
|||
|
|
@ -164,8 +164,9 @@ void DirectoryLevelStorage::PlayerMappings::writeMappings(
|
|||
DataOutputStream* dos) {
|
||||
dos->writeInt(m_mappings.size());
|
||||
for (auto it = m_mappings.begin(); it != m_mappings.end(); ++it) {
|
||||
Log::info(" -- %lld (0x%016llx) = %d\n", it->first, it->first,
|
||||
it->second);
|
||||
Log::info(" -- %lld (0x%016llx) = %d\n",
|
||||
static_cast<long long>(it->first),
|
||||
static_cast<unsigned long long>(it->first), it->second);
|
||||
dos->writeLong(it->first);
|
||||
dos->writeInt(it->second);
|
||||
}
|
||||
|
|
@ -177,7 +178,9 @@ void DirectoryLevelStorage::PlayerMappings::readMappings(DataInputStream* dis) {
|
|||
int64_t index = dis->readLong();
|
||||
int id = dis->readInt();
|
||||
m_mappings[index] = id;
|
||||
Log::info(" -- %lld (0x%016llx) = %d\n", index, index, id);
|
||||
Log::info(" -- %lld (0x%016llx) = %d\n",
|
||||
static_cast<long long>(index),
|
||||
static_cast<unsigned long long>(index), id);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -278,10 +281,12 @@ LevelData* DirectoryLevelStorage::prepareLevel() {
|
|||
for (unsigned int i = 0; i < count; ++i) {
|
||||
PlayerUID playerUid = dis.readPlayerUID();
|
||||
#if defined(_WINDOWS64) || defined(__linux__)
|
||||
Log::info(" -- %d\n", playerUid);
|
||||
Log::info(" -- %llu\n",
|
||||
static_cast<unsigned long long>(playerUid));
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
Log::info(" -- %d\n", playerUid);
|
||||
Log::info(" -- %llu\n",
|
||||
static_cast<unsigned long long>(playerUid));
|
||||
#else
|
||||
Log::info(" -- %s\n", playerUid.toWString().c_str());
|
||||
#endif
|
||||
|
|
@ -633,11 +638,12 @@ void DirectoryLevelStorage::saveMapIdLookup() {
|
|||
ByteArrayOutputStream baos;
|
||||
DataOutputStream dos(&baos);
|
||||
dos.writeInt(m_playerMappings.size());
|
||||
Log::info("Saving %d mappings\n", m_playerMappings.size());
|
||||
Log::info("Saving %zu mappings\n", m_playerMappings.size());
|
||||
for (auto it = m_playerMappings.begin(); it != m_playerMappings.end();
|
||||
++it) {
|
||||
#if defined(_WINDOWS64) || defined(__linux__)
|
||||
Log::info(" -- %d\n", it->first);
|
||||
Log::info(" -- %llu\n",
|
||||
static_cast<unsigned long long>(it->first));
|
||||
#else
|
||||
#if defined(__linux__)
|
||||
Log::info(" -- %d\n", it->first);
|
||||
|
|
|
|||
Loading…
Reference in a new issue