Make new pv1/pv2 seg pointers, so AdjustSeg doesn't modify the v1/v2 pointers directly anymore

Yes I know they're void * in r_defs.h's seg_t definition, it's quicker than trying to figure out if including hardware/hw_glob.h is a good idea or not
This commit is contained in:
Monster Iestyn 2016-11-07 21:55:56 +00:00
parent 817f0908e4
commit 5be8e4f1b0
4 changed files with 42 additions and 38 deletions

View file

@ -916,7 +916,7 @@ static void AdjustSegs(void)
}
if (nearv1 <= NEARDIST*NEARDIST)
// share vertice with segs
lseg->v1 = (vertex_t *)&(p->pts[v1found]);
lseg->pv1 = &(p->pts[v1found]);
else
{
// BP: here we can do better, using PointInSeg and compute
@ -927,24 +927,24 @@ static void AdjustSegs(void)
polyvertex_t *pv = HWR_AllocVertex();
pv->x = FIXED_TO_FLOAT(lseg->v1->x);
pv->y = FIXED_TO_FLOAT(lseg->v1->y);
lseg->v1 = (vertex_t *)pv;
lseg->pv1 = pv;
}
if (nearv2 <= NEARDIST*NEARDIST)
lseg->v2 = (vertex_t *)&(p->pts[v2found]);
lseg->pv2 = &(p->pts[v2found]);
else
{
polyvertex_t *pv = HWR_AllocVertex();
pv->x = FIXED_TO_FLOAT(lseg->v2->x);
pv->y = FIXED_TO_FLOAT(lseg->v2->y);
lseg->v2 = (vertex_t *)pv;
lseg->pv2 = pv;
}
// recompute length
{
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);
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);
lseg->flength = (float)hypot(x, y);
// BP: debug see this kind of segs

View file

@ -858,11 +858,11 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf)
M_ClearBox(segbbox);
M_AddToBox(segbbox,
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y));
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y));
M_AddToBox(segbbox,
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y));
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y));
splat = (wallsplat_t *)gr_curline->linedef->splats;
for (; splat; splat = splat->next)
@ -1468,10 +1468,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac)
gr_sidedef = gr_curline->sidedef;
gr_linedef = gr_curline->linedef;
vs.x = ((polyvertex_t *)gr_curline->v1)->x;
vs.y = ((polyvertex_t *)gr_curline->v1)->y;
ve.x = ((polyvertex_t *)gr_curline->v2)->x;
ve.y = ((polyvertex_t *)gr_curline->v2)->y;
vs.x = ((polyvertex_t *)gr_curline->pv1)->x;
vs.y = ((polyvertex_t *)gr_curline->pv1)->y;
ve.x = ((polyvertex_t *)gr_curline->pv2)->x;
ve.y = ((polyvertex_t *)gr_curline->pv2)->y;
#ifdef ESLOPE
v1x = FLOAT_TO_FIXED(vs.x);
@ -2555,7 +2555,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
}
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);
}
// Now adjust the clip size.
@ -2579,8 +2579,8 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
}
else
{
lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2);
highfrac = HWR_ClipViewSegment((next+1)->first+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->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac);
}
next++;
@ -2614,7 +2614,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
}
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);
}
}
@ -2677,8 +2677,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
else
{
highfrac = HWR_ClipViewSegment(min(start->first + 1,
start->last), (polyvertex_t *)gr_curline->v1,
(polyvertex_t *)gr_curline->v2);
start->last), (polyvertex_t *)gr_curline->pv1,
(polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(0, highfrac);
}
}
@ -2697,8 +2697,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
}
else
{
lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (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->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->pv1, (polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac);
}
start++;
@ -2728,8 +2728,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
else
{
lowfrac = HWR_ClipViewSegment(max(start->last - 1,
start->first), (polyvertex_t *)gr_curline->v1,
(polyvertex_t *)gr_curline->v2);
start->first), (polyvertex_t *)gr_curline->pv1,
(polyvertex_t *)gr_curline->pv2);
HWR_StoreWallRange(lowfrac, 1);
}
}
@ -2790,10 +2790,10 @@ static void HWR_AddLine(seg_t * line)
gr_curline = line;
// OPTIMIZE: quickly reject orthogonal back sides.
angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y));
angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y));
angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y));
angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x),
FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y));
// Clip to view edges.
span = angle1 - angle2;
@ -2835,8 +2835,8 @@ static void HWR_AddLine(seg_t * line)
float fx1,fx2,fy1,fy2;
//BP: test with a better projection than viewangletox[R_PointToAngle(angle)]
// do not enable this at release 4 mul and 2 div
fx1 = ((polyvertex_t *)(line->v1))->x-gr_viewx;
fy1 = ((polyvertex_t *)(line->v1))->y-gr_viewy;
fx1 = ((polyvertex_t *)(line->pv1))->x-gr_viewx;
fy1 = ((polyvertex_t *)(line->pv1))->y-gr_viewy;
fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin);
if (fy2 < 0)
// the point is back
@ -2844,8 +2844,8 @@ static void HWR_AddLine(seg_t * line)
else
fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2;
fx2 = ((polyvertex_t *)(line->v2))->x-gr_viewx;
fy2 = ((polyvertex_t *)(line->v2))->y-gr_viewy;
fx2 = ((polyvertex_t *)(line->pv2))->x-gr_viewx;
fy2 = ((polyvertex_t *)(line->pv2))->y-gr_viewy;
fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin);
if (fy1 < 0)
// the point is back
@ -2888,10 +2888,10 @@ static void HWR_AddLine(seg_t * line)
fixed_t frontf1,frontf2, frontc1, frontc2; // front 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);
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);
#define SLOPEPARAMS(slope, end1, end2, normalheight) \
if (slope) { \
end1 = P_GetZAt(slope, v1x, v1y); \
@ -3086,8 +3086,8 @@ static inline void HWR_AddPolyObjectSegs(void)
pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x);
pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y);
gr_fakeline->v1 = (vertex_t *)pv1;
gr_fakeline->v2 = (vertex_t *)pv2;
gr_fakeline->pv1 = pv1;
gr_fakeline->pv2 = pv2;
HWR_AddLine(gr_fakeline);
}

View file

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

View file

@ -581,6 +581,9 @@ typedef struct seg_s
sector_t *backsector;
#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
lightmap_t *lightmaps; // for static lightmap