From d73d89762d0205a3a63fcc89eb8285e2c07179b9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 08:32:25 +0200 Subject: [PATCH 01/18] Don't let DEarthquake depend on r_viewpoint. The ticFrac value should be passed as a parameter, especially since this gets called from code that sets up r_viewpoint. --- src/g_shared/a_quake.cpp | 14 +++++++------- src/g_shared/a_sharedglobal.h | 4 ++-- src/r_utility.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/g_shared/a_quake.cpp b/src/g_shared/a_quake.cpp index 39ffd3c792..c81e1ff286 100644 --- a/src/g_shared/a_quake.cpp +++ b/src/g_shared/a_quake.cpp @@ -177,9 +177,9 @@ void DEarthquake::Tick () // //========================================================================== -double DEarthquake::GetModWave(double waveMultiplier) const +double DEarthquake::GetModWave(double ticFrac, double waveMultiplier) const { - double time = m_Countdown - r_viewpoint.TicFrac; + double time = m_Countdown - ticFrac; return g_sin(waveMultiplier * time * (M_PI * 2 / TICRATE)); } @@ -292,7 +292,7 @@ double DEarthquake::GetFalloff(double dist) const // //========================================================================== -int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jiggers) +int DEarthquake::StaticGetQuakeIntensities(double ticFrac, AActor *victim, FQuakeJiggers &jiggers) { if (victim->player != NULL && (victim->player->cheats & CF_NOCLIP)) { @@ -339,12 +339,12 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jigger } else { - jiggers.RollWave = r * quake->GetModWave(quake->m_RollWave) * falloff * strength; + jiggers.RollWave = r * quake->GetModWave(ticFrac, quake->m_RollWave) * falloff * strength; - intensity.X *= quake->GetModWave(quake->m_WaveSpeed.X); - intensity.Y *= quake->GetModWave(quake->m_WaveSpeed.Y); - intensity.Z *= quake->GetModWave(quake->m_WaveSpeed.Z); + intensity.X *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.X); + intensity.Y *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.Y); + intensity.Z *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.Z); intensity *= strength * falloff; // [RH] This only gives effect to the last sine quake. I would diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index ce2376cec0..ca6c60144f 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -145,10 +145,10 @@ public: double m_RollIntensity, m_RollWave; double GetModIntensity(double intensity, bool fake = false) const; - double GetModWave(double waveMultiplier) const; + double GetModWave(double ticFrac, double waveMultiplier) const; double GetFalloff(double dist) const; - static int StaticGetQuakeIntensities(AActor *viewer, FQuakeJiggers &jiggers); + static int StaticGetQuakeIntensities(double ticFrac, AActor *viewer, FQuakeJiggers &jiggers); private: DEarthquake (); diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 05dafee9b0..127ac45979 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -872,7 +872,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor FQuakeJiggers jiggers; memset(&jiggers, 0, sizeof(jiggers)); - if (DEarthquake::StaticGetQuakeIntensities(viewpoint.camera, jiggers) > 0) + if (DEarthquake::StaticGetQuakeIntensities(viewpoint.TicFrac, viewpoint.camera, jiggers) > 0) { double quakefactor = r_quakeintensity; DAngle an; From 8787905fedd7b70bab683164e4bc16e32fa69ab9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 09:00:50 +0200 Subject: [PATCH 02/18] Fixed: DBaseStatusBar::Draw did not use its ticFrac parameter when being called from scripts Instead it directly went to the global viewpoint again which would be inconsistent. --- src/d_main.cpp | 6 +++--- src/g_statusbar/sbar.h | 8 ++++---- src/g_statusbar/shared_sbar.cpp | 11 ++++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 6542b950a2..c507ecc574 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -817,7 +817,7 @@ void D_Display () { StatusBar->DrawCrosshair(); } - StatusBar->CallDraw (HUD_AltHud); + StatusBar->CallDraw (HUD_AltHud, r_viewpoint.TicFrac); StatusBar->DrawTopStuff (HUD_AltHud); } else @@ -825,13 +825,13 @@ void D_Display () { EHudState state = DrawFSHUD ? HUD_Fullscreen : HUD_None; StatusBar->DrawBottomStuff (state); - StatusBar->CallDraw (state); + StatusBar->CallDraw (state, r_viewpoint.TicFrac); StatusBar->DrawTopStuff (state); } else { StatusBar->DrawBottomStuff (HUD_StatusBar); - StatusBar->CallDraw (HUD_StatusBar); + StatusBar->CallDraw (HUD_StatusBar, r_viewpoint.TicFrac); StatusBar->DrawTopStuff (HUD_StatusBar); } //stb.Unclock(); diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index a0f8edbdaf..a98111a29a 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -397,10 +397,10 @@ public: void SetScale(); virtual void Tick (); void CallTick(); - virtual void Draw (EHudState state); - void CallDraw(EHudState state); - void DrawBottomStuff (EHudState state); - void DrawTopStuff (EHudState state); + virtual void Draw (EHudState state, double ticFrac); + void CallDraw(EHudState state, double ticFrac); + void DrawBottomStuff (EHudState state); + void DrawTopStuff (EHudState state); void FlashItem (const PClass *itemtype); void AttachToPlayer(player_t *player); DVector2 GetHUDScale() const; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 4d6d6e7376..e0e2cc9d51 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1006,7 +1006,7 @@ void DBaseStatusBar::DrawMessages (int layer, int bottom) // //--------------------------------------------------------------------------- -void DBaseStatusBar::Draw (EHudState state) +void DBaseStatusBar::Draw (EHudState state, double ticFrac) { // HUD_AltHud state is for popups only if (state == HUD_AltHud) @@ -1048,18 +1048,19 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, Draw) { PARAM_SELF_PROLOGUE(DBaseStatusBar); PARAM_INT(state); - self->Draw((EHudState)state); + PARAM_FLOAT(ticFrac); + self->Draw((EHudState)state, ticFrac); return 0; } -void DBaseStatusBar::CallDraw(EHudState state) +void DBaseStatusBar::CallDraw(EHudState state, double ticFrac) { IFVIRTUAL(DBaseStatusBar, Draw) { - VMValue params[] = { (DObject*)this, state, r_viewpoint.TicFrac }; + VMValue params[] = { (DObject*)this, state, ticFrac }; VMCall(func, params, countof(params), nullptr, 0); } - else Draw(state); + else Draw(state, ticFrac); screen->ClearClipRect(); // make sure the scripts don't leave a valid clipping rect behind. BeginStatusBar(BaseSBarHorizontalResolution, BaseSBarVerticalResolution, BaseRelTop, false); } From 46d73e7b4b230a68bd579bd56bcdfafed1978977 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 09:18:27 +0200 Subject: [PATCH 03/18] Pass ticFrac to the model renderer as a parameter This also removes the rather pointless gl_RenderModel functions because with their two lines of content they can just be placed inline. --- src/gl/models/gl_models.cpp | 24 ------------------------ src/gl/models/gl_models.h | 2 -- src/gl/scene/gl_sprite.cpp | 3 ++- src/gl/scene/gl_weapon.cpp | 3 ++- src/polyrenderer/scene/poly_model.cpp | 2 +- src/r_data/models/models.cpp | 4 ++-- src/r_data/models/models.h | 2 +- src/swrenderer/things/r_model.cpp | 2 +- 8 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index 8669d7bab2..25b8182ca5 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -338,27 +338,3 @@ void FModelVertexBuffer::SetupFrame(FModelRenderer *renderer, unsigned int frame } } } - -//=========================================================================== -// -// gl_RenderModel -// -//=========================================================================== - -void gl_RenderModel(GLSprite * spr, int mli) -{ - FGLModelRenderer renderer(mli); - renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor); -} - -//=========================================================================== -// -// gl_RenderHUDModel -// -//=========================================================================== - -void gl_RenderHUDModel(DPSprite *psp, float ofsX, float ofsY, int mli) -{ - FGLModelRenderer renderer(mli); - renderer.RenderHUDModel(psp, ofsX, ofsY); -} diff --git a/src/gl/models/gl_models.h b/src/gl/models/gl_models.h index 0fb82f9f42..9cab5ecfca 100644 --- a/src/gl/models/gl_models.h +++ b/src/gl/models/gl_models.h @@ -51,5 +51,3 @@ public: void DrawElements(int numIndices, size_t offset) override; }; -void gl_RenderModel(GLSprite * spr, int mli); -void gl_RenderHUDModel(DPSprite *psp, float ofsx, float ofsy, int mli); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index b4116d60eb..cc988ec730 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -276,7 +276,8 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) } else { - gl_RenderModel(sprite, sprite->dynlightindex); + FGLModelRenderer renderer(sprite->dynlightindex); + renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, r_viewpoint.TicFrac); } } diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 6ab0d52228..a842eda6e6 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -66,7 +66,8 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds) if (huds->mframe) { gl_RenderState.AlphaFunc(GL_GEQUAL, 0); - gl_RenderHUDModel(huds->weapon, huds->mx, huds->my, huds->lightindex); + FGLModelRenderer renderer(huds->lightindex); + renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); } else { diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index 46d064a7b5..4251589d97 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -37,7 +37,7 @@ void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_ { PolyModelRenderer renderer(thread, worldToClip, stencilValue); renderer.AddLights(actor); - renderer.RenderModel(x, y, z, smf, actor); + renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); } diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 316281f654..b248f2895a 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -54,7 +54,7 @@ extern TDeletingArray VoxelDefs; DeletingModelArray Models; -void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor) +void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, double ticFrac) { // Setup transformation. @@ -128,7 +128,7 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s if (actor->renderflags & RF_INTERPOLATEANGLES) { // [Nash] use interpolated angles - DRotator Angles = actor->InterpolatedAngles(r_viewpoint.TicFrac); + DRotator Angles = actor->InterpolatedAngles(ticFrac); angle = Angles.Yaw.Degrees; } diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index 213e9ab211..e4da6efaca 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -60,7 +60,7 @@ class FModelRenderer public: virtual ~FModelRenderer() { } - void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor); + void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac); void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); virtual ModelRendererType GetType() const = 0; diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index aa94376709..0991d1d45d 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -76,7 +76,7 @@ namespace swrenderer { SWModelRenderer renderer(thread, clip3DFloor, &WorldToClip, MirrorWorldToClip); renderer.AddLights(actor); - renderer.RenderModel(x, y, z, smf, actor); + renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); } From 74d8c929cc0b08fd2424ba261dfd7459047367fb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 09:37:49 +0200 Subject: [PATCH 04/18] Give the clipper a reference to the current viewpoint This is both for efficiency and encapsulation. At last on MSVC in 64 bit, accessing global variables is very inefficient and the clipper was doing it repeatedly in its worker functions. It is also one less place where the global viewpoint gets checked. --- src/gl/scene/gl_drawinfo.cpp | 1 + src/gl/scene/gl_portal.cpp | 4 +--- src/hwrenderer/scene/hw_clipper.cpp | 15 ++++++++------- src/hwrenderer/scene/hw_clipper.h | 25 ++++++++++++++++--------- src/r_defs.h | 2 -- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index abcdbe70b2..c7e02314cf 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -201,6 +201,7 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer) di->mDrawer = drawer; di->mVBO = GLRenderer->mVBO; di->mClipper = &staticClipper; + di->mClipper->SetViewpoint(r_viewpoint); staticClipper.Clear(); di->FixedColormap = drawer->FixedColormap; di->StartScene(); diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 3f8ede410a..bb0d09adb3 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -941,9 +941,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) angle_t af = drawer->FrustumAngle(); if (afmClipper->SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af); - angle_t a2 = linedef->v1->GetClipAngle(); - angle_t a1 = linedef->v2->GetClipAngle(); - di->mClipper->SafeAddClipRange(a1,a2); + di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2); gl_RenderState.SetClipLine(linedef); gl_RenderState.EnableClipLine(true); diff --git a/src/hwrenderer/scene/hw_clipper.cpp b/src/hwrenderer/scene/hw_clipper.cpp index e1811dd8c4..85646f84c1 100644 --- a/src/hwrenderer/scene/hw_clipper.cpp +++ b/src/hwrenderer/scene/hw_clipper.cpp @@ -373,10 +373,10 @@ angle_t Clipper::AngleToPseudo(angle_t ang) // //----------------------------------------------------------------------------- -angle_t R_PointToPseudoAngle(double x, double y) +angle_t Clipper::PointToPseudoAngle(double x, double y) { - double vecx = x - r_viewpoint.Pos.X; - double vecy = y - r_viewpoint.Pos.Y; + double vecx = x - viewpoint->Pos.X; + double vecy = y - viewpoint->Pos.Y; if (vecx == 0 && vecy == 0) { @@ -427,14 +427,15 @@ bool Clipper::CheckBox(const float *bspcoord) // Find the corners of the box // that define the edges from current viewpoint. - boxpos = (r_viewpoint.Pos.X <= bspcoord[BOXLEFT] ? 0 : r_viewpoint.Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + - (r_viewpoint.Pos.Y >= bspcoord[BOXTOP ] ? 0 : r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); + auto &vp = viewpoint; + boxpos = (vp->Pos.X <= bspcoord[BOXLEFT] ? 0 : vp->Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + + (vp->Pos.Y >= bspcoord[BOXTOP ] ? 0 : vp->Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); if (boxpos == 5) return true; check = checkcoord[boxpos]; - angle1 = R_PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]); - angle2 = R_PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]); + angle1 = PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]); + angle2 = PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]); return SafeCheckRange(angle2, angle1); } diff --git a/src/hwrenderer/scene/hw_clipper.h b/src/hwrenderer/scene/hw_clipper.h index c3897bd56f..e8da8172cf 100644 --- a/src/hwrenderer/scene/hw_clipper.h +++ b/src/hwrenderer/scene/hw_clipper.h @@ -6,14 +6,6 @@ #include "r_utility.h" #include "memarena.h" -angle_t R_PointToPseudoAngle(double x, double y); - -// Used to speed up angle calculations during clipping -inline angle_t vertex_t::GetClipAngle() -{ - return R_PointToPseudoAngle(p.X, p.Y); -} - class ClipNode { friend class Clipper; @@ -37,6 +29,7 @@ class Clipper ClipNode * clipnodes = nullptr; ClipNode * cliphead = nullptr; ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called + const FRenderViewpoint *viewpoint = nullptr; bool blocked = false; static angle_t AngleToPseudo(angle_t ang); @@ -78,6 +71,11 @@ public: c->next = c->prev = NULL; return c; } + + void SetViewpoint(const FRenderViewpoint &vp) + { + viewpoint = &vp; + } void SetSilhouette(); @@ -105,6 +103,13 @@ public: AddClipRange(startangle, endangle); } } + + void SafeAddClipRange(const vertex_t *v1, const vertex_t *v2) + { + angle_t a2 = PointToPseudoAngle(v1->p.X, v1->p.Y); + angle_t a1 = PointToPseudoAngle(v2->p.X, v2->p.Y); + SafeAddClipRange(a1,a2); + } void SafeAddClipRangeRealAngles(angle_t startangle, angle_t endangle) { @@ -141,13 +146,15 @@ public: { return blocked; } + + angle_t PointToPseudoAngle(double x, double y); bool CheckBox(const float *bspcoord); // Used to speed up angle calculations during clipping inline angle_t GetClipAngle(vertex_t *v) { - return unsigned(v->angletime) == starttime ? v->viewangle : (v->angletime = starttime, v->viewangle = R_PointToPseudoAngle(v->p.X, v->p.Y)); + return unsigned(v->angletime) == starttime ? v->viewangle : (v->angletime = starttime, v->viewangle = PointToPseudoAngle(v->p.X, v->p.Y)); } }; diff --git a/src/r_defs.h b/src/r_defs.h index 4ba0d45d35..4422fbf8dd 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -180,8 +180,6 @@ struct vertex_t { p.Zero(); } - - angle_t GetClipAngle(); }; // Forward of LineDefs, for Sectors. From f857d14e765e47d6912c846c27dd7614508eabd0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:22:27 +0200 Subject: [PATCH 05/18] -Code shortening --- src/hwrenderer/utility/hw_clock.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hwrenderer/utility/hw_clock.cpp b/src/hwrenderer/utility/hw_clock.cpp index f0480f2c45..74aa096a4c 100644 --- a/src/hwrenderer/utility/hw_clock.cpp +++ b/src/hwrenderer/utility/hw_clock.cpp @@ -160,8 +160,9 @@ void CheckBench() FString compose; + auto &vp = r_viewpoint; compose.Format("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", - level.MapName.GetChars(), level.LevelName.GetChars(), r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw.Degrees, r_viewpoint.Angles.Pitch.Degrees); + level.MapName.GetChars(), level.LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); AppendRenderStats(compose); AppendRenderTimes(compose); From cf1641d0f6134db1662542f40c2870c271ada21e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:25:11 +0200 Subject: [PATCH 06/18] - reduce number of places in weapon code which access r_viewpoint directly. --- src/hwrenderer/scene/hw_weapon.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index c22d2183a5..8a08357656 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -76,10 +76,10 @@ static bool isBright(DPSprite *psp) // //========================================================================== -static WeaponPosition GetWeaponPosition(player_t *player) +static WeaponPosition GetWeaponPosition(player_t *player, double ticFrac) { WeaponPosition w; - P_BobWeapon(player, &w.bobx, &w.boby, r_viewpoint.TicFrac); + P_BobWeapon(player, &w.bobx, &w.boby, ticFrac); // Interpolate the main weapon layer once so as to be able to add it to other layers. if ((w.weapon = player->FindPSprite(PSP_WEAPON)) != nullptr) @@ -91,8 +91,8 @@ static WeaponPosition GetWeaponPosition(player_t *player) } else { - w.wx = (float)(w.weapon->oldx + (w.weapon->x - w.weapon->oldx) * r_viewpoint.TicFrac); - w.wy = (float)(w.weapon->oldy + (w.weapon->y - w.weapon->oldy) * r_viewpoint.TicFrac); + w.wx = (float)(w.weapon->oldx + (w.weapon->x - w.weapon->oldx) * ticFrac); + w.wy = (float)(w.weapon->oldy + (w.weapon->y - w.weapon->oldy) * ticFrac); } } else @@ -109,7 +109,7 @@ static WeaponPosition GetWeaponPosition(player_t *player) // //========================================================================== -static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp) +static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp, double ticFrac) { if (psp->firstTic) { // Can't interpolate the first tic. @@ -118,8 +118,8 @@ static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp) psp->oldy = psp->y; } - float sx = float(psp->oldx + (psp->x - psp->oldx) * r_viewpoint.TicFrac); - float sy = float(psp->oldy + (psp->y - psp->oldy) * r_viewpoint.TicFrac); + float sx = float(psp->oldx + (psp->x - psp->oldx) * ticFrac); + float sy = float(psp->oldy + (psp->y - psp->oldy) * ticFrac); if (psp->Flags & PSPF_ADDBOB) { @@ -169,14 +169,14 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po if (ifloorplane.ZatPoint(r_viewpoint.Pos); + lightbottom = viewsector->floorplane.ZatPoint(pos); } - if (lightbottomplayer; const bool hudModelStep = IsHUDModelForPlayerAvailable(player); + + auto &vp = r_viewpoint; - AActor *camera = r_viewpoint.camera; + AActor *camera = vp.camera; // this is the same as the software renderer if (!player || @@ -437,8 +439,8 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) (r_deathcamera && camera->health <= 0)) return; - WeaponPosition weap = GetWeaponPosition(camera->player); - WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, FixedColormap, in_area, camera->Pos()); + WeaponPosition weap = GetWeaponPosition(camera->player, vp.TicFrac); + WeaponLighting light = GetWeaponLighting(viewsector, vp.Pos, FixedColormap, in_area, camera->Pos()); // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change // light mode here to draw the weapon sprite. @@ -460,7 +462,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) if (!hudsprite.GetWeaponRenderStyle(psp, camera, viewsector, light)) continue; - FVector2 spos = BobWeapon(weap, psp); + FVector2 spos = BobWeapon(weap, psp, vp.TicFrac); hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0; hudsprite.lightindex = -1; From 18f43dea1ed20ebbfeb291a999bf3b020edd9bdb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:29:09 +0200 Subject: [PATCH 07/18] - reduced number of references to r_viewpoint in hw_sprites.cpp --- src/hwrenderer/scene/hw_sprites.cpp | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 0e86b88ba4..e5660c26bc 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -403,7 +403,8 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t return; } - AActor *camera = r_viewpoint.camera; + auto &vp = r_viewpoint; + AActor *camera = vp.camera; if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha)) { @@ -425,26 +426,26 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t } // [RH] Interpolate the sprite's position to make it look smooth - DVector3 thingpos = thing->InterpolatedPosition(r_viewpoint.TicFrac); + DVector3 thingpos = thing->InterpolatedPosition(vp.TicFrac); if (thruportal == 1) thingpos += level.Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); // Some added checks if the camera actor is not supposed to be seen. It can happen that some portal setup has this actor in view in which case it may not be skipped here - if (thing == camera && !r_viewpoint.showviewer) + if (thing == camera && !vp.showviewer) { DVector3 thingorigin = thing->Pos(); if (thruportal == 1) thingorigin += level.Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); - if (fabs(thingorigin.X - r_viewpoint.ActorPos.X) < 2 && fabs(thingorigin.Y - r_viewpoint.ActorPos.Y) < 2) return; + if (fabs(thingorigin.X - vp.ActorPos.X) < 2 && fabs(thingorigin.Y - vp.ActorPos.Y) < 2) return; } // Thing is invisible if close to the camera. if (thing->renderflags & RF_MAYBEINVISIBLE) { - if (fabs(thingpos.X - r_viewpoint.Pos.X) < 32 && fabs(thingpos.Y - r_viewpoint.Pos.Y) < 32) return; + if (fabs(thingpos.X - vp.Pos.X) < 32 && fabs(thingpos.Y - vp.Pos.Y) < 32) return; } // Too close to the camera. This doesn't look good if it is a sprite. - if (fabs(thingpos.X - r_viewpoint.Pos.X) < 2 && fabs(thingpos.Y - r_viewpoint.Pos.Y) < 2) + if (fabs(thingpos.X - vp.Pos.X) < 2 && fabs(thingpos.Y - vp.Pos.Y) < 2) { - if (r_viewpoint.Pos.Z >= thingpos.Z - 2 && r_viewpoint.Pos.Z <= thingpos.Z + thing->Height + 2) + if (vp.Pos.Z >= thingpos.Z - 2 && vp.Pos.Z <= thingpos.Z + thing->Height + 2) { // exclude vertically moving objects from this check. if (!thing->Vel.isZero()) @@ -466,7 +467,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (speed >= thing->target->radius / 2) { double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius * 2); - if ((thingpos - r_viewpoint.Pos).LengthSquared() < clipdist * clipdist) return; + if ((thingpos - vp.Pos).LengthSquared() < clipdist * clipdist) return; } } thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again. @@ -479,7 +480,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t } // disabled because almost none of the actual game code is even remotely prepared for this. If desired, use the INTERPOLATE flag. if (thing->renderflags & RF_INTERPOLATEANGLES) - Angles = thing->InterpolatedAngles(r_viewpoint.TicFrac); + Angles = thing->InterpolatedAngles(vp.TicFrac); else Angles = thing->Angles; @@ -506,7 +507,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // [RH] Make floatbobbing a renderer-only effect. if (thing->flags2 & MF2_FLOATBOB) { - float fz = thing->GetBobOffset(r_viewpoint.TicFrac); + float fz = thing->GetBobOffset(vp.TicFrac); z += fz; } @@ -514,7 +515,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (!modelframe) { bool mirror; - DAngle ang = (thingpos - r_viewpoint.Pos).Angle(); + DAngle ang = (thingpos - vp.Pos).Angle(); FTextureID patch; // [ZZ] add direct picnum override if (isPicnumOverride) @@ -531,7 +532,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t int rot; if (!(thing->renderflags & RF_FLATSPRITE) || thing->flags7 & MF7_SPRITEANGLE) { - sprangle = thing->GetSpriteAngle(ang, r_viewpoint.TicFrac); + sprangle = thing->GetSpriteAngle(ang, vp.TicFrac); rot = -1; } else @@ -632,7 +633,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t gltexture = nullptr; } - depth = FloatToFixed((x - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin); + depth = FloatToFixed((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); // light calculation @@ -927,7 +928,8 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * } } - double timefrac = r_viewpoint.TicFrac; + auto &vp = r_viewpoint; + double timefrac = vp.TicFrac; if (paused || bglobal.freeze || (level.flags2 & LEVEL2_FROZEN)) timefrac = 0.; float xvf = (particle->Vel.X) * timefrac; @@ -954,7 +956,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * z1=z-scalefac; z2=z+scalefac; - depth = FloatToFixed((x - r_viewpoint.Pos.X) * r_viewpoint.TanCos + (y - r_viewpoint.Pos.Y) * r_viewpoint.TanSin); + depth = FloatToFixed((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); actor=nullptr; this->particle=particle; @@ -984,6 +986,7 @@ void HWDrawInfo::ProcessActorsInPortal(FLinePortalSpan *glport, area_t in_area) TMap processcheck; if (glport->validcount == validcount) return; // only process once per frame glport->validcount = validcount; + auto &vp = r_viewpoint; for (auto port : glport->lines) { line_t *line = port->mOrigin; @@ -1007,9 +1010,9 @@ void HWDrawInfo::ProcessActorsInPortal(FLinePortalSpan *glport, area_t in_area) DVector3 newpos = savedpos; sector_t fakesector; - if (!r_viewpoint.showviewer && th == r_viewpoint.camera) + if (!vp.showviewer && th == vp.camera) { - if (fabs(savedpos.X - r_viewpoint.ActorPos.X) < 2 && fabs(savedpos.Y - r_viewpoint.ActorPos.Y) < 2) + if (fabs(savedpos.X - vp.ActorPos.X) < 2 && fabs(savedpos.Y - vp.ActorPos.Y) < 2) { continue; } From 3eb4b137f3b6d9a6a42aba0b2f320f77731187c1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:30:18 +0200 Subject: [PATCH 08/18] - reduced number of references to r_viewpoint in hw_fakeflat.cpp --- src/hwrenderer/scene/hw_fakeflat.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hwrenderer/scene/hw_fakeflat.cpp b/src/hwrenderer/scene/hw_fakeflat.cpp index e4e986ca8b..c68677b138 100644 --- a/src/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/hwrenderer/scene/hw_fakeflat.cpp @@ -392,15 +392,16 @@ sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac //----------------------------------------------------------------------------- void HWDrawInfo::SetViewArea() { + auto &vp = r_viewpoint; // The render_sector is better suited to represent the current position in GL - r_viewpoint.sector = R_PointInSubsector(r_viewpoint.Pos)->render_sector; + vp.sector = R_PointInSubsector(vp.Pos)->render_sector; // Get the heightsec state from the render sector, not the current one! - if (r_viewpoint.sector->GetHeightSec()) + if (vp.sector->GetHeightSec()) { - in_area = r_viewpoint.Pos.Z <= r_viewpoint.sector->heightsec->floorplane.ZatPoint(r_viewpoint.Pos) ? area_below : - (r_viewpoint.Pos.Z > r_viewpoint.sector->heightsec->ceilingplane.ZatPoint(r_viewpoint.Pos) && - !(r_viewpoint.sector->heightsec->MoreFlags&SECMF_FAKEFLOORONLY)) ? area_above : area_normal; + in_area = vp.Pos.Z <= vp.sector->heightsec->floorplane.ZatPoint(vp.Pos) ? area_below : + (vp.Pos.Z > vp.sector->heightsec->ceilingplane.ZatPoint(vp.Pos) && + !(vp.sector->heightsec->MoreFlags&SECMF_FAKEFLOORONLY)) ? area_above : area_normal; } else { From fba5b872be4efb795f3503b90a3838732cabf7e8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:31:25 +0200 Subject: [PATCH 09/18] - reduced number of references to r_viewpoint in hw_flats --- src/hwrenderer/scene/hw_flats.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 27e31843f3..d4e01fa9a8 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -263,6 +263,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) dynlightindex = -1; uint8_t &srf = di->sectorrenderflags[sector->sectornum]; + auto &vp = r_viewpoint; // // @@ -271,7 +272,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) // // // - if (frontsector->floorplane.ZatPoint(r_viewpoint.Pos) <= r_viewpoint.Pos.Z) + if (frontsector->floorplane.ZatPoint(vp.Pos) <= vp.Pos.Z) { // process the original floor first. @@ -331,7 +332,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) // // // - if (frontsector->ceilingplane.ZatPoint(r_viewpoint.Pos) >= r_viewpoint.Pos.Z) + if (frontsector->ceilingplane.ZatPoint(vp.Pos) >= vp.Pos.Z) { // process the original ceiling first. @@ -422,7 +423,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) double ff_top = rover->top.plane->ZatPoint(sector->centerspot); if (ff_top < lastceilingheight) { - if (r_viewpoint.Pos.Z <= rover->top.plane->ZatPoint(r_viewpoint.Pos)) + if (vp.Pos.Z <= rover->top.plane->ZatPoint(vp.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; @@ -436,7 +437,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); if (ff_bottom < lastceilingheight) { - if (r_viewpoint.Pos.Z <= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) + if (vp.Pos.Z <= rover->bottom.plane->ZatPoint(vp.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; @@ -462,7 +463,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); if (ff_bottom > lastfloorheight || (rover->flags&FF_FIX)) { - if (r_viewpoint.Pos.Z >= rover->bottom.plane->ZatPoint(r_viewpoint.Pos)) + if (vp.Pos.Z >= rover->bottom.plane->ZatPoint(vp.Pos)) { SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; @@ -483,7 +484,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) double ff_top = rover->top.plane->ZatPoint(sector->centerspot); if (ff_top > lastfloorheight) { - if (r_viewpoint.Pos.Z >= rover->top.plane->ZatPoint(r_viewpoint.Pos)) + if (vp.Pos.Z >= rover->top.plane->ZatPoint(vp.Pos)) { SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG)); Colormap.FadeColor = frontsector->Colormap.FadeColor; From 12ad0caec058f8ebaa46b53d8f8782993cf63079 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:33:59 +0200 Subject: [PATCH 10/18] - small optimization --- src/hwrenderer/scene/hw_sky.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hwrenderer/scene/hw_sky.cpp b/src/hwrenderer/scene/hw_sky.cpp index 24bd48e936..666aeecdea 100644 --- a/src/hwrenderer/scene/hw_sky.cpp +++ b/src/hwrenderer/scene/hw_sky.cpp @@ -154,8 +154,9 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref } else if (allowreflect && sector->GetReflect(plane) > 0) { - if ((plane == sector_t::ceiling && r_viewpoint.Pos.Z > sector->ceilingplane.fD()) || - (plane == sector_t::floor && r_viewpoint.Pos.Z < -sector->floorplane.fD())) return; + auto vpz = r_viewpoint.Pos.Z; + if ((plane == sector_t::ceiling && vpz > sector->ceilingplane.fD()) || + (plane == sector_t::floor && vpz < -sector->floorplane.fD())) return; ptype = PORTALTYPE_PLANEMIRROR; planemirror = plane == sector_t::ceiling ? §or->ceilingplane : §or->floorplane; } From ae7053ee985faf6e51c21600e13d5c4d7c94fcce Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:40:50 +0200 Subject: [PATCH 11/18] - another small optimization --- src/hwrenderer/scene/hw_walls.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hwrenderer/scene/hw_walls.cpp b/src/hwrenderer/scene/hw_walls.cpp index f8ed6d30da..3c676f71d3 100644 --- a/src/hwrenderer/scene/hw_walls.cpp +++ b/src/hwrenderer/scene/hw_walls.cpp @@ -444,10 +444,11 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1, ztop[1] = ztop[0] = fs->GetPlaneTexZ(sector_t::ceiling); zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor); - if (r_viewpoint.Pos.Z < fs->GetPlaneTexZ(sector_t::ceiling)) + auto vpz = r_viewpoint.Pos.Z; + if (vpz < fs->GetPlaneTexZ(sector_t::ceiling)) { - if (r_viewpoint.Pos.Z > fs->GetPlaneTexZ(sector_t::floor)) - zbottom[1] = zbottom[0] = r_viewpoint.Pos.Z; + if (vpz > fs->GetPlaneTexZ(sector_t::floor)) + zbottom[1] = zbottom[0] = vpz; if (fs->GetTexture(sector_t::ceiling) == skyflatnum) { @@ -475,7 +476,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1, ztop[1] = ztop[0] = zbottom[0]; } - if (r_viewpoint.Pos.Z > fs->GetPlaneTexZ(sector_t::floor)) + if (vpz > fs->GetPlaneTexZ(sector_t::floor)) { zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor); if (fs->GetTexture(sector_t::floor) == skyflatnum) From 86975a71e8b4e7da68265d2841f9d838d22f7ab5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 10:50:48 +0200 Subject: [PATCH 12/18] - don't use r_viewpoint directly when sorting translucent geometry. Better store the view Z in a member variable and use that. --- src/hwrenderer/scene/hw_drawlist.cpp | 7 ++++--- src/hwrenderer/scene/hw_drawlist.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hwrenderer/scene/hw_drawlist.cpp b/src/hwrenderer/scene/hw_drawlist.cpp index 4d70e2f828..1df8d5763a 100644 --- a/src/hwrenderer/scene/hw_drawlist.cpp +++ b/src/hwrenderer/scene/hw_drawlist.cpp @@ -121,7 +121,7 @@ inline void SortNode::AddToEqual(SortNode *child) { child->UnlinkFromChain(); child->equal=equal; - equal=child; + equal=child; } //========================================================================== @@ -269,7 +269,7 @@ void HWDrawList::SortWallIntoPlane(SortNode * head, SortNode * sort) GLFlat * fh = flats[drawitems[head->itemindex].index]; GLWall * ws = walls[drawitems[sort->itemindex].index]; - bool ceiling = fh->z > r_viewpoint.Pos.Z; + bool ceiling = fh->z > SortZ; if ((ws->ztop[0] > fh->z || ws->ztop[1] > fh->z) && (ws->zbottom[0] < fh->z || ws->zbottom[1] < fh->z)) { @@ -327,7 +327,7 @@ void HWDrawList::SortSpriteIntoPlane(SortNode * head, SortNode * sort) GLFlat * fh = flats[drawitems[head->itemindex].index]; GLSprite * ss = sprites[drawitems[sort->itemindex].index]; - bool ceiling = fh->z > r_viewpoint.Pos.Z; + bool ceiling = fh->z > SortZ; auto hiz = ss->z1 > ss->z2 ? ss->z1 : ss->z2; auto loz = ss->z1 < ss->z2 ? ss->z1 : ss->z2; @@ -688,6 +688,7 @@ SortNode * HWDrawList::DoSort(HWDrawInfo *di, SortNode * head) //========================================================================== void HWDrawList::Sort(HWDrawInfo *di) { + SortZ = r_viewpoint.Pos.Z; MakeSortList(); sorted = DoSort(di, SortNodes[SortNodeStart]); } diff --git a/src/hwrenderer/scene/hw_drawlist.h b/src/hwrenderer/scene/hw_drawlist.h index 5e440df81d..22bf1cb31e 100644 --- a/src/hwrenderer/scene/hw_drawlist.h +++ b/src/hwrenderer/scene/hw_drawlist.h @@ -61,6 +61,7 @@ struct HWDrawList TArray sprites; TArray drawitems; int SortNodeStart; + float SortZ; SortNode * sorted; public: From 548ccb1df446a49e4fa58dabbe49a4563e6bb7d2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 11:20:36 +0200 Subject: [PATCH 13/18] - removed some references to r_viewpoint in game code Mainly to reduce number of search results. --- src/am_map.cpp | 7 ++++--- src/d_main.cpp | 11 ++++++----- src/events.cpp | 13 +++++++------ src/posix/sdl/i_main.cpp | 9 +++++---- src/v_draw.cpp | 9 +++++---- src/win32/i_main.cpp | 9 +++++---- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 20f99de363..e0296e797a 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2123,13 +2123,14 @@ void AM_drawSubsectors() double secx; double secy; double seczb, seczt; - double cmpz = r_viewpoint.Pos.Z; + auto &vp = r_viewpoint; + double cmpz = vp.Pos.Z; if (players[consoleplayer].camera && sec == players[consoleplayer].camera->Sector) { // For the actual camera sector use the current viewpoint as reference. - secx = r_viewpoint.Pos.X; - secy = r_viewpoint.Pos.Y; + secx = vp.Pos.X; + secy = vp.Pos.Y; } else { diff --git a/src/d_main.cpp b/src/d_main.cpp index c507ecc574..4172909bc1 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -679,6 +679,7 @@ void D_Display () players[consoleplayer].camera = players[consoleplayer].mo; } + auto &vp = r_viewpoint; if (viewactive) { DAngle fov = 90.f; @@ -689,7 +690,7 @@ void D_Display () fov = cam->player->FOV; else fov = cam->CameraFOV; } - R_SetFOV(r_viewpoint, fov); + R_SetFOV(vp, fov); } // [RH] change the screen mode if needed @@ -718,7 +719,7 @@ void D_Display () // change the view size if needed if (setsizeneeded && StatusBar != NULL) { - R_ExecuteSetViewSize (r_viewpoint, r_viewwindow); + R_ExecuteSetViewSize (vp, r_viewwindow); } setmodeneeded = false; @@ -817,7 +818,7 @@ void D_Display () { StatusBar->DrawCrosshair(); } - StatusBar->CallDraw (HUD_AltHud, r_viewpoint.TicFrac); + StatusBar->CallDraw (HUD_AltHud, vp.TicFrac); StatusBar->DrawTopStuff (HUD_AltHud); } else @@ -825,13 +826,13 @@ void D_Display () { EHudState state = DrawFSHUD ? HUD_Fullscreen : HUD_None; StatusBar->DrawBottomStuff (state); - StatusBar->CallDraw (state, r_viewpoint.TicFrac); + StatusBar->CallDraw (state, vp.TicFrac); StatusBar->DrawTopStuff (state); } else { StatusBar->DrawBottomStuff (HUD_StatusBar); - StatusBar->CallDraw (HUD_StatusBar, r_viewpoint.TicFrac); + StatusBar->CallDraw (HUD_StatusBar, vp.TicFrac); StatusBar->DrawTopStuff (HUD_StatusBar); } //stb.Unclock(); diff --git a/src/events.cpp b/src/events.cpp index c520359a53..eabf1b9313 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -857,12 +857,13 @@ void DStaticEventHandler::WorldTick() static FRenderEvent E_SetupRenderEvent() { FRenderEvent e; - e.ViewPos = r_viewpoint.Pos; - e.ViewAngle = r_viewpoint.Angles.Yaw; - e.ViewPitch = r_viewpoint.Angles.Pitch; - e.ViewRoll = r_viewpoint.Angles.Roll; - e.FracTic = r_viewpoint.TicFrac; - e.Camera = r_viewpoint.camera; + auto &vp = r_viewpoint; + e.ViewPos = vp.Pos; + e.ViewAngle = vp.Angles.Yaw; + e.ViewPitch = vp.Angles.Pitch; + e.ViewRoll = vp.Angles.Roll; + e.FracTic = vp.TicFrac; + e.Camera = vp.camera; return e; } diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index 127198df89..38f0355159 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -169,10 +169,11 @@ static int DoomSpecificInfo (char *buffer, char *end) } else { - p += snprintf (buffer+p, size-p, "\n\nviewx = %f", r_viewpoint.Pos.X); - p += snprintf (buffer+p, size-p, "\nviewy = %f", r_viewpoint.Pos.Y); - p += snprintf (buffer+p, size-p, "\nviewz = %f", r_viewpoint.Pos.Z); - p += snprintf (buffer+p, size-p, "\nviewangle = %f", r_viewpoint.Angles.Yaw.Degrees); + auto &vp = r_viewpoint; + p += snprintf (buffer+p, size-p, "\n\nviewx = %f", vp.Pos.X); + p += snprintf (buffer+p, size-p, "\nviewy = %f", vp.Pos.Y); + p += snprintf (buffer+p, size-p, "\nviewz = %f", vp.Pos.Z); + p += snprintf (buffer+p, size-p, "\nviewangle = %f", vp.Angles.Yaw.Degrees); } } buffer[p++] = '\n'; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index f43bffd193..49e4459957 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -1341,12 +1341,13 @@ void DFrameBuffer::DrawBlend(sector_t * viewsector) // don't draw sector based blends when any fullbright screen effect is active. if (!fullbright) { + const auto &vpp = r_viewpoint.Pos; if (!viewsector->e->XFloor.ffloors.Size()) { if (viewsector->GetHeightSec()) { auto s = viewsector->heightsec; - blendv = s->floorplane.PointOnSide(r_viewpoint.Pos) < 0 ? s->bottommap : s->ceilingplane.PointOnSide(r_viewpoint.Pos) < 0 ? s->topmap : s->midmap; + blendv = s->floorplane.PointOnSide(vpp) < 0 ? s->bottommap : s->ceilingplane.PointOnSide(vpp) < 0 ? s->topmap : s->midmap; } } else @@ -1357,11 +1358,11 @@ void DFrameBuffer::DrawBlend(sector_t * viewsector) { double lightbottom; if (i < lightlist.Size() - 1) - lightbottom = lightlist[i + 1].plane.ZatPoint(r_viewpoint.Pos); + lightbottom = lightlist[i + 1].plane.ZatPoint(vpp); else - lightbottom = viewsector->floorplane.ZatPoint(r_viewpoint.Pos); + lightbottom = viewsector->floorplane.ZatPoint(vpp); - if (lightbottom < r_viewpoint.Pos.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS))) + if (lightbottom < vpp.Z && (!lightlist[i].caster || !(lightlist[i].caster->flags&FF_FADEWALLS))) { // 3d floor 'fog' is rendered as a blending value blendv = lightlist[i].blend; diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 21b758094c..b1d7a7bb79 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -1105,10 +1105,11 @@ void DoomSpecificInfo (char *buffer, size_t bufflen) } else { - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", r_viewpoint.Pos.X); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", r_viewpoint.Pos.Y); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", r_viewpoint.Pos.Z); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", r_viewpoint.Angles.Yaw); + auto &vp = r_viewpoint; + buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", vp.Pos.X); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", vp.Pos.Y); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", vp.Pos.Z); + buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", vp.Angles.Yaw); } } *buffer++ = '\r'; From 22b8d0a8d7864e8c305e61c5a1139db164a51c86 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 11:21:13 +0200 Subject: [PATCH 14/18] - r_viewpoint reduction in hwrenderer --- src/hwrenderer/scene/hw_bsp.cpp | 5 +++-- src/hwrenderer/scene/hw_drawstructs.h | 2 +- src/hwrenderer/scene/hw_sprites.cpp | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hwrenderer/scene/hw_bsp.cpp b/src/hwrenderer/scene/hw_bsp.cpp index 4393424c1c..d44bf0679e 100644 --- a/src/hwrenderer/scene/hw_bsp.cpp +++ b/src/hwrenderer/scene/hw_bsp.cpp @@ -353,6 +353,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector) SetupSprite.Clock(); sector_t * sec=sub->sector; // Handle all things in sector. + auto &vp = r_viewpoint; for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext) { auto thing = p->m_thing; @@ -362,7 +363,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector) FIntCVar *cvar = thing->GetInfo()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); + double dist = (thing->Pos() - vp.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { @@ -383,7 +384,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector) FIntCVar *cvar = thing->GetInfo()->distancecheck; if (cvar != nullptr && *cvar >= 0) { - double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); + double dist = (thing->Pos() - vp.Pos).LengthSquared(); double check = (double)**cvar; if (dist >= check * check) { diff --git a/src/hwrenderer/scene/hw_drawstructs.h b/src/hwrenderer/scene/hw_drawstructs.h index 8dcc4632aa..e98f4a3890 100644 --- a/src/hwrenderer/scene/hw_drawstructs.h +++ b/src/hwrenderer/scene/hw_drawstructs.h @@ -383,7 +383,7 @@ public: void SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool translucent); void PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingpos, float spriteheight); - bool CalculateVertices(HWDrawInfo *di, FVector3 *v); + bool CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp); public: diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index e5660c26bc..882712145f 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -68,7 +68,7 @@ EXTERN_CVAR(Float, transsouls) // //========================================================================== -bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v) +bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp) { if (actor != nullptr && (actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) { @@ -146,8 +146,8 @@ bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v) { // [CMB] Rotate relative to camera XY position, not just camera direction, // which is nicer in VR - float xrel = xcenter - r_viewpoint.Pos.X; - float yrel = ycenter - r_viewpoint.Pos.Y; + float xrel = xcenter - vp->X; + float yrel = ycenter - vp->Y; float absAngleDeg = RAD2DEG(atan2(-yrel, xrel)); float counterRotationDeg = 270. - di->mAngles.Yaw.Degrees; // counteracts existing sprite rotation float relAngleDeg = counterRotationDeg + absAngleDeg; From 2c655322c3aaa82a93c2c0a993aec518540a6b9d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 11:21:32 +0200 Subject: [PATCH 15/18] =?UTF-8?q?=E2=80=A6=20and=20in=20gl=5Fsprites.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gl/scene/gl_sprite.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index cc988ec730..cfdbbdae73 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -79,6 +79,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) bool additivefog = false; bool foglayer = false; int rel = sprite->fullbright? 0 : getExtraLight(); + auto &vp = r_viewpoint; if (pass==GLPASS_TRANSLUCENT) { @@ -112,7 +113,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) // fog + fuzz don't work well without some fiddling with the alpha value! if (!sprite->Colormap.FadeColor.isBlack()) { - float dist=Dist2(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, sprite->x, sprite->y); + float dist=Dist2(vp.Pos.X, vp.Pos.Y, sprite->x, sprite->y); int fogd = hw_GetFogDensity(sprite->lightlevel, sprite->Colormap.FadeColor, sprite->Colormap.FogDensity); // this value was determined by trial and error and is scale dependent! @@ -221,7 +222,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) secplane_t *lowplane = i == (*lightlist).Size() - 1 ? &bottomp : &(*lightlist)[i + 1].plane; int thislight = (*lightlist)[i].caster != nullptr ? hw_ClampLight(*(*lightlist)[i].p_lightlevel) : sprite->lightlevel; - int thisll = sprite->actor == nullptr? thislight : (uint8_t)sprite->actor->Sector->CheckSpriteGlow(thislight, sprite->actor->InterpolatedPosition(r_viewpoint.TicFrac)); + int thisll = sprite->actor == nullptr? thislight : (uint8_t)sprite->actor->Sector->CheckSpriteGlow(thislight, sprite->actor->InterpolatedPosition(vp.TicFrac)); FColormap thiscm; thiscm.CopyFog(sprite->Colormap); @@ -249,7 +250,8 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) FVector3 v[4]; gl_RenderState.SetNormal(0, 0, 0); - if (sprite->CalculateVertices(this, v)) + + if (sprite->CalculateVertices(this, v, &vp.Pos)) { glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(-1.0f, -128.0f); @@ -277,7 +279,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) else { FGLModelRenderer renderer(sprite->dynlightindex); - renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, r_viewpoint.TicFrac); + renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, vp.TicFrac); } } From 753cd0aeded2412a39ace246fd4504cd28be1661 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 17:44:11 +0200 Subject: [PATCH 16/18] - made R_SetViewAngle a member of r_viewpoint --- src/gl/scene/gl_scene.cpp | 5 +++-- src/polyrenderer/scene/poly_portal.cpp | 8 ++++---- src/r_utility.cpp | 12 ++++++------ src/r_utility.h | 5 +++++ src/swrenderer/scene/r_portal.cpp | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 95f915b1eb..5afd63bad3 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -148,12 +148,13 @@ void GLSceneDrawer::Set3DViewport(bool mainview) void GLSceneDrawer::SetViewAngle(DAngle viewangle) { + FRenderViewpoint &vp = r_viewpoint; GLRenderer->mAngles.Yaw = float(270.0-viewangle.Degrees); - DVector2 v = r_viewpoint.Angles.Yaw.ToVector(); + DVector2 v = vp.Angles.Yaw.ToVector(); GLRenderer->mViewVector.X = v.X; GLRenderer->mViewVector.Y = v.Y; - R_SetViewAngle(r_viewpoint, r_viewwindow); + vp.SetViewAngle(r_viewwindow); } diff --git a/src/polyrenderer/scene/poly_portal.cpp b/src/polyrenderer/scene/poly_portal.cpp index f85314564b..a4a7ec467a 100644 --- a/src/polyrenderer/scene/poly_portal.cpp +++ b/src/polyrenderer/scene/poly_portal.cpp @@ -88,7 +88,7 @@ void PolyDrawSectorPortal::SaveGlobals() viewpoint.camera = nullptr; viewpoint.sector = Portal->mDestination; - R_SetViewAngle(viewpoint, viewwindow); + viewpoint.SetViewAngle(viewwindow); Portal->mFlags |= PORTSF_INSKYBOX; if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].mFlags |= PORTSF_INSKYBOX; @@ -114,7 +114,7 @@ void PolyDrawSectorPortal::RestoreGlobals() //PolyRenderer::Instance()->Light.SetVisibility(savedvisibility); - R_SetViewAngle(viewpoint, viewwindow); + viewpoint.SetViewAngle(viewwindow); } ///////////////////////////////////////////////////////////////////////////// @@ -236,7 +236,7 @@ void PolyDrawLinePortal::SaveGlobals() viewpoint.camera = nullptr; viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector; - R_SetViewAngle(viewpoint, viewwindow); + viewpoint.SetViewAngle(viewwindow); } void PolyDrawLinePortal::RestoreGlobals() @@ -254,5 +254,5 @@ void PolyDrawLinePortal::RestoreGlobals() viewpoint.camera->renderflags &= ~RF_INVISIBLE; } - R_SetViewAngle(viewpoint, viewwindow); + viewpoint.SetViewAngle(viewwindow); } diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 127ac45979..82ab62f2bf 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -602,13 +602,13 @@ void R_ResetViewInterpolation () // //========================================================================== -void R_SetViewAngle (FRenderViewpoint &viewpoint, const FViewWindow &viewwindow) +void FRenderViewpoint::SetViewAngle (const FViewWindow &viewwindow) { - viewpoint.Sin = viewpoint.Angles.Yaw.Sin(); - viewpoint.Cos = viewpoint.Angles.Yaw.Cos(); + Sin = Angles.Yaw.Sin(); + Cos = Angles.Yaw.Cos(); - viewpoint.TanSin = viewwindow.FocalTangent * viewpoint.Sin; - viewpoint.TanCos = viewwindow.FocalTangent * viewpoint.Cos; + TanSin = viewwindow.FocalTangent * Sin; + TanCos = viewwindow.FocalTangent * Cos; } //========================================================================== @@ -844,7 +844,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor } R_InterpolateView (viewpoint, player, viewpoint.TicFrac, iview); - R_SetViewAngle (viewpoint, viewwindow); + viewpoint.SetViewAngle (viewwindow); interpolator.DoInterpolations (viewpoint.TicFrac); diff --git a/src/r_utility.h b/src/r_utility.h index 3874614264..122e6f0797 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -5,6 +5,7 @@ #include "vectors.h" class FSerializer; +struct FViewWindow; // // Stuff from r_main.h that's needed outside the rendering code. @@ -36,6 +37,10 @@ struct FRenderViewpoint int extralight; // extralight to be added to this viewpoint bool showviewer; // show the camera actor? + + + void SetViewAngle(const FViewWindow &viewwindow); + }; extern FRenderViewpoint r_viewpoint; diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp index 323480c328..b56ddc457d 100644 --- a/src/swrenderer/scene/r_portal.cpp +++ b/src/swrenderer/scene/r_portal.cpp @@ -172,7 +172,7 @@ namespace swrenderer Thread->Viewport->viewpoint.camera = nullptr; Thread->Viewport->viewpoint.sector = port->mDestination; assert(Thread->Viewport->viewpoint.sector != nullptr); - R_SetViewAngle(Thread->Viewport->viewpoint, Thread->Viewport->viewwindow); + Thread->Viewport->viewpoint.SetViewAngle(Thread->Viewport->viewwindow); Thread->Viewport->SetupPolyViewport(Thread); Thread->OpaquePass->ClearSeenSprites(); Thread->Clip3D->ClearFakeFloors(); @@ -260,7 +260,7 @@ namespace swrenderer Thread->Light->SetVisibility(Thread->Viewport.get(), savedvisibility); Thread->Viewport->viewpoint.extralight = savedextralight; Thread->Viewport->viewpoint.Angles = savedangles; - R_SetViewAngle(Thread->Viewport->viewpoint, Thread->Viewport->viewwindow); + Thread->Viewport->viewpoint.SetViewAngle(Thread->Viewport->viewwindow); Thread->Viewport->SetupPolyViewport(Thread); CurrentPortalInSkybox = false; From 87dfa34f1feb0d2b9480be7a621ddd3ad1a38c76 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 17:55:42 +0200 Subject: [PATCH 17/18] - save r_viewpoint as a whole when processing portals. --- src/gl/renderer/gl_renderer.cpp | 1 - src/gl/renderer/gl_renderer.h | 1 - src/gl/scene/gl_portal.cpp | 26 +++++++------------------- src/gl/scene/gl_portal.h | 7 ++----- src/gl/scene/gl_scene.cpp | 5 ++--- src/hwrenderer/scene/hw_drawinfo.h | 1 - src/hwrenderer/scene/hw_sprites.cpp | 8 ++++---- src/r_utility.h | 1 + 8 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 81b9a401db..8d0a7c43e5 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -90,7 +90,6 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb) mMirrorCount = 0; mPlaneMirrorCount = 0; mAngles = FRotator(0.f, 0.f, 0.f); - mViewVector = FVector2(0,0); mVBO = nullptr; mSkyVBO = nullptr; mShaderManager = nullptr; diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index a537d15b52..24356c1ee8 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -129,7 +129,6 @@ public: FShadowMap mShadowMap; FRotator mAngles; - FVector2 mViewVector; FFlatVertexBuffer *mVBO; FSkyVertexBuffer *mSkyVBO; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index bb0d09adb3..f2fd1a61ee 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -266,13 +266,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi) } // save viewpoint - savedViewPos = r_viewpoint.Pos; - savedViewActorPos = r_viewpoint.ActorPos; - savedshowviewer = r_viewpoint.showviewer; - savedAngles = r_viewpoint.Angles; + savedviewpoint = r_viewpoint; savedviewactor=GLRenderer->mViewActor; - savedviewpath[0] = r_viewpoint.Path[0]; - savedviewpath[1] = r_viewpoint.Path[1]; savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0); @@ -286,7 +281,8 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi) inline void GLPortal::ClearClipper(FDrawInfo *di) { - DAngle angleOffset = deltaangle(savedAngles.Yaw, r_viewpoint.Angles.Yaw); + FRenderViewpoint &oldvp = savedviewpoint; + DAngle angleOffset = deltaangle(oldvp.Angles.Yaw, r_viewpoint.Angles.Yaw); di->mClipper->Clear(); @@ -294,8 +290,8 @@ inline void GLPortal::ClearClipper(FDrawInfo *di) di->mClipper->SafeAddClipRange(0,0xffffffff); for (unsigned int i = 0; i < lines.Size(); i++) { - DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - savedViewPos).Angle() + angleOffset; - DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - savedViewPos).Angle() + angleOffset; + DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - oldvp.Pos).Angle() + angleOffset; + DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - oldvp.Pos).Angle() + angleOffset; if (deltaangle(endAngle, startAngle) < 0) { @@ -329,12 +325,7 @@ void GLPortal::End(bool usestencil) if (needdepth) FDrawInfo::EndDrawInfo(); // Restore the old view - r_viewpoint.Path[0] = savedviewpath[0]; - r_viewpoint.Path[1] = savedviewpath[1]; - r_viewpoint.Pos = savedViewPos; - r_viewpoint.showviewer = savedshowviewer; - r_viewpoint.ActorPos = savedViewActorPos; - r_viewpoint.Angles = savedAngles; + r_viewpoint = savedviewpoint; GLRenderer->mViewActor=savedviewactor; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); @@ -389,10 +380,7 @@ void GLPortal::End(bool usestencil) glDepthMask(true); } // Restore the old view - r_viewpoint.showviewer = savedshowviewer; - r_viewpoint.ActorPos = savedViewActorPos; - r_viewpoint.Pos = savedViewPos; - r_viewpoint.Angles = savedAngles; + r_viewpoint = savedviewpoint; GLRenderer->mViewActor=savedviewactor; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index 5f646f41c2..7f219541ae 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -37,6 +37,7 @@ #define __GL_PORTAL_H #include "tarray.h" +#include "r_utility.h" #include "actor.h" #include "gl/renderer/gl_renderer.h" #include "gl/scene/gl_drawinfo.h" @@ -69,13 +70,9 @@ public: private: void DrawPortalStencil(); - DVector3 savedviewpath[2]; - DVector3 savedViewPos; - DVector3 savedViewActorPos; - DRotator savedAngles; - bool savedshowviewer; AActor * savedviewactor; ActorRenderFlags savedvisibility; + FRenderViewpoint savedviewpoint; GLPortal *PrevPortal; TArray mPrimIndices; diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 5afd63bad3..b822c32a78 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -151,8 +151,8 @@ void GLSceneDrawer::SetViewAngle(DAngle viewangle) FRenderViewpoint &vp = r_viewpoint; GLRenderer->mAngles.Yaw = float(270.0-viewangle.Degrees); DVector2 v = vp.Angles.Yaw.ToVector(); - GLRenderer->mViewVector.X = v.X; - GLRenderer->mViewVector.Y = v.Y; + vp.ViewVector.X = v.X; + vp.ViewVector.Y = v.Y; vp.SetViewAngle(r_viewwindow); } @@ -236,7 +236,6 @@ void GLSceneDrawer::CreateScene(FDrawInfo *di) validcount++; // used for processing sidedefs only once by the renderer. di->mAngles = GLRenderer->mAngles; - di->mViewVector = GLRenderer->mViewVector; di->mViewActor = GLRenderer->mViewActor; di->mShadowMap = &GLRenderer->mShadowMap; diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 8bec0df27e..9eff4ec28b 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -84,7 +84,6 @@ struct HWDrawInfo std::atomic spriteindex; IPortal *mClipPortal; FRotator mAngles; - FVector2 mViewVector; AActor *mViewActor; IShadowMap *mShadowMap; Clipper *mClipper; diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 882712145f..29b522c0ee 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -597,8 +597,8 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t switch (spritetype) { case RF_FACESPRITE: - viewvecX = di->mViewVector.X; - viewvecY = di->mViewVector.Y; + viewvecX = vp.ViewVector.X; + viewvecY = vp.ViewVector.Y; x1 = x - viewvecY*leftfac; x2 = x - viewvecY*rightfac; @@ -946,8 +946,8 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * else factor = 1 / 7.f; float scalefac=particle->size * factor; - float viewvecX = di->mViewVector.X; - float viewvecY = di->mViewVector.Y; + float viewvecX = vp.ViewVector.X; + float viewvecY = vp.ViewVector.Y; x1=x+viewvecY*scalefac; x2=x-viewvecY*scalefac; diff --git a/src/r_utility.h b/src/r_utility.h index 122e6f0797..ef093c8ed7 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -21,6 +21,7 @@ struct FRenderViewpoint DVector3 Pos; // Camera position DVector3 ActorPos; // Camera actor's position DRotator Angles; // Camera angles + DVector2 ViewVector; // HWR only: direction the camera is facing. DVector3 Path[2]; // View path for portal calculations double Cos; // cos(Angles.Yaw) From eddb179e36ea8271ed978b6e77c22ffc51df601f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 19 Jun 2018 18:51:46 +0200 Subject: [PATCH 18/18] - moved ViewActor variable into FRenderViewpoint. --- src/gl/renderer/gl_renderer.h | 1 - src/gl/scene/gl_portal.cpp | 31 +++++++++++++---------------- src/gl/scene/gl_scene.cpp | 9 ++++----- src/hwrenderer/scene/hw_drawinfo.h | 1 - src/hwrenderer/scene/hw_sprites.cpp | 2 +- src/r_utility.h | 1 + 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 24356c1ee8..a66d5ced22 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -93,7 +93,6 @@ public: int mMirrorCount; int mPlaneMirrorCount; float mCurrentFoV; - AActor *mViewActor; FShaderManager *mShaderManager; FSamplerManager *mSamplerManager; unsigned int mFBID; diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index f2fd1a61ee..42cc61ab7c 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -267,14 +267,13 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo **pDi) // save viewpoint savedviewpoint = r_viewpoint; - savedviewactor=GLRenderer->mViewActor; savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0); PrevPortal = GLRenderer->mCurrentPortal; GLRenderer->mCurrentPortal = this; - if (PrevPortal != NULL) PrevPortal->PushState(); + if (PrevPortal != nullptr) PrevPortal->PushState(); return true; } @@ -317,7 +316,7 @@ void GLPortal::End(bool usestencil) bool needdepth = NeedDepthBuffer(); Clocker c(PortalAll); - if (PrevPortal != NULL) PrevPortal->PopState(); + if (PrevPortal != nullptr) PrevPortal->PopState(); GLRenderer->mCurrentPortal = PrevPortal; if (usestencil) @@ -326,7 +325,6 @@ void GLPortal::End(bool usestencil) // Restore the old view r_viewpoint = savedviewpoint; - GLRenderer->mViewActor=savedviewactor; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); @@ -381,7 +379,6 @@ void GLPortal::End(bool usestencil) } // Restore the old view r_viewpoint = savedviewpoint; - GLRenderer->mViewActor=savedviewactor; if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); @@ -458,7 +455,7 @@ void GLPortal::EndFrame() // Only use occlusion query if there are more than 2 portals. // Otherwise there's too much overhead. - // (And don't forget to consider the separating NULL pointers!) + // (And don't forget to consider the separating nullptr pointers!) bool usequery = portals.Size() > 2 + (unsigned)renderdepth; while (portals.Pop(p) && p) @@ -494,13 +491,13 @@ void GLPortal::EndFrame() bool GLPortal::RenderFirstSkyPortal(int recursion) { GLPortal * p; - GLPortal * best = NULL; + GLPortal * best = nullptr; unsigned bestindex=0; // Find the one with the highest amount of lines. // Normally this is also the one that saves the largest amount // of time by drawing it before the scene itself. - for(int i = portals.Size()-1; i >= 0 && portals[i] != NULL; --i) + for(int i = portals.Size()-1; i >= 0 && portals[i] != nullptr; --i) { p=portals[i]; if (p->lines.Size() > 0 && p->IsSky()) @@ -538,7 +535,7 @@ GLPortal * GLPortal::FindPortal(const void * src) int i=portals.Size()-1; while (i>=0 && portals[i] && portals[i]->GetSource()!=src) i--; - return i>=0? portals[i]:NULL; + return i>=0? portals[i]:nullptr; } @@ -587,7 +584,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di) if (r_viewpoint.Pos.Z < floorh + 4) r_viewpoint.Pos.Z = floorh + 4; if (r_viewpoint.Pos.Z > ceilh - 4) r_viewpoint.Pos.Z = ceilh - 4; - GLRenderer->mViewActor = origin; + r_viewpoint.ViewActor = origin; inskybox = true; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); @@ -625,7 +622,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di) GLSectorStackPortal *FSectorPortalGroup::GetRenderState() { - if (glportal == NULL) glportal = new GLSectorStackPortal(this); + if (glportal == nullptr) glportal = new GLSectorStackPortal(this); return glportal; } @@ -633,9 +630,9 @@ GLSectorStackPortal *FSectorPortalGroup::GetRenderState() GLSectorStackPortal::~GLSectorStackPortal() { - if (origin != NULL && origin->glportal == this) + if (origin != nullptr && origin->glportal == this) { - origin->glportal = NULL; + origin->glportal = nullptr; } } @@ -692,7 +689,7 @@ void GLSectorStackPortal::DrawContents(FDrawInfo *di) r_viewpoint.Pos += origin->mDisplacement; r_viewpoint.ActorPos += origin->mDisplacement; - GLRenderer->mViewActor = NULL; + r_viewpoint.ViewActor = nullptr; // avoid recursions! if (origin->plane != -1) screen->instack[origin->plane]++; @@ -748,7 +745,7 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di) double planez = origin->ZatPoint(r_viewpoint.Pos); r_viewpoint.Pos.Z = 2 * planez - r_viewpoint.Pos.Z; - GLRenderer->mViewActor = NULL; + r_viewpoint.ViewActor = nullptr; PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorFlag++; @@ -919,7 +916,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di) } r_viewpoint.Angles.Yaw = linedef->Delta().Angle() * 2. - StartAngle; - GLRenderer->mViewActor = NULL; + r_viewpoint.ViewActor = nullptr; MirrorFlag++; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); @@ -998,7 +995,7 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di) di->CurrentMapSections.Set(sub->mapsection); } - GLRenderer->mViewActor = nullptr; + r_viewpoint.ViewActor = nullptr; drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); ClearClipper(di); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index b822c32a78..c64f0cc277 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -236,7 +236,6 @@ void GLSceneDrawer::CreateScene(FDrawInfo *di) validcount++; // used for processing sidedefs only once by the renderer. di->mAngles = GLRenderer->mAngles; - di->mViewActor = GLRenderer->mViewActor; di->mShadowMap = &GLRenderer->mShadowMap; di->RenderBSPNode (level.HeadNode()); @@ -633,14 +632,14 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl GLRenderer->mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; - if (camera->player && camera->player-players==consoleplayer && - ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera==camera->player->mo) + if (camera->player && camera->player - players == consoleplayer && + ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera == camera->player->mo) { - GLRenderer->mViewActor=NULL; + r_viewpoint.ViewActor = nullptr; } else { - GLRenderer->mViewActor=camera; + r_viewpoint.ViewActor = camera; } // 'viewsector' will not survive the rendering so it cannot be used anymore below. diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 9eff4ec28b..e30beeec6d 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -84,7 +84,6 @@ struct HWDrawInfo std::atomic spriteindex; IPortal *mClipPortal; FRotator mAngles; - AActor *mViewActor; IShadowMap *mShadowMap; Clipper *mClipper; diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index 29b522c0ee..d1595756af 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -461,7 +461,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // don't draw first frame of a player missile if (thing->flags&MF_MISSILE) { - if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target == di->mViewActor && di->mViewActor != nullptr) + if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target == vp.ViewActor && vp.ViewActor != nullptr) { double speed = thing->Vel.Length(); if (speed >= thing->target->radius / 2) diff --git a/src/r_utility.h b/src/r_utility.h index ef093c8ed7..35cedde8f3 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -22,6 +22,7 @@ struct FRenderViewpoint DVector3 ActorPos; // Camera actor's position DRotator Angles; // Camera angles DVector2 ViewVector; // HWR only: direction the camera is facing. + AActor *ViewActor; // either the same as camera or nullptr DVector3 Path[2]; // View path for portal calculations double Cos; // cos(Angles.Yaw)