Merge remote-tracking branch 'remotes/origin/master' into modern

# Conflicts:
#	src/d_main.cpp
#	src/hwrenderer/scene/hw_weapon.cpp
This commit is contained in:
Christoph Oelckers 2018-06-19 19:40:52 +02:00
commit d2309af3d5
43 changed files with 221 additions and 235 deletions

View file

@ -2123,13 +2123,14 @@ void AM_drawSubsectors()
double secx; double secx;
double secy; double secy;
double seczb, seczt; 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) if (players[consoleplayer].camera && sec == players[consoleplayer].camera->Sector)
{ {
// For the actual camera sector use the current viewpoint as reference. // For the actual camera sector use the current viewpoint as reference.
secx = r_viewpoint.Pos.X; secx = vp.Pos.X;
secy = r_viewpoint.Pos.Y; secy = vp.Pos.Y;
} }
else else
{ {

View file

@ -662,6 +662,7 @@ void D_Display ()
players[consoleplayer].camera = players[consoleplayer].mo; players[consoleplayer].camera = players[consoleplayer].mo;
} }
auto &vp = r_viewpoint;
if (viewactive) if (viewactive)
{ {
DAngle fov = 90.f; DAngle fov = 90.f;
@ -672,7 +673,7 @@ void D_Display ()
fov = cam->player->FOV; fov = cam->player->FOV;
else fov = cam->CameraFOV; else fov = cam->CameraFOV;
} }
R_SetFOV(r_viewpoint, fov); R_SetFOV(vp, fov);
} }
// fullscreen toggle has been requested // fullscreen toggle has been requested
@ -681,7 +682,7 @@ void D_Display ()
screen->ToggleFullscreen(fullscreen); screen->ToggleFullscreen(fullscreen);
V_OutputResized(screen->GetWidth(), screen->GetHeight()); V_OutputResized(screen->GetWidth(), screen->GetHeight());
setmodeneeded = false; setmodeneeded = false;
} }
// change the view size if needed // change the view size if needed
if (setsizeneeded) if (setsizeneeded)
@ -694,8 +695,8 @@ void D_Display ()
} }
else else
{ {
R_ExecuteSetViewSize (r_viewpoint, r_viewwindow); R_ExecuteSetViewSize (vp, r_viewwindow);
} }
} }
// [RH] Allow temporarily disabling wipes // [RH] Allow temporarily disabling wipes
@ -793,7 +794,7 @@ void D_Display ()
{ {
StatusBar->DrawCrosshair(); StatusBar->DrawCrosshair();
} }
StatusBar->CallDraw (HUD_AltHud); StatusBar->CallDraw (HUD_AltHud, vp.TicFrac);
StatusBar->DrawTopStuff (HUD_AltHud); StatusBar->DrawTopStuff (HUD_AltHud);
} }
else else
@ -801,13 +802,13 @@ void D_Display ()
{ {
EHudState state = DrawFSHUD ? HUD_Fullscreen : HUD_None; EHudState state = DrawFSHUD ? HUD_Fullscreen : HUD_None;
StatusBar->DrawBottomStuff (state); StatusBar->DrawBottomStuff (state);
StatusBar->CallDraw (state); StatusBar->CallDraw (state, vp.TicFrac);
StatusBar->DrawTopStuff (state); StatusBar->DrawTopStuff (state);
} }
else else
{ {
StatusBar->DrawBottomStuff (HUD_StatusBar); StatusBar->DrawBottomStuff (HUD_StatusBar);
StatusBar->CallDraw (HUD_StatusBar); StatusBar->CallDraw (HUD_StatusBar, vp.TicFrac);
StatusBar->DrawTopStuff (HUD_StatusBar); StatusBar->DrawTopStuff (HUD_StatusBar);
} }
//stb.Unclock(); //stb.Unclock();

View file

@ -857,12 +857,13 @@ void DStaticEventHandler::WorldTick()
static FRenderEvent E_SetupRenderEvent() static FRenderEvent E_SetupRenderEvent()
{ {
FRenderEvent e; FRenderEvent e;
e.ViewPos = r_viewpoint.Pos; auto &vp = r_viewpoint;
e.ViewAngle = r_viewpoint.Angles.Yaw; e.ViewPos = vp.Pos;
e.ViewPitch = r_viewpoint.Angles.Pitch; e.ViewAngle = vp.Angles.Yaw;
e.ViewRoll = r_viewpoint.Angles.Roll; e.ViewPitch = vp.Angles.Pitch;
e.FracTic = r_viewpoint.TicFrac; e.ViewRoll = vp.Angles.Roll;
e.Camera = r_viewpoint.camera; e.FracTic = vp.TicFrac;
e.Camera = vp.camera;
return e; return e;
} }

View file

@ -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)); 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)) if (victim->player != NULL && (victim->player->cheats & CF_NOCLIP))
{ {
@ -339,12 +339,12 @@ int DEarthquake::StaticGetQuakeIntensities(AActor *victim, FQuakeJiggers &jigger
} }
else 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.X *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.X);
intensity.Y *= quake->GetModWave(quake->m_WaveSpeed.Y); intensity.Y *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.Y);
intensity.Z *= quake->GetModWave(quake->m_WaveSpeed.Z); intensity.Z *= quake->GetModWave(ticFrac, quake->m_WaveSpeed.Z);
intensity *= strength * falloff; intensity *= strength * falloff;
// [RH] This only gives effect to the last sine quake. I would // [RH] This only gives effect to the last sine quake. I would

View file

@ -145,10 +145,10 @@ public:
double m_RollIntensity, m_RollWave; double m_RollIntensity, m_RollWave;
double GetModIntensity(double intensity, bool fake = false) const; 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; double GetFalloff(double dist) const;
static int StaticGetQuakeIntensities(AActor *viewer, FQuakeJiggers &jiggers); static int StaticGetQuakeIntensities(double ticFrac, AActor *viewer, FQuakeJiggers &jiggers);
private: private:
DEarthquake (); DEarthquake ();

View file

@ -397,10 +397,10 @@ public:
void SetScale(); void SetScale();
virtual void Tick (); virtual void Tick ();
void CallTick(); void CallTick();
virtual void Draw (EHudState state); virtual void Draw (EHudState state, double ticFrac);
void CallDraw(EHudState state); void CallDraw(EHudState state, double ticFrac);
void DrawBottomStuff (EHudState state); void DrawBottomStuff (EHudState state);
void DrawTopStuff (EHudState state); void DrawTopStuff (EHudState state);
void FlashItem (const PClass *itemtype); void FlashItem (const PClass *itemtype);
void AttachToPlayer(player_t *player); void AttachToPlayer(player_t *player);
DVector2 GetHUDScale() const; DVector2 GetHUDScale() const;

