Merge branch 'opengl-improvements-backport' into 'master'

Opengl improvements backport

See merge request STJr/SRB2!304
This commit is contained in:
Monster Iestyn 2018-11-10 09:25:18 -05:00
commit 925a56ad98
10 changed files with 221 additions and 276 deletions

View File

@ -417,10 +417,13 @@ static void D_Display(void)
} }
// Image postprocessing effect // Image postprocessing effect
if (postimgtype) if (rendermode == render_soft)
V_DoPostProcessor(0, postimgtype, postimgparam); {
if (postimgtype2) if (postimgtype)
V_DoPostProcessor(1, postimgtype2, postimgparam2); V_DoPostProcessor(0, postimgtype, postimgparam);
if (postimgtype2)
V_DoPostProcessor(1, postimgtype2, postimgparam2);
}
} }
if (lastdraw) if (lastdraw)

View File

@ -878,8 +878,8 @@ static void AdjustSegs(void)
count = subsectors[i].numlines; count = subsectors[i].numlines;
lseg = &segs[subsectors[i].firstline]; lseg = &segs[subsectors[i].firstline];
p = extrasubsectors[i].planepoly; p = extrasubsectors[i].planepoly;
if (!p) //if (!p)
continue; //continue;
for (; count--; lseg++) for (; count--; lseg++)
{ {
float distv1,distv2,tmp; float distv1,distv2,tmp;
@ -892,29 +892,31 @@ static void AdjustSegs(void)
continue; continue;
#endif #endif
for (j = 0; j < p->numpts; j++) if (p) {
{ for (j = 0; j < p->numpts; j++)
distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x);
tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y);
distv1 = distv1*distv1+tmp*tmp;
if (distv1 <= nearv1)
{ {
v1found = j; distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x);
nearv1 = distv1; tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y);
} distv1 = distv1*distv1+tmp*tmp;
// the same with v2 if (distv1 <= nearv1)
distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); {
tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); v1found = j;
distv2 = distv2*distv2+tmp*tmp; nearv1 = distv1;
if (distv2 <= nearv2) }
{ // the same with v2
v2found = j; distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x);
nearv2 = distv2; tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y);
distv2 = distv2*distv2+tmp*tmp;
if (distv2 <= nearv2)
{
v2found = j;
nearv2 = distv2;
}
} }
} }
if (nearv1 <= NEARDIST*NEARDIST) if (p && nearv1 <= NEARDIST*NEARDIST)
// share vertice with segs // share vertice with segs
lseg->v1 = (vertex_t *)&(p->pts[v1found]); lseg->pv1 = &(p->pts[v1found]);
else else
{ {
// BP: here we can do better, using PointInSeg and compute // BP: here we can do better, using PointInSeg and compute
@ -925,24 +927,24 @@ static void AdjustSegs(void)
polyvertex_t *pv = HWR_AllocVertex(); polyvertex_t *pv = HWR_AllocVertex();
pv->x = FIXED_TO_FLOAT(lseg->v1->x); pv->x = FIXED_TO_FLOAT(lseg->v1->x);
pv->y = FIXED_TO_FLOAT(lseg->v1->y); pv->y = FIXED_TO_FLOAT(lseg->v1->y);
lseg->v1 = (vertex_t *)pv; lseg->pv1 = pv;
} }
if (nearv2 <= NEARDIST*NEARDIST) if (p && nearv2 <= NEARDIST*NEARDIST)
lseg->v2 = (vertex_t *)&(p->pts[v2found]); lseg->pv2 = &(p->pts[v2found]);
else else
{ {
polyvertex_t *pv = HWR_AllocVertex(); polyvertex_t *pv = HWR_AllocVertex();
pv->x = FIXED_TO_FLOAT(lseg->v2->x); pv->x = FIXED_TO_FLOAT(lseg->v2->x);
pv->y = FIXED_TO_FLOAT(lseg->v2->y); pv->y = FIXED_TO_FLOAT(lseg->v2->y);
lseg->v2 = (vertex_t *)pv; lseg->pv2 = pv;
} }
// recompute length // recompute length
{ {
float x,y; float x,y;
x = ((polyvertex_t *)lseg->v2)->x - ((polyvertex_t *)lseg->v1)->x x = ((polyvertex_t *)lseg->pv2)->x - ((polyvertex_t *)lseg->pv1)->x
+ FIXED_TO_FLOAT(FRACUNIT/2); + FIXED_TO_FLOAT(FRACUNIT/2);
y = ((polyvertex_t *)lseg->v2)->y - ((polyvertex_t *)lseg->v1)->y y = ((polyvertex_t *)lseg->pv2)->y - ((polyvertex_t *)lseg->pv1)->y
+ FIXED_TO_FLOAT(FRACUNIT/2); + FIXED_TO_FLOAT(FRACUNIT/2);
lseg->flength = (float)hypot(x, y); lseg->flength = (float)hypot(x, y);
// BP: debug see this kind of segs // BP: debug see this kind of segs

View File

@ -26,10 +26,6 @@
#include <windows.h> #include <windows.h>
#endif #endif
#if defined (VID_X11) && !defined (HAVE_SDL)
#include <GL/glx.h>
#endif
#include "../doomdef.h" #include "../doomdef.h"
//THIS MUST DISAPPEAR!!! //THIS MUST DISAPPEAR!!!
#include "hw_glide.h" #include "hw_glide.h"

View File

@ -32,10 +32,6 @@
// STANDARD DLL EXPORTS // STANDARD DLL EXPORTS
// ========================================================================== // ==========================================================================
#ifdef HAVE_SDL
#undef VID_X11
#endif
EXPORT boolean HWRAPI(Init) (I_Error_t ErrorFunction); EXPORT boolean HWRAPI(Init) (I_Error_t ErrorFunction);
#ifndef HAVE_SDL #ifndef HAVE_SDL
EXPORT void HWRAPI(Shutdown) (void); EXPORT void HWRAPI(Shutdown) (void);
@ -43,9 +39,6 @@ EXPORT void HWRAPI(Shutdown) (void);
#ifdef _WINDOWS #ifdef _WINDOWS
EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes); EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes);
#endif #endif
#ifdef VID_X11
EXPORT Window HWRAPI(HookXwin) (Display *, INT32, INT32, boolean);
#endif
#if defined (PURESDL) || defined (macintosh) #if defined (PURESDL) || defined (macintosh)
EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma);
#else #else
@ -71,10 +64,6 @@ EXPORT void HWRAPI(SetTransform) (FTransform *ptransform);
EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetTextureUsed) (void);
EXPORT INT32 HWRAPI(GetRenderVersion) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void);
#ifdef VID_X11 // ifdef to be removed as soon as windoze supports that as well
// metzgermeister: added for Voodoo detection
EXPORT char *HWRAPI(GetRenderer) (void);
#endif
#ifdef SHUFFLE #ifdef SHUFFLE
#define SCREENVERTS 10 #define SCREENVERTS 10
EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]);
@ -115,10 +104,6 @@ struct hwdriver_s
#ifdef _WINDOWS #ifdef _WINDOWS
GetModeList pfnGetModeList; GetModeList pfnGetModeList;
#endif #endif
#ifdef VID_X11
HookXwin pfnHookXwin;
GetRenderer pfnGetRenderer;
#endif
#ifndef HAVE_SDL #ifndef HAVE_SDL
Shutdown pfnShutdown; Shutdown pfnShutdown;
#endif #endif

