- refactoring of palette loader.

This commit is contained in:
Christoph Oelckers 2019-10-20 22:26:53 +02:00
parent 6e7db1b63a
commit 449a5a4717
6 changed files with 20 additions and 43 deletions

View file

@ -79,7 +79,7 @@ extern void setup_blend(int32_t blend, int32_t doreverse);
extern uint8_t basepalreset;
extern int32_t curbrightness;
extern int32_t paletteLoadLookupTable(buildvfs_kfd fp);
extern int32_t paletteLoadLookupTable(FileReader &fp);
extern void paletteSetupDefaultFog(void);
extern void palettePostLoadLookups(void);
extern void paletteFixTranslucencyMask(void);

View file

@ -462,19 +462,19 @@ void paletteFixTranslucencyMask(void)
// - on success, 0
// - on error, -1 (didn't read enough data)
// - -2: error, we already wrote an error message ourselves
int32_t paletteLoadLookupTable(buildvfs_kfd fp)
int32_t paletteLoadLookupTable(FileReader &fp)
{
uint8_t numlookups;
char remapbuf[256];
if (kread_and_test(fp, &numlookups, 1))
if (1 != fp.Read(&numlookups, 1))
return -1;
for (bssize_t j=0; j<numlookups; j++)
{
uint8_t palnum;
if (kread_and_test(fp, &palnum, 1))
if (1 != fp.Read(&palnum, 1))
return -1;
if (palnum >= 256-RESERVEDPALS)
@ -483,7 +483,7 @@ int32_t paletteLoadLookupTable(buildvfs_kfd fp)
return -2;
}
if (kread_and_test(fp, remapbuf, 256))
if (256 != fp.Read(remapbuf, 256))
return -1;
paletteMakeLookupTable(palnum, remapbuf, 0, 0, 0, 0);

View file

@ -121,7 +121,6 @@ int32_t r_yshearing = 0;
// used for fogcalc
static float fogresult, fogresult2;
coltypef fogcol, fogtable[MAXPALOOKUPS];
int32_t r_useindexedcolortextures = -1;
@ -245,14 +244,6 @@ static void calcmat(vec3f_t a0, const vec2f_t *offset, float f, float mat[16], i
void polymost_glreset()
{
for (bssize_t i=0; i<=MAXPALOOKUPS-1; i++)
{
fogtable[i].r = palookupfog[i].r * (1.f/255.f);
fogtable[i].g = palookupfog[i].g * (1.f/255.f);
fogtable[i].b = palookupfog[i].b * (1.f/255.f);
fogtable[i].a = 0;
}
//Reset if this is -1 (meaning 1st texture call ever), or > 0 (textures in memory)
if (gltexcacnum < 0)
{

View file

@ -1022,20 +1022,19 @@ void G_DoAutoload(const char *dirname)
void G_LoadLookups(void)
{
int32_t j;
buildvfs_kfd fp;
if ((fp=kopen4loadfrommod("lookup.dat",0)) == buildvfs_kfd_invalid)
if ((fp=kopen4loadfrommod("lookup.dat",1)) == buildvfs_kfd_invalid)
return;
auto fr = kopenFileReader("lookup.dat", 0);
if (!fr.isOpen())
return;
j = paletteLoadLookupTable(fp);
j = paletteLoadLookupTable(fr);
if (j < 0)
{
if (j == -1)
initprintf("ERROR loading \"lookup.dat\": failed reading enough data.\n");
return kclose(fp);
return;
}
uint8_t paldata[768];
@ -1045,16 +1044,14 @@ void G_LoadLookups(void)
// Account for TITLE and REALMS swap between basepal number and on-disk order.
int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j;
if (kread_and_test(fp, paldata, 768))
return kclose(fp);
if (fr.Read(paldata, 768) != 768)
return;
for (unsigned char & k : paldata)
k <<= 2;
paletteSetColorTable(basepalnum, paldata);
}
kclose(fp);
}
//////////

View file

@ -992,20 +992,20 @@ void G_DoAutoload(const char *dirname)
void G_LoadLookups(void)
{
int32_t fp, j;
int32_t j;
if ((fp=kopen4loadfrommod("lookup.dat",0)) == -1)
if ((fp=kopen4loadfrommod("lookup.dat",1)) == -1)
return;
auto fr = kopenFileReader("lookup.dat", 0);
if (!fr.isOpen())
return;
j = paletteLoadLookupTable(fp);
j = paletteLoadLookupTable(fr);
if (j < 0)
{
if (j == -1)
initprintf("ERROR loading \"lookup.dat\": failed reading enough data.\n");
return kclose(fp);
return;
}
uint8_t paldata[768];
@ -1015,8 +1015,8 @@ void G_LoadLookups(void)
// Account for TITLE and REALMS swap between basepal number and on-disk order.
int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j;
if (kread_and_test(fp, paldata, 768))
return kclose(fp);
if (fr.Read(paldata, 768) != 768)
return;
for (bssize_t k = 0; k < 768; k++)
paldata[k] <<= 2;
@ -1028,8 +1028,6 @@ void G_LoadLookups(void)
paldata[767] = palette[767];
paletteSetColorTable(DRUGPAL, paldata);
kclose(fp);
if (RR)
{
char table[256];

View file

@ -28,8 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "savegame.h"
#include "cmdline.h"
extern coltypef fogtable[MAXPALOOKUPS];
BEGIN_RR_NS
static int32_t g_whichPalForPlayer = 9;
@ -2646,13 +2644,6 @@ void G_SetFog(int fogtype)
#ifdef USE_OPENGL
if (videoGetRenderMode() >= REND_POLYMOST)
{
for (bssize_t i=0; i<=MAXPALOOKUPS-1; i++)
{
fogtable[i].r = palookupfog[i].r * (1.f/255.f);
fogtable[i].g = palookupfog[i].g * (1.f/255.f);
fogtable[i].b = palookupfog[i].b * (1.f/255.f);
fogtable[i].a = 0;
}
//gltexinvalidatetype(INVALIDATE_ALL_NON_INDEXED);
static int swaps[] = { 0, 30, 33, 23, 8 };
uploadpalswaps(5, swaps);