From 1eb106e2c59b0d39fc7edc04ad75a810454d2625 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Mar 2016 13:35:16 +0100 Subject: [PATCH] - floatification of some alpha parameters. --- src/g_shared/a_artifacts.cpp | 19 +++++++++---------- src/g_shared/a_artifacts.h | 4 ++-- src/r_defs.h | 2 +- src/r_draw.h | 4 ++++ src/r_things.cpp | 14 +++++++------- src/thingdef/thingdef_properties.cpp | 4 ++-- src/v_draw.cpp | 12 ++++++------ src/v_video.h | 2 +- src/win32/fb_d3d9.cpp | 2 +- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp index a09c03c3d..d66df3552 100644 --- a/src/g_shared/a_artifacts.cpp +++ b/src/g_shared/a_artifacts.cpp @@ -499,8 +499,7 @@ int APowerInvulnerable::AlterWeaponSprite (visstyle_t *vis) { if (Mode == NAME_Ghost && !(Owner->flags & MF_SHADOW)) { - double wp_alpha = MIN(0.25 + Owner->Alpha*0.75, 1.); - vis->alpha = FLOAT2FIXED(wp_alpha); + vis->Alpha = MIN(0.25f + (float)Owner->Alpha*0.75f, 1.f); } } return changed; @@ -616,7 +615,7 @@ void APowerInvisibility::DoEffect () Super::DoEffect(); // Due to potential interference with other PowerInvisibility items // the effect has to be refreshed each tic. - double ts = FIXED2DBL((Strength/100) * (special1 + 1)); + double ts = (Strength / 100) * (special1 + 1); if (ts > 1.) ts = 1.; Owner->Alpha = clamp((1. - ts), 0., 1.); @@ -698,14 +697,14 @@ int APowerInvisibility::AlterWeaponSprite (visstyle_t *vis) if (changed == 0 && EffectTics < 4*32 && !(EffectTics & 8)) { vis->RenderStyle = STYLE_Normal; - vis->alpha = OPAQUE; + vis->Alpha = 1.f; return 1; } else if (changed == 1) { // something else set the weapon sprite back to opaque but this item is still active. - fixed_t ts = (Strength/100) * (special1 + 1); if (ts > FRACUNIT) ts = FRACUNIT; - vis->alpha = clamp((OPAQUE - ts), 0, OPAQUE); + float ts = float((Strength / 100) * (special1 + 1)); + vis->Alpha = clamp<>((1.f - ts), 0.f, 1.f); switch (Mode) { case (NAME_Fuzzy): @@ -735,9 +734,9 @@ int APowerInvisibility::AlterWeaponSprite (visstyle_t *vis) } } // Handling of Strife-like cumulative invisibility powerups, the weapon itself shouldn't become invisible - if ((vis->alpha < TRANSLUC25 && special1 > 0) || (vis->alpha == 0)) + if ((vis->Alpha < 0.25f && special1 > 0) || (vis->Alpha == 0)) { - vis->alpha = clamp((OPAQUE - (Strength/100)), 0, OPAQUE); + vis->Alpha = clamp((1.f - float(Strength/100)), 0.f, 1.f); vis->colormap = SpecialColormaps[INVERSECOLORMAP].Colormap; } return -1; // This item is valid so another one shouldn't reset the translucency @@ -754,7 +753,7 @@ int APowerInvisibility::AlterWeaponSprite (visstyle_t *vis) bool APowerInvisibility::HandlePickup (AInventory *item) { - if (Mode == NAME_Cumulative && ((Strength * special1) < FRACUNIT) && item->GetClass() == GetClass()) + if (Mode == NAME_Cumulative && ((Strength * special1) < 1.) && item->GetClass() == GetClass()) { APowerup *power = static_cast(item); if (power->EffectTics == 0) @@ -1789,7 +1788,7 @@ void APowerRegeneration::DoEffect() Super::DoEffect(); if (Owner != NULL && Owner->health > 0 && (level.time & 31) == 0) { - if (P_GiveBody(Owner, Strength/FRACUNIT)) + if (P_GiveBody(Owner, int(Strength))) { S_Sound(Owner, CHAN_ITEM, "*regenerate", 1, ATTN_NORM ); } diff --git a/src/g_shared/a_artifacts.h b/src/g_shared/a_artifacts.h index 23ff347d3..747729423 100644 --- a/src/g_shared/a_artifacts.h +++ b/src/g_shared/a_artifacts.h @@ -25,7 +25,7 @@ public: int EffectTics; PalEntry BlendColor; FNameNoInit Mode; - fixed_t Strength; + double Strength; protected: virtual void InitEffect (); @@ -58,7 +58,7 @@ public: int EffectTics; // Non-0 to override the powerup's default tics PalEntry BlendColor; // Non-0 to override the powerup's default blend FNameNoInit Mode; // Meaning depends on powerup - used for Invulnerability and Invisibility - fixed_t Strength; // Meaning depends on powerup - currently used only by Invisibility + double Strength; // Meaning depends on powerup - currently used only by Invisibility }; class APowerInvulnerable : public APowerup diff --git a/src/r_defs.h b/src/r_defs.h index 0eb374c6f..5f63045ca 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1287,7 +1287,7 @@ typedef BYTE lighttable_t; // This could be wider for >8 bit display. struct visstyle_t { lighttable_t *colormap; - fixed_t alpha; + float Alpha; FRenderStyle RenderStyle; }; diff --git a/src/r_draw.h b/src/r_draw.h index 819306d2e..326ce217b 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -269,6 +269,10 @@ enum ESPSResult DoDraw1, // draw this as if r_columnmethod is 1 }; ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation, DWORD color); +inline ESPSResult R_SetPatchStyle(FRenderStyle style, float alpha, int translation, DWORD color) +{ + return R_SetPatchStyle(style, FLOAT2FIXED(alpha), translation, color); +} // Call this after finished drawing the current thing, in case its // style was STYLE_Shade diff --git a/src/r_things.cpp b/src/r_things.cpp index f0082e6c4..ac1a7725f 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -408,7 +408,7 @@ void R_DrawVisSprite (vissprite_t *vis) dc_colormap = vis->Style.colormap; - mode = R_SetPatchStyle (vis->Style.RenderStyle, vis->Style.alpha, vis->Translation, vis->FillColor); + mode = R_SetPatchStyle (vis->Style.RenderStyle, vis->Style.Alpha, vis->Translation, vis->FillColor); if (vis->Style.RenderStyle == LegacyRenderStyles[STYLE_Shaded]) { // For shaded sprites, R_SetPatchStyle sets a dc_colormap to an alpha table, but @@ -564,7 +564,7 @@ void R_DrawWallSprite(vissprite_t *spr) dc_x = x1; ESPSResult mode; - mode = R_SetPatchStyle (spr->Style.RenderStyle, spr->Style.alpha, spr->Translation, spr->FillColor); + mode = R_SetPatchStyle (spr->Style.RenderStyle, spr->Style.Alpha, spr->Translation, spr->FillColor); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap) @@ -655,7 +655,7 @@ void R_DrawVisVoxel(vissprite_t *spr, int minslabz, int maxslabz, short *cliptop // Do setup for blending. dc_colormap = spr->Style.colormap; - mode = R_SetPatchStyle(spr->Style.RenderStyle, spr->Style.alpha, spr->Translation, spr->FillColor); + mode = R_SetPatchStyle(spr->Style.RenderStyle, spr->Style.Alpha, spr->Translation, spr->FillColor); if (mode == DontDraw) { @@ -1063,7 +1063,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor vis->FillColor = thing->fillcolor; vis->Translation = thing->Translation; // [RH] thing translation table vis->FakeFlatStat = fakeside; - vis->Style.alpha = FLOAT2FIXED(thing->Alpha); + vis->Style.Alpha = float(thing->Alpha); vis->fakefloor = fakefloor; vis->fakeceiling = fakeceiling; vis->ColormapNum = 0; @@ -1204,7 +1204,7 @@ static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t f vis->FillColor = thing->fillcolor; vis->Translation = thing->Translation; vis->FakeFlatStat = 0; - vis->Style.alpha = FLOAT2FIXED(thing->Alpha); + vis->Style.Alpha = float(thing->Alpha); vis->fakefloor = NULL; vis->fakeceiling = NULL; vis->ColormapNum = 0; @@ -1388,7 +1388,7 @@ void R_DrawPSprite (pspdef_t* psp, int pspnum, AActor *owner, fixed_t sx, fixed_ noaccel = false; if (pspnum <= ps_flash) { - vis->Style.alpha = FLOAT2FIXED(owner->Alpha); + vis->Style.Alpha = float(owner->Alpha); vis->Style.RenderStyle = owner->RenderStyle; // The software renderer cannot invert the source without inverting the overlay @@ -1665,7 +1665,7 @@ void R_DrawRemainingPlayerSprites() DTA_ClipTop, viewwindowy, DTA_ClipRight, viewwindowx + viewwidth, DTA_ClipBottom, viewwindowy + viewheight, - DTA_Alpha, vis->Style.alpha, + DTA_AlphaF, vis->Style.Alpha, DTA_RenderStyle, vis->Style.RenderStyle, DTA_FillColor, vis->FillColor, DTA_SpecialColormap, special, diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 270ac19ce..49b1e24f6 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -2258,7 +2258,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, duration, I, Inventory) //========================================================================== DEFINE_CLASS_PROPERTY_PREFIX(powerup, strength, F, Inventory) { - fixed_t *pStrength; + double *pStrength; if (info->IsDescendantOf(RUNTIME_CLASS(APowerup))) { @@ -2273,7 +2273,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, strength, F, Inventory) I_Error("\"powerup.strength\" requires an actor of type \"Powerup\"\n"); return; } - PROP_FIXED_PARM(f, 0); + PROP_DOUBLE_PARM(f, 0); *pStrength = f; } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 6ae8ae4e5..8d3453fa4 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -167,7 +167,7 @@ void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, double x, double y, uint32 } fixedcolormap = dc_colormap; - ESPSResult mode = R_SetPatchStyle (parms.style, parms.alpha, 0, parms.fillcolor); + ESPSResult mode = R_SetPatchStyle (parms.style, parms.Alpha, 0, parms.fillcolor); BYTE *destorgsave = dc_destorg; dc_destorg = screen->GetBuffer(); @@ -363,7 +363,7 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag parms->destheight = parms->texheight; parms->top = img->GetScaledTopOffset(); parms->left = img->GetScaledLeftOffset(); - parms->alpha = FRACUNIT; + parms->Alpha = 1.f; parms->fillcolor = -1; parms->remap = NULL; parms->translation = NULL; @@ -531,11 +531,11 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag break; case DTA_Alpha: - parms->alpha = MIN(OPAQUE, va_arg (tags, fixed_t)); + parms->Alpha = FIXED2FLOAT(MIN(OPAQUE, va_arg (tags, fixed_t))); break; case DTA_AlphaF: - parms->alpha = FLOAT2FIXED(MIN(1., va_arg(tags, double))); + parms->Alpha = (float)(MIN(1., va_arg(tags, double))); break; case DTA_AlphaChannel: @@ -723,7 +723,7 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag { parms->style = STYLE_Shaded; } - else if (parms->alpha < OPAQUE) + else if (parms->Alpha < 1.f) { parms->style = STYLE_TranslucentStencil; } @@ -732,7 +732,7 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag parms->style = STYLE_Stencil; } } - else if (parms->alpha < OPAQUE) + else if (parms->Alpha < 1.f) { parms->style = STYLE_Translucent; } diff --git a/src/v_video.h b/src/v_video.h index 5f137937e..269641373 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -240,7 +240,7 @@ public: int rclip; double top; double left; - fixed_t alpha; + float Alpha; uint32 fillcolor; FRemapTable *remap; const BYTE *translation; diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index ec8684ad9..17c548c29 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -3535,7 +3535,7 @@ bool D3DFB::SetStyle(D3DTex *tex, DrawParms &parms, D3DCOLOR &color0, D3DCOLOR & } else { - alpha = clamp (parms.alpha, 0, FRACUNIT) / 65536.f; + alpha = clamp(parms.Alpha, 0.f, 1.f); } style.CheckFuzz();