View File

@ -323,9 +323,6 @@ static angle_t gr_xtoviewangle[MAXVIDWIDTH+1];
// test change fov when looking up/down but bsp projection messup :( // test change fov when looking up/down but bsp projection messup :(
//#define NOCRAPPYMLOOK //#define NOCRAPPYMLOOK
/// \note crappy
#define drawtextured true
// base values set at SetViewSize // base values set at SetViewSize
static float gr_basecentery; static float gr_basecentery;
@ -856,11 +853,11 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
M_ClearBox(segbbox); M_ClearBox(segbbox);
M_AddToBox(segbbox, M_AddToBox(segbbox,
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y));
M_AddToBox(segbbox, M_AddToBox(segbbox,
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y));
splat = (wallsplat_t *)gr_curline->linedef->splats; splat = (wallsplat_t *)gr_curline->linedef->splats;
for (; splat; splat = splat->next) for (; splat; splat = splat->next)
@ -1367,10 +1364,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
gr_sidedef = gr_curline->sidedef; gr_sidedef = gr_curline->sidedef;
gr_linedef = gr_curline->linedef; gr_linedef = gr_curline->linedef;
vs.x = ((polyvertex_t *)gr_curline->v1)->x; vs.x = ((polyvertex_t *)gr_curline->pv1)->x;
vs.y = ((polyvertex_t *)gr_curline->v1)->y; vs.y = ((polyvertex_t *)gr_curline->pv1)->y;
ve.x = ((polyvertex_t *)gr_curline->v2)->x; ve.x = ((polyvertex_t *)gr_curline->pv2)->x;
ve.y = ((polyvertex_t *)gr_curline->v2)->y; ve.y = ((polyvertex_t *)gr_curline->pv2)->y;
#ifdef ESLOPE #ifdef ESLOPE
v1x = FLOAT_TO_FIXED(vs.x); v1x = FLOAT_TO_FIXED(vs.x);
@ -1378,44 +1375,21 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
v2x = FLOAT_TO_FIXED(ve.x); v2x = FLOAT_TO_FIXED(ve.x);
v2y = FLOAT_TO_FIXED(ve.y); v2y = FLOAT_TO_FIXED(ve.y);
#endif #endif
if (gr_frontsector->heightsec != -1)
{
#ifdef ESLOPE #ifdef ESLOPE
worldtop = worldtopslope = sectors[gr_frontsector->heightsec].ceilingheight;
worldbottom = worldbottomslope = sectors[gr_frontsector->heightsec].floorheight;
#else
worldtop = sectors[gr_frontsector->heightsec].ceilingheight;
worldbottom = sectors[gr_frontsector->heightsec].floorheight;
#endif
}
else
{
#ifdef ESLOPE
if (gr_frontsector->c_slope)
{
worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y);
worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y);
}
else
{
worldtop = worldtopslope = gr_frontsector->ceilingheight;
}
if (gr_frontsector->f_slope) #define SLOPEPARAMS(slope, end1, end2, normalheight) \
{ if (slope) { \
worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); end1 = P_GetZAt(slope, v1x, v1y); \
worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); end2 = P_GetZAt(slope, v2x, v2y); \
} } else \
else end1 = end2 = normalheight;
{
worldbottom = worldbottomslope = gr_frontsector->floorheight; SLOPEPARAMS(gr_frontsector->c_slope, worldtop, worldtopslope, gr_frontsector->ceilingheight)
} SLOPEPARAMS(gr_frontsector->f_slope, worldbottom, worldbottomslope, gr_frontsector->floorheight)
#else #else
worldtop = gr_frontsector->ceilingheight; worldtop = gr_frontsector->ceilingheight;
worldbottom = gr_frontsector->floorheight; worldbottom = gr_frontsector->floorheight;
#endif #endif
}
// remember vertices ordering // remember vertices ordering
// 3--2 // 3--2
@ -1430,7 +1404,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
wallVerts[2].z = wallVerts[1].z = ve.y; wallVerts[2].z = wallVerts[1].z = ve.y;
wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f;
if (drawtextured)
{ {
// x offset the texture // x offset the texture
fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset;
@ -1459,43 +1432,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
{ {
INT32 gr_toptexture, gr_bottomtexture; INT32 gr_toptexture, gr_bottomtexture;
// two sided line // two sided line
if (gr_backsector->heightsec != -1)
{
#ifdef ESLOPE
worldhigh = worldhighslope = sectors[gr_backsector->heightsec].ceilingheight;
worldlow = worldlowslope = sectors[gr_backsector->heightsec].floorheight;
#else
worldhigh = sectors[gr_backsector->heightsec].ceilingheight;
worldlow = sectors[gr_backsector->heightsec].floorheight;
#endif
}
else
{
#ifdef ESLOPE
if (gr_backsector->c_slope)
{
worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y);
worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y);
}
else
{
worldhigh = worldhighslope = gr_backsector->ceilingheight;
}
if (gr_backsector->f_slope) #ifdef ESLOPE
{ SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight)
worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); SLOPEPARAMS(gr_backsector->f_slope, worldlow, worldlowslope, gr_backsector->floorheight)
worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); #undef SLOPEPARAMS
}
else
{
worldlow = worldlowslope = gr_backsector->floorheight;
}
#else #else
worldhigh = gr_backsector->ceilingheight; worldhigh = gr_backsector->ceilingheight;
worldlow = gr_backsector->floorheight; worldlow = gr_backsector->floorheight;
#endif #endif
}
// hack to allow height changes in outdoor areas // hack to allow height changes in outdoor areas
// This is what gets rid of the upper textures if there should be sky // This is what gets rid of the upper textures if there should be sky
@ -1519,7 +1464,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
worldhigh < worldtop worldhigh < worldtop
) && gr_toptexture) ) && gr_toptexture)
{ {
if (drawtextured)
{ {
fixed_t texturevpegtop; // top fixed_t texturevpegtop; // top
@ -1600,7 +1544,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
#endif #endif
worldlow > worldbottom) && gr_bottomtexture) //only if VISIBLE!!! worldlow > worldbottom) && gr_bottomtexture) //only if VISIBLE!!!
{ {
if (drawtextured)
{ {
fixed_t texturevpegbottom = 0; // bottom fixed_t texturevpegbottom = 0; // bottom
@ -1792,7 +1735,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
h = min(highcut, polytop); h = min(highcut, polytop);
l = max(polybottom, lowcut); l = max(polybottom, lowcut);
if (drawtextured)
{ {
// PEGGING // PEGGING
#ifdef ESLOPE #ifdef ESLOPE
@ -1848,7 +1790,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
h = min(highcut, polytop); h = min(highcut, polytop);
l = max(polybottom, lowcut); l = max(polybottom, lowcut);
if (drawtextured)
{ {
// PEGGING // PEGGING
if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3))
@ -2039,7 +1980,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture);
if (gr_midtexture) if (gr_midtexture)
{ {
if (drawtextured)
{ {
fixed_t texturevpeg; fixed_t texturevpeg;
// PEGGING // PEGGING
@ -2180,7 +2120,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
wallVerts[0].s = wallVerts[3].s = 0; wallVerts[0].s = wallVerts[3].s = 0;
wallVerts[2].s = wallVerts[1].s = 0; wallVerts[2].s = wallVerts[1].s = 0;
} }
else if (drawtextured) else
{ {
fixed_t texturevpeg; fixed_t texturevpeg;
@ -2316,7 +2256,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
wallVerts[0].s = wallVerts[3].s = 0; wallVerts[0].s = wallVerts[3].s = 0;
wallVerts[2].s = wallVerts[1].s = 0; wallVerts[2].s = wallVerts[1].s = 0;
} }
else if (drawtextured) else
{ {
grTex = HWR_GetTexture(texnum); grTex = HWR_GetTexture(texnum);
@ -2456,7 +2396,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
} }
else else
{ {
highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(0, highfrac); HWR_StoreWallRange(0, highfrac);
} }
// Now adjust the clip size. // Now adjust the clip size.
@ -2480,8 +2420,8 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
} }
else else
{ {
lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac); HWR_StoreWallRange(lowfrac, highfrac);
} }
next++; next++;
@ -2515,7 +2455,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
} }
else else
{ {
lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, 1); HWR_StoreWallRange(lowfrac, 1);
} }
} }
@ -2578,8 +2518,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
else else
{ {
highfrac = HWR_ClipViewSegment(min(start->first + 1, highfrac = HWR_ClipViewSegment(min(start->first + 1,
start->last), (polyvertex_t *)gr_curline->v1, start->last), (polyvertex_t *)gr_curline->pv1,
(polyvertex_t *)gr_curline->v2); (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(0, highfrac); HWR_StoreWallRange(0, highfrac);
} }
} }
@ -2598,8 +2538,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
} }
else else
{ {
lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac); HWR_StoreWallRange(lowfrac, highfrac);
} }
start++; start++;
@ -2629,8 +2569,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
else else
{ {
lowfrac = HWR_ClipViewSegment(max(start->last - 1, lowfrac = HWR_ClipViewSegment(max(start->last - 1,
start->first), (polyvertex_t *)gr_curline->v1, start->first), (polyvertex_t *)gr_curline->pv1,
(polyvertex_t *)gr_curline->v2); (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, 1); HWR_StoreWallRange(lowfrac, 1);
} }
} }
@ -2685,16 +2625,21 @@ static void HWR_AddLine(seg_t * line)
// SoM: Backsector needs to be run through R_FakeFlat // SoM: Backsector needs to be run through R_FakeFlat
static sector_t tempsec; static sector_t tempsec;
fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t
if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES))
return; return;
gr_curline = line; gr_curline = line;
v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x);
v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y);
v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x);
v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y);
// OPTIMIZE: quickly reject orthogonal back sides. // OPTIMIZE: quickly reject orthogonal back sides.
angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), angle1 = R_PointToAngle(v1x, v1y);
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); angle2 = R_PointToAngle(v2x, v2y);
angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y));
// Clip to view edges. // Clip to view edges.
span = angle1 - angle2; span = angle1 - angle2;
@ -2736,8 +2681,8 @@ static void HWR_AddLine(seg_t * line)
float fx1,fx2,fy1,fy2; float fx1,fx2,fy1,fy2;
//BP: test with a better projection than viewangletox[R_PointToAngle(angle)] //BP: test with a better projection than viewangletox[R_PointToAngle(angle)]
// do not enable this at release 4 mul and 2 div // do not enable this at release 4 mul and 2 div
fx1 = ((polyvertex_t *)(line->v1))->x-gr_viewx; fx1 = ((polyvertex_t *)(line->pv1))->x-gr_viewx;
fy1 = ((polyvertex_t *)(line->v1))->y-gr_viewy; fy1 = ((polyvertex_t *)(line->pv1))->y-gr_viewy;
fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin); fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin);
if (fy2 < 0) if (fy2 < 0)
// the point is back // the point is back
@ -2745,8 +2690,8 @@ static void HWR_AddLine(seg_t * line)
else else
fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2; fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2;
fx2 = ((polyvertex_t *)(line->v2))->x-gr_viewx; fx2 = ((polyvertex_t *)(line->pv2))->x-gr_viewx;
fy2 = ((polyvertex_t *)(line->v2))->y-gr_viewy; fy2 = ((polyvertex_t *)(line->pv2))->y-gr_viewy;
fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin); fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin);
if (fy1 < 0) if (fy1 < 0)
// the point is back // the point is back
@ -2785,14 +2730,9 @@ static void HWR_AddLine(seg_t * line)
#ifdef ESLOPE #ifdef ESLOPE
if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope)
{ {
fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t
fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends
fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends
v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x);
v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y);
v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x);
v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y);
#define SLOPEPARAMS(slope, end1, end2, normalheight) \ #define SLOPEPARAMS(slope, end1, end2, normalheight) \
if (slope) { \ if (slope) { \
end1 = P_GetZAt(slope, v1x, v1y); \ end1 = P_GetZAt(slope, v1x, v1y); \
@ -2813,6 +2753,13 @@ static void HWR_AddLine(seg_t * line)
goto clipsolid; goto clipsolid;
} }
// Check for automap fix.
if (backc1 <= backf1 && backc2 <= backf2
&& ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture)
&& ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture)
&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum))
goto clipsolid;
// Window. // Window.
if (backc1 != frontc1 || backc2 != frontc2 if (backc1 != frontc1 || backc2 != frontc2
|| backf1 != frontf1 || backf2 != frontf2) || backf1 != frontf1 || backf2 != frontf2)
@ -2828,6 +2775,13 @@ static void HWR_AddLine(seg_t * line)
gr_backsector->floorheight >= gr_frontsector->ceilingheight) gr_backsector->floorheight >= gr_frontsector->ceilingheight)
goto clipsolid; goto clipsolid;
// Check for automap fix.
if (gr_backsector->ceilingheight <= gr_backsector->floorheight
&& ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture)
&& ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture)
&& (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum))
goto clipsolid;
// Window. // Window.
if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight ||
gr_backsector->floorheight != gr_frontsector->floorheight) gr_backsector->floorheight != gr_frontsector->floorheight)
@ -2849,8 +2803,21 @@ static void HWR_AddLine(seg_t * line)
&& gr_backsector->c_slope == gr_frontsector->c_slope && gr_backsector->c_slope == gr_frontsector->c_slope
#endif #endif
&& gr_backsector->lightlevel == gr_frontsector->lightlevel && gr_backsector->lightlevel == gr_frontsector->lightlevel
&& gr_curline->sidedef->midtexture == 0 && !gr_curline->sidedef->midtexture
&& !gr_backsector->ffloors && !gr_frontsector->ffloors) // Check offsets too!
&& gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs
&& gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs
&& gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle
&& gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs
&& gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs
&& gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle
// Consider altered lighting.
&& gr_backsector->floorlightsec == gr_frontsector->floorlightsec
&& gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec
// Consider colormaps
&& gr_backsector->extra_colormap == gr_frontsector->extra_colormap
&& ((!gr_frontsector->ffloors && !gr_backsector->ffloors)
|| gr_frontsector->tag == gr_backsector->tag))
// SoM: For 3D sides... Boris, would you like to take a // SoM: For 3D sides... Boris, would you like to take a
// crack at rendering 3D sides? You would need to add the // crack at rendering 3D sides? You would need to add the
// above check and add code to HWR_StoreWallRange... // above check and add code to HWR_StoreWallRange...
@ -2987,8 +2954,8 @@ static inline void HWR_AddPolyObjectSegs(void)
pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x); pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x);
pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y); pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y);
gr_fakeline->v1 = (vertex_t *)pv1; gr_fakeline->pv1 = pv1;
gr_fakeline->v2 = (vertex_t *)pv2; gr_fakeline->pv2 = pv2;
HWR_AddLine(gr_fakeline); HWR_AddLine(gr_fakeline);
} }

View File

@ -304,8 +304,8 @@ static md2_model_t *md2_readModel(const char *filename)
// initialize model and read header // initialize model and read header
if (fread(&model->header, sizeof (model->header), 1, file) != 1 if (fread(&model->header, sizeof (model->header), 1, file) != 1
|| model->header.magic != || model->header.magic != MD2_IDENT
(INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')) || model->header.version != MD2_VERSION)
{ {
fclose(file); fclose(file);
free(model); free(model);
@ -319,6 +319,7 @@ static md2_model_t *md2_readModel(const char *filename)
{ \ { \
CONS_Alert(CONS_ERROR, "md2_readModel: %s has too many " msgname " (# found: %d, maximum: %d)\n", filename, field, max); \ CONS_Alert(CONS_ERROR, "md2_readModel: %s has too many " msgname " (# found: %d, maximum: %d)\n", filename, field, max); \
md2_freeModel (model); \ md2_freeModel (model); \
fclose(file); \
return 0; \ return 0; \
} }
@ -340,6 +341,7 @@ static md2_model_t *md2_readModel(const char *filename)
fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file)) fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file))
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
} }
@ -353,6 +355,7 @@ static md2_model_t *md2_readModel(const char *filename)
fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file)) fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file))
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
} }
@ -366,6 +369,7 @@ static md2_model_t *md2_readModel(const char *filename)
fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file)) fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file))
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
} }
@ -378,6 +382,7 @@ static md2_model_t *md2_readModel(const char *filename)
if (!model->frames) if (!model->frames)
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
@ -391,6 +396,7 @@ static md2_model_t *md2_readModel(const char *filename)
fread(frame, 1, model->header.frameSize, file)) fread(frame, 1, model->header.frameSize, file))
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
@ -416,6 +422,7 @@ static md2_model_t *md2_readModel(const char *filename)
fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file)) fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file))
{ {
md2_freeModel (model); md2_freeModel (model);
fclose(file);
return 0; return 0;
} }
} }