View file

@ -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 // HUD_AltHud state is for popups only
if (state == HUD_AltHud) if (state == HUD_AltHud)
@ -1048,18 +1048,19 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, Draw)
{ {
PARAM_SELF_PROLOGUE(DBaseStatusBar); PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT(state); PARAM_INT(state);
self->Draw((EHudState)state); PARAM_FLOAT(ticFrac);
self->Draw((EHudState)state, ticFrac);
return 0; return 0;
} }
void DBaseStatusBar::CallDraw(EHudState state) void DBaseStatusBar::CallDraw(EHudState state, double ticFrac)
{ {
IFVIRTUAL(DBaseStatusBar, Draw) IFVIRTUAL(DBaseStatusBar, Draw)
{ {
VMValue params[] = { (DObject*)this, state, r_viewpoint.TicFrac }; VMValue params[] = { (DObject*)this, state, ticFrac };
VMCall(func, params, countof(params), nullptr, 0); 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. screen->ClearClipRect(); // make sure the scripts don't leave a valid clipping rect behind.
BeginStatusBar(BaseSBarHorizontalResolution, BaseSBarVerticalResolution, BaseRelTop, false); BeginStatusBar(BaseSBarHorizontalResolution, BaseSBarVerticalResolution, BaseRelTop, false);
} }

View file

@ -314,27 +314,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);
}

View file

@ -51,5 +51,3 @@ public:
void DrawElements(int numIndices, size_t offset) override; 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);

View file

@ -90,7 +90,6 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
mMirrorCount = 0; mMirrorCount = 0;
mPlaneMirrorCount = 0; mPlaneMirrorCount = 0;
mAngles = FRotator(0.f, 0.f, 0.f); mAngles = FRotator(0.f, 0.f, 0.f);
mViewVector = FVector2(0,0);
mVBO = nullptr; mVBO = nullptr;
mSkyVBO = nullptr; mSkyVBO = nullptr;
mShaderManager = nullptr; mShaderManager = nullptr;

View file

@ -70,7 +70,6 @@ public:
int mMirrorCount; int mMirrorCount;
int mPlaneMirrorCount; int mPlaneMirrorCount;
float mCurrentFoV; float mCurrentFoV;
AActor *mViewActor;
FShaderManager *mShaderManager; FShaderManager *mShaderManager;
FSamplerManager *mSamplerManager; FSamplerManager *mSamplerManager;
unsigned int mFBID; unsigned int mFBID;
@ -106,7 +105,6 @@ public:
FShadowMap mShadowMap; FShadowMap mShadowMap;
FRotator mAngles; FRotator mAngles;
FVector2 mViewVector;
FFlatVertexBuffer *mVBO; FFlatVertexBuffer *mVBO;
FSkyVertexBuffer *mSkyVBO; FSkyVertexBuffer *mSkyVBO;

View file

@ -196,6 +196,7 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer)
di->mDrawer = drawer; di->mDrawer = drawer;
di->mVBO = GLRenderer->mVBO; di->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper; di->mClipper = &staticClipper;
di->mClipper->SetViewpoint(r_viewpoint);
staticClipper.Clear(); staticClipper.Clear();
di->StartScene(); di->StartScene();
return di; return di;

View file

@ -268,27 +268,22 @@ bool GLPortal::Start(bool usestencil, bool doquery, FDrawInfo *outer_di, FDrawIn
} }
// save viewpoint // save viewpoint
savedViewPos = r_viewpoint.Pos; savedviewpoint = r_viewpoint;
savedViewActorPos = r_viewpoint.ActorPos;
savedshowviewer = r_viewpoint.showviewer;
savedAngles = r_viewpoint.Angles;
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); savedvisibility = r_viewpoint.camera ? r_viewpoint.camera->renderflags & RF_MAYBEINVISIBLE : ActorRenderFlags::FromInt(0);
PrevPortal = GLRenderer->mCurrentPortal; PrevPortal = GLRenderer->mCurrentPortal;
GLRenderer->mCurrentPortal = this; GLRenderer->mCurrentPortal = this;
if (PrevPortal != NULL) PrevPortal->PushState(); if (PrevPortal != nullptr) PrevPortal->PushState();
return true; return true;
} }
inline void GLPortal::ClearClipper(FDrawInfo *di) 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(); di->mClipper->Clear();
@ -296,8 +291,8 @@ inline void GLPortal::ClearClipper(FDrawInfo *di)
di->mClipper->SafeAddClipRange(0,0xffffffff); di->mClipper->SafeAddClipRange(0,0xffffffff);
for (unsigned int i = 0; i < lines.Size(); i++) for (unsigned int i = 0; i < lines.Size(); i++)
{ {
DAngle startAngle = (DVector2(lines[i].glseg.x2, lines[i].glseg.y2) - 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) - savedViewPos).Angle() + angleOffset; DAngle endAngle = (DVector2(lines[i].glseg.x1, lines[i].glseg.y1) - oldvp.Pos).Angle() + angleOffset;
if (deltaangle(endAngle, startAngle) < 0) if (deltaangle(endAngle, startAngle) < 0)
{ {
@ -323,7 +318,7 @@ void GLPortal::End(bool usestencil)
bool needdepth = NeedDepthBuffer(); bool needdepth = NeedDepthBuffer();
Clocker c(PortalAll); Clocker c(PortalAll);
if (PrevPortal != NULL) PrevPortal->PopState(); if (PrevPortal != nullptr) PrevPortal->PopState();
GLRenderer->mCurrentPortal = PrevPortal; GLRenderer->mCurrentPortal = PrevPortal;
if (usestencil) if (usestencil)
@ -331,13 +326,7 @@ void GLPortal::End(bool usestencil)
if (needdepth) FDrawInfo::EndDrawInfo(); if (needdepth) FDrawInfo::EndDrawInfo();
// Restore the old view // Restore the old view
r_viewpoint.Path[0] = savedviewpath[0]; r_viewpoint = savedviewpoint;
r_viewpoint.Path[1] = savedviewpath[1];
r_viewpoint.Pos = savedViewPos;
r_viewpoint.showviewer = savedshowviewer;
r_viewpoint.ActorPos = savedViewActorPos;
r_viewpoint.Angles = savedAngles;
GLRenderer->mViewActor=savedviewactor;
if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags = (r_viewpoint.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; 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)); drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
@ -391,11 +380,7 @@ void GLPortal::End(bool usestencil)
glDepthMask(true); glDepthMask(true);
} }
// Restore the old view // Restore the old view
r_viewpoint.showviewer = savedshowviewer; r_viewpoint = savedviewpoint;
r_viewpoint.ActorPos = savedViewActorPos;
r_viewpoint.Pos = savedViewPos;
r_viewpoint.Angles = savedAngles;
GLRenderer->mViewActor=savedviewactor;
if (r_viewpoint.camera != nullptr) r_viewpoint.camera->renderflags |= savedvisibility; 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)); drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
@ -472,7 +457,7 @@ void GLPortal::EndFrame(FDrawInfo *outer_di)
// Only use occlusion query if there are more than 2 portals. // Only use occlusion query if there are more than 2 portals.
// Otherwise there's too much overhead. // 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; bool usequery = portals.Size() > 2 + (unsigned)renderdepth;
while (portals.Pop(p) && p) while (portals.Pop(p) && p)
@ -508,13 +493,13 @@ void GLPortal::EndFrame(FDrawInfo *outer_di)
bool GLPortal::RenderFirstSkyPortal(int recursion, FDrawInfo *outer_di) bool GLPortal::RenderFirstSkyPortal(int recursion, FDrawInfo *outer_di)
{ {
GLPortal * p; GLPortal * p;
GLPortal * best = NULL; GLPortal * best = nullptr;
unsigned bestindex=0; unsigned bestindex=0;
// Find the one with the highest amount of lines. // Find the one with the highest amount of lines.
// Normally this is also the one that saves the largest amount // Normally this is also the one that saves the largest amount
// of time by drawing it before the scene itself. // 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]; p=portals[i];
if (p->lines.Size() > 0 && p->IsSky()) if (p->lines.Size() > 0 && p->IsSky())
@ -552,7 +537,7 @@ GLPortal * GLPortal::FindPortal(const void * src)
int i=portals.Size()-1; int i=portals.Size()-1;
while (i>=0 && portals[i] && portals[i]->GetSource()!=src) i--; while (i>=0 && portals[i] && portals[i]->GetSource()!=src) i--;
return i>=0? portals[i]:NULL; return i>=0? portals[i]:nullptr;
} }
@ -601,7 +586,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di)
if (r_viewpoint.Pos.Z < floorh + 4) r_viewpoint.Pos.Z = floorh + 4; 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; if (r_viewpoint.Pos.Z > ceilh - 4) r_viewpoint.Pos.Z = ceilh - 4;
GLRenderer->mViewActor = origin; r_viewpoint.ViewActor = origin;
inskybox = true; inskybox = true;
drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1)); drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
@ -639,7 +624,7 @@ void GLSkyboxPortal::DrawContents(FDrawInfo *di)
GLSectorStackPortal *FSectorPortalGroup::GetRenderState() GLSectorStackPortal *FSectorPortalGroup::GetRenderState()
{ {
if (glportal == NULL) glportal = new GLSectorStackPortal(this); if (glportal == nullptr) glportal = new GLSectorStackPortal(this);
return glportal; return glportal;
} }
@ -647,9 +632,9 @@ GLSectorStackPortal *FSectorPortalGroup::GetRenderState()
GLSectorStackPortal::~GLSectorStackPortal() GLSectorStackPortal::~GLSectorStackPortal()
{ {
if (origin != NULL && origin->glportal == this) if (origin != nullptr && origin->glportal == this)
{ {
origin->glportal = NULL; origin->glportal = nullptr;
} }
} }
@ -706,7 +691,7 @@ void GLSectorStackPortal::DrawContents(FDrawInfo *di)
r_viewpoint.Pos += origin->mDisplacement; r_viewpoint.Pos += origin->mDisplacement;
r_viewpoint.ActorPos += origin->mDisplacement; r_viewpoint.ActorPos += origin->mDisplacement;
GLRenderer->mViewActor = NULL; r_viewpoint.ViewActor = nullptr;
// avoid recursions! // avoid recursions!
if (origin->plane != -1) screen->instack[origin->plane]++; if (origin->plane != -1) screen->instack[origin->plane]++;
@ -762,7 +747,7 @@ void GLPlaneMirrorPortal::DrawContents(FDrawInfo *di)
double planez = origin->ZatPoint(r_viewpoint.Pos); double planez = origin->ZatPoint(r_viewpoint.Pos);
r_viewpoint.Pos.Z = 2 * planez - r_viewpoint.Pos.Z; r_viewpoint.Pos.Z = 2 * planez - r_viewpoint.Pos.Z;
GLRenderer->mViewActor = NULL; r_viewpoint.ViewActor = nullptr;
PlaneMirrorMode = origin->fC() < 0 ? -1 : 1; PlaneMirrorMode = origin->fC() < 0 ? -1 : 1;
PlaneMirrorFlag++; PlaneMirrorFlag++;
@ -933,7 +918,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
} }
r_viewpoint.Angles.Yaw = linedef->Delta().Angle() * 2. - StartAngle; r_viewpoint.Angles.Yaw = linedef->Delta().Angle() * 2. - StartAngle;
GLRenderer->mViewActor = NULL; r_viewpoint.ViewActor = nullptr;
MirrorFlag++; MirrorFlag++;
drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1)); drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
@ -943,9 +928,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
angle_t af = drawer->FrustumAngle(); angle_t af = drawer->FrustumAngle();
if (af<ANGLE_180) di->mClipper->SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af); if (af<ANGLE_180) di->mClipper->SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af);
angle_t a2 = linedef->v1->GetClipAngle(); di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2);
angle_t a1 = linedef->v2->GetClipAngle();
di->mClipper->SafeAddClipRange(a1,a2);
gl_RenderState.SetClipLine(linedef); gl_RenderState.SetClipLine(linedef);
gl_RenderState.EnableClipLine(true); gl_RenderState.EnableClipLine(true);
@ -1014,7 +997,7 @@ void GLLineToLinePortal::DrawContents(FDrawInfo *di)
di->CurrentMapSections.Set(sub->mapsection); 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)); drawer->SetupView(r_viewpoint.Pos.X, r_viewpoint.Pos.Y, r_viewpoint.Pos.Z, r_viewpoint.Angles.Yaw, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
ClearClipper(di); ClearClipper(di);

View file

@ -37,6 +37,7 @@
#define __GL_PORTAL_H #define __GL_PORTAL_H
#include "tarray.h" #include "tarray.h"
#include "r_utility.h"
#include "actor.h" #include "actor.h"
#include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderer.h"
#include "gl/scene/gl_drawinfo.h" #include "gl/scene/gl_drawinfo.h"
@ -69,13 +70,9 @@ public:
private: private:
void DrawPortalStencil(); void DrawPortalStencil();
DVector3 savedviewpath[2];
DVector3 savedViewPos;
DVector3 savedViewActorPos;
DRotator savedAngles;
bool savedshowviewer;
AActor * savedviewactor; AActor * savedviewactor;
ActorRenderFlags savedvisibility; ActorRenderFlags savedvisibility;
FRenderViewpoint savedviewpoint;
GLPortal *PrevPortal; GLPortal *PrevPortal;
TArray<unsigned int> mPrimIndices; TArray<unsigned int> mPrimIndices;

View file

@ -148,12 +148,13 @@ void GLSceneDrawer::Set3DViewport(bool mainview)
void GLSceneDrawer::SetViewAngle(DAngle viewangle) void GLSceneDrawer::SetViewAngle(DAngle viewangle)
{ {
FRenderViewpoint &vp = r_viewpoint;
GLRenderer->mAngles.Yaw = float(270.0-viewangle.Degrees); 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; vp.ViewVector.X = v.X;
GLRenderer->mViewVector.Y = v.Y; vp.ViewVector.Y = v.Y;
R_SetViewAngle(r_viewpoint, r_viewwindow); vp.SetViewAngle(r_viewwindow);
} }
@ -235,8 +236,6 @@ void GLSceneDrawer::CreateScene(FDrawInfo *di)
validcount++; // used for processing sidedefs only once by the renderer. validcount++; // used for processing sidedefs only once by the renderer.
di->mAngles = GLRenderer->mAngles; di->mAngles = GLRenderer->mAngles;
di->mViewVector = GLRenderer->mViewVector;
di->mViewActor = GLRenderer->mViewActor;
di->mShadowMap = &GLRenderer->mShadowMap; di->mShadowMap = &GLRenderer->mShadowMap;
di->RenderBSPNode (level.HeadNode()); di->RenderBSPNode (level.HeadNode());
@ -560,14 +559,14 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl
GLRenderer->mAngles.Pitch = (float)RAD2DEG(asin(angy / alen)); GLRenderer->mAngles.Pitch = (float)RAD2DEG(asin(angy / alen));
GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees;
if (camera->player && camera->player-players==consoleplayer && if (camera->player && camera->player - players == consoleplayer &&
((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera==camera->player->mo) ((camera->player->cheats & CF_CHASECAM) || (r_deathcamera && camera->health <= 0)) && camera == camera->player->mo)
{ {
GLRenderer->mViewActor=NULL; r_viewpoint.ViewActor = nullptr;
} }
else else
{ {
GLRenderer->mViewActor=camera; r_viewpoint.ViewActor = camera;
} }
// 'viewsector' will not survive the rendering so it cannot be used anymore below. // 'viewsector' will not survive the rendering so it cannot be used anymore below.

View file

@ -79,6 +79,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
bool additivefog = false; bool additivefog = false;
bool foglayer = false; bool foglayer = false;
int rel = sprite->fullbright? 0 : getExtraLight(); int rel = sprite->fullbright? 0 : getExtraLight();
auto &vp = r_viewpoint;
if (pass==GLPASS_TRANSLUCENT) 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! // fog + fuzz don't work well without some fiddling with the alpha value!
if (!sprite->Colormap.FadeColor.isBlack()) 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); int fogd = hw_GetFogDensity(sprite->lightlevel, sprite->Colormap.FadeColor, sprite->Colormap.FogDensity);
// this value was determined by trial and error and is scale dependent! // 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; 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 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; FColormap thiscm;
thiscm.CopyFog(sprite->Colormap); thiscm.CopyFog(sprite->Colormap);
@ -249,7 +250,8 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
FVector3 v[4]; FVector3 v[4];
gl_RenderState.SetNormal(0, 0, 0); gl_RenderState.SetNormal(0, 0, 0);
if (sprite->CalculateVertices(this, v))
if (sprite->CalculateVertices(this, v, &vp.Pos))
{ {
glEnable(GL_POLYGON_OFFSET_FILL); glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-1.0f, -128.0f); glPolygonOffset(-1.0f, -128.0f);
@ -276,7 +278,8 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
} }
else else
{ {
gl_RenderModel(sprite, sprite->dynlightindex); FGLModelRenderer renderer(sprite->dynlightindex);
renderer.RenderModel(sprite->x, sprite->y, sprite->z, sprite->modelframe, sprite->actor, vp.TicFrac);
} }
} }

