mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-25 21:03:51 +00:00
refactor: extract magic numbers in terrain alpha map and texture compositing
terrain_manager: replace bare 4096/2048/0x80/0x7F with named constants ALPHA_MAP_SIZE, ALPHA_MAP_PACKED, ALPHA_FILL_FLAG, ALPHA_COUNT_MASK — documents the WoW alpha map RLE format. character_renderer: replace bare 256/512 texture sizes with kBaseTexSize/kUpscaleTexSize for NPC skin upscaling logic.
This commit is contained in:
parent
5b91ef398e
commit
53a4377ed7
2 changed files with 28 additions and 18 deletions
|
|
@ -42,6 +42,12 @@ namespace rendering {
|
|||
|
||||
namespace {
|
||||
|
||||
// Alpha map format constants
|
||||
constexpr size_t ALPHA_MAP_SIZE = 4096; // 64×64 uncompressed alpha bytes
|
||||
constexpr size_t ALPHA_MAP_PACKED = 2048; // 64×64 packed 4-bit alpha (half size)
|
||||
constexpr uint8_t ALPHA_FILL_FLAG = 0x80; // RLE command: fill vs. copy
|
||||
constexpr uint8_t ALPHA_COUNT_MASK = 0x7F; // RLE command: count bits
|
||||
|
||||
int computeTerrainWorkerCount() {
|
||||
const char* raw = std::getenv("WOWEE_TERRAIN_WORKERS");
|
||||
if (raw && *raw) {
|
||||
|
|
@ -78,24 +84,24 @@ bool decodeLayerAlpha(const pipeline::MapChunk& chunk, size_t layerIdx, std::vec
|
|||
}
|
||||
}
|
||||
|
||||
outAlpha.assign(4096, 255);
|
||||
outAlpha.assign(ALPHA_MAP_SIZE, 255);
|
||||
|
||||
if (layer.compressedAlpha()) {
|
||||
size_t readPos = offset;
|
||||
size_t writePos = 0;
|
||||
while (writePos < 4096 && readPos < chunk.alphaMap.size()) {
|
||||
while (writePos < ALPHA_MAP_SIZE && readPos < chunk.alphaMap.size()) {
|
||||
uint8_t cmd = chunk.alphaMap[readPos++];
|
||||
bool fill = (cmd & 0x80) != 0;
|
||||
int count = (cmd & 0x7F) + 1;
|
||||
bool fill = (cmd & ALPHA_FILL_FLAG) != 0;
|
||||
int count = (cmd & ALPHA_COUNT_MASK) + 1;
|
||||
|
||||
if (fill) {
|
||||
if (readPos >= chunk.alphaMap.size()) break;
|
||||
uint8_t val = chunk.alphaMap[readPos++];
|
||||
for (int i = 0; i < count && writePos < 4096; i++) {
|
||||
for (int i = 0; i < count && writePos < ALPHA_MAP_SIZE; i++) {
|
||||
outAlpha[writePos++] = val;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < count && writePos < 4096 && readPos < chunk.alphaMap.size(); i++) {
|
||||
for (int i = 0; i < count && writePos < ALPHA_MAP_SIZE && readPos < chunk.alphaMap.size(); i++) {
|
||||
outAlpha[writePos++] = chunk.alphaMap[readPos++];
|
||||
}
|
||||
}
|
||||
|
|
@ -103,13 +109,13 @@ bool decodeLayerAlpha(const pipeline::MapChunk& chunk, size_t layerIdx, std::vec
|
|||
return true;
|
||||
}
|
||||
|
||||
if (layerSize >= 4096) {
|
||||
std::copy(chunk.alphaMap.begin() + offset, chunk.alphaMap.begin() + offset + 4096, outAlpha.begin());
|
||||
if (layerSize >= ALPHA_MAP_SIZE) {
|
||||
std::copy(chunk.alphaMap.begin() + offset, chunk.alphaMap.begin() + offset + ALPHA_MAP_SIZE, outAlpha.begin());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (layerSize >= 2048) {
|
||||
for (size_t i = 0; i < 2048; i++) {
|
||||
if (layerSize >= ALPHA_MAP_PACKED) {
|
||||
for (size_t i = 0; i < ALPHA_MAP_PACKED; i++) {
|
||||
uint8_t v = chunk.alphaMap[offset + i];
|
||||
outAlpha[i * 2] = (v & 0x0F) * 17;
|
||||
outAlpha[i * 2 + 1] = (v >> 4) * 17;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue