This fixes the cocksucker palette corruption bug that happened when switching video modes back and forth between software and polymost in fullscreen

This has been pissing me off for about 4 years.


git-svn-id: https://svn.eduke32.com/eduke32@902 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-07-25 13:42:37 +00:00
parent 0f28a14ba3
commit 7e4d003302
8 changed files with 60 additions and 88 deletions

View file

@ -131,7 +131,7 @@ void begindrawing(void);
void enddrawing(void);
void showframe(int);
int setpalette(int start, int num, char *dapal);
int setpalette(int start, int num);
//int getpalette(int start, int num, char *dapal);
int setgamma(void);
double vid_gamma, vid_contrast, vid_brightness;

View file

@ -7819,7 +7819,7 @@ int setgamemode(char davidoption, int daxdim, int daydim, int dabpp)
setview(0L,0L,xdim-1,ydim-1);
clearallviews(0L);
setbrightness(curbrightness,&palette[0],0);
setbrightness(curbrightness,palette,0);
if (searchx < 0) { searchx = halfxdimen; searchy = (ydimen>>1); }
@ -9985,7 +9985,7 @@ void setvgapalette(void)
curpalettefaded[i].g = curpalette[i].g = vgapal16[4*i+1] << 2;
curpalettefaded[i].r = curpalette[i].r = vgapal16[4*i+2] << 2;
}
setpalette(0,256,vgapal16);
setpalette(0,256);
}
//
@ -10014,13 +10014,13 @@ void setbrightness(char dabrightness, char *dapal, char noapply)
curpalette[i].f = 0;
// brightness adjust the palette
curpalettefaded[i].b = (tempbuf[k++] = britable[j][ curpalette[i].b ]);
curpalettefaded[i].g = (tempbuf[k++] = britable[j][ curpalette[i].g ]);
curpalettefaded[i].r = (tempbuf[k++] = britable[j][ curpalette[i].r ]);
curpalettefaded[i].f = tempbuf[k++] = 0;
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 ((noapply&1) == 0) setpalette(0,256,(char*)tempbuf);
if ((noapply&1) == 0) setpalette(0,256);
#if defined(POLYMOST) && defined(USE_OPENGL)
if (rendmode >= 3)
@ -10068,19 +10068,16 @@ void setpalettefade(char r, char g, char b, char offset)
p.r = britable[curbrightness][ curpalette[i].r ];
}
tempbuf[k++] =
(curpalettefaded[i].b =
p.b + ((((int)palfadergb.b - (int)p.b) * (int)offset) >> 6)) >> 2;
tempbuf[k++] =
(curpalettefaded[i].g =
p.g + ((((int)palfadergb.g - (int)p.g) * (int)offset) >> 6)) >> 2;
tempbuf[k++] =
(curpalettefaded[i].r =
p.r + ((((int)palfadergb.r - (int)p.r) * (int)offset) >> 6)) >> 2;
tempbuf[k++] = curpalettefaded[i].f = 0;
curpalettefaded[i].b =
p.b + (((palfadergb.b - p.b) * offset) >> 6);
curpalettefaded[i].g =
p.g + (((palfadergb.g - p.g) * offset) >> 6);
curpalettefaded[i].r =
p.r + (((palfadergb.r - p.r) * offset) >> 6);
curpalettefaded[i].f = 0;
}
setpalette(0,256,(char*)tempbuf);
setpalette(0,256);
}

View file