View file

@ -66,7 +66,8 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds)
if (huds->mframe) if (huds->mframe)
{ {
gl_RenderState.AlphaFunc(GL_GEQUAL, 0); 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 else
{ {

View file

@ -353,6 +353,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector)
SetupSprite.Clock(); SetupSprite.Clock();
sector_t * sec=sub->sector; sector_t * sec=sub->sector;
// Handle all things in sector. // Handle all things in sector.
auto &vp = r_viewpoint;
for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext) for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext)
{ {
auto thing = p->m_thing; auto thing = p->m_thing;
@ -362,7 +363,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector)
FIntCVar *cvar = thing->GetInfo()->distancecheck; FIntCVar *cvar = thing->GetInfo()->distancecheck;
if (cvar != nullptr && *cvar >= 0) if (cvar != nullptr && *cvar >= 0)
{ {
double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double dist = (thing->Pos() - vp.Pos).LengthSquared();
double check = (double)**cvar; double check = (double)**cvar;
if (dist >= check * check) if (dist >= check * check)
{ {
@ -383,7 +384,7 @@ void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector)
FIntCVar *cvar = thing->GetInfo()->distancecheck; FIntCVar *cvar = thing->GetInfo()->distancecheck;
if (cvar != nullptr && *cvar >= 0) if (cvar != nullptr && *cvar >= 0)
{ {
double dist = (thing->Pos() - r_viewpoint.Pos).LengthSquared(); double dist = (thing->Pos() - vp.Pos).LengthSquared();
double check = (double)**cvar; double check = (double)**cvar;
if (dist >= check * check) if (dist >= check * check)
{ {

View file

@ -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 vecx = x - viewpoint->Pos.X;
double vecy = y - r_viewpoint.Pos.Y; double vecy = y - viewpoint->Pos.Y;
if (vecx == 0 && vecy == 0) if (vecx == 0 && vecy == 0)
{ {
@ -427,14 +427,15 @@ bool Clipper::CheckBox(const float *bspcoord)
// Find the corners of the box // Find the corners of the box
// that define the edges from current viewpoint. // that define the edges from current viewpoint.
boxpos = (r_viewpoint.Pos.X <= bspcoord[BOXLEFT] ? 0 : r_viewpoint.Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + auto &vp = viewpoint;
(r_viewpoint.Pos.Y >= bspcoord[BOXTOP ] ? 0 : r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); 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; if (boxpos == 5) return true;
check = checkcoord[boxpos]; check = checkcoord[boxpos];
angle1 = R_PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]); angle1 = PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]);
angle2 = R_PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]); angle2 = PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]);
return SafeCheckRange(angle2, angle1); return SafeCheckRange(angle2, angle1);
} }

View file

@ -6,14 +6,6 @@
#include "r_utility.h" #include "r_utility.h"
#include "memarena.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 class ClipNode
{ {
friend class Clipper; friend class Clipper;
@ -37,6 +29,7 @@ class Clipper
ClipNode * clipnodes = nullptr; ClipNode * clipnodes = nullptr;
ClipNode * cliphead = nullptr; ClipNode * cliphead = nullptr;
ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called
const FRenderViewpoint *viewpoint = nullptr;
bool blocked = false; bool blocked = false;
static angle_t AngleToPseudo(angle_t ang); static angle_t AngleToPseudo(angle_t ang);
@ -78,6 +71,11 @@ public:
c->next = c->prev = NULL; c->next = c->prev = NULL;
return c; return c;
} }
void SetViewpoint(const FRenderViewpoint &vp)
{
viewpoint = &vp;
}
void SetSilhouette(); void SetSilhouette();
@ -105,6 +103,13 @@ public:
AddClipRange(startangle, endangle); 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) void SafeAddClipRangeRealAngles(angle_t startangle, angle_t endangle)
{ {
@ -141,13 +146,15 @@ public:
{ {
return blocked; return blocked;
} }
angle_t PointToPseudoAngle(double x, double y);
bool CheckBox(const float *bspcoord); bool CheckBox(const float *bspcoord);
// Used to speed up angle calculations during clipping // Used to speed up angle calculations during clipping
inline angle_t GetClipAngle(vertex_t *v) 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));
} }
}; };

