mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-11 18:50:46 +00:00
Move palette related functionality from engine.c to palette.c/h.
git-svn-id: https://svn.eduke32.com/eduke32@5789 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
cdcc983a22
commit
205a757109
20 changed files with 859 additions and 806 deletions
|
@ -44,6 +44,7 @@ ENGINE_OBJS = \
|
|||
defs \
|
||||
engine \
|
||||
hash \
|
||||
palette \
|
||||
polymost \
|
||||
texcache \
|
||||
dxtfilter \
|
||||
|
|
|
@ -138,6 +138,7 @@ ENGINE_OBJS= \
|
|||
$(ENGINE_OBJ)\colmatch.$o \
|
||||
$(ENGINE_OBJ)\engine.$o \
|
||||
$(ENGINE_OBJ)\hash.$o \
|
||||
$(ENGINE_OBJ)\palette.$o \
|
||||
$(ENGINE_OBJ)\glbuild.$o \
|
||||
$(ENGINE_OBJ)\texcache.$o \
|
||||
$(ENGINE_OBJ)\kplib.$o \
|
||||
|
|
|
@ -11,6 +11,7 @@ $(ENGINE_OBJ)/crc32.$o: $(ENGINE_SRC)/crc32.c $(ENGINE_INC)/crc32.h
|
|||
$(ENGINE_OBJ)/defs.$o: $(ENGINE_SRC)/defs.c $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/baselayer.h $(ENGINE_INC)/scriptfile.h $(ENGINE_INC)/compat.h
|
||||
$(ENGINE_OBJ)/engine.$o: $(ENGINE_SRC)/engine.c $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/pragmas.h $(ENGINE_INC)/cache1d.h $(ENGINE_INC)/a.h $(ENGINE_INC)/osd.h $(ENGINE_INC)/baselayer.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_SRC)/engine_oldmap.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/polymer.h
|
||||
$(ENGINE_OBJ)/hash.$o: $(ENGINE_SRC)/hash.c $(ENGINE_INC)/hash.h
|
||||
$(ENGINE_OBJ)/palette.$o: $(ENGINE_SRC)/palette.c $(ENGINE_INC)/palette.h
|
||||
$(ENGINE_OBJ)/polymost.$o: $(ENGINE_SRC)/polymost.c $(ENGINE_INC)/lz4.h $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/texcache.h
|
||||
$(ENGINE_OBJ)/texcache.$o: $(ENGINE_SRC)/texcache.c $(ENGINE_INC)/texcache.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/dxtfilter.h $(ENGINE_INC)/kplib.h
|
||||
$(ENGINE_OBJ)/dxtfilter.$o: $(ENGINE_SRC)/dxtfilter.c $(ENGINE_INC)/dxtfilter.h $(ENGINE_INC)/texcache.h
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "compat.h"
|
||||
#include "pragmas.h"
|
||||
#include "glbuild.h"
|
||||
#include "palette.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -78,20 +79,11 @@ enum rendmode_t {
|
|||
#define MAXVOXELS 4096
|
||||
#define MAXSTATUS 1024
|
||||
#define MAXPLAYERS 16
|
||||
#define MAXBASEPALS 256
|
||||
#define MAXPALOOKUPS 256
|
||||
#define MAXBLENDTABS 256
|
||||
// Maximum number of component tiles in a multi-psky:
|
||||
#define MAXPSKYTILES 8
|
||||
#define MAXSPRITESONSCREEN 4096
|
||||
#define MAXUNIQHUDID 256 //Extra slots so HUD models can store animation state without messing game sprites
|
||||
|
||||
#define RESERVEDPALS 4 // don't forget to increment this when adding reserved pals
|
||||
#define DETAILPAL (MAXPALOOKUPS - 1)
|
||||
#define GLOWPAL (MAXPALOOKUPS - 2)
|
||||
#define SPECULARPAL (MAXPALOOKUPS - 3)
|
||||
#define NORMALPAL (MAXPALOOKUPS - 4)
|
||||
|
||||
#define TSPR_TEMP 99
|
||||
|
||||
#define PR_LIGHT_PRIO_MAX 0
|
||||
|
@ -849,13 +841,6 @@ extern uint32_t drawlinepat;
|
|||
extern void faketimerhandler(void);
|
||||
|
||||
extern char apptitle[256];
|
||||
typedef struct {
|
||||
char r,g,b,f;
|
||||
} palette_t;
|
||||
extern palette_t curpalette[256], curpalettefaded[256], palfadergb;
|
||||
extern char palfadedelta;
|
||||
|
||||
extern int8_t g_noFloorPal[MAXPALOOKUPS];
|
||||
|
||||
extern int32_t novoxmips;
|
||||
|
||||
|
@ -873,6 +858,8 @@ extern int32_t rendmode;
|
|||
EXTERN uint16_t h_xsize[MAXTILES], h_ysize[MAXTILES];
|
||||
EXTERN int8_t h_xoffs[MAXTILES], h_yoffs[MAXTILES];
|
||||
|
||||
EXTERN char *globalpalwritten;
|
||||
|
||||
enum {
|
||||
GLOBAL_NO_GL_TILESHADES = 1<<0,
|
||||
GLOBAL_NO_GL_FULLBRIGHT = 1<<1,
|
||||
|
@ -1007,13 +994,9 @@ typedef struct artheader_t {
|
|||
|
||||
int32_t preinitengine(void); // a partial setup of the engine used for launch windows
|
||||
int32_t initengine(void);
|
||||
int32_t E_PostInit(void);
|
||||
void uninitengine(void);
|
||||
void initspritelists(void);
|
||||
int32_t loadlookups(int32_t fp);
|
||||
void generatefogpals(void);
|
||||
void fillemptylookups(void);
|
||||
void E_ReplaceTransparentColorWithBlack(void);
|
||||
int32_t E_FatalError(char const * const msg);
|
||||
|
||||
int32_t loadboard(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum);
|
||||
int32_t loadmaphack(const char *filename);
|
||||
|
|
|
@ -267,7 +267,6 @@ extern void showspritedata(int16_t spritenum, int16_t small);
|
|||
|
||||
extern void drawsmallabel(const char *text, char col, char backcol, char border, int32_t dax, int32_t day, int32_t daz);
|
||||
|
||||
extern uint8_t blackcol;
|
||||
extern int32_t circlewall;
|
||||
extern int32_t searchlock;
|
||||
|
||||
|
|
80
polymer/eduke32/build/include/palette.h
Normal file
80
polymer/eduke32/build/include/palette.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef palette_h_
|
||||
#define palette_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAXBASEPALS 256
|
||||
#define MAXPALOOKUPS 256
|
||||
#define MAXBLENDTABS 256
|
||||
|
||||
#define RESERVEDPALS 4 // don't forget to increment this when adding reserved pals
|
||||
#define DETAILPAL (MAXPALOOKUPS - 1)
|
||||
#define GLOWPAL (MAXPALOOKUPS - 2)
|
||||
#define SPECULARPAL (MAXPALOOKUPS - 3)
|
||||
#define NORMALPAL (MAXPALOOKUPS - 4)
|
||||
|
||||
extern uint8_t curbasepal;
|
||||
|
||||
#ifdef LUNATIC
|
||||
extern const char *(getblendtab) (int32_t blend);
|
||||
#else
|
||||
#define getblendtab(blend) (blendtable[blend])
|
||||
#endif
|
||||
|
||||
extern uint32_t PaletteIndexFullbrights[8];
|
||||
#define IsPaletteIndexFullbright(col) (PaletteIndexFullbrights[(col)>>5] & (1u<<((col)&31)))
|
||||
#define SetPaletteIndexFullbright(col) (PaletteIndexFullbrights[(col)>>5] |= (1u<<((col)&31)))
|
||||
|
||||
typedef struct {
|
||||
char r, g, b, f;
|
||||
} palette_t;
|
||||
extern palette_t curpalette[256], curpalettefaded[256], palfadergb;
|
||||
extern char palfadedelta;
|
||||
|
||||
extern int32_t globalblend;
|
||||
extern uint32_t g_lastpalettesum;
|
||||
extern palette_t getpal(int32_t col);
|
||||
extern void loadpalette(void);
|
||||
extern int32_t E_PostInitTables(void);
|
||||
extern void setup_blend(int32_t blend, int32_t doreverse);
|
||||
extern uint8_t basepalreset;
|
||||
extern int32_t curbrightness, gammabrightness;
|
||||
|
||||
extern int32_t loadlookups(int32_t fp);
|
||||
extern void generatefogpals(void);
|
||||
extern void fillemptylookups(void);
|
||||
extern void E_ReplaceTransparentColorWithBlack(void);
|
||||
|
||||
extern int8_t g_noFloorPal[MAXPALOOKUPS];
|
||||
|
||||
extern char britable[16][256];
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
extern palette_t palookupfog[MAXPALOOKUPS];
|
||||
|
||||
static inline void bricolor(palette_t *wpptr, int32_t dacol)
|
||||
{
|
||||
if (gammabrightness)
|
||||
{
|
||||
wpptr->r = curpalette[dacol].r;
|
||||
wpptr->g = curpalette[dacol].g;
|
||||
wpptr->b = curpalette[dacol].b;
|
||||
}
|
||||
else
|
||||
{
|
||||
wpptr->r = britable[curbrightness][curpalette[dacol].r];
|
||||
wpptr->g = britable[curbrightness][curpalette[dacol].g];
|
||||
wpptr->b = britable[curbrightness][curpalette[dacol].b];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -13,6 +13,7 @@
|
|||
#include "editor.h"
|
||||
#include "common.h"
|
||||
#include "colmatch.h"
|
||||
#include "palette.h"
|
||||
|
||||
#include "baselayer.h"
|
||||
#include "renderlayer.h"
|
||||
|
@ -690,7 +691,7 @@ int32_t app_main(int32_t argc, char const * const * argv)
|
|||
DO_FREE_AND_NULL(g_defModules);
|
||||
g_defModulesNum = 0;
|
||||
|
||||
if (E_PostInit())
|
||||
if (E_PostInitTables())
|
||||
M32_FatalEngineError();
|
||||
|
||||
CallExtPostInit();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "a.h"
|
||||
#include "osd.h"
|
||||
#include "crc32.h"
|
||||
#include "xxhash.h"
|
||||
#include "lz4.h"
|
||||
#include "colmatch.h"
|
||||
|
||||
|
@ -48,6 +47,7 @@
|
|||
#include <math.h> // pow
|
||||
|
||||
#include "engine_priv.h"
|
||||
#include "palette.h"
|
||||
|
||||
#ifdef LUNATIC
|
||||
# include "lunatic.h"
|
||||
|
@ -184,8 +184,6 @@ uint32_t r_screenxy = 0;
|
|||
|
||||
int32_t globalflags;
|
||||
|
||||
int32_t curbrightness = 0, gammabrightness = 0;
|
||||
|
||||
float vid_gamma = DEFAULT_GAMMA;
|
||||
float vid_contrast = DEFAULT_CONTRAST;
|
||||
float vid_brightness = DEFAULT_BRIGHTNESS;
|
||||
|
@ -214,14 +212,6 @@ int32_t globalx1, globaly2, globalx3, globaly3;
|
|||
|
||||
int32_t sloptable[16384];
|
||||
static intptr_t slopalookup[16384]; // was 2048
|
||||
#if defined(USE_OPENGL)
|
||||
palette_t palookupfog[MAXPALOOKUPS];
|
||||
#endif
|
||||
|
||||
// For every pal number, whether tsprite pal should not be taken over from
|
||||
// floor pal.
|
||||
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
|
||||
int8_t g_noFloorPal[MAXPALOOKUPS];
|
||||
|
||||
static void *pic = NULL;
|
||||
|
||||
|
@ -273,8 +263,6 @@ int32_t showfirstwall=0;
|
|||
int32_t showheightindicators=1;
|
||||
int32_t circlewall=-1;
|
||||
|
||||
uint8_t blackcol;
|
||||
|
||||
#ifdef POLYMER
|
||||
static int16_t maphacklightcnt=0;
|
||||
static int16_t maphacklight[PR_MAXLIGHTS];
|
||||
|
@ -284,9 +272,6 @@ static int16_t maphacklight[PR_MAXLIGHTS];
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef LUNATIC
|
||||
extern const char *(getblendtab)(int32_t blend);
|
||||
#endif
|
||||
void setup_sideview_sincos(void);
|
||||
int32_t getscreenvdisp(int32_t bz, int32_t zoome);
|
||||
void screencoords(int32_t *xres, int32_t *yres, int32_t x, int32_t y, int32_t zoome);
|
||||
|
@ -2297,9 +2282,7 @@ int32_t globalposx, globalposy, globalposz, globalhoriz;
|
|||
float fglobalposx, fglobalposy, fglobalposz;
|
||||
int16_t globalang, globalcursectnum;
|
||||
int32_t globalpal, cosglobalang, singlobalang;
|
||||
static int32_t globalblend;
|
||||
int32_t cosviewingrangeglobalang, sinviewingrangeglobalang;
|
||||
static char *globalpalwritten;
|
||||
static int32_t globaluclip, globaldclip;
|
||||
int32_t globvis, globalvisibility;
|
||||
int32_t globalhisibility, globalpisibility, globalcisibility;
|
||||
|
@ -2405,60 +2388,9 @@ static int32_t baktile;
|
|||
|
||||
char apptitle[256] = "Build Engine";
|
||||
|
||||
uint8_t *basepaltable[MAXBASEPALS] = { palette };
|
||||
static uint8_t basepalreset=1;
|
||||
uint8_t curbasepal;
|
||||
|
||||
static uint32_t g_lastpalettesum = 0;
|
||||
palette_t curpalette[256]; // the current palette, unadjusted for brightness or tint
|
||||
palette_t curpalettefaded[256]; // the current palette, adjusted for brightness and tint (ie. what gets sent to the card)
|
||||
palette_t palfadergb = { 0,0,0,0 };
|
||||
char palfadedelta = 0;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Internal Engine Functions
|
||||
//
|
||||
#define getblendtab(blend) (blendtable[blend])
|
||||
|
||||
static void setpalettefade_calc(uint8_t offset);
|
||||
|
||||
void fade_screen_black(int32_t moreopaquep)
|
||||
{
|
||||
#ifdef USE_OPENGL
|
||||
if (getrendermode() >= REND_POLYMOST)
|
||||
fullscreen_tint_gl(0,0,0, moreopaquep ? 168 : 84);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Bassert(!offscreenrendering);
|
||||
|
||||
begindrawing();
|
||||
{
|
||||
char *const p = (char *)frameplace;
|
||||
const char *const trans = getblendtab(0);
|
||||
const int32_t shiftamnt = ((!!moreopaquep)*8);
|
||||
const int32_t dimprod = xdim*ydim;
|
||||
int32_t i = 0;
|
||||
|
||||
#ifdef CLASSIC_SLICE_BY_4
|
||||
for (; i<dimprod-4; i+=4)
|
||||
{
|
||||
p[i] = trans[p[i]<<shiftamnt];
|
||||
p[i+1] = trans[p[i+1]<<shiftamnt];
|
||||
p[i+2] = trans[p[i+2]<<shiftamnt];
|
||||
p[i+3] = trans[p[i+3]<<shiftamnt];
|
||||
}
|
||||
#endif
|
||||
|
||||
for (; i<dimprod; i++)
|
||||
p[i] = trans[p[i]<<shiftamnt];
|
||||
}
|
||||
enddrawing();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// returns: 0=continue sprite collecting;
|
||||
// 1=break out of sprite collecting;
|
||||
|
@ -3683,23 +3615,6 @@ static int32_t setup_globals_cf1(const sectortype *sec, int32_t pal, int32_t zd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void setup_blend(int32_t blend, int32_t doreverse)
|
||||
{
|
||||
if (blendtable[blend] == NULL)
|
||||
blend = 0;
|
||||
|
||||
if (globalblend != blend)
|
||||
{
|
||||
globalblend = blend;
|
||||
fixtransluscence(FP_OFF(getblendtab(blend)));
|
||||
}
|
||||
|
||||
if (doreverse)
|
||||
settransreverse();
|
||||
else
|
||||
settransnormal();
|
||||
}
|
||||
|
||||
//
|
||||
// ceilscan (internal)
|
||||
//
|
||||
|
@ -8233,334 +8148,6 @@ static int32_t loadtables(void)
|
|||
}
|
||||
|
||||
|
||||
static void alloc_palookup(int32_t pal)
|
||||
{
|
||||
#if defined ENGINE_USING_A_C || (defined CLASSIC_NONPOW2_YSIZE_WALLS && defined CLASSIC_NONPOW2_YSIZE_SPRITES)
|
||||
palookup[pal] = (char *)Xmalloc(numshades*256);
|
||||
#else
|
||||
// The asm functions vlineasm1, mvlineasm1 (maybe others?) access the next
|
||||
// palookup[...] shade entry for tilesizy==512 tiles.
|
||||
// See DEBUG_TILESIZY_512 and the comment in a.nasm: vlineasm1.
|
||||
palookup[pal] = (char *)Xcalloc(numshades+1, 256);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void maybe_alloc_palookup(int32_t palnum);
|
||||
|
||||
//
|
||||
// loadpalette (internal)
|
||||
//
|
||||
static void loadpalette(void)
|
||||
{
|
||||
initfastcolorlookup_scale(30, 59, 11);
|
||||
initfastcolorlookup_gridvectors();
|
||||
|
||||
int32_t fil;
|
||||
if ((fil = kopen4load("palette.dat",0)) == -1)
|
||||
return;
|
||||
|
||||
|
||||
// PALETTE_MAIN
|
||||
|
||||
if (kread_and_test(fil,palette,768))
|
||||
return kclose(fil);
|
||||
|
||||
for (int k = 0; k < 768; k++)
|
||||
palette[k] <<= 2;
|
||||
|
||||
initfastcolorlookup_palette(palette);
|
||||
|
||||
paletteloaded |= PALETTE_MAIN;
|
||||
|
||||
|
||||
// PALETTE_SHADES
|
||||
|
||||
if (kread_and_test(fil,&numshades,2))
|
||||
return kclose(fil);
|
||||
numshades = B_LITTLE16(numshades);
|
||||
|
||||
if (numshades <= 1)
|
||||
{
|
||||
initprintf("Warning: Invalid number of shades in \"palette.dat\"!\n");
|
||||
numshades = 0;
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
// Auto-detect LameDuke. Its PALETTE.DAT doesn't have a 'numshades' 16-bit
|
||||
// int after the base palette, but starts directly with the shade tables.
|
||||
// Thus, the first two bytes will be 00 01, which is 256 if read as
|
||||
// little-endian int16_t.
|
||||
int32_t lamedukep = 0;
|
||||
if (numshades >= 256)
|
||||
{
|
||||
static char const * const seekfail = "Warning: klseek() failed in loadpalette()!\n";
|
||||
|
||||
uint16_t temp;
|
||||
if (kread_and_test(fil,&temp,2))
|
||||
return kclose(fil);
|
||||
temp = B_LITTLE16(temp);
|
||||
if (temp == 770 || numshades > 256) // 02 03
|
||||
{
|
||||
if (klseek(fil, -4, BSEEK_CUR) < 0)
|
||||
{
|
||||
initputs(seekfail);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
numshades = 32;
|
||||
lamedukep = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (klseek(fil, -2, BSEEK_CUR) < 0)
|
||||
{
|
||||
initputs(seekfail);
|
||||
return kclose(fil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read base shade table (palookup 0).
|
||||
maybe_alloc_palookup(0);
|
||||
if (kread_and_test(fil, palookup[0], numshades<<8))
|
||||
return kclose(fil);
|
||||
|
||||
paletteloaded |= PALETTE_SHADE;
|
||||
|
||||
|
||||
// PALETTE_TRANSLUC
|
||||
|
||||
char * const transluc = blendtable[0] = (char *)Xcalloc(256, 256);
|
||||
|
||||
// Read translucency (blending) table.
|
||||
if (lamedukep)
|
||||
{
|
||||
for (int i=0; i<255; i++)
|
||||
{
|
||||
// NOTE: LameDuke's table doesn't have the last row or column (i==255).
|
||||
|
||||
// Read the entries above and on the diagonal, if the table is
|
||||
// thought as being row-major.
|
||||
if (kread_and_test(fil, &transluc[256*i + i], 256-i-1))
|
||||
return kclose(fil);
|
||||
|
||||
// Duplicate the entries below the diagonal.
|
||||
for (int j=0; j<i; j++)
|
||||
transluc[256*i + j] = transluc[256*j + i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kread_and_test(fil, transluc, 65536))
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
paletteloaded |= PALETTE_TRANSLUC;
|
||||
|
||||
|
||||
// additional blending tables
|
||||
|
||||
uint8_t magic[12];
|
||||
if (!kread_and_test(fil, magic, sizeof(magic)) && !Bmemcmp(magic, "MoreBlendTab", sizeof(magic)))
|
||||
{
|
||||
uint8_t addblendtabs;
|
||||
if (kread_and_test(fil, &addblendtabs, 1))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table count\n");
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
uint8_t blendnum;
|
||||
char *tab = (char *)Xmalloc(256*256);
|
||||
for (int i=0; i<addblendtabs; i++)
|
||||
{
|
||||
if (kread_and_test(fil, &blendnum, 1))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table index\n");
|
||||
Bfree(tab);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
if (getblendtab(blendnum) != NULL)
|
||||
initprintf("Warning: duplicate blending table index %3d encountered\n", blendnum);
|
||||
|
||||
if (kread_and_test(fil, tab, 256*256))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table\n");
|
||||
Bfree(tab);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
setblendtab(blendnum, tab);
|
||||
}
|
||||
Bfree(tab);
|
||||
|
||||
// Read log2 of count of alpha blending tables.
|
||||
uint8_t lognumalphatabs;
|
||||
if (!kread_and_test(fil, &lognumalphatabs, 1))
|
||||
{
|
||||
if (!(lognumalphatabs >= 1 && lognumalphatabs <= 7))
|
||||
initprintf("invalid lognumalphatabs value, must be in [1 .. 7]\n");
|
||||
else
|
||||
numalphatabs = 1<<lognumalphatabs;
|
||||
}
|
||||
}
|
||||
|
||||
kclose(fil);
|
||||
}
|
||||
|
||||
uint32_t PaletteIndexFullbrights[8];
|
||||
|
||||
static void E_PostLoadPalette(void)
|
||||
{
|
||||
globalpal = 0;
|
||||
globalpalwritten = palookup[0];
|
||||
setpalookupaddress(globalpalwritten);
|
||||
|
||||
fixtransluscence(FP_OFF(blendtable[0]));
|
||||
|
||||
#ifdef DEBUG_TILESIZY_512
|
||||
// Bump shade 1 by 16.
|
||||
for (int i=256; i<512; i++)
|
||||
palookup[0][i] = palookup[0][i+(16<<8)];
|
||||
#endif
|
||||
|
||||
// find white and black colors
|
||||
for (int i=0, j, k=0; i<256; i++)
|
||||
{
|
||||
j = palette[i*3] + palette[i*3+1] + palette[i*3+2];
|
||||
if (j > k) { k = j; whitecol = i; }
|
||||
}
|
||||
for (int i=0, j, k=768; i<256; i++)
|
||||
{
|
||||
j = palette[i*3] + palette[i*3+1] + palette[i*3+2];
|
||||
if (j < k) { k = j; blackcol = i; }
|
||||
}
|
||||
|
||||
redcol = getclosestcol(255, 0, 0);
|
||||
|
||||
// Bmemset(PaletteIndexFullbrights, 0, sizeof(PaletteIndexFullbrights));
|
||||
for (int c = 0; c < 255; ++c) // skipping transparent color
|
||||
{
|
||||
char const * const thispalookup = palookup[0];
|
||||
char const color = thispalookup[c];
|
||||
|
||||
if (EDUKE32_PREDICT_FALSE(palette[color*3] == 0 &&
|
||||
palette[color*3+1] == 0 &&
|
||||
palette[color*3+2] == 0))
|
||||
continue; // don't consider #000000 fullbright
|
||||
|
||||
for (int s = c + 256; s < 256*32; s += 256)
|
||||
if (EDUKE32_PREDICT_FALSE(thispalookup[s] != color))
|
||||
goto PostLoad_NotFullbright;
|
||||
|
||||
SetPaletteIndexFullbright(c);
|
||||
|
||||
PostLoad_NotFullbright:
|
||||
continue; // should be optimized out
|
||||
}
|
||||
}
|
||||
|
||||
void E_ReplaceTransparentColorWithBlack(void)
|
||||
{
|
||||
for (int i=0; i<MAXPALOOKUPS; i++)
|
||||
{
|
||||
char * const thispalookup = palookup[i];
|
||||
if (thispalookup == NULL)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<numshades; j++)
|
||||
{
|
||||
thispalookup[(j<<8) + 255] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// fix up translucency table so that transluc(255,x)
|
||||
// and transluc(x,255) is black instead of purple.
|
||||
for (int i=0; i<MAXBLENDTABS; i++)
|
||||
{
|
||||
char * const transluc = blendtable[i];
|
||||
if (transluc == NULL)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<255; j++)
|
||||
{
|
||||
transluc[(255<<8) + j] = transluc[(blackcol<<8) + j];
|
||||
transluc[255 + (j<<8)] = transluc[blackcol + (j<<8)];
|
||||
}
|
||||
transluc[(255<<8) + 255] = transluc[(blackcol<<8) + blackcol];
|
||||
}
|
||||
}
|
||||
|
||||
// Load LOOKUP.DAT, which contains lookup tables and additional base palettes.
|
||||
//
|
||||
// <fp>: kopen4load file handle
|
||||
//
|
||||
// Returns:
|
||||
// - on success, 0
|
||||
// - on error, -1 (didn't read enough data)
|
||||
// - -2: error, we already wrote an error message ourselves
|
||||
int32_t loadlookups(int32_t fp)
|
||||
{
|
||||
uint8_t numlookups;
|
||||
char remapbuf[256];
|
||||
|
||||
if (kread_and_test(fp, &numlookups, 1))
|
||||
return -1;
|
||||
|
||||
for (int j=0; j<numlookups; j++)
|
||||
{
|
||||
uint8_t palnum;
|
||||
|
||||
if (kread_and_test(fp, &palnum, 1))
|
||||
return -1;
|
||||
|
||||
if (palnum >= 256-RESERVEDPALS)
|
||||
{
|
||||
initprintf("ERROR: attempt to load lookup at reserved pal %d\n", palnum);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (kread_and_test(fp, remapbuf, 256))
|
||||
return -1;
|
||||
|
||||
makepalookup(palnum, remapbuf, 0,0,0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void generatefogpals(void)
|
||||
{
|
||||
// Find a gap of four consecutive unused pal numbers to generate fog shade
|
||||
// tables.
|
||||
for (int32_t j=1; j<=255-3; j++)
|
||||
if (!palookup[j] && !palookup[j+1] && !palookup[j+2] && !palookup[j+3])
|
||||
{
|
||||
makepalookup(j, NULL, 60, 60, 60, 1);
|
||||
makepalookup(j+1, NULL, 60, 0, 0, 1);
|
||||
makepalookup(j+2, NULL, 0, 60, 0, 1);
|
||||
makepalookup(j+3, NULL, 0, 0, 60, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void fillemptylookups(void)
|
||||
{
|
||||
// Alias remaining unused pal numbers to the base shade table.
|
||||
for (int32_t j=1; j<MAXPALOOKUPS; j++)
|
||||
{
|
||||
// If an existing lookup is identical to #0, free it.
|
||||
if (palookup[j] && palookup[j] != palookup[0] && !Bmemcmp(palookup[0], palookup[j], 256*numshades))
|
||||
removepalookup(j);
|
||||
|
||||
if (!palookup[j])
|
||||
makepalookup(j, NULL, 0,0,0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////// SPRITE LIST MANIPULATION FUNCTIONS //////////
|
||||
|
||||
#ifdef NETCODE_DISABLE
|
||||
|
@ -8996,7 +8583,7 @@ static void sighandler(int sig, siginfo_t *info, void *ctx)
|
|||
//
|
||||
// E_FatalError
|
||||
//
|
||||
static int32_t E_FatalError(char const * const msg)
|
||||
int32_t E_FatalError(char const * const msg)
|
||||
{
|
||||
engineerrstr = msg;
|
||||
initprintf("ERROR: %s\n", engineerrstr);
|
||||
|
@ -9178,24 +8765,6 @@ int32_t initengine(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// E_PostInit
|
||||
//
|
||||
|
||||
int32_t E_PostInit(void)
|
||||
{
|
||||
if (!(paletteloaded & PALETTE_MAIN))
|
||||
return E_FatalError("No palette found.");
|
||||
if (!(paletteloaded & PALETTE_SHADE))
|
||||
return E_FatalError("No shade table found.");
|
||||
if (!(paletteloaded & PALETTE_TRANSLUC))
|
||||
return E_FatalError("No translucency table found.");
|
||||
|
||||
E_PostLoadPalette();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// uninitengine
|
||||
//
|
||||
|
@ -15421,328 +14990,6 @@ void rotatesprite_(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t palookup_isdefault(int32_t palnum) // KEEPINSYNC engine.lua
|
||||
{
|
||||
return (palookup[palnum] == NULL || (palnum!=0 && palookup[palnum] == palookup[0]));
|
||||
}
|
||||
|
||||
static void maybe_alloc_palookup(int32_t palnum)
|
||||
{
|
||||
if (palookup_isdefault(palnum))
|
||||
{
|
||||
alloc_palookup(palnum);
|
||||
if (palookup[palnum] == NULL)
|
||||
Bexit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void setblendtab(int32_t blend, const char *tab)
|
||||
{
|
||||
if (blendtable[blend] == NULL)
|
||||
blendtable[blend] = (char *)Xmalloc(256*256);
|
||||
|
||||
Bmemcpy(blendtable[blend], tab, 256*256);
|
||||
}
|
||||
void removeblendtab(int32_t const blend)
|
||||
{
|
||||
DO_FREE_AND_NULL(blendtable[blend]);
|
||||
}
|
||||
|
||||
#ifdef LUNATIC
|
||||
const char *(getblendtab)(int32_t blend)
|
||||
{
|
||||
return blendtable[blend];
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t setpalookup(int32_t palnum, const uint8_t *shtab)
|
||||
{
|
||||
if (numshades != 32)
|
||||
return -1;
|
||||
|
||||
if (shtab != NULL)
|
||||
{
|
||||
maybe_alloc_palookup(palnum);
|
||||
Bmemcpy(palookup[palnum], shtab, 256*numshades);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
void removepalookup(int32_t const palnum)
|
||||
{
|
||||
if (palnum == 0 && palookup[palnum] != NULL)
|
||||
{
|
||||
for (int i = 1; i < MAXPALOOKUPS; i++)
|
||||
if (palookup[i] == palookup[palnum])
|
||||
palookup[i] = NULL;
|
||||
|
||||
DO_FREE_AND_NULL(palookup[palnum]);
|
||||
}
|
||||
else if (palookup[palnum] == palookup[0])
|
||||
palookup[palnum] = NULL;
|
||||
else
|
||||
DO_FREE_AND_NULL(palookup[palnum]);
|
||||
}
|
||||
|
||||
//
|
||||
// makepalookup
|
||||
//
|
||||
void makepalookup(int32_t palnum, const char *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal)
|
||||
{
|
||||
int32_t i, j;
|
||||
|
||||
static char idmap[256] = {1};
|
||||
|
||||
if (paletteloaded == 0)
|
||||
return;
|
||||
|
||||
// NOTE: palnum==0 is allowed
|
||||
if ((unsigned)palnum >= MAXPALOOKUPS)
|
||||
return;
|
||||
|
||||
g_noFloorPal[palnum] = noFloorPal;
|
||||
|
||||
if (remapbuf==NULL)
|
||||
{
|
||||
if ((r|g|b) == 0)
|
||||
{
|
||||
palookup[palnum] = palookup[0]; // Alias to base shade table!
|
||||
return;
|
||||
}
|
||||
|
||||
if (idmap[0]==1) // init identity map
|
||||
for (i=0; i<256; i++)
|
||||
idmap[i] = i;
|
||||
|
||||
remapbuf = idmap;
|
||||
}
|
||||
|
||||
maybe_alloc_palookup(palnum);
|
||||
|
||||
if ((r|g|b) == 0)
|
||||
{
|
||||
// "black fog"/visibility case -- only remap color indices
|
||||
|
||||
for (j=0; j<numshades; j++)
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
const char *src = palookup[0];
|
||||
palookup[palnum][256*j + i] = src[256*j + remapbuf[i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// colored fog case
|
||||
|
||||
char *ptr2 = palookup[palnum];
|
||||
|
||||
for (i=0; i<numshades; i++)
|
||||
{
|
||||
int32_t palscale = divscale16(i,numshades-1);
|
||||
|
||||
for (j=0; j<256; j++)
|
||||
{
|
||||
const char *ptr = (const char *)&palette[remapbuf[j]*3];
|
||||
*ptr2++ = getclosestcol(ptr[0] + mulscale16(r-ptr[0],palscale),
|
||||
ptr[1] + mulscale16(g-ptr[1],palscale),
|
||||
ptr[2] + mulscale16(b-ptr[2],palscale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL)
|
||||
palookupfog[palnum].r = r;
|
||||
palookupfog[palnum].g = g;
|
||||
palookupfog[palnum].b = b;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// setbasepal
|
||||
//
|
||||
void setbasepal(int32_t id, uint8_t const * const table)
|
||||
{
|
||||
if (basepaltable[id] == NULL)
|
||||
basepaltable[id] = (uint8_t *)Xmalloc(768);
|
||||
|
||||
Bmemcpy(basepaltable[id], table, 768);
|
||||
}
|
||||
void removebasepal(int32_t const id)
|
||||
{
|
||||
if (id == 0)
|
||||
Bmemset(basepaltable[id], 0, 768);
|
||||
else
|
||||
DO_FREE_AND_NULL(basepaltable[id]);
|
||||
}
|
||||
|
||||
//
|
||||
// setbrightness
|
||||
//
|
||||
// flags:
|
||||
// 1: don't setpalette(), DON'T USE THIS FLAG!
|
||||
// 2: don't gltexinvalidateall()
|
||||
// 4: don't calc curbrightness from dabrightness, DON'T USE THIS FLAG!
|
||||
// 8: don't gltexinvalidate8()
|
||||
// 16: don't reset palfade*
|
||||
void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags)
|
||||
{
|
||||
int32_t i, j, nohwgamma;
|
||||
const uint8_t *dapal;
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
int32_t paldidchange;
|
||||
#endif
|
||||
int32_t palsumdidchange;
|
||||
// uint32_t lastbright = curbrightness;
|
||||
|
||||
Bassert((flags&4)==0);
|
||||
|
||||
if (/*(unsigned)dapalid >= MAXBASEPALS ||*/ basepaltable[dapalid] == NULL)
|
||||
dapalid = 0;
|
||||
#ifdef USE_OPENGL
|
||||
paldidchange = (curbasepal != dapalid || basepalreset);
|
||||
#endif
|
||||
curbasepal = dapalid;
|
||||
basepalreset = 0;
|
||||
|
||||
dapal = basepaltable[curbasepal];
|
||||
|
||||
if (!(flags&4))
|
||||
{
|
||||
curbrightness = clamp(dabrightness, 0, 15);
|
||||
// if (lastbright != (unsigned)curbrightness)
|
||||
// vid_gamma = 1.0 + ((float)curbrightness / 10.0);
|
||||
}
|
||||
|
||||
nohwgamma = setgamma();
|
||||
j = nohwgamma ? curbrightness : 0;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
// save palette without any brightness adjustment
|
||||
curpalette[i].r = dapal[i*3+0];
|
||||
curpalette[i].g = dapal[i*3+1];
|
||||
curpalette[i].b = dapal[i*3+2];
|
||||
curpalette[i].f = 0;
|
||||
|
||||
// brightness adjust the palette
|
||||
curpalettefaded[i].b = britable[j][ curpalette[i].b ];
|
||||
curpalettefaded[i].g = britable[j][ curpalette[i].g ];
|
||||
curpalettefaded[i].r = britable[j][ curpalette[i].r ];
|
||||
curpalettefaded[i].f = 0;
|
||||
}
|
||||
|
||||
if ((flags&16) && palfadedelta) // keep the fade
|
||||
setpalettefade_calc(palfadedelta>>2);
|
||||
|
||||
{
|
||||
static uint32_t lastpalettesum=0;
|
||||
uint32_t newpalettesum = XXH32((uint8_t *)curpalettefaded, sizeof(curpalettefaded), sizeof(curpalettefaded));
|
||||
|
||||
palsumdidchange = (newpalettesum != lastpalettesum);
|
||||
|
||||
if (palsumdidchange || newpalettesum != g_lastpalettesum)
|
||||
{
|
||||
// if ((flags&1) == 0)
|
||||
setpalette(0,256);
|
||||
}
|
||||
|
||||
g_lastpalettesum = lastpalettesum = newpalettesum;
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (getrendermode() >= REND_POLYMOST)
|
||||
{
|
||||
// Only reset the textures if the corresponding preserve flags are clear and
|
||||
// either (a) the new palette is different to the last, or (b) the brightness
|
||||
// changed and we couldn't set it using hardware gamma.
|
||||
|
||||
// XXX: no-HW-gamma OpenGL platforms will exhibit bad performance with
|
||||
// simultaneous basepal and tint changes?
|
||||
const int32_t doinvalidate = (paldidchange || (palsumdidchange && nohwgamma));
|
||||
|
||||
if (!(flags&2) && doinvalidate)
|
||||
gltexinvalidatetype(INVALIDATE_ALL);
|
||||
if (!(flags&8) && doinvalidate)
|
||||
gltexinvalidatetype(INVALIDATE_ART);
|
||||
#ifdef POLYMER
|
||||
if ((getrendermode() == REND_POLYMER) && doinvalidate)
|
||||
polymer_texinvalidate();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((flags&16)==0)
|
||||
{
|
||||
palfadergb.r = palfadergb.g = palfadergb.b = 0;
|
||||
palfadedelta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline palette_t getpal(int32_t col)
|
||||
{
|
||||
if (gammabrightness) return curpalette[col];
|
||||
else
|
||||
{
|
||||
palette_t p;
|
||||
p.b = britable[curbrightness][ curpalette[col].b ];
|
||||
p.g = britable[curbrightness][ curpalette[col].g ];
|
||||
p.r = britable[curbrightness][ curpalette[col].r ];
|
||||
//#ifdef __APPLE__
|
||||
p.f = 0; // make gcc on osx happy
|
||||
//#endif
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
static void setpalettefade_calc(uint8_t offset)
|
||||
{
|
||||
int32_t i;
|
||||
palette_t p;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
p = getpal(i);
|
||||
|
||||
curpalettefaded[i].b =
|
||||
p.b + (((palfadergb.b - p.b) * offset) >> 8);
|
||||
curpalettefaded[i].g =
|
||||
p.g + (((palfadergb.g - p.g) * offset) >> 8);
|
||||
curpalettefaded[i].r =
|
||||
p.r + (((palfadergb.r - p.r) * offset) >> 8);
|
||||
curpalettefaded[i].f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//#define DEBUG_PALETTEFADE
|
||||
|
||||
//
|
||||
// setpalettefade
|
||||
//
|
||||
void setpalettefade(uint8_t r, uint8_t g, uint8_t b, uint8_t offset)
|
||||
{
|
||||
palfadergb.r = r;
|
||||
palfadergb.g = g;
|
||||
palfadergb.b = b;
|
||||
#ifdef DEBUG_PALETTEFADE
|
||||
if (offset)
|
||||
offset = max(offset, 128);
|
||||
#endif
|
||||
palfadedelta = offset;
|
||||
|
||||
setpalettefade_calc(offset);
|
||||
|
||||
{
|
||||
static uint32_t lastpalettesum=0;
|
||||
uint32_t newpalettesum = XXH32((uint8_t *)curpalettefaded, sizeof(curpalettefaded), sizeof(curpalettefaded));
|
||||
|
||||
if (newpalettesum != lastpalettesum || newpalettesum != g_lastpalettesum)
|
||||
setpalette(0,256);
|
||||
|
||||
g_lastpalettesum = lastpalettesum = newpalettesum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// clearview
|
||||
|
|
|
@ -28,8 +28,6 @@ extern "C" {
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint8_t curbasepal;
|
||||
|
||||
extern int16_t thesector[MAXWALLSB], thewall[MAXWALLSB];
|
||||
extern int16_t bunchfirst[MAXWALLSB], bunchlast[MAXWALLSB];
|
||||
extern int16_t maskwall[MAXWALLSB], maskwallcnt;
|
||||
|
@ -59,8 +57,6 @@ extern int16_t searchbottomwall, searchisbottom;
|
|||
|
||||
extern char inpreparemirror;
|
||||
|
||||
extern int32_t curbrightness, gammabrightness;
|
||||
extern char britable[16][256];
|
||||
extern char picsiz[MAXTILES];
|
||||
extern int16_t sectorborder[256];
|
||||
extern int32_t qsetmode;
|
||||
|
@ -76,15 +72,10 @@ extern int16_t numscans, numbunches;
|
|||
// For GL_EXP2 fog:
|
||||
#define FOGSCALE 0.0000768f
|
||||
|
||||
extern palette_t palookupfog[MAXPALOOKUPS];
|
||||
void calc_and_apply_fog(int32_t tile, int32_t shade, int32_t vis, int32_t pal);
|
||||
void calc_and_apply_fog_factor(int32_t tile, int32_t shade, int32_t vis, int32_t pal, float factor);
|
||||
#endif
|
||||
|
||||
extern uint32_t PaletteIndexFullbrights[8];
|
||||
#define IsPaletteIndexFullbright(col) (PaletteIndexFullbrights[(col)>>5] & (1u<<((col)&31)))
|
||||
#define SetPaletteIndexFullbright(col) (PaletteIndexFullbrights[(col)>>5] |= (1u<<((col)&31)))
|
||||
|
||||
// int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat);
|
||||
int32_t wallfront(int32_t l1, int32_t l2);
|
||||
|
||||
|
@ -202,22 +193,6 @@ FORCE_INLINE void setgotpic(int32_t tilenume)
|
|||
|
||||
#endif
|
||||
|
||||
static inline void bricolor(palette_t *wpptr, int32_t dacol)
|
||||
{
|
||||
if (gammabrightness)
|
||||
{
|
||||
wpptr->r = curpalette[dacol].r;
|
||||
wpptr->g = curpalette[dacol].g;
|
||||
wpptr->b = curpalette[dacol].b;
|
||||
}
|
||||
else
|
||||
{
|
||||
wpptr->r = britable[curbrightness][ curpalette[dacol].r ];
|
||||
wpptr->g = britable[curbrightness][ curpalette[dacol].g ];
|
||||
wpptr->b = britable[curbrightness][ curpalette[dacol].b ];
|
||||
}
|
||||
}
|
||||
|
||||
// Get properties of parallaxed sky to draw.
|
||||
// Returns: pointer to tile offset array. Sets-by-pointer the other two.
|
||||
static inline const int8_t *getpsky(int32_t picnum, int32_t *dapyscale, int32_t *dapskybits)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "cache1d.h"
|
||||
#include "kplib.h"
|
||||
#include "common.h"
|
||||
#include "palette.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
|
748
polymer/eduke32/build/src/palette.c
Normal file
748
polymer/eduke32/build/src/palette.c
Normal file
|
@ -0,0 +1,748 @@
|
|||
#include "compat.h"
|
||||
#include "build.h"
|
||||
#include "colmatch.h"
|
||||
#include "cache1d.h"
|
||||
#include "palette.h"
|
||||
#include "a.h"
|
||||
#include "xxhash.h"
|
||||
|
||||
uint8_t *basepaltable[MAXBASEPALS] ={ palette };
|
||||
uint8_t basepalreset=1;
|
||||
uint8_t curbasepal;
|
||||
int32_t globalblend;
|
||||
|
||||
uint32_t g_lastpalettesum = 0;
|
||||
palette_t curpalette[256]; // the current palette, unadjusted for brightness or tint
|
||||
palette_t curpalettefaded[256]; // the current palette, adjusted for brightness and tint (ie. what gets sent to the card)
|
||||
palette_t palfadergb ={ 0,0,0,0 };
|
||||
char palfadedelta = 0;
|
||||
uint8_t blackcol;
|
||||
|
||||
#if defined(USE_OPENGL)
|
||||
palette_t palookupfog[MAXPALOOKUPS];
|
||||
#endif
|
||||
|
||||
// For every pal number, whether tsprite pal should not be taken over from
|
||||
// floor pal.
|
||||
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
|
||||
int8_t g_noFloorPal[MAXPALOOKUPS];
|
||||
|
||||
int32_t curbrightness = 0, gammabrightness = 0;
|
||||
|
||||
static void setpalettefade_calc(uint8_t offset);
|
||||
|
||||
void fade_screen_black(int32_t moreopaquep)
|
||||
{
|
||||
#ifdef USE_OPENGL
|
||||
if (getrendermode() >= REND_POLYMOST)
|
||||
fullscreen_tint_gl(0, 0, 0, moreopaquep ? 168 : 84);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Bassert(!offscreenrendering);
|
||||
|
||||
begindrawing();
|
||||
{
|
||||
char *const p = (char *) frameplace;
|
||||
const char *const trans = getblendtab(0);
|
||||
const int32_t shiftamnt = ((!!moreopaquep)*8);
|
||||
const int32_t dimprod = xdim*ydim;
|
||||
int32_t i = 0;
|
||||
|
||||
#ifdef CLASSIC_SLICE_BY_4
|
||||
for (; i<dimprod-4; i+=4)
|
||||
{
|
||||
p[i] = trans[p[i]<<shiftamnt];
|
||||
p[i+1] = trans[p[i+1]<<shiftamnt];
|
||||
p[i+2] = trans[p[i+2]<<shiftamnt];
|
||||
p[i+3] = trans[p[i+3]<<shiftamnt];
|
||||
}
|
||||
#endif
|
||||
|
||||
for (; i<dimprod; i++)
|
||||
p[i] = trans[p[i]<<shiftamnt];
|
||||
}
|
||||
enddrawing();
|
||||
}
|
||||
}
|
||||
|
||||
void setup_blend(int32_t blend, int32_t doreverse)
|
||||
{
|
||||
if (blendtable[blend] == NULL)
|
||||
blend = 0;
|
||||
|
||||
if (globalblend != blend)
|
||||
{
|
||||
globalblend = blend;
|
||||
fixtransluscence(FP_OFF(getblendtab(blend)));
|
||||
}
|
||||
|
||||
if (doreverse)
|
||||
settransreverse();
|
||||
else
|
||||
settransnormal();
|
||||
}
|
||||
|
||||
static void alloc_palookup(int32_t pal)
|
||||
{
|
||||
#if defined ENGINE_USING_A_C || (defined CLASSIC_NONPOW2_YSIZE_WALLS && defined CLASSIC_NONPOW2_YSIZE_SPRITES)
|
||||
palookup[pal] = (char *) Xmalloc(numshades*256);
|
||||
#else
|
||||
// The asm functions vlineasm1, mvlineasm1 (maybe others?) access the next
|
||||
// palookup[...] shade entry for tilesizy==512 tiles.
|
||||
// See DEBUG_TILESIZY_512 and the comment in a.nasm: vlineasm1.
|
||||
palookup[pal] = (char *) Xcalloc(numshades+1, 256);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void maybe_alloc_palookup(int32_t palnum);
|
||||
|
||||
//
|
||||
// loadpalette (internal)
|
||||
//
|
||||
void loadpalette(void)
|
||||
{
|
||||
initfastcolorlookup_scale(30, 59, 11);
|
||||
initfastcolorlookup_gridvectors();
|
||||
|
||||
int32_t fil;
|
||||
if ((fil = kopen4load("palette.dat", 0)) == -1)
|
||||
return;
|
||||
|
||||
|
||||
// PALETTE_MAIN
|
||||
|
||||
if (kread_and_test(fil, palette, 768))
|
||||
return kclose(fil);
|
||||
|
||||
for (int k = 0; k < 768; k++)
|
||||
palette[k] <<= 2;
|
||||
|
||||
initfastcolorlookup_palette(palette);
|
||||
|
||||
paletteloaded |= PALETTE_MAIN;
|
||||
|
||||
|
||||
// PALETTE_SHADES
|
||||
|
||||
if (kread_and_test(fil, &numshades, 2))
|
||||
return kclose(fil);
|
||||
numshades = B_LITTLE16(numshades);
|
||||
|
||||
if (numshades <= 1)
|
||||
{
|
||||
initprintf("Warning: Invalid number of shades in \"palette.dat\"!\n");
|
||||
numshades = 0;
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
// Auto-detect LameDuke. Its PALETTE.DAT doesn't have a 'numshades' 16-bit
|
||||
// int after the base palette, but starts directly with the shade tables.
|
||||
// Thus, the first two bytes will be 00 01, which is 256 if read as
|
||||
// little-endian int16_t.
|
||||
int32_t lamedukep = 0;
|
||||
if (numshades >= 256)
|
||||
{
|
||||
static char const * const seekfail = "Warning: klseek() failed in loadpalette()!\n";
|
||||
|
||||
uint16_t temp;
|
||||
if (kread_and_test(fil, &temp, 2))
|
||||
return kclose(fil);
|
||||
temp = B_LITTLE16(temp);
|
||||
if (temp == 770 || numshades > 256) // 02 03
|
||||
{
|
||||
if (klseek(fil, -4, BSEEK_CUR) < 0)
|
||||
{
|
||||
initputs(seekfail);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
numshades = 32;
|
||||
lamedukep = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (klseek(fil, -2, BSEEK_CUR) < 0)
|
||||
{
|
||||
initputs(seekfail);
|
||||
return kclose(fil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read base shade table (palookup 0).
|
||||
maybe_alloc_palookup(0);
|
||||
if (kread_and_test(fil, palookup[0], numshades<<8))
|
||||
return kclose(fil);
|
||||
|
||||
paletteloaded |= PALETTE_SHADE;
|
||||
|
||||
|
||||
// PALETTE_TRANSLUC
|
||||
|
||||
char * const transluc = blendtable[0] = (char *) Xcalloc(256, 256);
|
||||
|
||||
// Read translucency (blending) table.
|
||||
if (lamedukep)
|
||||
{
|
||||
for (int i=0; i<255; i++)
|
||||
{
|
||||
// NOTE: LameDuke's table doesn't have the last row or column (i==255).
|
||||
|
||||
// Read the entries above and on the diagonal, if the table is
|
||||
// thought as being row-major.
|
||||
if (kread_and_test(fil, &transluc[256*i + i], 256-i-1))
|
||||
return kclose(fil);
|
||||
|
||||
// Duplicate the entries below the diagonal.
|
||||
for (int j=0; j<i; j++)
|
||||
transluc[256*i + j] = transluc[256*j + i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kread_and_test(fil, transluc, 65536))
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
paletteloaded |= PALETTE_TRANSLUC;
|
||||
|
||||
|
||||
// additional blending tables
|
||||
|
||||
uint8_t magic[12];
|
||||
if (!kread_and_test(fil, magic, sizeof(magic)) && !Bmemcmp(magic, "MoreBlendTab", sizeof(magic)))
|
||||
{
|
||||
uint8_t addblendtabs;
|
||||
if (kread_and_test(fil, &addblendtabs, 1))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table count\n");
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
uint8_t blendnum;
|
||||
char *tab = (char *) Xmalloc(256*256);
|
||||
for (int i=0; i<addblendtabs; i++)
|
||||
{
|
||||
if (kread_and_test(fil, &blendnum, 1))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table index\n");
|
||||
Bfree(tab);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
if (getblendtab(blendnum) != NULL)
|
||||
initprintf("Warning: duplicate blending table index %3d encountered\n", blendnum);
|
||||
|
||||
if (kread_and_test(fil, tab, 256*256))
|
||||
{
|
||||
initprintf("Warning: failed reading additional blending table\n");
|
||||
Bfree(tab);
|
||||
return kclose(fil);
|
||||
}
|
||||
|
||||
setblendtab(blendnum, tab);
|
||||
}
|
||||
Bfree(tab);
|
||||
|
||||
// Read log2 of count of alpha blending tables.
|
||||
uint8_t lognumalphatabs;
|
||||
if (!kread_and_test(fil, &lognumalphatabs, 1))
|
||||
{
|
||||
if (!(lognumalphatabs >= 1 && lognumalphatabs <= 7))
|
||||
initprintf("invalid lognumalphatabs value, must be in [1 .. 7]\n");
|
||||
else
|
||||
numalphatabs = 1<<lognumalphatabs;
|
||||
}
|
||||
}
|
||||
|
||||
kclose(fil);
|
||||
}
|
||||
|
||||
uint32_t PaletteIndexFullbrights[8];
|
||||
|
||||
static void E_PostLoadPalette(void)
|
||||
{
|
||||
globalpal = 0;
|
||||
globalpalwritten = palookup[0];
|
||||
setpalookupaddress(globalpalwritten);
|
||||
|
||||
fixtransluscence(FP_OFF(blendtable[0]));
|
||||
|
||||
#ifdef DEBUG_TILESIZY_512
|
||||
// Bump shade 1 by 16.
|
||||
for (int i=256; i<512; i++)
|
||||
palookup[0][i] = palookup[0][i+(16<<8)];
|
||||
#endif
|
||||
|
||||
// find white and black colors
|
||||
for (int i=0, j, k=0; i<256; i++)
|
||||
{
|
||||
j = palette[i*3] + palette[i*3+1] + palette[i*3+2];
|
||||
if (j > k) { k = j; whitecol = i; }
|
||||
}
|
||||
for (int i=0, j, k=768; i<256; i++)
|
||||
{
|
||||
j = palette[i*3] + palette[i*3+1] + palette[i*3+2];
|
||||
if (j < k) { k = j; blackcol = i; }
|
||||
}
|
||||
|
||||
redcol = getclosestcol(255, 0, 0);
|
||||
|
||||
// Bmemset(PaletteIndexFullbrights, 0, sizeof(PaletteIndexFullbrights));
|
||||
for (int c = 0; c < 255; ++c) // skipping transparent color
|
||||
{
|
||||
char const * const thispalookup = palookup[0];
|
||||
char const color = thispalookup[c];
|
||||
|
||||
if (EDUKE32_PREDICT_FALSE(palette[color*3] == 0 &&
|
||||
palette[color*3+1] == 0 &&
|
||||
palette[color*3+2] == 0))
|
||||
continue; // don't consider #000000 fullbright
|
||||
|
||||
for (int s = c + 256; s < 256*32; s += 256)
|
||||
if (EDUKE32_PREDICT_FALSE(thispalookup[s] != color))
|
||||
goto PostLoad_NotFullbright;
|
||||
|
||||
SetPaletteIndexFullbright(c);
|
||||
|
||||
PostLoad_NotFullbright:
|
||||
continue; // should be optimized out
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// E_PostInitTables
|
||||
//
|
||||
|
||||
int32_t E_PostInitTables(void)
|
||||
{
|
||||
if (!(paletteloaded & PALETTE_MAIN))
|
||||
return E_FatalError("No palette found.");
|
||||
if (!(paletteloaded & PALETTE_SHADE))
|
||||
return E_FatalError("No shade table found.");
|
||||
if (!(paletteloaded & PALETTE_TRANSLUC))
|
||||
return E_FatalError("No translucency table found.");
|
||||
|
||||
E_PostLoadPalette();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void E_ReplaceTransparentColorWithBlack(void)
|
||||
{
|
||||
for (int i=0; i<MAXPALOOKUPS; i++)
|
||||
{
|
||||
char * const thispalookup = palookup[i];
|
||||
if (thispalookup == NULL)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<numshades; j++)
|
||||
{
|
||||
thispalookup[(j<<8) + 255] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// fix up translucency table so that transluc(255,x)
|
||||
// and transluc(x,255) is black instead of purple.
|
||||
for (int i=0; i<MAXBLENDTABS; i++)
|
||||
{
|
||||
char * const transluc = blendtable[i];
|
||||
if (transluc == NULL)
|
||||
continue;
|
||||
|
||||
for (int j=0; j<255; j++)
|
||||
{
|
||||
transluc[(255<<8) + j] = transluc[(blackcol<<8) + j];
|
||||
transluc[255 + (j<<8)] = transluc[blackcol + (j<<8)];
|
||||
}
|
||||
transluc[(255<<8) + 255] = transluc[(blackcol<<8) + blackcol];
|
||||
}
|
||||
}
|
||||
|
||||
// Load LOOKUP.DAT, which contains lookup tables and additional base palettes.
|
||||
//
|
||||
// <fp>: kopen4load file handle
|
||||
//
|
||||
// Returns:
|
||||
// - on success, 0
|
||||
// - on error, -1 (didn't read enough data)
|
||||
// - -2: error, we already wrote an error message ourselves
|
||||
int32_t loadlookups(int32_t fp)
|
||||
{
|
||||
uint8_t numlookups;
|
||||
char remapbuf[256];
|
||||
|
||||
if (kread_and_test(fp, &numlookups, 1))
|
||||
return -1;
|
||||
|
||||
for (int j=0; j<numlookups; j++)
|
||||
{
|
||||
uint8_t palnum;
|
||||
|
||||
if (kread_and_test(fp, &palnum, 1))
|
||||
return -1;
|
||||
|
||||
if (palnum >= 256-RESERVEDPALS)
|
||||
{
|
||||
initprintf("ERROR: attempt to load lookup at reserved pal %d\n", palnum);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (kread_and_test(fp, remapbuf, 256))
|
||||
return -1;
|
||||
|
||||
makepalookup(palnum, remapbuf, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void generatefogpals(void)
|
||||
{
|
||||
// Find a gap of four consecutive unused pal numbers to generate fog shade
|
||||
// tables.
|
||||
for (int32_t j=1; j<=255-3; j++)
|
||||
if (!palookup[j] && !palookup[j+1] && !palookup[j+2] && !palookup[j+3])
|
||||
{
|
||||
makepalookup(j, NULL, 60, 60, 60, 1);
|
||||
makepalookup(j+1, NULL, 60, 0, 0, 1);
|
||||
makepalookup(j+2, NULL, 0, 60, 0, 1);
|
||||
makepalookup(j+3, NULL, 0, 0, 60, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void fillemptylookups(void)
|
||||
{
|
||||
// Alias remaining unused pal numbers to the base shade table.
|
||||
for (int32_t j=1; j<MAXPALOOKUPS; j++)
|
||||
{
|
||||
// If an existing lookup is identical to #0, free it.
|
||||
if (palookup[j] && palookup[j] != palookup[0] && !Bmemcmp(palookup[0], palookup[j], 256*numshades))
|
||||
removepalookup(j);
|
||||
|
||||
if (!palookup[j])
|
||||
makepalookup(j, NULL, 0, 0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t palookup_isdefault(int32_t palnum) // KEEPINSYNC engine.lua
|
||||
{
|
||||
return (palookup[palnum] == NULL || (palnum!=0 && palookup[palnum] == palookup[0]));
|
||||
}
|
||||
|
||||
static void maybe_alloc_palookup(int32_t palnum)
|
||||
{
|
||||
if (palookup_isdefault(palnum))
|
||||
{
|
||||
alloc_palookup(palnum);
|
||||
if (palookup[palnum] == NULL)
|
||||
Bexit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void setblendtab(int32_t blend, const char *tab)
|
||||
{
|
||||
if (blendtable[blend] == NULL)
|
||||
blendtable[blend] = (char *) Xmalloc(256*256);
|
||||
|
||||
Bmemcpy(blendtable[blend], tab, 256*256);
|
||||
}
|
||||
void removeblendtab(int32_t const blend)
|
||||
{
|
||||
DO_FREE_AND_NULL(blendtable[blend]);
|
||||
}
|
||||
|
||||
#ifdef LUNATIC
|
||||
const char *(getblendtab) (int32_t blend)
|
||||
{
|
||||
return blendtable[blend];
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t setpalookup(int32_t palnum, const uint8_t *shtab)
|
||||
{
|
||||
if (numshades != 32)
|
||||
return -1;
|
||||
|
||||
if (shtab != NULL)
|
||||
{
|
||||
maybe_alloc_palookup(palnum);
|
||||
Bmemcpy(palookup[palnum], shtab, 256*numshades);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
void removepalookup(int32_t const palnum)
|
||||
{
|
||||
if (palnum == 0 && palookup[palnum] != NULL)
|
||||
{
|
||||
for (int i = 1; i < MAXPALOOKUPS; i++)
|
||||
if (palookup[i] == palookup[palnum])
|
||||
palookup[i] = NULL;
|
||||
|
||||
DO_FREE_AND_NULL(palookup[palnum]);
|
||||
}
|
||||
else if (palookup[palnum] == palookup[0])
|
||||
palookup[palnum] = NULL;
|
||||
else
|
||||
DO_FREE_AND_NULL(palookup[palnum]);
|
||||
}
|
||||
|
||||
//
|
||||
// makepalookup
|
||||
//
|
||||
void makepalookup(int32_t palnum, const char *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal)
|
||||
{
|
||||
int32_t i, j;
|
||||
|
||||
static char idmap[256] ={ 1 };
|
||||
|
||||
if (paletteloaded == 0)
|
||||
return;
|
||||
|
||||
// NOTE: palnum==0 is allowed
|
||||
if ((unsigned) palnum >= MAXPALOOKUPS)
|
||||
return;
|
||||
|
||||
g_noFloorPal[palnum] = noFloorPal;
|
||||
|
||||
if (remapbuf==NULL)
|
||||
{
|
||||
if ((r|g|b) == 0)
|
||||
{
|
||||
palookup[palnum] = palookup[0]; // Alias to base shade table!
|
||||
return;
|
||||
}
|
||||
|
||||
if (idmap[0]==1) // init identity map
|
||||
for (i=0; i<256; i++)
|
||||
idmap[i] = i;
|
||||
|
||||
remapbuf = idmap;
|
||||
}
|
||||
|
||||
maybe_alloc_palookup(palnum);
|
||||
|
||||
if ((r|g|b) == 0)
|
||||
{
|
||||
// "black fog"/visibility case -- only remap color indices
|
||||
|
||||
for (j=0; j<numshades; j++)
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
const char *src = palookup[0];
|
||||
palookup[palnum][256*j + i] = src[256*j + remapbuf[i]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// colored fog case
|
||||
|
||||
char *ptr2 = palookup[palnum];
|
||||
|
||||
for (i=0; i<numshades; i++)
|
||||
{
|
||||
int32_t palscale = divscale16(i, numshades-1);
|
||||
|
||||
for (j=0; j<256; j++)
|
||||
{
|
||||
const char *ptr = (const char *) &palette[remapbuf[j]*3];
|
||||
*ptr2++ = getclosestcol(ptr[0] + mulscale16(r-ptr[0], palscale),
|
||||
ptr[1] + mulscale16(g-ptr[1], palscale),
|
||||
ptr[2] + mulscale16(b-ptr[2], palscale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL)
|
||||
palookupfog[palnum].r = r;
|
||||
palookupfog[palnum].g = g;
|
||||
palookupfog[palnum].b = b;
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// setbasepal
|
||||
//
|
||||
void setbasepal(int32_t id, uint8_t const * const table)
|
||||
{
|
||||
if (basepaltable[id] == NULL)
|
||||
basepaltable[id] = (uint8_t *) Xmalloc(768);
|
||||
|
||||
Bmemcpy(basepaltable[id], table, 768);
|
||||
}
|
||||
void removebasepal(int32_t const id)
|
||||
{
|
||||
if (id == 0)
|
||||
Bmemset(basepaltable[id], 0, 768);
|
||||
else
|
||||
DO_FREE_AND_NULL(basepaltable[id]);
|
||||
}
|
||||
|
||||
//
|
||||
// setbrightness
|
||||
//
|
||||
// flags:
|
||||
// 1: don't setpalette(), DON'T USE THIS FLAG!
|
||||
// 2: don't gltexinvalidateall()
|
||||
// 4: don't calc curbrightness from dabrightness, DON'T USE THIS FLAG!
|
||||
// 8: don't gltexinvalidate8()
|
||||
// 16: don't reset palfade*
|
||||
void setbrightness(char dabrightness, uint8_t dapalid, uint8_t flags)
|
||||
{
|
||||
int32_t i, j, nohwgamma;
|
||||
const uint8_t *dapal;
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
int32_t paldidchange;
|
||||
#endif
|
||||
int32_t palsumdidchange;
|
||||
// uint32_t lastbright = curbrightness;
|
||||
|
||||
Bassert((flags&4)==0);
|
||||
|
||||
if (/*(unsigned)dapalid >= MAXBASEPALS ||*/ basepaltable[dapalid] == NULL)
|
||||
dapalid = 0;
|
||||
#ifdef USE_OPENGL
|
||||
paldidchange = (curbasepal != dapalid || basepalreset);
|
||||
#endif
|
||||
curbasepal = dapalid;
|
||||
basepalreset = 0;
|
||||
|
||||
dapal = basepaltable[curbasepal];
|
||||
|
||||
if (!(flags&4))
|
||||
{
|
||||
curbrightness = clamp(dabrightness, 0, 15);
|
||||
// if (lastbright != (unsigned)curbrightness)
|
||||
// vid_gamma = 1.0 + ((float)curbrightness / 10.0);
|
||||
}
|
||||
|
||||
nohwgamma = setgamma();
|
||||
j = nohwgamma ? curbrightness : 0;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
// save palette without any brightness adjustment
|
||||
curpalette[i].r = dapal[i*3+0];
|
||||
curpalette[i].g = dapal[i*3+1];
|
||||
curpalette[i].b = dapal[i*3+2];
|
||||
curpalette[i].f = 0;
|
||||
|
||||
// brightness adjust the palette
|
||||
curpalettefaded[i].b = britable[j][curpalette[i].b];
|
||||
curpalettefaded[i].g = britable[j][curpalette[i].g];
|
||||
curpalettefaded[i].r = britable[j][curpalette[i].r];
|
||||
curpalettefaded[i].f = 0;
|
||||
}
|
||||
|
||||
if ((flags&16) && palfadedelta) // keep the fade
|
||||
setpalettefade_calc(palfadedelta>>2);
|
||||
|
||||
{
|
||||
static uint32_t lastpalettesum=0;
|
||||
uint32_t newpalettesum = XXH32((uint8_t *) curpalettefaded, sizeof(curpalettefaded), sizeof(curpalettefaded));
|
||||
|
||||
palsumdidchange = (newpalettesum != lastpalettesum);
|
||||
|
||||
if (palsumdidchange || newpalettesum != g_lastpalettesum)
|
||||
{
|
||||
// if ((flags&1) == 0)
|
||||
setpalette(0, 256);
|
||||
}
|
||||
|
||||
g_lastpalettesum = lastpalettesum = newpalettesum;
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (getrendermode() >= REND_POLYMOST)
|
||||
{
|
||||
// Only reset the textures if the corresponding preserve flags are clear and
|
||||
// either (a) the new palette is different to the last, or (b) the brightness
|
||||
// changed and we couldn't set it using hardware gamma.
|
||||
|
||||
// XXX: no-HW-gamma OpenGL platforms will exhibit bad performance with
|
||||
// simultaneous basepal and tint changes?
|
||||
const int32_t doinvalidate = (paldidchange || (palsumdidchange && nohwgamma));
|
||||
|
||||
if (!(flags&2) && doinvalidate)
|
||||
gltexinvalidatetype(INVALIDATE_ALL);
|
||||
if (!(flags&8) && doinvalidate)
|
||||
gltexinvalidatetype(INVALIDATE_ART);
|
||||
#ifdef POLYMER
|
||||
if ((getrendermode() == REND_POLYMER) && doinvalidate)
|
||||
polymer_texinvalidate();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((flags&16)==0)
|
||||
{
|
||||
palfadergb.r = palfadergb.g = palfadergb.b = 0;
|
||||
palfadedelta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline palette_t getpal(int32_t col)
|
||||
{
|
||||
if (!gammabrightness)
|
||||
{
|
||||
palette_t p ={ britable[curbrightness][curpalette[col].b],
|
||||
britable[curbrightness][curpalette[col].g],
|
||||
britable[curbrightness][curpalette[col].r], 0 };
|
||||
return p;
|
||||
}
|
||||
|
||||
return curpalette[col];
|
||||
}
|
||||
|
||||
static void setpalettefade_calc(uint8_t offset)
|
||||
{
|
||||
int32_t i;
|
||||
palette_t p;
|
||||
|
||||
for (i=0; i<256; i++)
|
||||
{
|
||||
p = getpal(i);
|
||||
|
||||
curpalettefaded[i].b =
|
||||
p.b + (((palfadergb.b - p.b) * offset) >> 8);
|
||||
curpalettefaded[i].g =
|
||||
p.g + (((palfadergb.g - p.g) * offset) >> 8);
|
||||
curpalettefaded[i].r =
|
||||
p.r + (((palfadergb.r - p.r) * offset) >> 8);
|
||||
curpalettefaded[i].f = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//#define DEBUG_PALETTEFADE
|
||||
|
||||
//
|
||||
// setpalettefade
|
||||
//
|
||||
void setpalettefade(uint8_t r, uint8_t g, uint8_t b, uint8_t offset)
|
||||
{
|
||||
palfadergb.r = r;
|
||||
palfadergb.g = g;
|
||||
palfadergb.b = b;
|
||||
#ifdef DEBUG_PALETTEFADE
|
||||
if (offset)
|
||||
offset = max(offset, 128);
|
||||
#endif
|
||||
palfadedelta = offset;
|
||||
|
||||
setpalettefade_calc(offset);
|
||||
|
||||
{
|
||||
static uint32_t lastpalettesum=0;
|
||||
uint32_t newpalettesum = XXH32((uint8_t *) curpalettefaded, sizeof(curpalettefaded), sizeof(curpalettefaded));
|
||||
|
||||
if (newpalettesum != lastpalettesum || newpalettesum != g_lastpalettesum)
|
||||
setpalette(0, 256);
|
||||
|
||||
g_lastpalettesum = lastpalettesum = newpalettesum;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ Ken Silverman's official web site: http://www.advsys.net/ken
|
|||
#include "kplib.h"
|
||||
#include "texcache.h"
|
||||
#include "common.h"
|
||||
#include "palette.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
extern int32_t filelength(int h); // kplib.c
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "build.h"
|
||||
#include "osd.h"
|
||||
#include "engine_priv.h"
|
||||
#include "palette.h"
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
# include "glbuild.h"
|
||||
|
@ -97,7 +98,6 @@ int32_t nofog=0;
|
|||
#ifndef EDUKE32_GLES
|
||||
static uint16_t sysgamma[3][256];
|
||||
#endif
|
||||
extern int32_t curbrightness, gammabrightness;
|
||||
#ifdef USE_OPENGL
|
||||
// OpenGL stuff
|
||||
char nogl=0;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "mdsprite.h"
|
||||
#include "cache1d.h"
|
||||
#include "kplib.h"
|
||||
#include "palette.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ static HWND hWindow = 0;
|
|||
static BOOL window_class_registered = FALSE;
|
||||
|
||||
static DDGAMMARAMP sysgamma;
|
||||
extern int32_t curbrightness, gammabrightness;
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
// OpenGL stuff
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
<ClInclude Include="build\include\build.h" />
|
||||
<ClInclude Include="build\include\buildtypes.h" />
|
||||
<ClInclude Include="build\include\cache1d.h" />
|
||||
<ClInclude Include="build\include\colmatch.h" />
|
||||
<ClInclude Include="build\include\compat.h" />
|
||||
<ClInclude Include="build\include\common.h" />
|
||||
<ClInclude Include="build\include\crc32.h" />
|
||||
|
@ -129,6 +130,7 @@
|
|||
<ClInclude Include="build\include\osd.h" />
|
||||
<ClInclude Include="build\include\osxbits.h" />
|
||||
<ClInclude Include="build\include\osxmain.h" />
|
||||
<ClInclude Include="build\include\palette.h" />
|
||||
<ClInclude Include="build\include\polymer.h" />
|
||||
<ClInclude Include="build\include\polymost.h" />
|
||||
<ClInclude Include="build\include\pragmas.h" />
|
||||
|
@ -275,6 +277,7 @@
|
|||
<ClCompile Include="build\src\mdsprite.c" />
|
||||
<ClCompile Include="build\src\mutex.c" />
|
||||
<ClCompile Include="build\src\osd.c" />
|
||||
<ClCompile Include="build\src\palette.c" />
|
||||
<ClCompile Include="build\src\polymer.c" />
|
||||
<ClCompile Include="build\src\polymost.c" />
|
||||
<ClCompile Include="build\src\pragmas.c" />
|
||||
|
|
|
@ -531,6 +531,12 @@
|
|||
<ClInclude Include="build\include\hash.h">
|
||||
<Filter>build\headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="build\include\palette.h">
|
||||
<Filter>build\headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="build\include\colmatch.h">
|
||||
<Filter>build\headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="build\src\a-c.c">
|
||||
|
@ -932,6 +938,9 @@
|
|||
<ClCompile Include="build\src\hash.c">
|
||||
<Filter>build\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="build\src\palette.c">
|
||||
<Filter>build\source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Makefile.msvc">
|
||||
|
|
|
@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "macros.h"
|
||||
#include "lz4.h"
|
||||
#include "colmatch.h"
|
||||
#include "palette.h"
|
||||
|
||||
#include "m32script.h"
|
||||
#include "m32def.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "compat.h"
|
||||
#include "build.h"
|
||||
#include "baselayer.h"
|
||||
#include "palette.h"
|
||||
|
||||
#include "grpscan.h"
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "sbar.h"
|
||||
#include "screens.h"
|
||||
#include "cmdline.h"
|
||||
#include "palette.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "android.h"
|
||||
|
@ -6298,7 +6299,7 @@ int32_t app_main(int32_t argc, char const * const * argv)
|
|||
DO_FREE_AND_NULL(g_defModules);
|
||||
g_defModulesNum = 0;
|
||||
|
||||
if (E_PostInit())
|
||||
if (E_PostInitTables())
|
||||
G_FatalEngineError();
|
||||
|
||||
G_PostLoadPalette();
|
||||
|
|
Loading…
Reference in a new issue