From 8facd5f3f32fe63c1264b41c0fb27da3673c405f Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Mon, 16 Mar 2020 07:00:10 +0800 Subject: [PATCH] Colorize opaque decals using the bleeding actor's blood color, if the 'Shaded' keyword is omitted from the DECALDEF. --- src/playsim/a_decals.cpp | 32 ++++++++++++++++++++++++++++---- src/playsim/a_sharedglobal.h | 5 +++-- src/playsim/p_map.cpp | 4 +++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index 97a9ce5c3..a7d9afcc1 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -242,6 +242,17 @@ void DBaseDecal::SetShade (int r, int g, int b) AlphaColor = MAKEARGB(ColorMatcher.Pick (r, g, b), r, g, b); } +//---------------------------------------------------------------------------- +// +// +// +//---------------------------------------------------------------------------- + +void DBaseDecal::SetTranslation(uint32_t trans) +{ + Translation = trans; +} + //---------------------------------------------------------------------------- // // Returns the texture the decal stuck to. @@ -696,7 +707,7 @@ void DImpactDecal::Expired() // //---------------------------------------------------------------------------- -DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) +DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation) { if (cl_maxdecals > 0) { @@ -704,7 +715,7 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, if (tpl != NULL && (tpl = tpl->GetDecal()) != NULL) { - return StaticCreate (Level, tpl, pos, wall, ffloor, color); + return StaticCreate (Level, tpl, pos, wall, ffloor, color, bloodTranslation); } } return NULL; @@ -716,7 +727,7 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const char *name, // //---------------------------------------------------------------------------- -DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) +DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color, uint32_t bloodTranslation) { DImpactDecal *decal = NULL; if (tpl != NULL && cl_maxdecals > 0 && !(wall->Flags & WALLF_NOAUTODECALS)) @@ -730,7 +741,10 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTempl // apply the custom color as well. if (tpl->ShadeColor != tpl_low->ShadeColor) lowercolor=0; else lowercolor = color; - StaticCreate (Level, tpl_low, pos, wall, ffloor, lowercolor); + + uint32_t lowerTrans = (bloodTranslation != 0 ? bloodTranslation : 0); + + StaticCreate (Level, tpl_low, pos, wall, ffloor, lowercolor, lowerTrans); } decal = Level->CreateThinker(pos.Z); if (decal == NULL) @@ -750,6 +764,12 @@ DImpactDecal *DImpactDecal::StaticCreate (FLevelLocals *Level, const FDecalTempl decal->SetShade (color.r, color.g, color.b); } + // [Nash] For compatibility reasons, only do this if the 'Shaded' keyword is omitted from the base decal. + if (bloodTranslation != 0 && tpl->ShadeColor == 0) + { + decal->SetTranslation(bloodTranslation); + } + if (!cl_spreaddecals || !decal->PicNum.isValid()) { return decal; @@ -782,6 +802,10 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl decal->CheckMax(); tpl->ApplyToDecal (decal, wall); decal->AlphaColor = AlphaColor; + + // [Nash] For compatibility reasons, only do this if the 'Shaded' keyword is omitted from the base decal. + if (tpl->ShadeColor == 0) decal->SetTranslation(Translation); + decal->RenderFlags = (decal->RenderFlags & RF_DECALMASK) | (this->RenderFlags & ~RF_DECALMASK); } diff --git a/src/playsim/a_sharedglobal.h b/src/playsim/a_sharedglobal.h index 77d30acbb..9396b10a8 100644 --- a/src/playsim/a_sharedglobal.h +++ b/src/playsim/a_sharedglobal.h @@ -31,6 +31,7 @@ public: double GetRealZ (const side_t *wall) const; void SetShade (uint32_t rgb); void SetShade (int r, int g, int b); + void SetTranslation(uint32_t trans); void Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor); void GetXY (side_t *side, double &x, double &y) const; @@ -68,8 +69,8 @@ public: } void Construct(side_t *wall, const FDecalTemplate *templ); - static DImpactDecal *StaticCreate(FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0); - static DImpactDecal *StaticCreate(FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0); + static DImpactDecal *StaticCreate(FLevelLocals *Level, const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, uint32_t bloodTranslation = 0); + static DImpactDecal *StaticCreate(FLevelLocals *Level, const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0, uint32_t bloodTranslation = 0); void BeginPlay (); void Expired() override; diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index 00d47aa37..ae0eecef0 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -4967,8 +4967,10 @@ void P_TraceBleed(int damage, const DVector3 &pos, AActor *actor, DAngle angle, bloodcolor.a = 1; } + uint32_t bloodTrans = (bloodcolor != 0 ? actor->BloodTranslation : 0); + DImpactDecal::StaticCreate(actor->Level, bloodType, bleedtrace.HitPos, - bleedtrace.Line->sidedef[bleedtrace.Side], bleedtrace.ffloor, bloodcolor); + bleedtrace.Line->sidedef[bleedtrace.Side], bleedtrace.ffloor, bloodcolor, bloodTrans); } } }