Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
f27b2900
Commit
f27b2900
authored
5 months ago
by
Lactozilla
Browse files
Options
Downloads
Patches
Plain Diff
Fix plane offsets overflow in the software renderer
parent
33ceb5c1
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2575
Fix plane offsets overflow in the software renderer
Pipeline
#6439
passed
5 months ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/r_plane.c
+34
-23
34 additions, 23 deletions
src/r_plane.c
src/r_plane.h
+2
-2
2 additions, 2 deletions
src/r_plane.h
src/r_splats.c
+1
-1
1 addition, 1 deletion
src/r_splats.c
with
37 additions
and
26 deletions
src/r_plane.c
+
34
−
23
View file @
f27b2900
...
@@ -83,7 +83,7 @@ static fixed_t planeheight;
...
@@ -83,7 +83,7 @@ static fixed_t planeheight;
fixed_t
yslopetab
[
MAXVIDHEIGHT
*
16
];
fixed_t
yslopetab
[
MAXVIDHEIGHT
*
16
];
fixed_t
*
yslope
;
fixed_t
*
yslope
;
static
fixed_t
xoffs
,
yoffs
;
static
INT64
xoffs
,
yoffs
;
static
dvector3_t
slope_origin
,
slope_u
,
slope_v
;
static
dvector3_t
slope_origin
,
slope_u
,
slope_v
;
static
dvector3_t
slope_lightu
,
slope_lightv
;
static
dvector3_t
slope_lightu
,
slope_lightv
;
...
@@ -376,19 +376,25 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
...
@@ -376,19 +376,25 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
visplane_t
*
check
;
visplane_t
*
check
;
unsigned
hash
;
unsigned
hash
;
float
offset_xd
=
FixedToFloat
(
xoff
)
/
FixedToFloat
(
xscale
?
xscale
:
1
);
float
offset_yd
=
FixedToFloat
(
yoff
)
/
FixedToFloat
(
yscale
?
yscale
:
1
);
INT64
offset_x
=
offset_xd
*
FRACUNIT
;
INT64
offset_y
=
offset_yd
*
FRACUNIT
;
if
(
!
slope
)
// Don't mess with this right now if a slope is involved
if
(
!
slope
)
// Don't mess with this right now if a slope is involved
{
{
x
off
+=
FixedMul
(
viewx
,
xscale
)
;
off
set_x
+=
viewx
;
y
off
-=
FixedMul
(
viewy
,
yscale
)
;
off
set_y
-=
viewy
;
if
(
plangle
!=
0
)
if
(
plangle
!=
0
)
{
{
// Add the view offset, rotated by the plane angle.
// Add the view offset, rotated by the plane angle.
float
ang
=
ANG2RAD
(
plangle
);
float
ang
=
ANG2RAD
(
plangle
);
float
x
=
FixedToFloat
(
xoff
)
;
float
x
=
offset_x
/
(
float
)
FRACUNIT
;
float
y
=
FixedToFloat
(
yoff
)
;
float
y
=
offset_y
/
(
float
)
FRACUNIT
;
x
off
=
FloatToFixed
(
x
*
cos
(
ang
)
+
y
*
sin
(
ang
));
off
set_x
=
(
x
*
cos
(
ang
)
+
y
*
sin
(
ang
))
*
FRACUNIT
;
y
off
=
FloatToFixed
(
-
x
*
sin
(
ang
)
+
y
*
cos
(
ang
));
off
set_y
=
(
-
x
*
sin
(
ang
)
+
y
*
cos
(
ang
))
*
FRACUNIT
;
}
}
}
}
...
@@ -399,16 +405,19 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
...
@@ -399,16 +405,19 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
float
ang
=
ANG2RAD
(
polyobj
->
angle
);
float
ang
=
ANG2RAD
(
polyobj
->
angle
);
float
x
=
FixedToFloat
(
polyobj
->
centerPt
.
x
);
float
x
=
FixedToFloat
(
polyobj
->
centerPt
.
x
);
float
y
=
FixedToFloat
(
polyobj
->
centerPt
.
y
);
float
y
=
FixedToFloat
(
polyobj
->
centerPt
.
y
);
x
off
-=
FloatToFixed
(
x
*
cos
(
ang
)
+
y
*
sin
(
ang
));
off
set_x
-=
(
x
*
cos
(
ang
)
+
y
*
sin
(
ang
))
*
FRACUNIT
;
y
off
-=
FloatToFixed
(
x
*
sin
(
ang
)
-
y
*
cos
(
ang
));
off
set_y
-=
(
x
*
sin
(
ang
)
-
y
*
cos
(
ang
))
*
FRACUNIT
;
}
}
else
else
{
{
x
off
-=
polyobj
->
centerPt
.
x
;
off
set_x
-=
polyobj
->
centerPt
.
x
;
y
off
+=
polyobj
->
centerPt
.
y
;
off
set_y
+=
polyobj
->
centerPt
.
y
;
}
}
}
}
offset_x
=
((
INT64
)
offset_x
*
xscale
)
/
FRACUNIT
;
offset_y
=
((
INT64
)
offset_y
*
yscale
)
/
FRACUNIT
;
// This appears to fix the Nimbus Ruins sky bug.
// This appears to fix the Nimbus Ruins sky bug.
if
(
picnum
==
skyflatnum
&&
pfloor
)
if
(
picnum
==
skyflatnum
&&
pfloor
)
{
{
...
@@ -423,7 +432,7 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
...
@@ -423,7 +432,7 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
{
{
if
(
height
==
check
->
height
&&
picnum
==
check
->
picnum
if
(
height
==
check
->
height
&&
picnum
==
check
->
picnum
&&
lightlevel
==
check
->
lightlevel
&&
lightlevel
==
check
->
lightlevel
&&
x
off
==
check
->
xoffs
&&
y
off
==
check
->
yoffs
&&
off
set_x
==
check
->
xoffs
&&
off
set_y
==
check
->
yoffs
&&
xscale
==
check
->
xscale
&&
yscale
==
check
->
yscale
&&
xscale
==
check
->
xscale
&&
yscale
==
check
->
yscale
&&
planecolormap
==
check
->
extra_colormap
&&
planecolormap
==
check
->
extra_colormap
&&
check
->
viewx
==
viewx
&&
check
->
viewy
==
viewy
&&
check
->
viewz
==
viewz
&&
check
->
viewx
==
viewx
&&
check
->
viewy
==
viewy
&&
check
->
viewz
==
viewz
...
@@ -449,8 +458,8 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
...
@@ -449,8 +458,8 @@ visplane_t *R_FindPlane(sector_t *sector, fixed_t height, INT32 picnum, INT32 li
check
->
lightlevel
=
lightlevel
;
check
->
lightlevel
=
lightlevel
;
check
->
minx
=
vid
.
width
;
check
->
minx
=
vid
.
width
;
check
->
maxx
=
-
1
;
check
->
maxx
=
-
1
;
check
->
xoffs
=
x
off
;
check
->
xoffs
=
off
set_x
;
check
->
yoffs
=
y
off
;
check
->
yoffs
=
off
set_y
;
check
->
xscale
=
xscale
;
check
->
xscale
=
xscale
;
check
->
yscale
=
yscale
;
check
->
yscale
=
yscale
;
check
->
extra_colormap
=
planecolormap
;
check
->
extra_colormap
=
planecolormap
;
...
@@ -658,13 +667,13 @@ static void R_DrawSkyPlane(visplane_t *pl)
...
@@ -658,13 +667,13 @@ static void R_DrawSkyPlane(visplane_t *pl)
}
}
// Returns the height of the sloped plane at (x, y) as a double
// Returns the height of the sloped plane at (x, y) as a double
static
double
R_GetSlopeZAt
(
const
pslope_t
*
slope
,
fixed_t
x
,
fixed_t
y
)
static
double
R_GetSlopeZAt
(
const
pslope_t
*
slope
,
INT64
x
,
INT64
y
)
{
{
// If you want to reimplement this using just the equation constants, use this instead:
// If you want to reimplement this using just the equation constants, use this instead:
// (d + a*x + b*y) * -(1.0 / c)
// (d + a*x + b*y) * -(1.0 / c)
double
px
=
FixedToDouble
(
x
)
-
slope
->
dorigin
.
x
;
double
px
=
(
x
/
(
double
)
FRACUNIT
)
-
slope
->
dorigin
.
x
;
double
py
=
FixedToDouble
(
y
)
-
slope
->
dorigin
.
y
;
double
py
=
(
y
/
(
double
)
FRACUNIT
)
-
slope
->
dorigin
.
y
;
double
dist
=
(
px
*
slope
->
dnormdir
.
x
)
+
(
py
*
slope
->
dnormdir
.
y
);
double
dist
=
(
px
*
slope
->
dnormdir
.
x
)
+
(
py
*
slope
->
dnormdir
.
y
);
...
@@ -672,10 +681,10 @@ static double R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
...
@@ -672,10 +681,10 @@ static double R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
}
}
// Sets the texture origin vector of the sloped plane.
// Sets the texture origin vector of the sloped plane.
static
void
R_SetSlopePlaneOrigin
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xoff
,
fixed_t
yoff
,
fixed_t
angle
)
static
void
R_SetSlopePlaneOrigin
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
INT64
xoff
,
INT64
yoff
,
fixed_t
angle
)
{
{
INT64
vx
=
(
INT64
)
xpos
+
(
INT64
)
xoff
;
INT64
vx
=
(
INT64
)
xpos
+
xoff
;
INT64
vy
=
(
INT64
)
ypos
-
(
INT64
)
yoff
;
INT64
vy
=
(
INT64
)
ypos
-
yoff
;
float
vxf
=
vx
/
(
float
)
FRACUNIT
;
float
vxf
=
vx
/
(
float
)
FRACUNIT
;
float
vyf
=
vy
/
(
float
)
FRACUNIT
;
float
vyf
=
vy
/
(
float
)
FRACUNIT
;
...
@@ -702,7 +711,7 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
...
@@ -702,7 +711,7 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
slope
->
moved
=
false
;
slope
->
moved
=
false
;
}
}
R_SetSlopePlaneOrigin
(
slope
,
xpos
,
ypos
,
zpos
,
xoff
,
yoff
,
angle
);
R_SetSlopePlaneOrigin
(
slope
,
xpos
,
ypos
,
zpos
,
(
INT64
)
xoff
,
(
INT64
)
yoff
,
angle
);
height
=
R_GetSlopeZAt
(
slope
,
xpos
,
ypos
);
height
=
R_GetSlopeZAt
(
slope
,
xpos
,
ypos
);
zeroheight
=
height
-
FixedToDouble
(
zpos
);
zeroheight
=
height
-
FixedToDouble
(
zpos
);
...
@@ -735,7 +744,7 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
...
@@ -735,7 +744,7 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
}
}
// This function calculates all of the vectors necessary for drawing a sloped and scaled plane.
// This function calculates all of the vectors necessary for drawing a sloped and scaled plane.
void
R_SetScaledSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xs
,
fixed_t
ys
,
fixed_t
xoff
,
fixed_t
yoff
,
angle_t
angle
,
angle_t
plangle
)
void
R_SetScaledSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xs
,
fixed_t
ys
,
INT64
xoff
,
INT64
yoff
,
angle_t
angle
,
angle_t
plangle
)
{
{
double
height
,
z_at_xy
;
double
height
,
z_at_xy
;
float
ang
;
float
ang
;
...
@@ -836,9 +845,11 @@ static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff)
...
@@ -836,9 +845,11 @@ static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff)
{
{
if
(
!
ds_fog
&&
(
pl
->
xscale
!=
FRACUNIT
||
pl
->
yscale
!=
FRACUNIT
))
if
(
!
ds_fog
&&
(
pl
->
xscale
!=
FRACUNIT
||
pl
->
yscale
!=
FRACUNIT
))
{
{
float
offset_x
=
FixedToFloat
(
xoff
)
/
FixedToFloat
(
pl
->
xscale
?
pl
->
xscale
:
1
);
float
offset_y
=
FixedToFloat
(
yoff
)
/
FixedToFloat
(
pl
->
yscale
?
pl
->
yscale
:
1
);
R_SetScaledSlopePlane
(
pl
->
slope
,
pl
->
viewx
,
pl
->
viewy
,
pl
->
viewz
,
R_SetScaledSlopePlane
(
pl
->
slope
,
pl
->
viewx
,
pl
->
viewy
,
pl
->
viewz
,
FixedDiv
(
FRACUNIT
,
pl
->
xscale
),
FixedDiv
(
FRACUNIT
,
pl
->
yscale
),
FixedDiv
(
FRACUNIT
,
pl
->
xscale
),
FixedDiv
(
FRACUNIT
,
pl
->
yscale
),
FixedDiv
(
xoff
,
pl
->
xscale
),
FixedDiv
(
yoff
,
pl
->
yscale
),
pl
->
viewangle
,
pl
->
plangle
);
(
INT64
)(
offset_x
*
FRACUNIT
),
(
INT64
)(
offset_y
*
FRACUNIT
),
pl
->
viewangle
,
pl
->
plangle
);
}
}
else
else
R_SetSlopePlane
(
pl
->
slope
,
pl
->
viewx
,
pl
->
viewy
,
pl
->
viewz
,
xoff
,
yoff
,
pl
->
viewangle
,
pl
->
plangle
);
R_SetSlopePlane
(
pl
->
slope
,
pl
->
viewx
,
pl
->
viewy
,
pl
->
viewz
,
xoff
,
yoff
,
pl
->
viewangle
,
pl
->
plangle
);
...
...
This diff is collapsed.
Click to expand it.
src/r_plane.h
+
2
−
2
View file @
f27b2900
...
@@ -48,7 +48,7 @@ typedef struct visplane_s
...
@@ -48,7 +48,7 @@ typedef struct visplane_s
UINT16
padbottomstart
,
bottom
[
MAXVIDWIDTH
],
padbottomend
;
UINT16
padbottomstart
,
bottom
[
MAXVIDWIDTH
],
padbottomend
;
INT32
high
,
low
;
// R_PlaneBounds should set these.
INT32
high
,
low
;
// R_PlaneBounds should set these.
fixed_t
xoffs
,
yoffs
;
// Scrolling flats.
INT64
xoffs
,
yoffs
;
// Scrolling flats.
fixed_t
xscale
,
yscale
;
fixed_t
xscale
,
yscale
;
sector_t
*
sector
;
sector_t
*
sector
;
...
@@ -85,7 +85,7 @@ void R_DrawSinglePlane(visplane_t *pl);
...
@@ -85,7 +85,7 @@ void R_DrawSinglePlane(visplane_t *pl);
// Calculates the slope vectors needed for tilted span drawing.
// Calculates the slope vectors needed for tilted span drawing.
void
R_SetSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xoff
,
fixed_t
yoff
,
angle_t
angle
,
angle_t
plangle
);
void
R_SetSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xoff
,
fixed_t
yoff
,
angle_t
angle
,
angle_t
plangle
);
void
R_SetScaledSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xs
,
fixed_t
ys
,
fixed_t
xoff
,
fixed_t
yoff
,
angle_t
angle
,
angle_t
plangle
);
void
R_SetScaledSlopePlane
(
pslope_t
*
slope
,
fixed_t
xpos
,
fixed_t
ypos
,
fixed_t
zpos
,
fixed_t
xs
,
fixed_t
ys
,
INT64
xoff
,
INT64
yoff
,
angle_t
angle
,
angle_t
plangle
);
typedef
struct
planemgr_s
typedef
struct
planemgr_s
{
{
...
...
This diff is collapsed.
Click to expand it.
src/r_splats.c
+
1
−
1
View file @
f27b2900
...
@@ -381,7 +381,7 @@ static void R_RasterizeFloorSplat(floorsplat_t *pSplat, vector2_t *verts, visspr
...
@@ -381,7 +381,7 @@ static void R_RasterizeFloorSplat(floorsplat_t *pSplat, vector2_t *verts, visspr
if
(
pSplat
->
slope
)
if
(
pSplat
->
slope
)
{
{
R_SetScaledSlopePlane
(
pSplat
->
slope
,
vis
->
viewpoint
.
x
,
vis
->
viewpoint
.
y
,
vis
->
viewpoint
.
z
,
pSplat
->
xscale
,
pSplat
->
yscale
,
-
pSplat
->
verts
[
0
].
x
,
pSplat
->
verts
[
0
].
y
,
vis
->
viewpoint
.
angle
,
pSplat
->
angle
);
R_SetScaledSlopePlane
(
pSplat
->
slope
,
vis
->
viewpoint
.
x
,
vis
->
viewpoint
.
y
,
vis
->
viewpoint
.
z
,
(
INT64
)
pSplat
->
xscale
,
(
INT64
)
pSplat
->
yscale
,
-
pSplat
->
verts
[
0
].
x
,
pSplat
->
verts
[
0
].
y
,
vis
->
viewpoint
.
angle
,
pSplat
->
angle
);
}
}
else
if
(
!
ds_solidcolor
)
else
if
(
!
ds_solidcolor
)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment