- fixed: The global viewpoint's Level member was accessed before it was set.

All affected code needs to get a Level parameter passed in through its arguments.
This commit is contained in:
Christoph Oelckers 2019-02-08 13:12:46 +01:00
parent bd1f5d9750
commit 0b2494f9ca
6 changed files with 13 additions and 14 deletions

View file

@ -95,7 +95,7 @@ namespace swrenderer
/////////////////////////////////////////////////////////////////////////
// Changes how rapidly things get dark with distance
void LightVisibility::SetVisibility(RenderViewport *viewport, double vis)
void LightVisibility::SetVisibility(RenderViewport *viewport, double vis, bool nolightfade)
{
vis = R_ClampVisibility(vis);
@ -140,7 +140,7 @@ namespace swrenderer
TiltVisibility = float(vis * viewport->viewwindow.FocalTangent * (16.f * 320.f) / viewwidth);
NoLightFade = !!(viewport->Level()->flags3 & LEVEL3_NOLIGHTFADE);
NoLightFade = nolightfade;
}
fixed_t LightVisibility::LightLevelToShadeImpl(RenderViewport *viewport, int lightlevel, bool foggy)

View file

@ -77,7 +77,7 @@ namespace swrenderer
class LightVisibility
{
public:
void SetVisibility(RenderViewport *viewport, double visibility);
void SetVisibility(RenderViewport *viewport, double visibility, bool nolightfade);
double GetVisibility() const { return CurrentVisibility; }
// The vis value to pass into the GETPALOOKUP or LIGHTSCALE macros

View file

@ -118,6 +118,7 @@ namespace swrenderer
double savedvisibility = Thread->Light->GetVisibility();
AActor *savedcamera = Thread->Viewport->viewpoint.camera;
sector_t *savedsector = Thread->Viewport->viewpoint.sector;
auto Level = Thread->Viewport->Level();
for (VisiblePlane *pl = planes->PopFirstPortalPlane(); pl != nullptr; pl = planes->PopFirstPortalPlane())
{
@ -137,7 +138,7 @@ namespace swrenderer
// Don't let gun flashes brighten the sky box
AActor *sky = port->mSkybox;
Thread->Viewport->viewpoint.extralight = 0;
Thread->Light->SetVisibility(Thread->Viewport.get(), sky->args[0] * 0.25f);
Thread->Light->SetVisibility(Thread->Viewport.get(), sky->args[0] * 0.25f, !!(Level->flags3 & LEVEL3_NOLIGHTFADE));
Thread->Viewport->viewpoint.Pos = sky->InterpolatedPosition(Thread->Viewport->viewpoint.TicFrac);
Thread->Viewport->viewpoint.Angles.Yaw = savedangles.Yaw + (sky->PrevAngles.Yaw + deltaangle(sky->PrevAngles.Yaw, sky->Angles.Yaw) * Thread->Viewport->viewpoint.TicFrac);
@ -150,7 +151,7 @@ namespace swrenderer
case PORTS_PORTAL:
case PORTS_LINKEDPORTAL:
Thread->Viewport->viewpoint.extralight = pl->extralight;
Thread->Light->SetVisibility(Thread->Viewport.get(), pl->visibility);
Thread->Light->SetVisibility(Thread->Viewport.get(), pl->visibility, !!(Level->flags3 & LEVEL3_NOLIGHTFADE));
Thread->Viewport->viewpoint.Pos.X = pl->viewpos.X + port->mDisplacement.X;
Thread->Viewport->viewpoint.Pos.Y = pl->viewpos.Y + port->mDisplacement.Y;
Thread->Viewport->viewpoint.Pos.Z = pl->viewpos.Z;
@ -167,8 +168,6 @@ namespace swrenderer
continue;
}
auto Level = Thread->Viewport->Level();
SetInSkyBox(port);
if (port->mPartner > 0) SetInSkyBox(&Level->sectorPortals[port->mPartner]);
Thread->Viewport->viewpoint.camera = nullptr;
@ -256,7 +255,7 @@ namespace swrenderer
Thread->Viewport->viewpoint.camera = savedcamera;
Thread->Viewport->viewpoint.sector = savedsector;
Thread->Viewport->viewpoint.Pos = savedpos;
Thread->Light->SetVisibility(Thread->Viewport.get(), savedvisibility);
Thread->Light->SetVisibility(Thread->Viewport.get(), savedvisibility, !!(Level->flags3 & LEVEL3_NOLIGHTFADE));
Thread->Viewport->viewpoint.extralight = savedextralight;
Thread->Viewport->viewpoint.Angles = savedangles;
Thread->Viewport->viewpoint.SetViewAngle(Thread->Viewport->viewwindow);

View file

@ -102,7 +102,7 @@ namespace swrenderer
int height = SCREENHEIGHT;
float trueratio;
ActiveRatio(width, height, &trueratio);
viewport->SetViewport(MainThread(), width, height, trueratio);
viewport->SetViewport(player->camera->Level, MainThread(), width, height, trueratio);
r_modelscene = r_models && Models.Size() > 0;
if (r_modelscene)
@ -379,7 +379,7 @@ namespace swrenderer
viewwindowx = x;
viewwindowy = y;
viewactive = true;
viewport->SetViewport(MainThread(), width, height, MainThread()->Viewport->viewwindow.WidescreenRatio);
viewport->SetViewport(actor->Level, MainThread(), width, height, MainThread()->Viewport->viewwindow.WidescreenRatio);
if (r_modelscene)
PolyTriangleDrawer::ResizeBuffers(viewport->RenderTarget);

View file

@ -95,7 +95,7 @@ namespace swrenderer
return Mat4f::Frustum(-width, width, -height + offset, height + offset, near, far, Handedness::Right, ClipZRange::NegativePositiveW);
}
void RenderViewport::SetViewport(RenderThread *thread, int fullWidth, int fullHeight, float trueratio)
void RenderViewport::SetViewport(FLevelLocals *Level, RenderThread *thread, int fullWidth, int fullHeight, float trueratio)
{
int virtheight, virtwidth, virtwidth2, virtheight2;
@ -135,7 +135,7 @@ namespace swrenderer
virtwidth = virtwidth * AspectMultiplier(viewwindow.WidescreenRatio) / 48;
}
double ypixelstretch = (Level()->info) ? Level()->info->pixelstretch : 1.2;
double ypixelstretch = (Level->info) ? Level->info->pixelstretch : 1.2;
BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2);
YaspectMul = 320.0 * virtheight / (r_Yaspect * virtwidth) * ypixelstretch / 1.2;
@ -150,7 +150,7 @@ namespace swrenderer
InitTextureMapping();
// Reset r_*Visibility vars
thread->Light->SetVisibility(this, r_visibility);
thread->Light->SetVisibility(this, r_visibility, !!(Level->flags3 & LEVEL3_NOLIGHTFADE));
SetupBuffer();
}

View file

@ -20,7 +20,7 @@ namespace swrenderer
RenderViewport();
~RenderViewport();
void SetViewport(RenderThread *thread, int width, int height, float trueratio);
void SetViewport(FLevelLocals *Level, RenderThread *thread, int width, int height, float trueratio);
void SetupFreelook();
void SetupPolyViewport(RenderThread *thread);