don't Sys_Error with NULL Q2 setmodel call, properly fallthrough if bSetupPixelFormat fails

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2364 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-07-21 23:38:24 +00:00
parent f530e5f782
commit 0089cf5a3f
3 changed files with 80 additions and 11 deletions

View file

@ -3540,10 +3540,7 @@ void MVD_Interpolate(void)
oldents = oldframe->packet_entities.entities;
f = (demtime - olddemotime) / (nextdemotime - olddemotime);
if (f < 0)
f = 0;
if (f > 1)
f = 1;
f = bound(0, f, 1);
// interpolate nails
/* for (i = 0; i < cl_num_projectiles; i++)

View file

@ -803,8 +803,8 @@ qboolean VID_AttachGL (rendererstate_t *info)
{
maindc = GetDC(mainwindow);
TRACE(("dbg: VID_AttachGL: bSetupPixelFormat\n"));
bSetupPixelFormat(maindc);
break;
if (bSetupPixelFormat(maindc))
break;
}
if (!*info->glrenderer || !stricmp(info->glrenderer, "opengl32.dll") || !stricmp(info->glrenderer, "opengl32")) //go for windows system dir if we failed with the default. Should help to avoid the 3dfx problem.
@ -821,8 +821,8 @@ qboolean VID_AttachGL (rendererstate_t *info)
{
maindc = GetDC(mainwindow);
TRACE(("dbg: VID_AttachGL: bSetupPixelFormat\n"));
bSetupPixelFormat(maindc);
break;
if (bSetupPixelFormat(maindc))
break;
}
}
@ -1101,6 +1101,71 @@ BOOL CheckForcePixelFormat(rendererstate_t *info)
return false;
}
BYTE IntensityFromShifted(unsigned int index, unsigned int shift, unsigned int bits)
{
unsigned int val;
val = (index >> shift) & ((1 << bits) - 1);
switch (bits)
{
case 1:
val = val ? 0xFF : 0;
break;
case 2:
val |= val << 2;
val |= val << 4;
break;
case 3:
val = val << (8 - bits);
val |= val >> 3;
break;
case 4:
case 5:
case 6:
case 7:
val = val << (8 - bits);
val |= val >> bits;
break;
case 8:
break;
default:
return 0;
}
return val;
}
void FixPaletteInDescriptor(HDC hDC, PIXELFORMATDESCRIPTOR *pfd)
{
LOGPALETTE *ppal;
HPALETTE hpal;
int idx, clrs;
if (pfd->dwFlags & PFD_NEED_PALETTE)
{
clrs = 1 << pfd->cColorBits;
ppal = Z_Malloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * clrs);
ppal->palVersion = 0x300;
ppal->palNumEntries = clrs;
for (idx = 0; idx < clrs; idx++)
{
ppal->palPalEntry[idx].peRed = IntensityFromShifted(idx, pfd->cRedShift, pfd->cRedBits);
ppal->palPalEntry[idx].peGreen = IntensityFromShifted(idx, pfd->cGreenShift, pfd->cGreenBits);
ppal->palPalEntry[idx].peBlue = IntensityFromShifted(idx, pfd->cBlueShift, pfd->cBlueBits);
ppal->palPalEntry[idx].peFlags = 0;
}
hpal = CreatePalette(ppal);
SelectPalette(hDC, hpal, FALSE);
RealizePalette(hDC);
Z_Free(ppal);
}
}
BOOL bSetupPixelFormat(HDC hDC)
{
static PIXELFORMATDESCRIPTOR pfd = {
@ -1137,9 +1202,11 @@ BOOL bSetupPixelFormat(HDC hDC)
if ((pixelformat = ChoosePixelFormat(hDC, &pfd)))
{
TRACE(("dbg: ChoosePixelFormat 1: worked\n"));
if (SetPixelFormat(hDC, pixelformat, &pfd))
{
TRACE(("dbg: bSetupPixelFormat: we can use the stencil buffer. woot\n"));
FixPaletteInDescriptor(hDC, &pfd);
gl_canstencil = pfd.cStencilBits;
return TRUE;
}
@ -1151,17 +1218,18 @@ BOOL bSetupPixelFormat(HDC hDC)
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
{
Con_Printf("bSetupPixelFormat: ChoosePixelFormat failed\n");
Con_Printf("bSetupPixelFormat: ChoosePixelFormat failed (%i)\n", GetLastError());
return FALSE;
}
}
if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE)
{
Con_Printf("bSetupPixelFormat: SetPixelFormat failed\n");
Con_Printf("bSetupPixelFormat: SetPixelFormat failed (%i)\n", GetLastError());
return FALSE;
}
FixPaletteInDescriptor(hDC, &pfd);
return TRUE;
}

View file

@ -287,7 +287,11 @@ static void VARGS PFQ2_setmodel (q2edict_t *ent, char *name)
model_t *mod;
if (!name)
Sys_Error ("PF_setmodel: NULL");
{
Con_Printf (S_ERROR "ERROR: PF_setmodel: NULL\n");
ent->s.modelindex = 0;
return;
}
i = SVQ2_ModelIndex (name);