View file

@ -95,8 +95,6 @@ struct HWDrawInfo
std::atomic<int> spriteindex; std::atomic<int> spriteindex;
IPortal *mClipPortal; IPortal *mClipPortal;
FRotator mAngles; FRotator mAngles;
FVector2 mViewVector;
AActor *mViewActor;
IShadowMap *mShadowMap; IShadowMap *mShadowMap;
Clipper *mClipper; Clipper *mClipper;

View file

@ -121,7 +121,7 @@ inline void SortNode::AddToEqual(SortNode *child)
{ {
child->UnlinkFromChain(); child->UnlinkFromChain();
child->equal=equal; 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]; GLFlat * fh = flats[drawitems[head->itemindex].index];
GLWall * ws = walls[drawitems[sort->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)) 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]; GLFlat * fh = flats[drawitems[head->itemindex].index];
GLSprite * ss = sprites[drawitems[sort->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 hiz = ss->z1 > ss->z2 ? ss->z1 : ss->z2;
auto loz = 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) void HWDrawList::Sort(HWDrawInfo *di)
{ {
SortZ = r_viewpoint.Pos.Z;
MakeSortList(); MakeSortList();
sorted = DoSort(di, SortNodes[SortNodeStart]); sorted = DoSort(di, SortNodes[SortNodeStart]);
} }

View file

@ -61,6 +61,7 @@ struct HWDrawList
TArray<GLSprite*> sprites; TArray<GLSprite*> sprites;
TArray<GLDrawItem> drawitems; TArray<GLDrawItem> drawitems;
int SortNodeStart; int SortNodeStart;
float SortZ;
SortNode * sorted; SortNode * sorted;
public: public:

View file

@ -384,7 +384,7 @@ public:
void SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool translucent); void SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool translucent);
void PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingpos, float spriteheight); void PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingpos, float spriteheight);
bool CalculateVertices(HWDrawInfo *di, FVector3 *v); bool CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp);
public: public:

View file

@ -394,15 +394,16 @@ sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool bac
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void HWDrawInfo::SetViewArea() void HWDrawInfo::SetViewArea()
{ {
auto &vp = r_viewpoint;
// The render_sector is better suited to represent the current position in GL // 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! // 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 : in_area = vp.Pos.Z <= vp.sector->heightsec->floorplane.ZatPoint(vp.Pos) ? area_below :
(r_viewpoint.Pos.Z > r_viewpoint.sector->heightsec->ceilingplane.ZatPoint(r_viewpoint.Pos) && (vp.Pos.Z > vp.sector->heightsec->ceilingplane.ZatPoint(vp.Pos) &&
!(r_viewpoint.sector->heightsec->MoreFlags&SECMF_FAKEFLOORONLY)) ? area_above : area_normal; !(vp.sector->heightsec->MoreFlags&SECMF_FAKEFLOORONLY)) ? area_above : area_normal;
} }
else else
{ {

View file

@ -306,6 +306,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector)
dynlightindex = -1; dynlightindex = -1;
uint8_t &srf = di->sectorrenderflags[sector->sectornum]; uint8_t &srf = di->sectorrenderflags[sector->sectornum];
auto &vp = r_viewpoint;
// //
// //
@ -314,7 +315,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. // process the original floor first.
@ -374,7 +375,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. // process the original ceiling first.
@ -465,7 +466,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector)
double ff_top = rover->top.plane->ZatPoint(sector->centerspot); double ff_top = rover->top.plane->ZatPoint(sector->centerspot);
if (ff_top < lastceilingheight) 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)); SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG));
Colormap.FadeColor = frontsector->Colormap.FadeColor; Colormap.FadeColor = frontsector->Colormap.FadeColor;
@ -479,7 +480,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector)
double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot);
if (ff_bottom < lastceilingheight) 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)); SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG));
Colormap.FadeColor = frontsector->Colormap.FadeColor; Colormap.FadeColor = frontsector->Colormap.FadeColor;
@ -505,7 +506,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector)
double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot);
if (ff_bottom > lastfloorheight || (rover->flags&FF_FIX)) 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)); SetFrom3DFloor(rover, false, !(rover->flags&FF_FOG));
Colormap.FadeColor = frontsector->Colormap.FadeColor; Colormap.FadeColor = frontsector->Colormap.FadeColor;
@ -526,7 +527,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector)
double ff_top = rover->top.plane->ZatPoint(sector->centerspot); double ff_top = rover->top.plane->ZatPoint(sector->centerspot);
if (ff_top > lastfloorheight) 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)); SetFrom3DFloor(rover, true, !!(rover->flags&FF_FOG));
Colormap.FadeColor = frontsector->Colormap.FadeColor; Colormap.FadeColor = frontsector->Colormap.FadeColor;

View file

