diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index 73b3b263a..0ec0287da 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -241,27 +241,36 @@ void palettePostLoadLookups(void) if (numpalettes == 0) return; auto basepalette = GPalette.GetTranslation(Translation_BasePalettes, 0); - for (int l = 0; l < MAXPALOOKUPS; l++) + for (int i = 0; i < numpalettes; i++) { - if (!LookupTables[l].IsEmpty()) + auto palette = GPalette.GetTranslation(Translation_BasePalettes, i); + if (!palette) continue; + + if (palette->Inactive) { - const uint8_t* lookup = paletteGetLookupTable(l); - FRemapTable remap; - for (int i = 0; i < numpalettes; i++) + palette->Inactive = false; + GPalette.CopyTranslation(TRANSLATION(Translation_Remap + i, 0), TRANSLATION(Translation_BasePalettes, i)); + } + else + { + for (int l = 0; l < MAXPALOOKUPS; l++) { - auto palette = GPalette.GetTranslation(Translation_BasePalettes, i); - if (!palette) continue; - if (i == 0 || (palette != basepalette && !palette->Inactive)) + if (!LookupTables[l].IsEmpty()) { - memcpy(remap.Remap, lookup, 256); - for (int j = 0; j < 256; j++) + const uint8_t* lookup = (uint8_t*)LookupTables[l].GetChars(); + FRemapTable remap; + if (i == 0 || (palette != basepalette && !palette->Inactive)) { - remap.Palette[j] = palette->Palette[remap.Remap[j]]; + memcpy(remap.Remap, lookup, 256); + for (int j = 0; j < 256; j++) + { + remap.Palette[j] = palette->Palette[remap.Remap[j]]; + } + remap.NumEntries = 256; + GPalette.UpdateTranslation(TRANSLATION(i + Translation_Remap, l), &remap); } - remap.NumEntries = 256; - GPalette.UpdateTranslation(TRANSLATION(i + Translation_Remap, l), &remap); + if (palette != basepalette) palette->Inactive = false; // clear the marker flag } - if (palette != basepalette) palette->Inactive = false; // clear the marker flag } } } diff --git a/source/common/engine/palettecontainer.cpp b/source/common/engine/palettecontainer.cpp index a4ee23b82..4cd4a28bc 100644 --- a/source/common/engine/palettecontainer.cpp +++ b/source/common/engine/palettecontainer.cpp @@ -203,7 +203,7 @@ FRemapTable* PaletteContainer::AddRemap(FRemapTable* remap) for (auto uremap : uniqueRemaps) { - if (uremap->crc32 == remap->crc32 && uremap->NumEntries == remap->NumEntries && *uremap == *remap) + if (uremap->crc32 == remap->crc32 && uremap->NumEntries == remap->NumEntries && *uremap == *remap && remap->Inactive == uremap->Inactive) return uremap; } auto newremap = (FRemapTable*)remapArena.Alloc(sizeof(FRemapTable)); @@ -250,7 +250,7 @@ int PaletteContainer::AddTranslation(int slot, FRemapTable* remap, int count) void PaletteContainer::CopyTranslation(int dest, int src) { - TranslationTables[GetTranslationType(dest)][GetTranslationType(src)] = TranslationToTable(src); + TranslationTables[GetTranslationType(dest)].SetVal(GetTranslationIndex(dest), TranslationToTable(src)); } //----------------------------------------------------------------------------