@ -1339,7 +1339,7 @@ void showframe(int w)
//
// setpalette() -- set palette values
//
int setpalette(int start, int num, char *dapal)
int setpalette(int start, int num)
{
SDL_Color pal[256];
int i,n;
@ -1349,15 +1349,7 @@ int setpalette(int start, int num, char *dapal)
copybuf(curpalettefaded, pal, 256);
for (i=start, n=num; n>0; i++, n--)
{
/*
pal[i].b = dapal[0] << 2;
pal[i].g = dapal[1] << 2;
pal[i].r = dapal[2] << 2;
*/
curpalettefaded[i].f = pal[i].unused = 0;
dapal += 4;
}
//return SDL_SetPalette(sdl_surface, SDL_LOGPAL|SDL_PHYSPAL, pal, 0, 256);
return SDL_SetColors(sdl_surface, pal, 0, 256);

View file

@ -2503,35 +2503,24 @@ void showframe(int w)
// New behaviour: curpalettefaded is the live palette, and any changes this function
// makes are done to it and not the base palette.
//
int setpalette(int start, int num, char *dapal)
int setpalette(int start, int num)
{
int i, n;
HRESULT result;
RGBQUAD *rgb;
//HPALETTE hPalPrev;
struct logpal
static struct logpal
{
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[256];
} lpal;
UNREFERENCED_PARAMETER(dapal);
copybuf(curpalettefaded, lpal.palPalEntry, 256);
for (i=start, n=num; n>0; i++, n--)
{
/*
lpal.palPalEntry[i].peBlue = dapal[0] << 2;
lpal.palPalEntry[i].peGreen = dapal[1] << 2;
lpal.palPalEntry[i].peRed = dapal[2] << 2;
*/
curpalettefaded[i].f = lpal.palPalEntry[i].peFlags = PC_RESERVED | PC_NOCOLLAPSE;
//dapal += 4;
}
// copybufbyte(curpalettefaded, lpal.palPalEntry, 256);
Bmemcpy(lpal.palPalEntry, curpalettefaded, sizeof(lpal.palPalEntry));
for (i=start, n=num-1; n>0; i++, n--)
curpalettefaded[i].f = lpal.palPalEntry[i].peFlags = PC_NOCOLLAPSE;
if (bpp > 8) return 0; // no palette in opengl
@ -2600,12 +2589,11 @@ int setpalette(int start, int num, char *dapal)
}
SetBWSystemColours();
}
else
{
if (!lpDDPalette) return -1;
result = IDirectDrawPalette_SetEntries(lpDDPalette, 0, start, num, (PALETTEENTRY*)&lpal.palPalEntry[start]);
result = IDirectDrawPalette_SetEntries(lpDDPalette, 0, 0, 256, (LPPALETTEENTRY)lpal.palPalEntry);
if (result != DD_OK)
{
initprintf("Palette set failed: %s\n", GetDDrawError(result));
@ -2937,6 +2925,7 @@ static int SetupDirectDraw(int width, int height)
{
HRESULT result;
DDSURFACEDESC ddsd;
int i;
// now create the DirectDraw surfaces
ZeroMemory(&ddsd, sizeof(ddsd));
@ -2978,7 +2967,9 @@ static int SetupDirectDraw(int width, int height)
// attach a palette to the primary surface
initprintf(" - Creating palette\n");
result = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256, (PALETTEENTRY*)curpalette, &lpDDPalette, NULL);
for (i=0; i<256; i++)
curpalettefaded[i].f = PC_NOCOLLAPSE;
result = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_ALLOW256, (LPPALETTEENTRY)curpalettefaded, &lpDDPalette, NULL);
if (result != DD_OK)
{
ShowDDrawErrorBox("Failure creating palette", result);
@ -3519,7 +3510,6 @@ static BOOL CreateAppWindow(int modenum)
}
modesetusing = -1;
}
else
{
@ -4072,7 +4062,7 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
{
if (appactive)
{
setpalette(0,0,0);
setpalette(0,0);
SetBWSystemColours();
// initprintf("Resetting palette.\n");
}
@ -4094,7 +4084,19 @@ static LRESULT CALLBACK WndProcCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPA
case WM_PALETTECHANGED:
// someone stole the palette so try and steal it back
if (appactive && (HWND)wParam != hWindow) setpalette(0,0,0);
if (appactive && (HWND)wParam != hWindow) setpalette(0,0);
if (bDDrawInited && bpp == 8 && fullscreen)
{
int result = IDirectDrawSurface_SetPalette(lpDDSPrimary, lpDDPalette);
OSD_Printf("DirectDraw palette stolen! Resetting...\n");
if (result != DD_OK)
{
ShowDDrawErrorBox("Failure setting palette", result);
UninitDirectDraw();
break;
}
setpalette(0,0);
}
break;
case WM_DISPLAYCHANGE:

View file

@ -4535,11 +4535,13 @@ static void Keys3d(void)
*/
if (sector[cursectnum].lotag==2)
{
if (sector[cursectnum].floorpal==8) SetBOSS1Palette();
if (sector[cursectnum].ceilingpicnum==FLOORSLIME) SetSLIMEPalette();
else SetWATERPalette();
}
else SetGAMEPalette();
if (keystatus[buildkeys[BK_MODE2D_3D]]) // Enter
SetGAMEPalette();
//Stick this in 3D part of ExtCheckKeys
//Also choose your own key scan codes
@ -8166,50 +8168,34 @@ void faketimerhandler(void)
}
}
static void SetBOSS1Palette()
extern short brightness;
static inline void SetBOSS1Palette()
{
if (acurpalette==3) return;
acurpalette=3;
kensetpalette(BOSS1palette);
setbrightness(brightness,BOSS1palette,0);
}
/*
static void SetSLIMEPalette()
static inline void SetSLIMEPalette()
{
if (acurpalette==2) return;
acurpalette=2;
kensetpalette(SLIMEpalette);
setbrightness(brightness,SLIMEpalette,0);
}
*/
static void SetWATERPalette()
static inline void SetWATERPalette()
{
if (acurpalette==1) return;
acurpalette=1;
kensetpalette(WATERpalette);
setbrightness(brightness,WATERpalette,0);
}
static void SetGAMEPalette()
static inline void SetGAMEPalette()
{
if (acurpalette==0) return;
acurpalette=0;
kensetpalette(GAMEpalette);
}
static void kensetpalette(char *vgapal)
{
int i;
char vesapal[1024];
for (i=0;i<256;i++)
{
vesapal[i*4+0] = vgapal[i*3+2];
vesapal[i*4+1] = vgapal[i*3+1];
vesapal[i*4+2] = vgapal[i*3+0];
vesapal[i*4+3] = 0;
}
setpalette(0L,256L,vesapal);
setbrightness(brightness,GAMEpalette,0);
}
static void SearchSectorsForward()

