From 92bb9c53198019045fe4c42eae62206afbc18361 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 29 Mar 2021 21:48:23 +0200 Subject: [PATCH] - fixed display of player in mirrors. --- source/core/gamestruct.h | 3 +++ source/core/rendering/scene/hw_portal.cpp | 25 ++++++++++++++++------- source/core/rendering/scene/hw_portal.h | 16 ++++++--------- source/games/blood/src/animatesprite.cpp | 20 ++++++++++++++++++ source/games/blood/src/blood.h | 2 ++ source/games/duke/src/duke3d.h | 2 ++ source/games/duke/src/render.cpp | 10 +++++++++ source/games/sw/src/_polymost.cpp | 4 ++-- source/games/sw/src/draw.cpp | 5 +++-- source/games/sw/src/game.h | 2 ++ source/games/sw/src/jsector.cpp | 11 ++++++++++ 11 files changed, 79 insertions(+), 21 deletions(-) diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index fa5c76eee..43a5c7801 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -12,6 +12,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m class FSerializer; struct FRenderViewpoint; +struct spritetype; struct GameStats { @@ -104,6 +105,8 @@ struct GameInterface virtual int chaseCamZ(fixedhoriz horiz) { return 0; } virtual void processSprites(int viewx, int viewy, int viewz, binangle viewang, double smoothRatio) = 0; virtual void UpdateCameras(double smoothratio) {} + virtual void EnterPortal(spritetype* viewer, int type) {} + virtual void LeavePortal(spritetype* viewer, int type) {} virtual FString statFPS() { diff --git a/source/core/rendering/scene/hw_portal.cpp b/source/core/rendering/scene/hw_portal.cpp index 8f51565b9..569f02686 100644 --- a/source/core/rendering/scene/hw_portal.cpp +++ b/source/core/rendering/scene/hw_portal.cpp @@ -390,6 +390,24 @@ void HWPortal::RemoveStencil(HWDrawInfo *di, FRenderState &state, bool usestenci } +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +void HWScenePortalBase::DrawContents(HWDrawInfo* di, FRenderState& state) +{ + if (Setup(di, state, di->mClipper)) + { + gi->EnterPortal(di->Viewpoint.CameraSprite, GetType()); + di->DrawScene(DM_PORTAL); + gi->LeavePortal(di->Viewpoint.CameraSprite, GetType()); + Shutdown(di, state); + } + else state.ClearScreen(); +} + //----------------------------------------------------------------------------- // // @@ -570,13 +588,6 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe vp.TanCos = FocalTangent * an.Cos(); vp.ViewVector = an.ToVector(); - int oldstat = 0; - if (vp.CameraSprite) - { - oldstat = vp.CameraSprite->cstat; - vp.CameraSprite->cstat &= ~CSTAT_SPRITE_INVISIBLE; - } - state->MirrorFlag++; di->SetClipLine(line); di->SetupView(rstate, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, !!(state->MirrorFlag & 1), !!(state->PlaneMirrorFlag & 1)); diff --git a/source/core/rendering/scene/hw_portal.h b/source/core/rendering/scene/hw_portal.h index 3001af0c2..5ee2ff316 100644 --- a/source/core/rendering/scene/hw_portal.h +++ b/source/core/rendering/scene/hw_portal.h @@ -160,6 +160,7 @@ public: virtual bool NeedDepthBuffer() { return true; } virtual void DrawContents(HWDrawInfo *di, FRenderState &state) = 0; virtual void RenderAttached(HWDrawInfo *di) {} + virtual int GetType() { return -1; } void SetupStencil(HWDrawInfo *di, FRenderState &state, bool usestencil); void RemoveStencil(HWDrawInfo *di, FRenderState &state, bool usestencil); @@ -221,15 +222,7 @@ protected: public: void ClearClipper(HWDrawInfo *di, Clipper *clipper); virtual bool NeedDepthBuffer() { return true; } - virtual void DrawContents(HWDrawInfo *di, FRenderState &state) - { - if (Setup(di, state, di->mClipper)) - { - di->DrawScene(DM_PORTAL); - Shutdown(di, state); - } - else state.ClearScreen(); - } + virtual void DrawContents(HWDrawInfo* di, FRenderState& state); virtual bool Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clipper) = 0; virtual void Shutdown(HWDrawInfo *di, FRenderState &rstate) {} }; @@ -267,12 +260,12 @@ protected: struct HWMirrorPortal : public HWLinePortal { - protected: bool Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clipper) override; void Shutdown(HWDrawInfo *di, FRenderState &rstate) override; void * GetSource() const override { return line; } const char *GetName() override; + virtual int GetType() { return PORTAL_WALL_MIRROR; } public: @@ -291,6 +284,7 @@ protected: virtual void * GetSource() const override { return origin; } virtual const char *GetName() override; virtual walltype *ClipLine() override { return line; } + virtual int GetType() { return PORTAL_WALL_VIEW; } public: @@ -309,6 +303,7 @@ protected: virtual void* GetSource() const override { return origin; } virtual const char* GetName() override; virtual walltype* ClipLine() override { return line; } + virtual int GetType() { return PORTAL_WALL_TO_SPRITE; } public: @@ -358,6 +353,7 @@ protected: virtual void * GetSource() const { return origin; } virtual bool IsSky() { return true; } // although this isn't a real sky it can be handled as one. virtual const char *GetName(); + virtual int GetType() { return PORTAL_SECTOR_CEILING; } PortalDesc *origin; public: diff --git a/source/games/blood/src/animatesprite.cpp b/source/games/blood/src/animatesprite.cpp index 322a64ad0..fd9c94e29 100644 --- a/source/games/blood/src/animatesprite.cpp +++ b/source/games/blood/src/animatesprite.cpp @@ -892,4 +892,24 @@ void GameInterface::processSprites(int viewx, int viewy, int viewz, binangle vie viewProcessSprites(viewx, viewy, viewz, viewang.asbuild(), int(smoothRatio)); } +int display_mirror; + +void GameInterface::EnterPortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) + { + display_mirror++; + if (viewer) viewer->cstat &= ~CSTAT_SPRITE_INVISIBLE; + } +} + +void GameInterface::LeavePortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) + { + display_mirror--; + if (viewer && display_mirror == 0 && !(viewer->cstat & CSTAT_SPRITE_TRANSLUCENT)) viewer->cstat |= CSTAT_SPRITE_INVISIBLE; + } +} + END_BLD_NS diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index b16a315f6..bbdfbcbd8 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -148,6 +148,8 @@ struct GameInterface : ::GameInterface int chaseCamY(binangle ang) override { return MulScale(-Sin(ang.asbuild()), 1280, 30); } int chaseCamZ(fixedhoriz horiz) override { return FixedToInt(MulScale(horiz.asq16(), 1280, 3)) - (16 << 8); } void processSprites(int viewx, int viewy, int viewz, binangle viewang, double smoothRatio) override; + void EnterPortal(spritetype* viewer, int type) override; + void LeavePortal(spritetype* viewer, int type) override; GameStats getStats() override; }; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 368aafb60..dc5969c6c 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -67,6 +67,8 @@ struct GameInterface : public ::GameInterface int chaseCamZ(fixedhoriz horiz) { return horiz.asq16() >> 9; } void processSprites(int viewx, int viewy, int viewz, binangle viewang, double smoothRatio) override; void UpdateCameras(double smoothratio) override; + void EnterPortal(spritetype* viewer, int type) override; + void LeavePortal(spritetype* viewer, int type) override; }; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index b6905b1f6..e28cff2bf 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -134,6 +134,16 @@ void GameInterface::UpdateCameras(double smoothratio) } } +void GameInterface::EnterPortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) display_mirror++; +} + +void GameInterface::LeavePortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) display_mirror--; +} + //--------------------------------------------------------------------------- // // RRRA's drug distortion effect diff --git a/source/games/sw/src/_polymost.cpp b/source/games/sw/src/_polymost.cpp index 1bcca9888..499ff7ffa 100644 --- a/source/games/sw/src/_polymost.cpp +++ b/source/games/sw/src/_polymost.cpp @@ -317,7 +317,7 @@ void JS_DrawMirrors(PLAYERp pp, int tx, int ty, int tz, fixed_t tpq16ang, fixed // position into tposx, tposy, and tang (tposz == cposz) // Must call preparemirror before drawrooms and // completemirror after drawrooms - + display_mirror = true; renderPrepareMirror(tx, ty, tz, tpq16ang, tpq16horiz, mirror[cnt].mirrorwall, /*mirror[cnt].mirrorsector,*/ &tposx, &tposy, &tang); @@ -327,7 +327,7 @@ void JS_DrawMirrors(PLAYERp pp, int tx, int ty, int tz, fixed_t tpq16ang, fixed renderDrawMasks(); renderCompleteMirror(); // Reverse screen x-wise in this - // function + display_mirror = false; } diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 1b2527cce..ac5d8529d 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -62,6 +62,7 @@ EXTERN_CVAR(Bool, testnewrenderer) BEGIN_SW_NS +int display_mirror; static int OverlapDraw = false; extern bool QuitFlag, SpriteInfo; extern bool Voxel; @@ -753,7 +754,7 @@ analyzesprites(int viewx, int viewy, int viewz, int camang) if ((Player + screenpeek)->PlayerSprite == tu->SpriteNum) { PLAYERp pp = Player + screenpeek; - if (mirror || TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE|PF_VIEW_FROM_CAMERA)) + if (display_mirror || TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE|PF_VIEW_FROM_CAMERA)) { if (TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE)) SET(tsp->cstat, CSTAT_SPRITE_TRANSLUCENT); @@ -869,6 +870,7 @@ analyzesprites(int viewx, int viewy, int viewz, int camang) } + #if 1 tspriteptr_t get_tsprite(short SpriteNum) { @@ -1568,7 +1570,6 @@ drawscreen(PLAYERp pp, double smoothratio) { UpdateWallPortalState(); auto cstat = pp->SpriteP->cstat; - if (!TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE)) pp->SpriteP->cstat |= CSTAT_SPRITE_INVISIBLE; render_drawrooms(pp->SpriteP, { tx, ty, tz }, tsectnum, tang, thoriz, trotscrnang); pp->SpriteP->cstat = cstat; } diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 7cf22c150..ac0468e35 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -2250,6 +2250,8 @@ struct GameInterface : ::GameInterface int chaseCamZ(fixedhoriz horiz) { return horiz.asq16() >> 8; } void processSprites(int viewx, int viewy, int viewz, binangle viewang, double smoothRatio) override; void UpdateCameras(double smoothratio) override; + void EnterPortal(spritetype* viewer, int type) override; + void LeavePortal(spritetype* viewer, int type) override; GameStats getStats() override; diff --git a/source/games/sw/src/jsector.cpp b/source/games/sw/src/jsector.cpp index 533ead8a2..184a69022 100644 --- a/source/games/sw/src/jsector.cpp +++ b/source/games/sw/src/jsector.cpp @@ -739,6 +739,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz, double smoothratio) // Need to stash the parameters for later use. This is only used to find the nearest camera. static PLAYERp cam_pp; static int cam_tx, cam_ty, cam_tz; +static int oldstat; void JS_CameraParms(PLAYERp pp, int tx, int ty, int tz) { @@ -753,6 +754,16 @@ void GameInterface::UpdateCameras(double smoothratio) JS_DrawCameras(cam_pp, cam_tx, cam_ty, cam_tz, smoothratio); } +void GameInterface::EnterPortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) display_mirror++; +} + +void GameInterface::LeavePortal(spritetype* viewer, int type) +{ + if (type == PORTAL_WALL_MIRROR) display_mirror--; +} + void DoAutoSize(tspriteptr_t tspr)