View File

@ -23,6 +23,11 @@
#include "hw_glob.h" #include "hw_glob.h"
// magic number "IDP2" or 844121161
#define MD2_IDENT (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')
// model version
#define MD2_VERSION 8
#define MD2_MAX_TRIANGLES 8192 #define MD2_MAX_TRIANGLES 8192
#define MD2_MAX_VERTICES 4096 #define MD2_MAX_VERTICES 4096
#define MD2_MAX_TEXCOORDS 4096 #define MD2_MAX_TEXCOORDS 4096

View File

@ -107,17 +107,17 @@ static void releaseLineChains(void)
for (i = 0; i < numsectors; i++) for (i = 0; i < numsectors; i++)
{ {
sector = &sectors[i]; sector = &sectors[i];
nextElem = sector->sectorLines; nextElem = sector->sectorLines;
while (nextElem) while (nextElem)
{ {
thisElem = nextElem; thisElem = nextElem;
nextElem = thisElem->next; nextElem = thisElem->next;
free(thisElem); free(thisElem);
} }
sector->sectorLines = NULL; sector->sectorLines = NULL;
} }
} }
@ -397,7 +397,7 @@ static void sortStacklist(sector_t *sector)
i = 0; i = 0;
finished = true; finished = true;
while (NULL != *(list+i+1)) while (*(list+i+1))
{ {
sec1 = *(list+i); sec1 = *(list+i);
sec2 = *(list+i+1); sec2 = *(list+i+1);
@ -438,7 +438,7 @@ static double calcLineoutLength(sector_t *sector)
double length = 0.0L; double length = 0.0L;
chain = sector->sectorLines; chain = sector->sectorLines;
while (NULL != chain) // sum up lengths of all lines while (chain) // sum up lengths of all lines
{ {
length += lineLength(chain->line); length += lineLength(chain->line);
chain = chain->next; chain = chain->next;
@ -454,7 +454,7 @@ static void calcLineouts(sector_t *sector)
size_t secCount = 0; size_t secCount = 0;
sector_t *encSector = *(sector->stackList); sector_t *encSector = *(sector->stackList);
while (NULL != encSector) while (encSector)
{ {
if (encSector->lineoutLength < 0.0L) // if length has not yet been calculated if (encSector->lineoutLength < 0.0L) // if length has not yet been calculated
{ {
@ -552,7 +552,7 @@ static boolean areBottomtexturesMissing(sector_t *thisSector)
if (frontSector == backSector) // skip damn renderer tricks here if (frontSector == backSector) // skip damn renderer tricks here
continue; continue;
if (frontSector == NULL || backSector == NULL) if (!frontSector || !backSector)
continue; continue;
sider = &sides[thisElem->line->sidenum[0]]; sider = &sides[thisElem->line->sidenum[0]];
@ -587,73 +587,12 @@ static boolean areBottomtexturesMissing(sector_t *thisSector)
static boolean isCeilingFloating(sector_t *thisSector) static boolean isCeilingFloating(sector_t *thisSector)
{ {
sector_t *adjSector, *refSector = NULL, *frontSector, *backSector; sector_t *adjSector, *refSector = NULL, *frontSector, *backSector;
boolean floating = true;
linechain_t *thisElem, *nextElem; linechain_t *thisElem, *nextElem;
if (!thisSector) if (!thisSector)
return false; return false;
nextElem = thisSector->sectorLines; nextElem = thisSector->sectorLines;
while (NULL != nextElem) // walk through chain
{
thisElem = nextElem;
nextElem = thisElem->next;
frontSector = thisElem->line->frontsector;
backSector = thisElem->line->backsector;
if (frontSector == thisSector)
adjSector = backSector;
else
adjSector = frontSector;
if (!adjSector) // assume floating sectors have surrounding sectors
{
floating = false;
break;
}
if (!refSector)
{
refSector = adjSector;
continue;
}
// if adjacent sector has same height or more than one adjacent sector exists -> stop
if (thisSector->ceilingheight == adjSector->ceilingheight ||
refSector != adjSector)
{
floating = false;
break;
}
}
// now check for walltextures
if (floating)
{
if (!areToptexturesMissing(thisSector))
{
floating = false;
}
}
return floating;
}
//
// check if no adjacent sector has same ceiling height
// FIXME: throw that together with isCeilingFloating??
//
static boolean isFloorFloating(sector_t *thisSector)
{
sector_t *adjSector, *refSector = NULL, *frontSector, *backSector;
boolean floating = true;
linechain_t *thisElem, *nextElem;
if (!thisSector)
return false;
nextElem = thisSector->sectorLines;
while (nextElem) // walk through chain while (nextElem) // walk through chain
{ {
@ -668,36 +607,83 @@ static boolean isFloorFloating(sector_t *thisSector)
else else
adjSector = frontSector; adjSector = frontSector;
if (NULL == adjSector) // assume floating sectors have surrounding sectors if (!adjSector) // assume floating sectors have surrounding sectors
{ return false;
floating = false;
break;
}
if (NULL == refSector) #ifdef ESLOPE
if (adjSector->c_slope) // Don't bother with slopes
return false;
#endif
if (!refSector)
{ {
refSector = adjSector; refSector = adjSector;
continue; continue;
} }
// if adjacent sector has same height or more than one adjacent sector exists -> stop // if adjacent sector has same height or more than one adjacent sector exists -> stop
if (thisSector->floorheight == adjSector->floorheight || if (thisSector->ceilingheight == adjSector->ceilingheight || refSector != adjSector)
refSector != adjSector) return false;
{
floating = false;
break;
}
} }
// now check for walltextures // now check for walltextures
if (floating) if (!areToptexturesMissing(thisSector))
return false;
return true;
}
//
// check if no adjacent sector has same ceiling height
// FIXME: throw that together with isCeilingFloating??
//
static boolean isFloorFloating(sector_t *thisSector)
{
sector_t *adjSector, *refSector = NULL, *frontSector, *backSector;
linechain_t *thisElem, *nextElem;
if (!thisSector)
return false;
nextElem = thisSector->sectorLines;
while (nextElem) // walk through chain
{ {
if (!areBottomtexturesMissing(thisSector)) thisElem = nextElem;
nextElem = thisElem->next;
frontSector = thisElem->line->frontsector;
backSector = thisElem->line->backsector;
if (frontSector == thisSector)
adjSector = backSector;
else
adjSector = frontSector;
if (!adjSector) // assume floating sectors have surrounding sectors
return false;
#ifdef ESLOPE
if (adjSector->f_slope) // Don't bother with slopes
return false;
#endif
if (!refSector)
{ {
floating = false; refSector = adjSector;
continue;
} }
// if adjacent sector has same height or more than one adjacent sector exists -> stop
if (thisSector->floorheight == adjSector->floorheight || refSector != adjSector)
return false;
} }
return floating;
// now check for walltextures
if (!areBottomtexturesMissing(thisSector))
return false;
return true;
} }
// //
@ -707,14 +693,12 @@ static fixed_t estimateCeilHeight(sector_t *thisSector)
{ {
sector_t *adjSector; sector_t *adjSector;
if (!thisSector || if (!thisSector || !thisSector->sectorLines || !thisSector->sectorLines->line)
!thisSector->sectorLines ||
!thisSector->sectorLines->line)
return 0; return 0;
adjSector = thisSector->sectorLines->line->frontsector; adjSector = thisSector->sectorLines->line->frontsector;
if (adjSector == thisSector) if (adjSector == thisSector)
adjSector = thisSector->sectorLines->line->backsector; adjSector = thisSector->sectorLines->line->backsector;
if (!adjSector) if (!adjSector)
return 0; return 0;
@ -729,17 +713,15 @@ static fixed_t estimateFloorHeight(sector_t *thisSector)
{ {
sector_t *adjSector; sector_t *adjSector;
if (!thisSector || if (!thisSector || !thisSector->sectorLines || !thisSector->sectorLines->line)
!thisSector->sectorLines || return 0;
!thisSector->sectorLines->line)
return 0;
adjSector = thisSector->sectorLines->line->frontsector; adjSector = thisSector->sectorLines->line->frontsector;
if (adjSector == thisSector) if (adjSector == thisSector)
adjSector = thisSector->sectorLines->line->backsector; adjSector = thisSector->sectorLines->line->backsector;
if (NULL == adjSector) if (!adjSector)
return 0; return 0;
return adjSector->floorheight; return adjSector->floorheight;
} }
@ -845,18 +827,12 @@ void HWR_CorrectSWTricks(void)
// correct height of floating sectors // correct height of floating sectors
if (isCeilingFloating(floatSector)) if (isCeilingFloating(floatSector))
{ {
fixed_t corrheight; floatSector->virtualCeilingheight = estimateCeilHeight(floatSector);
corrheight = estimateCeilHeight(floatSector);
floatSector->virtualCeilingheight = corrheight;
floatSector->virtualCeiling = true; floatSector->virtualCeiling = true;
} }
if (isFloorFloating(floatSector)) if (isFloorFloating(floatSector))
{ {
fixed_t corrheight; floatSector->virtualFloorheight = estimateFloorHeight(floatSector);
corrheight = estimateFloorHeight(floatSector);
floatSector->virtualFloorheight = corrheight;
floatSector->virtualFloor = true; floatSector->virtualFloor = true;
} }
} }

View File

@ -451,6 +451,7 @@ static void P_LoadSegs(lumpnum_t lumpnum)
//Hurdler: 04/12/2000: for now, only used in hardware mode //Hurdler: 04/12/2000: for now, only used in hardware mode
li->lightmaps = NULL; // list of static lightmap for this seg li->lightmaps = NULL; // list of static lightmap for this seg
} }
li->pv1 = li->pv2 = NULL;
#endif #endif
li->angle = (SHORT(ml->angle))<<FRACBITS; li->angle = (SHORT(ml->angle))<<FRACBITS;

View File

@ -574,6 +574,9 @@ typedef struct seg_s
sector_t *backsector; sector_t *backsector;
#ifdef HWRENDER #ifdef HWRENDER
// new pointers so that AdjustSegs doesn't mess with v1/v2
void *pv1; // polyvertex_t
void *pv2; // polyvertex_t
float flength; // length of the seg, used by hardware renderer float flength; // length of the seg, used by hardware renderer
lightmap_t *lightmaps; // for static lightmap lightmap_t *lightmaps; // for static lightmap