@ -154,8 +154,9 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref
} }
else if (allowreflect && sector->GetReflect(plane) > 0) else if (allowreflect && sector->GetReflect(plane) > 0)
{ {
if ((plane == sector_t::ceiling && r_viewpoint.Pos.Z > sector->ceilingplane.fD()) || auto vpz = r_viewpoint.Pos.Z;
(plane == sector_t::floor && r_viewpoint.Pos.Z < -sector->floorplane.fD())) return; if ((plane == sector_t::ceiling && vpz > sector->ceilingplane.fD()) ||
(plane == sector_t::floor && vpz < -sector->floorplane.fD())) return;
ptype = PORTALTYPE_PLANEMIRROR; ptype = PORTALTYPE_PLANEMIRROR;
planemirror = plane == sector_t::ceiling ? &sector->ceilingplane : &sector->floorplane; planemirror = plane == sector_t::ceiling ? &sector->ceilingplane : &sector->floorplane;
} }

View file

@ -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) 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, // [CMB] Rotate relative to camera XY position, not just camera direction,
// which is nicer in VR // which is nicer in VR
float xrel = xcenter - r_viewpoint.Pos.X; float xrel = xcenter - vp->X;
float yrel = ycenter - r_viewpoint.Pos.Y; float yrel = ycenter - vp->Y;
float absAngleDeg = RAD2DEG(atan2(-yrel, xrel)); float absAngleDeg = RAD2DEG(atan2(-yrel, xrel));
float counterRotationDeg = 270. - di->mAngles.Yaw.Degrees; // counteracts existing sprite rotation float counterRotationDeg = 270. - di->mAngles.Yaw.Degrees; // counteracts existing sprite rotation
float relAngleDeg = counterRotationDeg + absAngleDeg; float relAngleDeg = counterRotationDeg + absAngleDeg;
@ -403,7 +403,8 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
return; return;
} }
AActor *camera = r_viewpoint.camera; auto &vp = r_viewpoint;
AActor *camera = vp.camera;
if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha)) 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 // [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); 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 // 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(); DVector3 thingorigin = thing->Pos();
if (thruportal == 1) thingorigin += level.Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); 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. // Thing is invisible if close to the camera.
if (thing->renderflags & RF_MAYBEINVISIBLE) 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. // 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. // exclude vertically moving objects from this check.
if (!thing->Vel.isZero()) if (!thing->Vel.isZero())
@ -460,13 +461,13 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
// don't draw first frame of a player missile // don't draw first frame of a player missile
if (thing->flags&MF_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(); double speed = thing->Vel.Length();
if (speed >= thing->target->radius / 2) if (speed >= thing->target->radius / 2)
{ {
double clipdist = clamp(thing->Speed, thing->target->radius, 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. 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. // 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) if (thing->renderflags & RF_INTERPOLATEANGLES)
Angles = thing->InterpolatedAngles(r_viewpoint.TicFrac); Angles = thing->InterpolatedAngles(vp.TicFrac);
else else
Angles = thing->Angles; 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. // [RH] Make floatbobbing a renderer-only effect.
if (thing->flags2 & MF2_FLOATBOB) if (thing->flags2 & MF2_FLOATBOB)
{ {
float fz = thing->GetBobOffset(r_viewpoint.TicFrac); float fz = thing->GetBobOffset(vp.TicFrac);
z += fz; z += fz;
} }
@ -514,7 +515,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
if (!modelframe) if (!modelframe)
{ {
bool mirror; bool mirror;
DAngle ang = (thingpos - r_viewpoint.Pos).Angle(); DAngle ang = (thingpos - vp.Pos).Angle();
FTextureID patch; FTextureID patch;
// [ZZ] add direct picnum override // [ZZ] add direct picnum override
if (isPicnumOverride) if (isPicnumOverride)
@ -531,7 +532,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
int rot; int rot;
if (!(thing->renderflags & RF_FLATSPRITE) || thing->flags7 & MF7_SPRITEANGLE) if (!(thing->renderflags & RF_FLATSPRITE) || thing->flags7 & MF7_SPRITEANGLE)
{ {
sprangle = thing->GetSpriteAngle(ang, r_viewpoint.TicFrac); sprangle = thing->GetSpriteAngle(ang, vp.TicFrac);
rot = -1; rot = -1;
} }
else else
@ -596,8 +597,8 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
switch (spritetype) switch (spritetype)
{ {
case RF_FACESPRITE: case RF_FACESPRITE:
viewvecX = di->mViewVector.X; viewvecX = vp.ViewVector.X;
viewvecY = di->mViewVector.Y; viewvecY = vp.ViewVector.Y;
x1 = x - viewvecY*leftfac; x1 = x - viewvecY*leftfac;
x2 = x - viewvecY*rightfac; x2 = x - viewvecY*rightfac;
@ -632,7 +633,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
gltexture = nullptr; 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 // light calculation
@ -923,7 +924,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)) if (paused || bglobal.freeze || (level.flags2 & LEVEL2_FROZEN))
timefrac = 0.; timefrac = 0.;
float xvf = (particle->Vel.X) * timefrac; float xvf = (particle->Vel.X) * timefrac;
@ -940,8 +942,8 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t *
else factor = 1 / 7.f; else factor = 1 / 7.f;
float scalefac=particle->size * factor; float scalefac=particle->size * factor;
float viewvecX = di->mViewVector.X; float viewvecX = vp.ViewVector.X;
float viewvecY = di->mViewVector.Y; float viewvecY = vp.ViewVector.Y;
x1=x+viewvecY*scalefac; x1=x+viewvecY*scalefac;
x2=x-viewvecY*scalefac; x2=x-viewvecY*scalefac;
@ -950,7 +952,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t *
z1=z-scalefac; z1=z-scalefac;
z2=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; actor=nullptr;
this->particle=particle; this->particle=particle;
@ -980,6 +982,7 @@ void HWDrawInfo::ProcessActorsInPortal(FLinePortalSpan *glport, area_t in_area)
TMap<AActor*, bool> processcheck; TMap<AActor*, bool> processcheck;
if (glport->validcount == validcount) return; // only process once per frame if (glport->validcount == validcount) return; // only process once per frame
glport->validcount = validcount; glport->validcount = validcount;
auto &vp = r_viewpoint;
for (auto port : glport->lines) for (auto port : glport->lines)
{ {
line_t *line = port->mOrigin; line_t *line = port->mOrigin;
@ -1003,9 +1006,9 @@ void HWDrawInfo::ProcessActorsInPortal(FLinePortalSpan *glport, area_t in_area)
DVector3 newpos = savedpos; DVector3 newpos = savedpos;
sector_t fakesector; 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; continue;
} }

View file

@ -443,10 +443,11 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1,
ztop[1] = ztop[0] = fs->GetPlaneTexZ(sector_t::ceiling); ztop[1] = ztop[0] = fs->GetPlaneTexZ(sector_t::ceiling);
zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor); 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)) if (vpz > fs->GetPlaneTexZ(sector_t::floor))
zbottom[1] = zbottom[0] = r_viewpoint.Pos.Z; zbottom[1] = zbottom[0] = vpz;
if (fs->GetTexture(sector_t::ceiling) == skyflatnum) if (fs->GetTexture(sector_t::ceiling) == skyflatnum)
{ {
@ -474,7 +475,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1,
ztop[1] = ztop[0] = zbottom[0]; 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); zbottom[1] = zbottom[0] = fs->GetPlaneTexZ(sector_t::floor);
if (fs->GetTexture(sector_t::floor) == skyflatnum) if (fs->GetTexture(sector_t::floor) == skyflatnum)

View file

@ -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; 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. // 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) if ((w.weapon = player->FindPSprite(PSP_WEAPON)) != nullptr)
@ -91,8 +91,8 @@ static WeaponPosition GetWeaponPosition(player_t *player)
} }
else else
{ {
w.wx = (float)(w.weapon->oldx + (w.weapon->x - w.weapon->oldx) * 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) * r_viewpoint.TicFrac); w.wy = (float)(w.weapon->oldy + (w.weapon->y - w.weapon->oldy) * ticFrac);
} }
} }
else 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) if (psp->firstTic)
{ // Can't interpolate the first tic. { // Can't interpolate the first tic.
@ -118,8 +118,8 @@ static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp)
psp->oldy = psp->y; psp->oldy = psp->y;
} }
float sx = float(psp->oldx + (psp->x - psp->oldx) * r_viewpoint.TicFrac); float sx = float(psp->oldx + (psp->x - psp->oldx) * ticFrac);
float sy = float(psp->oldy + (psp->y - psp->oldy) * r_viewpoint.TicFrac); float sy = float(psp->oldy + (psp->y - psp->oldy) * ticFrac);
if (psp->Flags & PSPF_ADDBOB) if (psp->Flags & PSPF_ADDBOB)
{ {
@ -169,14 +169,14 @@ static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &po
if (i<lightlist.Size() - 1) if (i<lightlist.Size() - 1)
{ {
lightbottom = lightlist[i + 1].plane.ZatPoint(r_viewpoint.Pos); lightbottom = lightlist[i + 1].plane.ZatPoint(pos);
} }
else else
{ {
lightbottom = viewsector->floorplane.ZatPoint(r_viewpoint.Pos); lightbottom = viewsector->floorplane.ZatPoint(pos);
} }
if (lightbottom<r_viewpoint.Pos.Z) if (lightbottom < pos.Z)
{ {
l.cm = lightlist[i].extra_colormap; l.cm = lightlist[i].extra_colormap;
l.lightlevel = hw_ClampLight(*lightlist[i].p_lightlevel); l.lightlevel = hw_ClampLight(*lightlist[i].p_lightlevel);
@ -426,8 +426,10 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
AActor * playermo = players[consoleplayer].camera; AActor * playermo = players[consoleplayer].camera;
player_t * player = playermo->player; player_t * player = playermo->player;
const bool hudModelStep = IsHUDModelForPlayerAvailable(player); 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 // this is the same as the software renderer
if (!player || if (!player ||
@ -437,8 +439,8 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
(r_deathcamera && camera->health <= 0)) (r_deathcamera && camera->health <= 0))
return; return;
WeaponPosition weap = GetWeaponPosition(camera->player); WeaponPosition weap = GetWeaponPosition(camera->player, vp.TicFrac);
WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, isFullbrightScene(), in_area, camera->Pos()); WeaponLighting light = GetWeaponLighting(viewsector, vp.Pos, isFullbrightScene(), in_area, camera->Pos());
// hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite. // 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; 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.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0;
hudsprite.lightindex = -1; hudsprite.lightindex = -1;

View file

@ -160,8 +160,9 @@ void CheckBench()
FString compose; 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", 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); AppendRenderStats(compose);
AppendRenderTimes(compose); AppendRenderTimes(compose);

View file

@ -37,7 +37,7 @@ void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_
{ {
PolyModelRenderer renderer(thread, worldToClip, stencilValue); PolyModelRenderer renderer(thread, worldToClip, stencilValue);
renderer.AddLights(actor); 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); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
} }

View file

@ -88,7 +88,7 @@ void PolyDrawSectorPortal::SaveGlobals()
viewpoint.camera = nullptr; viewpoint.camera = nullptr;
viewpoint.sector = Portal->mDestination; viewpoint.sector = Portal->mDestination;
R_SetViewAngle(viewpoint, viewwindow); viewpoint.SetViewAngle(viewwindow);
Portal->mFlags |= PORTSF_INSKYBOX; Portal->mFlags |= PORTSF_INSKYBOX;
if (Portal->mPartner > 0) level.sectorPortals[Portal->mPartner].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); //PolyRenderer::Instance()->Light.SetVisibility(savedvisibility);
R_SetViewAngle(viewpoint, viewwindow); viewpoint.SetViewAngle(viewwindow);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -236,7 +236,7 @@ void PolyDrawLinePortal::SaveGlobals()
viewpoint.camera = nullptr; viewpoint.camera = nullptr;
viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector; viewpoint.sector = R_PointInSubsector(viewpoint.Pos)->sector;
R_SetViewAngle(viewpoint, viewwindow); viewpoint.SetViewAngle(viewwindow);
} }
void PolyDrawLinePortal::RestoreGlobals() void PolyDrawLinePortal::RestoreGlobals()
@ -254,5 +254,5 @@ void PolyDrawLinePortal::RestoreGlobals()
viewpoint.camera->renderflags &= ~RF_INVISIBLE; viewpoint.camera->renderflags &= ~RF_INVISIBLE;
} }
R_SetViewAngle(viewpoint, viewwindow); viewpoint.SetViewAngle(viewwindow);
} }