View file

@ -194,7 +194,6 @@ extern void fadepal(int r, int g, int b, int start, int end, int step);
extern inline int minitextshade(int x,int y,const char *t,int s,int p,int sb);
extern inline int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,int orientation,int x1, int y1, int x2, int y2,int z);
extern void txdigitalnumberz(int starttile, int x,int y,int n,int s,int pal,int cs,int x1, int y1, int x2, int y2, int z);
extern void txdigitalnumber(int starttile, int x,int y,int n,int s,int pal,int cs,int x1, int y1, int x2, int y2);
extern void myosx(int x,int y,int tilenum,int shade,int orientation);
extern void myospalx(int x,int y,int tilenum,int shade,int orientation,int p);
extern void ResetGameVars(void);

View file

@ -1812,10 +1812,6 @@ void txdigitalnumberz(int starttile, int x,int y,int n,int s,int pal,int cs,int
j += (tilesizx[p]+1)*z/65536;
}
}
void txdigitalnumber(int starttile, int x,int y,int n,int s,int pal,int cs,int x1, int y1, int x2, int y2)
{
txdigitalnumberz(starttile,x,y,n,s,pal,cs,x1,y1,x2,y2,65536);
}
static void displayinventory(player_struct *p)
{
@ -2695,7 +2691,7 @@ static int strget_(int small,int x,int y,char *t,int dalen,int c)
{
if (g_player[myconnectindex].ps->gm&MODE_TYPE)
x = mpgametext(y,t,c,2+8+16);
else x = gametext(x,y,t,c,2+8+16);
else x = mgametext(x,y,t,c,2+8+16);
}
c = 4-(sintable[(totalclock<<4)&2047]>>11);

View file

@ -101,10 +101,10 @@ static void SearchSectorsForward();
static void SearchSectorsBackward();
static inline void SpriteName(short spritenum, char *lo2);
static void PrintStatus(char *string,int num,char x,char y,char color);
static void SetBOSS1Palette();
// static void SetSLIMEPalette();
static void SetWATERPalette();
static void SetGAMEPalette();
static inline void SetBOSS1Palette();
static inline void SetSLIMEPalette();
static inline void SetWATERPalette();
static inline void SetGAMEPalette();
static void kensetpalette(char *vgapal);
extern short grid;