- integrated GL parts of translation handling into the main module.

Now that this doesn't have to share assets with HW2D it could be simplified a lot.
This commit is contained in:
Christoph Oelckers 2018-04-01 00:59:49 +02:00
commit a9d5533603
14 changed files with 89 additions and 201 deletions

View file

@ -52,6 +52,7 @@
#include "r_state.h"
#include "vm.h"
#include "v_text.h"
#include "m_crc32.h"
#include "gi.h"
#include "stats.h"
@ -103,6 +104,38 @@ static bool IndexOutOfRange(const int start1, const int end1, const int start2,
return IndexOutOfRange(start2, end2) || outOfRange;
}
TArray<FUniquePalette::PalData> FUniquePalette::AllPalettes;
//----------------------------------------------------------------------------
//
// Helper class to deal with frequently changing translations from ACS
//
//----------------------------------------------------------------------------
bool FUniquePalette::Update()
{
PalData pd;
memset(pd.pe, 0, sizeof(pd.pe));
memcpy(pd.pe, remap->Palette, remap->NumEntries * sizeof(*remap->Palette));
pd.crc32 = CalcCRC32((uint8_t*)pd.pe, sizeof(pd.pe));
for (unsigned int i = 0; i< AllPalettes.Size(); i++)
{
if (pd.crc32 == AllPalettes[i].crc32)
{
if (!memcmp(pd.pe, AllPalettes[i].pe, sizeof(pd.pe)))
{
Index = 1 + i;
return true;
}
}
}
Index = 1 + AllPalettes.Push(pd);
return true;
}
/****************************************************/
/****************************************************/
@ -133,6 +166,23 @@ FRemapTable::~FRemapTable()
//
//----------------------------------------------------------------------------
int FRemapTable::GetUniqueIndex()
{
if (Inactive) return 0;
if (Native == nullptr)
{
Native = new FUniquePalette(this);
Native->Update();
}
return Native->GetIndex();
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
void FRemapTable::Alloc(int count)
{
Remap = (uint8_t *)M_Malloc(count*sizeof(*Remap) + count*sizeof(*Palette));
@ -356,21 +406,6 @@ void FRemapTable::UpdateNative()
//
//----------------------------------------------------------------------------
FNativePalette *FRemapTable::GetNative()
{
if (Native == NULL)
{
Native = screen->CreatePalette(this);
}
return Native;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
bool FRemapTable::AddIndexRange(int start, int end, int pal1, int pal2)
{
if (IndexOutOfRange(start, end, pal1, pal2))