View file

@ -169,10 +169,11 @@ static int DoomSpecificInfo (char *buffer, char *end)
} }
else else
{ {
p += snprintf (buffer+p, size-p, "\n\nviewx = %f", r_viewpoint.Pos.X); auto &vp = r_viewpoint;
p += snprintf (buffer+p, size-p, "\nviewy = %f", r_viewpoint.Pos.Y); p += snprintf (buffer+p, size-p, "\n\nviewx = %f", vp.Pos.X);
p += snprintf (buffer+p, size-p, "\nviewz = %f", r_viewpoint.Pos.Z); p += snprintf (buffer+p, size-p, "\nviewy = %f", vp.Pos.Y);
p += snprintf (buffer+p, size-p, "\nviewangle = %f", r_viewpoint.Angles.Yaw.Degrees); 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'; buffer[p++] = '\n';

View file

@ -54,7 +54,7 @@ extern TDeletingArray<FVoxelDef *> VoxelDefs;
DeletingModelArray Models; 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. // Setup transformation.
@ -128,7 +128,7 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s
if (actor->renderflags & RF_INTERPOLATEANGLES) if (actor->renderflags & RF_INTERPOLATEANGLES)
{ {
// [Nash] use interpolated angles // [Nash] use interpolated angles
DRotator Angles = actor->InterpolatedAngles(r_viewpoint.TicFrac); DRotator Angles = actor->InterpolatedAngles(ticFrac);
angle = Angles.Yaw.Degrees; angle = Angles.Yaw.Degrees;
} }

View file

@ -60,7 +60,7 @@ class FModelRenderer
public: public:
virtual ~FModelRenderer() { } 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); void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy);
virtual ModelRendererType GetType() const = 0; virtual ModelRendererType GetType() const = 0;

