mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-19 18:25:27 +00:00
fix: one raw terrain reader, in dZoneManager, after the merge
The dashboard's copy of the terrain reader in dCommon is gone; main's in dZoneManager reads for everyone, and keeps what the copy had over it: colour and texture maps from before version 32 become RGBA, cut to the resolution the client keeps. The scene map (ZoneScenes) and the dCommon tests compile against that reader. A scene ID takes its layer as the zone file numbers it (0 General, 1 Audio) as well as the enum, so main's scene tools and tests build; /getscene prints the layer as a number. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -157,14 +157,23 @@ NiPoint3 Chunk::GridToWorldPos(uint32_t i, uint32_t j) const {
|
||||
}
|
||||
chunk.colorMap.resize(colorMapPixelCount);
|
||||
stream.read(reinterpret_cast<char*>(chunk.colorMap.data()), static_cast<std::streamsize>(colorMapPixelCount));
|
||||
} else {
|
||||
} else if (chunk.width > 0) {
|
||||
// width x width BGRA pixels, of which the client keeps the (width - 1) x (width - 1) before the last row and
|
||||
// column, as RGBA (RAWReadColorandLightMaps)
|
||||
const size_t legacyColorBytes = static_cast<size_t>(chunk.width) * chunk.width * 4;
|
||||
if (legacyColorBytes > kMaxBlobBytes) {
|
||||
LOG("Chunk legacy colorMap size %zu exceeds maximum %zu bytes", legacyColorBytes, kMaxBlobBytes);
|
||||
return false;
|
||||
}
|
||||
chunk.colorMap.resize(legacyColorBytes);
|
||||
stream.read(reinterpret_cast<char*>(chunk.colorMap.data()), static_cast<std::streamsize>(legacyColorBytes));
|
||||
std::vector<uint8_t> pixels(legacyColorBytes);
|
||||
stream.read(reinterpret_cast<char*>(pixels.data()), static_cast<std::streamsize>(legacyColorBytes));
|
||||
chunk.colorMap.reserve(static_cast<size_t>(chunk.colorMapResolution) * chunk.colorMapResolution * 4);
|
||||
for (uint32_t y = 0; y < chunk.colorMapResolution; ++y) {
|
||||
for (uint32_t x = 0; x < chunk.colorMapResolution; ++x) {
|
||||
const auto* bgra = &pixels[(static_cast<size_t>(y) * chunk.width + x) * 4];
|
||||
chunk.colorMap.insert(chunk.colorMap.end(), { bgra[2], bgra[1], bgra[0], bgra[3] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stream.fail()) {
|
||||
@@ -202,6 +211,10 @@ NiPoint3 Chunk::GridToWorldPos(uint32_t i, uint32_t j) const {
|
||||
}
|
||||
chunk.textureMap.resize(textureMapPixelCount);
|
||||
stream.read(reinterpret_cast<char*>(chunk.textureMap.data()), static_cast<std::streamsize>(textureMapPixelCount));
|
||||
// Before version 32 the pixels are BGRA; the client keeps them as RGBA (0x0103aaf0)
|
||||
if (version < 32) {
|
||||
for (size_t i = 0; i + 3 < chunk.textureMap.size(); i += 4) std::swap(chunk.textureMap[i], chunk.textureMap[i + 2]);
|
||||
}
|
||||
|
||||
if (stream.fail()) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user