mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 11:10:47 +00:00
Factor out common parts of loading LOOKUP.DAT into engine.c:loadlookups().
Also, error if didn't read enough data and account for TITLE and REALMS swap between basepal number and on-disk order (sigh). git-svn-id: https://svn.eduke32.com/eduke32@4334 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
37ffae149e
commit
7e7507746d
6 changed files with 92 additions and 71 deletions
|
@ -1051,6 +1051,7 @@ int32_t preinitengine(void); // a partial setup of the engine used for launch
|
|||
int32_t initengine(void);
|
||||
void uninitengine(void);
|
||||
void initspritelists(void);
|
||||
int32_t loadlookups(int32_t fp, uint8_t **basepaltabptr);
|
||||
int32_t loadboard(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum);
|
||||
int32_t loadmaphack(const char *filename);
|
||||
void delete_maphack_lights();
|
||||
|
|
|
@ -8140,6 +8140,59 @@ static int32_t loadpalette(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Load LOOKUP.DAT, which contains lookup tables and additional base palettes.
|
||||
//
|
||||
// <fp>: kopen4load file handle
|
||||
//
|
||||
// basepaltabptr[j], for 1 <= j <= 5 must point to 768 addressable
|
||||
// bytes each: the additional base palettes (water, slime, ...) will be
|
||||
// written there.
|
||||
//
|
||||
// Returns:
|
||||
// - if generated fog shade tables, their first palnum P (fog pals are [P .. P+3])
|
||||
// - on error, -1
|
||||
int32_t loadlookups(int32_t fp, uint8_t **basepaltabptr)
|
||||
{
|
||||
uint8_t numlookups;
|
||||
char remapbuf[256];
|
||||
int32_t j;
|
||||
|
||||
if (kread(fp, &numlookups, 1) != 1)
|
||||
return -1;
|
||||
|
||||
for (j=numlookups+1; j<MAXPALOOKUPS; j++)
|
||||
makepalookup(j, NULL, 0,0,0, 1);
|
||||
|
||||
for (j=0; j<numlookups; j++)
|
||||
{
|
||||
uint8_t palnum;
|
||||
|
||||
if (kread(fp, &palnum, 1) != 1)
|
||||
return -1;
|
||||
if (kread(fp, remapbuf, 256) != 256)
|
||||
return -1;
|
||||
|
||||
makepalookup(palnum, remapbuf, 0,0,0, 1);
|
||||
}
|
||||
|
||||
numlookups++;
|
||||
makepalookup(numlookups, NULL, 15, 15, 15, 1);
|
||||
makepalookup(numlookups + 1, NULL, 15, 0, 0, 1);
|
||||
makepalookup(numlookups + 2, NULL, 0, 15, 0, 1);
|
||||
makepalookup(numlookups + 3, NULL, 0, 0, 15, 1);
|
||||
|
||||
for (j=1; j<=5; j++)
|
||||
{
|
||||
// Account for TITLE and REALMS swap between basepal number and on-disk order.
|
||||
// XXX: this reordering is better off as an argument to us.
|
||||
int32_t basepalnum = (j == 3 || j == 4) ? 4+3-j : j;
|
||||
|
||||
if (kread(fp, basepaltabptr[basepalnum], 768) != 768)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return numlookups;
|
||||
}
|
||||
|
||||
// Finds a color index in [0 .. lastokcol] closest to (r, g, b).
|
||||
// <lastokcol> must be in [0 .. 255].
|
||||
|
|
|
@ -2842,47 +2842,31 @@ static inline void SpriteName(int16_t spritenum, char *lo2)
|
|||
Bstrcpy(lo2, names[sprite[spritenum].picnum]);
|
||||
}// end SpriteName
|
||||
|
||||
static void ReadPaletteTable(void)
|
||||
// Returns: did error?
|
||||
static int32_t ReadPaletteTable(void)
|
||||
{
|
||||
int32_t i,j,fp;
|
||||
char lookup_num;
|
||||
|
||||
for (i=1; i<MAXPALOOKUPS; i++)
|
||||
makepalookup(i,NULL,0,0,0,1);
|
||||
int32_t fp;
|
||||
|
||||
if ((fp=kopen4load("lookup.dat",0)) == -1)
|
||||
{
|
||||
if ((fp=kopen4load("lookup.dat",1)) == -1)
|
||||
{
|
||||
initprintf("LOOKUP.DAT not found\n");
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// initprintf("Loading palette lookups... ");
|
||||
kread(fp,&num_tables,1);
|
||||
for (j=0; j<num_tables; j++)
|
||||
{
|
||||
kread(fp,&lookup_num,1);
|
||||
kread(fp,tempbuf,256);
|
||||
makepalookup(lookup_num,tempbuf,0,0,0,1);
|
||||
}
|
||||
for (j = 0; j < 256; j++)
|
||||
tempbuf[j] = j;
|
||||
|
||||
num_tables++;
|
||||
makepalookup(num_tables, NULL, 15, 15, 15, 1);
|
||||
makepalookup(num_tables + 1, NULL, 15, 0, 0, 1);
|
||||
makepalookup(num_tables + 2, NULL, 0, 15, 0, 1);
|
||||
makepalookup(num_tables + 3, NULL, 0, 0, 15, 1);
|
||||
|
||||
kread(fp,WATERpalette,768);
|
||||
kread(fp,SLIMEpalette,768);
|
||||
kread(fp,TITLEpalette,768);
|
||||
kread(fp,REALMSpalette,768);
|
||||
kread(fp,BOSS1palette,768);
|
||||
num_tables = loadlookups(fp, basepaltable);
|
||||
kclose(fp);
|
||||
// initprintf("success.\n");
|
||||
}// end ReadPaletteTable
|
||||
|
||||
if (num_tables < 0)
|
||||
{
|
||||
initprintf("ERROR loading PALOOKUP.DAT: failed reading enough data\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void m32_showmouse(void)
|
||||
|
@ -10500,7 +10484,8 @@ int32_t ExtInit(void)
|
|||
|
||||
showinvisibility = 1;
|
||||
|
||||
ReadPaletteTable();
|
||||
if (ReadPaletteTable())
|
||||
return -1;
|
||||
|
||||
InitCustomColors();
|
||||
|
||||
|
|
|
@ -117,9 +117,13 @@ static char g_rootDir[BMAX_PATH];
|
|||
char g_modDir[BMAX_PATH] = "/";
|
||||
|
||||
|
||||
uint8_t water_pal[768],slime_pal[768],title_pal[768],dre_alms[768],ending_pal[768];
|
||||
static uint8_t water_pal[768], slime_pal[768], title_pal[768], dre_alms[768], ending_pal[768];
|
||||
|
||||
uint8_t *basepaltable[BASEPALCOUNT] = { palette, water_pal, slime_pal, dre_alms, title_pal, ending_pal, NULL /*anim_pal*/ };
|
||||
uint8_t *basepaltable[BASEPALCOUNT] = {
|
||||
palette, water_pal, slime_pal,
|
||||
dre_alms, title_pal, ending_pal,
|
||||
NULL /*anim_pal*/
|
||||
};
|
||||
|
||||
int8_t g_noFloorPal[MAXPALOOKUPS]; // 1 if sprite pal should not be taken over from floor pal
|
||||
|
||||
|
@ -10627,46 +10631,22 @@ static inline void G_CheckGametype(void)
|
|||
|
||||
static void G_LoadExtraPalettes(void)
|
||||
{
|
||||
int32_t j, fp;
|
||||
uint8_t tmpbyte;
|
||||
int32_t fp;
|
||||
|
||||
fp = kopen4loadfrommod("lookup.dat", 0);
|
||||
if (fp != -1)
|
||||
kread(fp, &tmpbyte, 1);
|
||||
else
|
||||
if (fp == -1)
|
||||
G_GameExit("\nERROR: File 'lookup.dat' not found.");
|
||||
|
||||
g_numRealPalettes = tmpbyte;
|
||||
|
||||
for (j=g_numRealPalettes+1; j<MAXPALOOKUPS; j++)
|
||||
makepalookup(j, NULL ,0,0,0, 1);
|
||||
|
||||
for (j=g_numRealPalettes-1; j>=0; j--)
|
||||
{
|
||||
uint8_t look_pos;
|
||||
|
||||
kread(fp, &look_pos, 1);
|
||||
kread(fp, tempbuf, 256);
|
||||
makepalookup(look_pos, tempbuf, 0,0,0, 1);
|
||||
}
|
||||
|
||||
g_numRealPalettes++;
|
||||
makepalookup(g_numRealPalettes, NULL, 15, 15, 15, 1);
|
||||
makepalookup(g_numRealPalettes + 1, NULL, 15, 0, 0, 1);
|
||||
makepalookup(g_numRealPalettes + 2, NULL, 0, 15, 0, 1);
|
||||
makepalookup(g_numRealPalettes + 3, NULL, 0, 0, 15, 1);
|
||||
|
||||
kread(fp,&water_pal[0],768);
|
||||
kread(fp,&slime_pal[0],768);
|
||||
kread(fp,&title_pal[0],768);
|
||||
kread(fp,&dre_alms[0],768);
|
||||
kread(fp,&ending_pal[0],768);
|
||||
|
||||
palette[765] = palette[766] = palette[767] = 0;
|
||||
slime_pal[765] = slime_pal[766] = slime_pal[767] = 0;
|
||||
water_pal[765] = water_pal[766] = water_pal[767] = 0;
|
||||
|
||||
g_numRealPalettes = loadlookups(fp, basepaltable);
|
||||
kclose(fp);
|
||||
|
||||
if (g_numRealPalettes < 0)
|
||||
G_GameExit("\nERROR loading 'lookup.dat': failed reading enough data.");
|
||||
|
||||
// Make color index 255 of default/water/slime palette black.
|
||||
Bmemset(&palette[255*3], 0, 3);
|
||||
Bmemset(&water_pal[255*3], 0, 3);
|
||||
Bmemset(&slime_pal[255*3], 0, 3);
|
||||
}
|
||||
|
||||
#define SETBGFLAG(Tilenum) g_tile[Tilenum].flags |= SPRITE_HARDCODED_BADGUY
|
||||
|
|
|
@ -299,7 +299,6 @@ extern palette_t DefaultCrosshairColors;
|
|||
|
||||
extern uint32_t g_frameDelay;
|
||||
|
||||
extern uint8_t water_pal[768],slime_pal[768],title_pal[768],dre_alms[768],ending_pal[768];
|
||||
extern uint8_t *basepaltable[BASEPALCOUNT];
|
||||
extern int8_t g_noFloorPal[MAXPALOOKUPS];
|
||||
|
||||
|
|
|
@ -78,10 +78,13 @@ static void FuncMenu(void);
|
|||
static uint8_t WATERpalette[768], SLIMEpalette[768], TITLEpalette[768];
|
||||
static uint8_t REALMSpalette[768], BOSS1palette[768];
|
||||
|
||||
static uint8_t *basepaltable[BASEPALCOUNT] = { palette, WATERpalette, SLIMEpalette, TITLEpalette, REALMSpalette, BOSS1palette };
|
||||
static uint8_t *basepaltable[BASEPALCOUNT] = {
|
||||
palette, WATERpalette, SLIMEpalette,
|
||||
REALMSpalette, TITLEpalette, BOSS1palette,
|
||||
};
|
||||
|
||||
|
||||
static char num_tables;
|
||||
static int32_t num_tables;
|
||||
|
||||
static int32_t updownunits=1024;
|
||||
|
||||
|
|
Loading…
Reference in a new issue