View file

@ -180,8 +180,6 @@ struct vertex_t
{ {
p.Zero(); p.Zero();
} }
angle_t GetClipAngle();
}; };
// Forward of LineDefs, for Sectors. // Forward of LineDefs, for Sectors.

View file

@ -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(); Sin = Angles.Yaw.Sin();
viewpoint.Cos = viewpoint.Angles.Yaw.Cos(); Cos = Angles.Yaw.Cos();
viewpoint.TanSin = viewwindow.FocalTangent * viewpoint.Sin; TanSin = viewwindow.FocalTangent * Sin;
viewpoint.TanCos = viewwindow.FocalTangent * viewpoint.Cos; TanCos = viewwindow.FocalTangent * Cos;
} }
//========================================================================== //==========================================================================
@ -844,7 +844,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
} }
R_InterpolateView (viewpoint, player, viewpoint.TicFrac, iview); R_InterpolateView (viewpoint, player, viewpoint.TicFrac, iview);
R_SetViewAngle (viewpoint, viewwindow); viewpoint.SetViewAngle (viewwindow);
interpolator.DoInterpolations (viewpoint.TicFrac); interpolator.DoInterpolations (viewpoint.TicFrac);
@ -872,7 +872,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor
FQuakeJiggers jiggers; FQuakeJiggers jiggers;
memset(&jiggers, 0, sizeof(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; double quakefactor = r_quakeintensity;
DAngle an; DAngle an;

View file

@ -5,6 +5,7 @@
#include "vectors.h" #include "vectors.h"
class FSerializer; class FSerializer;
struct FViewWindow;
// //
// Stuff from r_main.h that's needed outside the rendering code. // Stuff from r_main.h that's needed outside the rendering code.
@ -20,6 +21,8 @@ struct FRenderViewpoint
DVector3 Pos; // Camera position DVector3 Pos; // Camera position
DVector3 ActorPos; // Camera actor's position DVector3 ActorPos; // Camera actor's position
DRotator Angles; // Camera angles 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 DVector3 Path[2]; // View path for portal calculations
double Cos; // cos(Angles.Yaw) double Cos; // cos(Angles.Yaw)
@ -36,6 +39,10 @@ struct FRenderViewpoint
int extralight; // extralight to be added to this viewpoint int extralight; // extralight to be added to this viewpoint
bool showviewer; // show the camera actor? bool showviewer; // show the camera actor?
void SetViewAngle(const FViewWindow &viewwindow);
}; };
extern FRenderViewpoint r_viewpoint; extern FRenderViewpoint r_viewpoint;

View file

@ -172,7 +172,7 @@ namespace swrenderer
Thread->Viewport->viewpoint.camera = nullptr; Thread->Viewport->viewpoint.camera = nullptr;
Thread->Viewport->viewpoint.sector = port->mDestination; Thread->Viewport->viewpoint.sector = port->mDestination;
assert(Thread->Viewport->viewpoint.sector != nullptr); 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->Viewport->SetupPolyViewport(Thread);
Thread->OpaquePass->ClearSeenSprites(); Thread->OpaquePass->ClearSeenSprites();
Thread->Clip3D->ClearFakeFloors(); Thread->Clip3D->ClearFakeFloors();
@ -260,7 +260,7 @@ namespace swrenderer
Thread->Light->SetVisibility(Thread->Viewport.get(), savedvisibility); Thread->Light->SetVisibility(Thread->Viewport.get(), savedvisibility);
Thread->Viewport->viewpoint.extralight = savedextralight; Thread->Viewport->viewpoint.extralight = savedextralight;
Thread->Viewport->viewpoint.Angles = savedangles; Thread->Viewport->viewpoint.Angles = savedangles;
R_SetViewAngle(Thread->Viewport->viewpoint, Thread->Viewport->viewwindow); Thread->Viewport->viewpoint.SetViewAngle(Thread->Viewport->viewwindow);
Thread->Viewport->SetupPolyViewport(Thread); Thread->Viewport->SetupPolyViewport(Thread);
CurrentPortalInSkybox = false; CurrentPortalInSkybox = false;

View file

@ -76,7 +76,7 @@ namespace swrenderer
{ {
SWModelRenderer renderer(thread, clip3DFloor, &WorldToClip, MirrorWorldToClip); SWModelRenderer renderer(thread, clip3DFloor, &WorldToClip, MirrorWorldToClip);
renderer.AddLights(actor); 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); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
} }

View file

@ -1342,12 +1342,13 @@ void DFrameBuffer::DrawBlend(sector_t * viewsector)
// don't draw sector based blends when any fullbright screen effect is active. // don't draw sector based blends when any fullbright screen effect is active.
if (!fullbright) if (!fullbright)
{ {
const auto &vpp = r_viewpoint.Pos;
if (!viewsector->e->XFloor.ffloors.Size()) if (!viewsector->e->XFloor.ffloors.Size())
{ {
if (viewsector->GetHeightSec()) if (viewsector->GetHeightSec())
{ {
auto s = viewsector->heightsec; 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 else
@ -1358,11 +1359,11 @@ void DFrameBuffer::DrawBlend(sector_t * viewsector)
{ {
double lightbottom; double lightbottom;
if (i < lightlist.Size() - 1) if (i < lightlist.Size() - 1)
lightbottom = lightlist[i + 1].plane.ZatPoint(r_viewpoint.Pos); lightbottom = lightlist[i + 1].plane.ZatPoint(vpp);
else 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 // 3d floor 'fog' is rendered as a blending value
blendv = lightlist[i].blend; blendv = lightlist[i].blend;

View file

@ -1105,10 +1105,11 @@ void DoomSpecificInfo (char *buffer, size_t bufflen)
} }
else else
{ {
buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", r_viewpoint.Pos.X); auto &vp = r_viewpoint;
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", r_viewpoint.Pos.Y); buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", vp.Pos.X);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", r_viewpoint.Pos.Z); buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", vp.Pos.Y);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", r_viewpoint.Angles.Yaw); buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", vp.Pos.Z);
buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", vp.Angles.Yaw);
} }
} }
*buffer++ = '\r'; *buffer++ = '\r';