From 1eb106e2c59b0d39fc7edc04ad75a810454d2625 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Mar 2016 13:35:16 +0100 Subject: [PATCH 1/4] - 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(); From af427b80bda47750222d0fd01de6fcc563b4953b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Mar 2016 16:35:41 +0100 Subject: [PATCH 2/4] - did some cleanup and consolidation on damage factor code while converting it all to floating point. - made armor properties floating point. --- src/d_dehacked.cpp | 4 +- src/d_player.h | 2 +- src/g_shared/a_action.cpp | 9 +++-- src/g_shared/a_armor.cpp | 48 +++++++++-------------- src/g_shared/a_artifacts.cpp | 29 ++++++-------- src/g_shared/a_pickups.h | 10 ++--- src/g_shared/a_soundsequence.cpp | 2 +- src/g_shared/sbarinfo_commands.cpp | 19 ++++----- src/g_shared/shared_hud.cpp | 5 +-- src/gi.cpp | 2 +- src/gi.h | 2 +- src/info.cpp | 41 +++++++++++-------- src/info.h | 11 +++--- src/m_cheat.cpp | 2 +- src/p_acs.cpp | 2 +- src/thingdef/thingdef_codeptr.cpp | 8 ++-- src/thingdef/thingdef_parse.cpp | 4 +- src/thingdef/thingdef_properties.cpp | 14 +++---- wadsrc/static/actors/shared/inventory.txt | 2 +- 19 files changed, 104 insertions(+), 112 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index aee1afd46..a9188411d 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1940,13 +1940,13 @@ static int PatchMisc (int dummy) if (armor!=NULL) { armor->SaveAmount = 100 * deh.GreenAC; - armor->SavePercent = deh.GreenAC == 1 ? FRACUNIT/3 : FRACUNIT/2; + armor->SavePercent = deh.GreenAC == 1 ? 0.33335 : 0.5; } armor = static_cast (GetDefaultByName ("BlueArmor")); if (armor!=NULL) { armor->SaveAmount = 100 * deh.BlueAC; - armor->SavePercent = deh.BlueAC == 1 ? FRACUNIT/3 : FRACUNIT/2; + armor->SavePercent = deh.BlueAC == 1 ? 0.33335 : 0.5; } ABasicArmorBonus *barmor; diff --git a/src/d_player.h b/src/d_player.h index 10297159c..7a8a0944e 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -89,7 +89,7 @@ public: FString Slot[10]; FName InvulMode; FName HealingRadiusType; - fixed_t HexenArmor[5]; + double HexenArmor[5]; BYTE ColorRangeStart; // Skin color range BYTE ColorRangeEnd; FPlayerColorSetMap ColorSets; diff --git a/src/g_shared/a_action.cpp b/src/g_shared/a_action.cpp index 56c691c88..50ff5bb90 100644 --- a/src/g_shared/a_action.cpp +++ b/src/g_shared/a_action.cpp @@ -287,13 +287,14 @@ DEFINE_ACTION_FUNCTION(AActor, A_FreezeDeathChunks) // base the number of shards on the size of the dead thing, so bigger // things break up into more shards than smaller things. // An actor with _f_radius() 20 and height 64 creates ~40 chunks. - numChunks = MAX (4, (self->_f_radius()>>FRACBITS)*(self->_f_height()>>FRACBITS)/32); + numChunks = MAX(4, int(self->radius * self->Height)/32); i = (pr_freeze.Random2()) % (numChunks/4); for (i = MAX (24, numChunks + i); i >= 0; i--) { - fixed_t xo = (((pr_freeze() - 128)*self->_f_radius()) >> 7); - fixed_t yo = (((pr_freeze() - 128)*self->_f_radius()) >> 7); - fixed_t zo = (pr_freeze()*self->_f_height() / 255); + double xo = (pr_freeze() - 128)*self->radius / 128; + double yo = (pr_freeze() - 128)*self->radius / 128; + double zo = (pr_freeze()*self->Height / 255); + mo = Spawn("IceChunk", self->Vec3Offset(xo, yo, zo), ALLOW_REPLACE); if (mo) { diff --git a/src/g_shared/a_armor.cpp b/src/g_shared/a_armor.cpp index 016633eff..18ab0f0e0 100644 --- a/src/g_shared/a_armor.cpp +++ b/src/g_shared/a_armor.cpp @@ -67,8 +67,8 @@ AInventory *ABasicArmor::CreateCopy (AActor *other) { // BasicArmor that is in use is stored in the inventory as BasicArmor. // BasicArmor that is in reserve is not. - ABasicArmor *copy = Spawn (0, 0, 0, NO_REPLACE); - copy->SavePercent = SavePercent != 0 ? SavePercent : FRACUNIT/3; + ABasicArmor *copy = Spawn (); + copy->SavePercent = SavePercent != 0 ? SavePercent : 0.33335; // slightly more than 1/3 to avoid roundoff errors. copy->Amount = Amount; copy->MaxAmount = MaxAmount; copy->Icon = Icon; @@ -130,7 +130,7 @@ void ABasicArmor::AbsorbDamage (int damage, FName damageType, int &newdamage) } else { - saved = full + FixedMul (damage - full, SavePercent); + saved = full + int((damage - full) * SavePercent); if (MaxAbsorb > 0 && saved + AbsorbCount > MaxAbsorb) { saved = MAX(0, MaxAbsorb - AbsorbCount); @@ -179,15 +179,10 @@ void ABasicArmor::AbsorbDamage (int damage, FName damageType, int &newdamage) // This code is taken and adapted from APowerProtection::ModifyDamage(). // The differences include not using a default value, and of course the way // the damage factor info is obtained. - const fixed_t *pdf = NULL; DmgFactors *df = PClass::FindActor(ArmorType)->DamageFactors; - if (df != NULL && df->CountUsed() != 0) + if (df != NULL) { - pdf = df->CheckFactor(damageType); - if (pdf != NULL) - { - damage = newdamage = FixedMul(damage, *pdf); - } + damage = newdamage = df->Apply(damageType, damage); } } if (Inventory != NULL) @@ -401,7 +396,7 @@ AInventory *AHexenArmor::CreateCopy (AActor *other) // Like BasicArmor, HexenArmor is used in the inventory but not the map. // health is the slot this armor occupies. // Amount is the quantity to give (0 = normal max). - AHexenArmor *copy = Spawn (0, 0, 0, NO_REPLACE); + AHexenArmor *copy = Spawn (); copy->AddArmorToSlot (other, health, Amount); GoAwayAndDie (); return copy; @@ -452,7 +447,7 @@ bool AHexenArmor::HandlePickup (AInventory *item) bool AHexenArmor::AddArmorToSlot (AActor *actor, int slot, int amount) { APlayerPawn *ppawn; - int hits; + double hits; if (actor->player != NULL) { @@ -478,9 +473,9 @@ bool AHexenArmor::AddArmorToSlot (AActor *actor, int slot, int amount) } else { - hits = amount * 5 * FRACUNIT; - fixed_t total = Slots[0]+Slots[1]+Slots[2]+Slots[3]+Slots[4]; - fixed_t max = SlotsIncrement[0]+SlotsIncrement[1]+SlotsIncrement[2]+SlotsIncrement[3]+Slots[4]+4*5*FRACUNIT; + hits = amount * 5; + auto total = Slots[0] + Slots[1] + Slots[2] + Slots[3] + Slots[4]; + auto max = SlotsIncrement[0] + SlotsIncrement[1] + SlotsIncrement[2] + SlotsIncrement[3] + Slots[4] + 4 * 5; if (total < max) { Slots[slot] += hits; @@ -500,13 +495,13 @@ void AHexenArmor::AbsorbDamage (int damage, FName damageType, int &newdamage) { if (!DamageTypeDefinition::IgnoreArmor(damageType)) { - fixed_t savedPercent = Slots[0] + Slots[1] + Slots[2] + Slots[3] + Slots[4]; + double savedPercent = Slots[0] + Slots[1] + Slots[2] + Slots[3] + Slots[4]; if (savedPercent) { // armor absorbed some damage - if (savedPercent > 100*FRACUNIT) + if (savedPercent > 100) { - savedPercent = 100*FRACUNIT; + savedPercent = 100; } for (int i = 0; i < 4; i++) { @@ -516,15 +511,8 @@ void AHexenArmor::AbsorbDamage (int damage, FName damageType, int &newdamage) // with the dragon skin bracers. if (damage < 10000) { -#if __APPLE__ && __GNUC__ == 4 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ == 1 - // -O1 optimizer bug work around. Only needed for - // GCC 4.2.1 on OS X for 10.4/10.5 tools compatibility. - volatile fixed_t tmp = 300; - Slots[i] -= ::Scale (damage, SlotsIncrement[i], tmp); -#else - Slots[i] -= ::Scale (damage, SlotsIncrement[i], 300); -#endif - if (Slots[i] < 2*FRACUNIT) + Slots[i] -= damage * SlotsIncrement[i] / 300.; + if (Slots[i] < 2) { Slots[i] = 0; } @@ -535,10 +523,10 @@ void AHexenArmor::AbsorbDamage (int damage, FName damageType, int &newdamage) } } } - int saved = ::Scale (damage, savedPercent, 100*FRACUNIT); - if (saved > savedPercent >> (FRACBITS-1)) + int saved = int(damage * savedPercent / 100.); + if (saved > savedPercent*2) { - saved = savedPercent >> (FRACBITS-1); + saved = int(savedPercent*2); } newdamage -= saved; damage = newdamage; diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp index d66df3552..7a615b0c4 100644 --- a/src/g_shared/a_artifacts.cpp +++ b/src/g_shared/a_artifacts.cpp @@ -1630,25 +1630,20 @@ void APowerDamage::EndEffect( ) void APowerDamage::ModifyDamage(int damage, FName damageType, int &newdamage, bool passive) { - static const fixed_t def = 4*FRACUNIT; if (!passive && damage > 0) { - const fixed_t *pdf = NULL; + int newdam; DmgFactors *df = GetClass()->DamageFactors; if (df != NULL && df->CountUsed() != 0) { - pdf = df->CheckFactor(damageType); + newdam = MIN(1, df->Apply(damageType, damage));// don't allow zero damage as result of an underflow } else { - pdf = &def; - } - if (pdf != NULL) - { - damage = newdamage = FixedMul(damage, *pdf); - if (*pdf > 0 && damage == 0) damage = newdamage = 1; // don't allow zero damage as result of an underflow - if (Owner != NULL && *pdf > FRACUNIT) S_Sound(Owner, 5, ActiveSound, 1.0f, ATTN_NONE); + newdam = damage * 4; } + if (Owner != NULL && newdam > damage) S_Sound(Owner, 5, ActiveSound, 1.0f, ATTN_NONE); + newdamage = newdam; } if (Inventory != NULL) Inventory->ModifyDamage(damage, damageType, newdamage, passive); } @@ -1710,22 +1705,20 @@ void APowerProtection::EndEffect( ) void APowerProtection::ModifyDamage(int damage, FName damageType, int &newdamage, bool passive) { - static const fixed_t def = FRACUNIT/4; if (passive && damage > 0) { - const fixed_t *pdf = NULL; + int newdam; DmgFactors *df = GetClass()->DamageFactors; if (df != NULL && df->CountUsed() != 0) { - pdf = df->CheckFactor(damageType); + newdam = MIN(0, df->Apply(damageType, damage)); } - else pdf = &def; - - if (pdf != NULL) + else { - damage = newdamage = FixedMul(damage, *pdf); - if (Owner != NULL && *pdf < FRACUNIT) S_Sound(Owner, CHAN_AUTO, ActiveSound, 1.0f, ATTN_NONE); + newdam = damage / 4; } + if (Owner != NULL && newdam < damage) S_Sound(Owner, CHAN_AUTO, ActiveSound, 1.0f, ATTN_NONE); + newdamage = newdam; } if (Inventory != NULL) { diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 67ec3d8c9..158c4130d 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -456,7 +456,7 @@ public: virtual void AbsorbDamage (int damage, FName damageType, int &newdamage); int AbsorbCount; - fixed_t SavePercent; + double SavePercent; int MaxAbsorb; int MaxFullAbsorb; int BonusCount; @@ -473,7 +473,7 @@ public: virtual AInventory *CreateCopy (AActor *other); virtual bool Use (bool pickup); - fixed_t SavePercent; + double SavePercent; int MaxAbsorb; int MaxFullAbsorb; int SaveAmount; @@ -488,7 +488,7 @@ public: virtual AInventory *CreateCopy (AActor *other); virtual bool Use (bool pickup); - fixed_t SavePercent; // The default, for when you don't already have armor + double SavePercent; // The default, for when you don't already have armor int MaxSaveAmount; int MaxAbsorb; int MaxFullAbsorb; @@ -510,8 +510,8 @@ public: virtual void AbsorbDamage (int damage, FName damageType, int &newdamage); void DepleteOrDestroy(); - fixed_t Slots[5]; - fixed_t SlotsIncrement[4]; + double Slots[5]; + double SlotsIncrement[4]; protected: bool AddArmorToSlot (AActor *actor, int slot, int amount); diff --git a/src/g_shared/a_soundsequence.cpp b/src/g_shared/a_soundsequence.cpp index 50dce9871..b7ef2d25b 100644 --- a/src/g_shared/a_soundsequence.cpp +++ b/src/g_shared/a_soundsequence.cpp @@ -146,7 +146,7 @@ void ASoundSequence::PostBeginPlay () } if (master == NULL) { - master = Spawn (0, 0, 0, NO_REPLACE); + master = Spawn (); master->Sequence = SN_StartSequence (master, slot, 0); GC::WriteBarrier(master, master->Sequence); } diff --git a/src/g_shared/sbarinfo_commands.cpp b/src/g_shared/sbarinfo_commands.cpp index 1e41a624c..d46e07499 100644 --- a/src/g_shared/sbarinfo_commands.cpp +++ b/src/g_shared/sbarinfo_commands.cpp @@ -282,7 +282,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl if (harmor->Slots[armorType] > 0 && harmor->SlotsIncrement[armorType] > 0) { //combine the alpha values - alpha = FixedMul(alpha, MIN (OPAQUE, Scale(harmor->Slots[armorType], OPAQUE, harmor->SlotsIncrement[armorType]))); + alpha = int(alpha * MIN(1., harmor->Slots[armorType] / harmor->SlotsIncrement[armorType])); texture = statusBar->Images[image]; } else @@ -1377,21 +1377,21 @@ class CommandDrawNumber : public CommandDrawString case ARMORCLASS: case SAVEPERCENT: { + double add = 0; AHexenArmor *harmor = statusBar->CPlayer->mo->FindInventory(); if(harmor != NULL) { - num = harmor->Slots[0] + harmor->Slots[1] + + add = harmor->Slots[0] + harmor->Slots[1] + harmor->Slots[2] + harmor->Slots[3] + harmor->Slots[4]; } //Hexen counts basic armor also so we should too. if(statusBar->armor != NULL) { - num += FixedMul(statusBar->armor->SavePercent, 100*FRACUNIT); + add += statusBar->armor->SavePercent * 100; } if(value == ARMORCLASS) - num /= (5*FRACUNIT); - else - num >>= FRACBITS; + add /= 5; + num = int(add); break; } case GLOBALVAR: @@ -2770,18 +2770,19 @@ class CommandDrawBar : public SBarInfoCommand } case SAVEPERCENT: { + double add = 0; AHexenArmor *harmor = statusBar->CPlayer->mo->FindInventory(); if(harmor != NULL) { - value = harmor->Slots[0] + harmor->Slots[1] + + add = harmor->Slots[0] + harmor->Slots[1] + harmor->Slots[2] + harmor->Slots[3] + harmor->Slots[4]; } //Hexen counts basic armor also so we should too. if(statusBar->armor != NULL) { - value += FixedMul(statusBar->armor->SavePercent, 100*FRACUNIT); + add += statusBar->armor->SavePercent * 100; } - value >>= FRACBITS; + value = int(add); max = 100; break; } diff --git a/src/g_shared/shared_hud.cpp b/src/g_shared/shared_hud.cpp index f3eb29cb6..7a1e7da16 100644 --- a/src/g_shared/shared_hud.cpp +++ b/src/g_shared/shared_hud.cpp @@ -313,9 +313,8 @@ static void DrawArmor(ABasicArmor * barmor, AHexenArmor * harmor, int x, int y) if (harmor) { - int ac = (harmor->Slots[0] + harmor->Slots[1] + harmor->Slots[2] + harmor->Slots[3] + harmor->Slots[4]); - ac >>= FRACBITS; - ap += ac; + auto ac = (harmor->Slots[0] + harmor->Slots[1] + harmor->Slots[2] + harmor->Slots[3] + harmor->Slots[4]); + ap += int(ac); if (ac) { diff --git a/src/gi.cpp b/src/gi.cpp index 7881c0006..9ade879df 100644 --- a/src/gi.cpp +++ b/src/gi.cpp @@ -279,7 +279,7 @@ void FMapInfoParser::ParseGameInfo() if (sc.CheckToken(',')) { sc.MustGetToken(TK_FloatConst); - gameinfo.Armor2Percent = FLOAT2FIXED(sc.Float); + gameinfo.Armor2Percent = sc.Float; sc.MustGetToken(','); sc.MustGetToken(TK_StringConst); gameinfo.ArmorIcon2 = sc.String; diff --git a/src/gi.h b/src/gi.h index 07839cacd..223aee2d0 100644 --- a/src/gi.h +++ b/src/gi.h @@ -135,7 +135,7 @@ struct gameinfo_t FString ArmorIcon2; FString PauseSign; FString Endoom; - fixed_t Armor2Percent; + double Armor2Percent; FString quitSound; gameborder_t Border; double telefogheight; diff --git a/src/info.cpp b/src/info.cpp index 09e8a576b..68488e0f2 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -532,7 +532,7 @@ PClassActor *PClassActor::GetReplacee(bool lookskill) // //========================================================================== -void PClassActor::SetDamageFactor(FName type, fixed_t factor) +void PClassActor::SetDamageFactor(FName type, double factor) { if (DamageFactors == NULL) { @@ -593,16 +593,18 @@ void PClassActor::ReplaceClassRef(PClass *oldclass, PClass *newclass) // //========================================================================== -fixed_t *DmgFactors::CheckFactor(FName type) +int DmgFactors::Apply(FName type, int damage) { - fixed_t *pdf = CheckKey(type); + auto pdf = CheckKey(type); if (pdf == NULL && type != NAME_None) { pdf = CheckKey(NAME_None); } - return pdf; + if (!pdf) return damage; + return int(damage * *pdf); } + static void SummonActor (int command, int command2, FCommandLine argv) { if (CheckCheatmode ()) @@ -689,32 +691,33 @@ bool DamageTypeDefinition::IgnoreArmor(FName type) // //========================================================================== -int DamageTypeDefinition::ApplyMobjDamageFactor(int damage, FName type, DmgFactors const * const factors) +double DamageTypeDefinition::GetMobjDamageFactor(FName type, DmgFactors const * const factors) { if (factors) { // If the actor has named damage factors, look for a specific factor - fixed_t const *pdf = factors->CheckKey(type); - if (pdf) return FixedMul(damage, *pdf); // type specific damage type + + auto pdf = factors->CheckKey(type); + if (pdf) return *pdf; // type specific damage type // If this was nonspecific damage, don't fall back to nonspecific search - if (type == NAME_None) return damage; + if (type == NAME_None) return 1.; } // If this was nonspecific damage, don't fall back to nonspecific search else if (type == NAME_None) { - return damage; + return 1.; } else { // Normal is unsupplied / 1.0, so there's no difference between modifying and overriding DamageTypeDefinition *dtd = Get(type); - return dtd ? FixedMul(damage, dtd->DefaultFactor) : damage; + return dtd ? dtd->DefaultFactor : 1.; } { - fixed_t const *pdf = factors->CheckKey(NAME_None); + auto pdf = factors->CheckKey(NAME_None); DamageTypeDefinition *dtd = Get(type); // Here we are looking for modifications to untyped damage // If the calling actor defines untyped damage factor, that is contained in "pdf". @@ -722,15 +725,21 @@ int DamageTypeDefinition::ApplyMobjDamageFactor(int damage, FName type, DmgFacto { if (dtd) { - if (dtd->ReplaceFactor) return FixedMul(damage, dtd->DefaultFactor); // use default instead of untyped factor - return FixedMul(damage, FixedMul(*pdf, dtd->DefaultFactor)); // use default as modification of untyped factor + if (dtd->ReplaceFactor) return dtd->DefaultFactor; // use default instead of untyped factor + return *pdf * dtd->DefaultFactor; // use default as modification of untyped factor } - return FixedMul(damage, *pdf); // there was no default, so actor default is used + return *pdf; // there was no default, so actor default is used } else if (dtd) { - return FixedMul(damage, dtd->DefaultFactor); // implicit untyped factor 1.0 does not need to be applied/replaced explicitly + return dtd->DefaultFactor; // implicit untyped factor 1.0 does not need to be applied/replaced explicitly } } - return damage; + return 1.; +} + +int DamageTypeDefinition::ApplyMobjDamageFactor(int damage, FName type, DmgFactors const * const factors) +{ + double factor = GetMobjDamageFactor(type, factors); + return int(damage * factor); } diff --git a/src/info.h b/src/info.h index 4fb150155..d6b3f5cf1 100644 --- a/src/info.h +++ b/src/info.h @@ -158,9 +158,9 @@ FArchive &operator<< (FArchive &arc, FState *&state); #include "gametype.h" -struct DmgFactors : public TMap +struct DmgFactors : public TMap { - fixed_t *CheckFactor(FName type); + int Apply(FName type, int damage); }; typedef TMap PainChanceList; @@ -169,20 +169,21 @@ struct DamageTypeDefinition public: DamageTypeDefinition() { Clear(); } - fixed_t DefaultFactor; + double DefaultFactor; bool ReplaceFactor; bool NoArmor; void Apply(FName type); void Clear() { - DefaultFactor = FRACUNIT; + DefaultFactor = 1.; ReplaceFactor = false; NoArmor = false; } static DamageTypeDefinition *Get(FName type); static bool IgnoreArmor(FName type); + static double GetMobjDamageFactor(FName type, DmgFactors const * const factors); static int ApplyMobjDamageFactor(int damage, FName type, DmgFactors const * const factors); }; @@ -206,7 +207,7 @@ public: void BuildDefaults(); void ApplyDefaults(BYTE *defaults); void RegisterIDs(); - void SetDamageFactor(FName type, fixed_t factor); + void SetDamageFactor(FName type, double factor); void SetPainChance(FName type, int chance); size_t PropagateMark(); void InitializeNativeDefaults(); diff --git a/src/m_cheat.cpp b/src/m_cheat.cpp index 5b88b5658..c9b478161 100644 --- a/src/m_cheat.cpp +++ b/src/m_cheat.cpp @@ -715,7 +715,7 @@ void cht_Give (player_t *player, const char *name, int amount) { ABasicArmorPickup *armor = Spawn (); armor->SaveAmount = 100*deh.BlueAC; - armor->SavePercent = gameinfo.Armor2Percent > 0? gameinfo.Armor2Percent : FRACUNIT/2; + armor->SavePercent = gameinfo.Armor2Percent > 0? gameinfo.Armor2Percent : 0.5; if (!armor->CallTryPickup (player->mo)) { armor->Destroy (); diff --git a/src/p_acs.cpp b/src/p_acs.cpp index dbfe1db29..a00d87a01 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5080,7 +5080,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) return equippedarmor->MaxAmount; case ARMORINFO_SAVEPERCENT: - return equippedarmor->SavePercent; + return DoubleToACS(equippedarmor->SavePercent); case ARMORINFO_MAXABSORB: return equippedarmor->MaxAbsorb; diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 9c6cbb8c3..06be8952b 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -3317,13 +3317,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Burst) // base the number of shards on the size of the dead thing, so bigger // things break up into more shards than smaller things. // An self with _f_radius() 20 and height 64 creates ~40 chunks. - numChunks = MAX (4, int(self->radius * self->Height)); + numChunks = MAX (4, int(self->radius * self->Height)/32); i = (pr_burst.Random2()) % (numChunks/4); for (i = MAX (24, numChunks + i); i >= 0; i--) { - fixed_t xo = (((pr_burst() - 128)*self->_f_radius()) >> 7); - fixed_t yo = (((pr_burst() - 128)*self->_f_radius()) >> 7); - fixed_t zo = (pr_burst()*self->_f_height() / 255 + self->GetBobOffset()); + double xo = (pr_burst() - 128) * self->radius / 128; + double yo = (pr_burst() - 128) * self->radius / 128; + double zo = (pr_burst() * self->Height / 255); mo = Spawn(chunk, self->Vec3Offset(xo, yo, zo), ALLOW_REPLACE); if (mo) diff --git a/src/thingdef/thingdef_parse.cpp b/src/thingdef/thingdef_parse.cpp index 97e22dc8c..4d64a6eb0 100644 --- a/src/thingdef/thingdef_parse.cpp +++ b/src/thingdef/thingdef_parse.cpp @@ -1283,8 +1283,8 @@ static void ParseDamageDefinition(FScanner &sc) if (sc.Compare("FACTOR")) { sc.MustGetFloat(); - dtd.DefaultFactor = FLOAT2FIXED(sc.Float); - if (!dtd.DefaultFactor) dtd.ReplaceFactor = true; // Multiply by 0 yields 0: FixedMul(damage, FixedMul(factor, 0)) is more wasteful than FixedMul(factor, 0) + dtd.DefaultFactor = sc.Float; + if (dtd.DefaultFactor == 0) dtd.ReplaceFactor = true; // Multiply by 0 yields 0: FixedMul(damage, FixedMul(factor, 0)) is more wasteful than FixedMul(factor, 0) } else if (sc.Compare("REPLACEFACTOR")) { diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 49b1e24f6..1d92a00e5 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -254,7 +254,7 @@ void HandleDeprecatedFlags(AActor *defaults, PClassActor *info, bool set, int in defaults->Gravity = set ? 1. / 4 : 1.; break; case DEPF_FIRERESIST: - info->SetDamageFactor(NAME_Fire, set? FRACUNIT/2 : FRACUNIT); + info->SetDamageFactor(NAME_Fire, set ? 0.5 : 1.); break; // the bounce flags will set the compatibility bounce modes to remain compatible case DEPF_HERETICBOUNCE: @@ -322,8 +322,8 @@ bool CheckDeprecatedFlags(const AActor *actor, PClassActor *info, int index) case DEPF_FIRERESIST: if (info->DamageFactors) { - fixed_t *df = info->DamageFactors->CheckKey(NAME_Fire); - return df && (*df) == FRACUNIT / 2; + double *df = info->DamageFactors->CheckKey(NAME_Fire); + return df && (*df) == 0.5; } return false; @@ -1229,7 +1229,7 @@ DEFINE_PROPERTY(damagefactor, ZF, Actor) if (!stricmp(str, "Normal")) dmgType = NAME_None; else dmgType=str; - info->SetDamageFactor(dmgType, FLOAT2FIXED(id)); + info->SetDamageFactor(dmgType, id); } } @@ -1639,9 +1639,9 @@ DEFINE_CLASS_PROPERTY(saveamount, I, Armor) //========================================================================== DEFINE_CLASS_PROPERTY(savepercent, F, Armor) { - PROP_FIXED_PARM(i, 0); + PROP_DOUBLE_PARM(i, 0); - i = clamp(i, 0, 100*FRACUNIT)/100; + i = clamp(i, 0., 100.)/100.; // Special case here because this property has to work for 2 unrelated classes if (info->IsDescendantOf(RUNTIME_CLASS(ABasicArmorPickup))) { @@ -2793,7 +2793,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, hexenarmor, FFFFF, PlayerPawn) assert(info->IsKindOf(RUNTIME_CLASS(PClassPlayerPawn))); for (int i = 0; i < 5; i++) { - PROP_FIXED_PARM(val, i); + PROP_DOUBLE_PARM(val, i); static_cast(info)->HexenArmor[i] = val; } } diff --git a/wadsrc/static/actors/shared/inventory.txt b/wadsrc/static/actors/shared/inventory.txt index 0d1ea8b92..cf01cd54c 100644 --- a/wadsrc/static/actors/shared/inventory.txt +++ b/wadsrc/static/actors/shared/inventory.txt @@ -105,7 +105,7 @@ ACTOR BasicArmorBonus : Armor native +Inventory.AUTOACTIVATE +Inventory.ALWAYSPICKUP Inventory.MaxAmount 0 - Armor.SavePercent 0.333333 + Armor.SavePercent 33.335 } From 6b3c0ecbd30ee2d8f933a649e8fdcd33f64f35ca Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Mar 2016 18:06:08 +0100 Subject: [PATCH 3/4] - floatified viewheight variables and some related code. --- src/am_map.cpp | 6 ++- src/d_player.h | 10 ++--- src/fragglescript/t_cmd.cpp | 2 +- src/p_acs.cpp | 8 ++-- src/p_map.cpp | 12 +++--- src/p_mobj.cpp | 62 ++++++++++++++-------------- src/p_setup.cpp | 3 +- src/p_spec.cpp | 8 ++-- src/p_teleport.cpp | 2 +- src/p_tick.cpp | 4 +- src/p_user.cpp | 46 ++++++++++----------- src/r_defs.h | 5 +++ src/r_utility.cpp | 2 +- src/thingdef/thingdef_properties.cpp | 2 +- 14 files changed, 90 insertions(+), 82 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 7c01b2a2f..2da1dee9c 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2668,7 +2668,8 @@ void AM_drawPlayers () mline_t *arrow; int numarrowlines; - fixedvec2 pos = am_portaloverlay? players[consoleplayer].camera->GetPortalTransition(players[consoleplayer].viewheight) : (fixedvec2)players[consoleplayer].camera->_f_Pos(); + fixed_t vh = FLOAT2FIXED(players[consoleplayer].viewheight); + fixedvec2 pos = am_portaloverlay? players[consoleplayer].camera->GetPortalTransition(vh) : (fixedvec2)players[consoleplayer].camera->_f_Pos(); pt.x = pos.x >> FRACTOMAPBITS; pt.y = pos.y >> FRACTOMAPBITS; if (am_rotate == 1 || (am_rotate == 2 && viewactive)) @@ -3078,7 +3079,8 @@ void AM_Drawer () if (am_portaloverlay) { sector_t *sec; - players[consoleplayer].camera->GetPortalTransition(players[consoleplayer].viewheight, &sec); + fixed_t vh = FLOAT2FIXED(players[consoleplayer].viewheight); + players[consoleplayer].camera->GetPortalTransition(vh, &sec); MapPortalGroup = sec->PortalGroup; } else MapPortalGroup = 0; diff --git a/src/d_player.h b/src/d_player.h index 7a8a0944e..2a2c99027 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -152,7 +152,7 @@ public: double JumpZ; fixed_t GruntSpeed; fixed_t FallingScreamMinSpeed, FallingScreamMaxSpeed; - fixed_t ViewHeight; + double ViewHeight; double ForwardMove1, ForwardMove2; double SideMove1, SideMove2; FTextureID ScoreIcon; @@ -402,8 +402,8 @@ public: float DesiredFOV; // desired field of vision float FOV; // current field of vision - fixed_t viewz; // focal origin above r.z - fixed_t viewheight; // base height above floor for viewz + double viewz; // focal origin above r.z + double viewheight; // base height above floor for viewz double deltaviewheight; // squat speed. double bob; // bounded/scaled total velocity @@ -493,7 +493,7 @@ public: double crouchfactor; double crouchoffset; - fixed_t crouchviewdelta; + double crouchviewdelta; FWeaponSlots weapons; @@ -504,7 +504,7 @@ public: double GetDeltaViewHeight() const { - return FIXED2DBL((mo->ViewHeight + crouchviewdelta - viewheight) >> 3); + return (mo->ViewHeight + crouchviewdelta - viewheight) / 8; } void Uncrouch() diff --git a/src/fragglescript/t_cmd.cpp b/src/fragglescript/t_cmd.cpp index 7398558bb..c5f77776f 100644 --- a/src/fragglescript/t_cmd.cpp +++ b/src/fragglescript/t_cmd.cpp @@ -165,7 +165,7 @@ void FS_EmulateCmd(char * string) else if (sc.Compare("viewheight")) { sc.MustGetFloat(); - fixed_t playerviewheight = (fixed_t)(sc.Float*FRACUNIT); + double playerviewheight = sc.Float*FRACUNIT; for(int i=0;iIsKindOf (RUNTIME_CLASS (APlayerPawn))) { - static_cast(actor)->ViewHeight = value; + static_cast(actor)->ViewHeight = ACSToDouble(value); if (actor->player != NULL) { - actor->player->viewheight = value; + actor->player->viewheight = ACSToDouble(value); } } break; @@ -4093,7 +4093,7 @@ int DLevelScript::GetActorProperty (int tid, int property) case APROP_MeleeRange: return actor->meleerange; case APROP_ViewHeight: if (actor->IsKindOf (RUNTIME_CLASS (APlayerPawn))) { - return static_cast(actor)->ViewHeight; + return DoubleToACS(static_cast(actor)->ViewHeight); } else { @@ -4994,7 +4994,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args) { if (actor->player != NULL) { - return actor->player->mo->ViewHeight + actor->player->crouchviewdelta; + return DoubleToACS(actor->player->mo->ViewHeight + actor->player->crouchviewdelta); } else { diff --git a/src/p_map.cpp b/src/p_map.cpp index 318f2b95f..b36517507 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -2236,9 +2236,7 @@ bool P_TryMove(AActor *thing, fixed_t x, fixed_t y, // it slopes or the player's eyes are bobbing in and out. bool oldAboveFakeFloor, oldAboveFakeCeiling; - fixed_t viewheight; - - viewheight = thing->player ? thing->player->viewheight : thing->_f_height() / 2; + double _viewheight = thing->player ? thing->player->viewheight : thing->Height / 2; oldAboveFakeFloor = oldAboveFakeCeiling = false; // pacify GCC if (oldsec->heightsec) @@ -2350,7 +2348,7 @@ bool P_TryMove(AActor *thing, fixed_t x, fixed_t y, { P_TranslatePortalXY(ld, hit.x, hit.y); P_TranslatePortalZ(ld, hit.z); - players[consoleplayer].viewz += hit.z; // needs to be done here because otherwise the renderer will not catch the change. + players[consoleplayer].viewz += FIXED2DBL(hit.z); // needs to be done here because otherwise the renderer will not catch the change. P_TranslatePortalAngle(ld, hit.angle); } R_AddInterpolationPoint(hit); @@ -5868,7 +5866,7 @@ void PIT_FloorRaise(AActor *thing, FChangePosition *cpos) } if (thing->player && thing->player->mo == thing) { - thing->player->viewz += thing->_f_Z() - oldz; + thing->player->viewz += thing->Z() - FIXED2DBL(oldz); } } @@ -5920,7 +5918,7 @@ void PIT_CeilingLower(AActor *thing, FChangePosition *cpos) } if (thing->player && thing->player->mo == thing) { - thing->player->viewz += thing->_f_Z() - oldz; + thing->player->viewz += thing->Z() - FIXED2DBL(oldz); } } @@ -5962,7 +5960,7 @@ void PIT_CeilingRaise(AActor *thing, FChangePosition *cpos) } if (thing->player && thing->player->mo == thing) { - thing->player->viewz += thing->_f_Z() - oldz; + thing->player->viewz += thing->Z() - FIXED2DBL(oldz); } } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index c7090f60d..c62498c13 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -24,6 +24,7 @@ // HEADER FILES ------------------------------------------------------------ +#include #include "templates.h" #include "i_system.h" #include "m_random.h" @@ -1739,14 +1740,14 @@ bool P_SeekerMissile (AActor *actor, double thresh, double turnMax, bool precise DAngle pitch = 0.; if (!(actor->flags3 & (MF3_FLOORHUGGER|MF3_CEILINGHUGGER))) { // Need to seek vertically - fixed_t dist = MAX(1, FLOAT2FIXED(actor->Distance2D(target))); + double dist = MAX(1., actor->Distance2D(target)); // Aim at a player's eyes and at the middle of the actor for everything else. - fixed_t aimheight = target->_f_height()/2; + double aimheight = target->Height/2; if (target->IsKindOf(RUNTIME_CLASS(APlayerPawn))) { aimheight = static_cast(target)->ViewHeight; } - pitch = ANGLE2DBL(R_PointToAngle2(0, actor->_f_Z() + actor->_f_height()/2, dist, target->_f_Z() + aimheight)); + pitch = DVector2(dist, target->Z() + aimheight - actor->Center()).Angle(); } actor->Vel3DFromAngle(pitch, speed); } @@ -2335,7 +2336,7 @@ void P_ZMovement (AActor *mo, fixed_t oldfloorz) // if (mo->player && mo->player->mo == mo && mo->Z() < mo->floorz) { - mo->player->viewheight -= mo->_f_floorz() - mo->_f_Z(); + mo->player->viewheight -= mo->floorz - mo->Z(); mo->player->deltaviewheight = mo->player->GetDeltaViewHeight(); } @@ -2623,8 +2624,9 @@ void P_ZMovement (AActor *mo, fixed_t oldfloorz) P_CheckFakeFloorTriggers (mo, oldz); } -void P_CheckFakeFloorTriggers (AActor *mo, fixed_t oldz, bool oldz_has_viewheight) +void P_CheckFakeFloorTriggers (AActor *mo, fixed_t _oldz, bool oldz_has_viewheight) { + double oldz = FIXED2FLOAT(_oldz); if (mo->player && (mo->player->cheats & CF_PREDICTING)) { return; @@ -2638,9 +2640,9 @@ void P_CheckFakeFloorTriggers (AActor *mo, fixed_t oldz, bool oldz_has_viewheigh if (sec->heightsec != NULL && sec->SecActTarget != NULL) { sector_t *hs = sec->heightsec; - fixed_t waterz = hs->floorplane.ZatPoint(mo); - fixed_t newz; - fixed_t viewheight; + double waterz = hs->floorplane.ZatPointF(mo); + double newz; + double viewheight; if (mo->player != NULL) { @@ -2648,15 +2650,15 @@ void P_CheckFakeFloorTriggers (AActor *mo, fixed_t oldz, bool oldz_has_viewheigh } else { - viewheight = mo->_f_height() / 2; + viewheight = mo->Height; } - if (oldz > waterz && mo->_f_Z() <= waterz) + if (oldz > waterz && mo->Z() <= waterz) { // Feet hit fake floor sec->SecActTarget->TriggerAction (mo, SECSPAC_HitFakeFloor); } - newz = mo->_f_Z() + viewheight; + newz = mo->Z() + viewheight; if (!oldz_has_viewheight) { oldz += viewheight; @@ -2673,7 +2675,7 @@ void P_CheckFakeFloorTriggers (AActor *mo, fixed_t oldz, bool oldz_has_viewheigh if (!(hs->MoreFlags & SECF_FAKEFLOORONLY)) { - waterz = hs->ceilingplane.ZatPoint(mo); + waterz = hs->ceilingplane.ZatPointF(mo); if (oldz <= waterz && newz > waterz) { // View went above fake ceiling sec->SecActTarget->TriggerAction (mo, SECSPAC_EyesAboveC); @@ -3814,14 +3816,14 @@ void AActor::Tick () { if (player && player->mo == this) { - player->viewheight -= onmo->_f_Top() - _f_Z(); + player->viewheight -= onmo->Top() - Z(); double deltaview = player->GetDeltaViewHeight(); if (deltaview > player->deltaviewheight) { player->deltaviewheight = deltaview; } } - _f_SetZ(onmo->_f_Top()); + SetZ(onmo->Top()); } // Check for MF6_BUMPSPECIAL // By default, only players can activate things by bumping into them @@ -4023,7 +4025,7 @@ void AActor::CheckSectorTransition(sector_t *oldsec) bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash) { BYTE lastwaterlevel = waterlevel; - fixed_t fh = FIXED_MIN; + double fh = -FLT_MAX; bool reset=false; waterlevel = 0; @@ -4042,23 +4044,23 @@ bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash) const sector_t *hsec = Sector->GetHeightSec(); if (hsec != NULL) { - fh = hsec->floorplane.ZatPoint (this); + fh = hsec->floorplane.ZatPointF (this); //if (hsec->MoreFlags & SECF_UNDERWATERMASK) // also check Boom-style non-swimmable sectors { - if (_f_Z() < fh) + if (Z() < fh) { waterlevel = 1; - if (_f_Z() + _f_height()/2 < fh) + if (Center() < fh) { waterlevel = 2; - if ((player && _f_Z() + player->viewheight <= fh) || - (_f_Z() + _f_height() <= fh)) + if ((player && Z() + player->viewheight <= fh) || + (Top() <= fh)) { waterlevel = 3; } } } - else if (!(hsec->MoreFlags & SECF_FAKEFLOORONLY) && (_f_Top() > hsec->ceilingplane.ZatPoint (this))) + else if (!(hsec->MoreFlags & SECF_FAKEFLOORONLY) && (Top() > hsec->ceilingplane.ZatPointF (this))) { waterlevel = 3; } @@ -4084,20 +4086,20 @@ bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash) if (!(rover->flags & FF_EXISTS)) continue; if(!(rover->flags & FF_SWIMMABLE) || rover->flags & FF_SOLID) continue; - fixed_t ff_bottom=rover->bottom.plane->ZatPoint(this); - fixed_t ff_top=rover->top.plane->ZatPoint(this); + double ff_bottom=rover->bottom.plane->ZatPointF(this); + double ff_top=rover->top.plane->ZatPointF(this); - if(ff_top <= _f_Z() || ff_bottom > (_f_Z() + (_f_height() >> 1))) continue; + if(ff_top <= Z() || ff_bottom > (Center())) continue; fh=ff_top; - if (_f_Z() < fh) + if (Z() < fh) { waterlevel = 1; - if (_f_Z() + _f_height()/2 < fh) + if (Center() < fh) { waterlevel = 2; - if ((player && _f_Z() + player->viewheight <= fh) || - (_f_Z() + _f_height() <= fh)) + if ((player && Z() + player->viewheight <= fh) || + (Top() <= fh)) { waterlevel = 3; } @@ -4113,7 +4115,7 @@ bool AActor::UpdateWaterLevel (fixed_t oldz, bool dosplash) // the water flags. if (boomwaterlevel == 0 && waterlevel != 0 && dosplash) { - P_HitWater(this, Sector, FIXED_MIN, FIXED_MIN, fh, true); + P_HitWater(this, Sector, FIXED_MIN, FIXED_MIN, FLOAT2FIXED(fh), true); } boomwaterlevel = waterlevel; if (reset) @@ -4551,7 +4553,7 @@ void AActor::AdjustFloorClip () } if (player && player->mo == this && oldclip != Floorclip) { - player->viewheight -= FLOAT2FIXED(oldclip - Floorclip); + player->viewheight -= (oldclip - Floorclip); player->deltaviewheight = player->GetDeltaViewHeight(); } } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 45b490bf7..3c3bc91d9 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -24,6 +24,7 @@ #include +#include #ifdef _MSC_VER #include // for alloca() #endif @@ -3608,7 +3609,7 @@ void P_SetupLevel (const char *lumpname, int position) translationtables[TRANSLATION_LevelScripted].Clear(); // Initial height of PointOfView will be set by player think. - players[consoleplayer].viewz = 1; + players[consoleplayer].viewz = -FLT_MAX; // Make sure all sounds are stopped before Z_FreeTags. S_Start (); diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 3d5e07638..1f20af78a 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -2205,7 +2205,7 @@ void DPusher::Tick () sector_t *sec; AActor *thing; msecnode_t *node; - int ht; + double ht; if (!var_pushers) return; @@ -2307,8 +2307,8 @@ void DPusher::Tick () } else // special water sector { - ht = hsec->floorplane.ZatPoint(pos); - if (thing->_f_Z() > ht) // above ground + ht = hsec->floorplane.ZatPointF(pos); + if (thing->Z() > ht) // above ground { pushvel = m_PushVec; // full force } @@ -2334,7 +2334,7 @@ void DPusher::Tick () { // special water sector floor = &hsec->floorplane; } - if (thing->_f_Z() > floor->ZatPoint(pos)) + if (thing->Z() > floor->ZatPointF(pos)) { // above ground pushvel.Zero(); // no force } diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 1441ae39b..577438c20 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -168,7 +168,7 @@ bool P_Teleport (AActor *thing, fixed_t x, fixed_t y, fixed_t z, DAngle angle, i } if (player) { - player->viewz = thing->_f_Z() + player->viewheight; + player->viewz = thing->Z() + player->viewheight; if (resetpitch) { player->mo->Angles.Pitch = 0.; diff --git a/src/p_tick.cpp b/src/p_tick.cpp index 0c9550428..9aa48c147 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -21,7 +21,7 @@ // //----------------------------------------------------------------------------- - +#include #include "p_local.h" #include "p_effect.h" #include "c_console.h" @@ -57,7 +57,7 @@ bool P_CheckTickerPaused () ConsoleState == c_down || ConsoleState == c_falling) && !demoplayback && !demorecording - && players[consoleplayer].viewz != 1 + && players[consoleplayer].viewz != -FLT_MAX && wipegamestate == gamestate) { S_PauseSound (!(level.flags2 & LEVEL2_PAUSE_MUSIC_IN_MENUS), false); diff --git a/src/p_user.cpp b/src/p_user.cpp index 2409a7475..8a27c3ecb 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -1846,14 +1846,14 @@ void P_CalcHeight (player_t *player) } } - fixed_t defaultviewheight = player->mo->ViewHeight + player->crouchviewdelta; + double defaultviewheight = player->mo->ViewHeight + player->crouchviewdelta; if (player->cheats & CF_NOVELOCITY) { - player->viewz = player->mo->_f_Z() + defaultviewheight; + player->viewz = player->mo->Z() + defaultviewheight; - if (player->viewz > player->mo->_f_ceilingz()-4*FRACUNIT) - player->viewz = player->mo->_f_ceilingz()-4*FRACUNIT; + if (player->viewz > player->mo->ceilingz-4) + player->viewz = player->mo->ceilingz-4; return; } @@ -1879,16 +1879,16 @@ void P_CalcHeight (player_t *player) // move viewheight if (player->playerstate == PST_LIVE) { - player->viewheight += FLOAT2FIXED(player->deltaviewheight); + player->viewheight += player->deltaviewheight; if (player->viewheight > defaultviewheight) { player->viewheight = defaultviewheight; player->deltaviewheight = 0; } - else if (player->viewheight < (defaultviewheight>>1)) + else if (player->viewheight < (defaultviewheight/2)) { - player->viewheight = defaultviewheight>>1; + player->viewheight = defaultviewheight/2; if (player->deltaviewheight <= 0) player->deltaviewheight = 1 / 65536.; } @@ -1905,19 +1905,19 @@ void P_CalcHeight (player_t *player) { bob = 0; } - player->viewz = player->mo->_f_Z() + player->viewheight + FLOAT2FIXED(bob); + player->viewz = player->mo->Z() + player->viewheight + bob; if (player->mo->Floorclip && player->playerstate != PST_DEAD && player->mo->Z() <= player->mo->floorz) { - player->viewz -= player->mo->_f_floorclip(); + player->viewz -= player->mo->Floorclip; } - if (player->viewz > player->mo->_f_ceilingz() - 4*FRACUNIT) + if (player->viewz > player->mo->ceilingz - 4) { - player->viewz = player->mo->_f_ceilingz() - 4*FRACUNIT; + player->viewz = player->mo->ceilingz - 4; } - if (player->viewz < player->mo->_f_floorz() + 4*FRACUNIT) + if (player->viewz < player->mo->floorz + 4) { - player->viewz = player->mo->_f_floorz() + 4*FRACUNIT; + player->viewz = player->mo->floorz + 4; } } @@ -2141,7 +2141,7 @@ void P_DeathThink (player_t *player) player->onground = (player->mo->Z() <= player->mo->floorz); if (player->mo->IsKindOf (RUNTIME_CLASS(APlayerChunk))) { // Flying bloody skull or flying ice chunk - player->viewheight = 6 * FRACUNIT; + player->viewheight = 6; player->deltaviewheight = 0; if (player->onground) { @@ -2155,13 +2155,13 @@ void P_DeathThink (player_t *player) else if (!(player->mo->flags & MF_ICECORPSE)) { // Fall to ground (if not frozen) player->deltaviewheight = 0; - if (player->viewheight > 6*FRACUNIT) + if (player->viewheight > 6) { - player->viewheight -= FRACUNIT; + player->viewheight -= 1; } - if (player->viewheight < 6*FRACUNIT) + if (player->viewheight < 6) { - player->viewheight = 6*FRACUNIT; + player->viewheight = 6; } if (player->mo->Angles.Pitch < 0) { @@ -2244,14 +2244,14 @@ void P_CrouchMove(player_t * player, int direction) double defaultheight = player->mo->GetDefault()->Height; double savedheight = player->mo->Height; double crouchspeed = direction * CROUCHSPEED; - fixed_t oldheight = player->viewheight; + double oldheight = player->viewheight; player->crouchdir = (signed char) direction; player->crouchfactor += crouchspeed; // check whether the move is ok player->mo->Height = defaultheight * player->crouchfactor; - if (!P_TryMove(player->mo, player->mo->_f_X(), player->mo->_f_Y(), false, NULL)) + if (!P_TryMove(player->mo, player->mo->Pos(), false, NULL)) { player->mo->Height = savedheight; if (direction > 0) @@ -2264,11 +2264,11 @@ void P_CrouchMove(player_t * player, int direction) player->mo->Height = savedheight; player->crouchfactor = clamp(player->crouchfactor, 0.5, 1.); - player->viewheight = fixed_t(player->mo->ViewHeight * player->crouchfactor); + player->viewheight = player->mo->ViewHeight * player->crouchfactor; player->crouchviewdelta = player->viewheight - player->mo->ViewHeight; // Check for eyes going above/below fake floor due to crouching motion. - P_CheckFakeFloorTriggers(player->mo, player->mo->_f_Z() + oldheight, true); + P_CheckFakeFloorTriggers(player->mo, player->mo->_f_Z() + FLOAT2FIXED(oldheight), true); } //---------------------------------------------------------------------------- @@ -2430,7 +2430,7 @@ void P_PlayerThink (player_t *player) player->Uncrouch(); } - player->crouchoffset = -(FIXED2DBL(player->mo->ViewHeight) * (1 - player->crouchfactor)); + player->crouchoffset = -(player->mo->ViewHeight) * (1 - player->crouchfactor); // MUSINFO stuff if (player->MUSINFOtics >= 0 && player->MUSINFOactor != NULL) diff --git a/src/r_defs.h b/src/r_defs.h index 5f63045ca..241f66f61 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -258,6 +258,11 @@ struct secplane_t return FixedMul(ic, -d - DMulScale16(a, spot.x, b, spot.y)); } + double ZatPointF(const fixedvec3 &spot) const + { + return FIXED2DBL(FixedMul(ic, -d - DMulScale16(a, spot.x, b, spot.y))); + } + // Returns the value of z at (x,y) fixed_t ZatPoint (fixed_t x, fixed_t y) const { diff --git a/src/r_utility.cpp b/src/r_utility.cpp index f69427a1c..3bc2fee2e 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -985,7 +985,7 @@ void R_SetupFrame (AActor *actor) { iview->nviewx = camera->_f_X(); iview->nviewy = camera->_f_Y(); - iview->nviewz = camera->player ? camera->player->viewz : FLOAT2FIXED(camera->Z() + camera->GetCameraHeight()); + iview->nviewz = FLOAT2FIXED(camera->player ? camera->player->viewz : camera->Z() + camera->GetCameraHeight()); viewsector = camera->Sector; r_showviewer = false; } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 1d92a00e5..ebc89dc4a 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -2573,7 +2573,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, spawnclass, L, PlayerPawn) //========================================================================== DEFINE_CLASS_PROPERTY_PREFIX(player, viewheight, F, PlayerPawn) { - PROP_FIXED_PARM(z, 0); + PROP_DOUBLE_PARM(z, 0); defaults->ViewHeight = z; } From 301f5abadcc65e5f9a2db835318edb1caf6f9e82 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Mar 2016 22:07:38 +0100 Subject: [PATCH 4/4] - floatified the decal code. --- src/d_net.cpp | 3 +- src/decallib.cpp | 54 ++++++------ src/decallib.h | 4 +- src/g_shared/a_bridge.cpp | 12 +-- src/g_shared/a_camera.cpp | 5 +- src/g_shared/a_decals.cpp | 162 +++++++++++++++++----------------- src/g_shared/a_sharedglobal.h | 39 ++++---- src/p_acs.cpp | 6 +- src/p_map.cpp | 6 +- src/p_mobj.cpp | 2 +- src/r_defs.h | 15 ++++ src/r_segs.cpp | 28 +++--- 12 files changed, 178 insertions(+), 158 deletions(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index e6ad65800..1659b72ac 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2382,7 +2382,8 @@ void Net_DoCommand (int type, BYTE **stream, int player) { if (trace.HitType == TRACE_HitWall) { - DImpactDecal::StaticCreate (s, trace.HitPos, trace.Line->sidedef[trace.Side], NULL); + DVector3 hp(FIXED2DBL(trace.HitPos.x), FIXED2DBL(trace.HitPos.y), FIXED2DBL(trace.HitPos.z)); + DImpactDecal::StaticCreate (s, hp, trace.Line->sidedef[trace.Side], NULL); } } } diff --git a/src/decallib.cpp b/src/decallib.cpp index 8f6678eff..fe8de4d0a 100644 --- a/src/decallib.cpp +++ b/src/decallib.cpp @@ -52,7 +52,7 @@ FDecalLib DecalLibrary; -static fixed_t ReadScale (FScanner &sc); +static double ReadScale (FScanner &sc); static TArray DecalTranslations; // A decal group holds multiple decals and returns one randomly @@ -148,7 +148,7 @@ public: int TimeToStartDecay; int TimeToEndDecay; - fixed_t StartTrans; + double StartTrans; private: DDecalFader () {} }; @@ -186,7 +186,7 @@ struct FDecalStretcherAnim : public FDecalAnimator int StretchStart; int StretchTime; - fixed_t GoalX, GoalY; + double GoalX, GoalY; }; class DDecalStretcher : public DDecalThinker @@ -199,10 +199,10 @@ public: int TimeToStart; int TimeToStop; - fixed_t GoalX; - fixed_t StartX; - fixed_t GoalY; - fixed_t StartY; + double GoalX; + double StartX; + double GoalY; + double StartY; bool bStretchX; bool bStretchY; bool bStarted; @@ -217,7 +217,7 @@ struct FDecalSliderAnim : public FDecalAnimator int SlideStart; int SlideTime; - fixed_t /*DistX,*/ DistY; + double /*DistX,*/ DistY; }; class DDecalSlider : public DDecalThinker @@ -230,10 +230,10 @@ public: int TimeToStart; int TimeToStop; -/* fixed_t DistX; */ - fixed_t DistY; - fixed_t StartX; - fixed_t StartY; +/* double DistX; */ + double DistY; + double StartX; + double StartY; bool bStarted; private: DDecalSlider () {} @@ -453,10 +453,10 @@ void FDecalLib::ParseDecal (FScanner &sc) memset ((void *)&newdecal, 0, sizeof(newdecal)); newdecal.PicNum.SetInvalid(); - newdecal.ScaleX = newdecal.ScaleY = FRACUNIT; + newdecal.ScaleX = newdecal.ScaleY = 1.; newdecal.RenderFlags = RF_WALLSPRITE; newdecal.RenderStyle = STYLE_Normal; - newdecal.Alpha = 0x8000; + newdecal.Alpha = 1.; for (;;) { @@ -492,13 +492,13 @@ void FDecalLib::ParseDecal (FScanner &sc) case DECAL_ADD: sc.MustGetFloat (); - newdecal.Alpha = (WORD)(32768.f * sc.Float); + newdecal.Alpha = sc.Float; newdecal.RenderStyle = STYLE_Add; break; case DECAL_TRANSLUCENT: sc.MustGetFloat (); - newdecal.Alpha = (WORD)(32768.f * sc.Float); + newdecal.Alpha = sc.Float; newdecal.RenderStyle = STYLE_Translucent; break; @@ -681,7 +681,7 @@ void FDecalLib::ParseFader (FScanner &sc) void FDecalLib::ParseStretcher (FScanner &sc) { FString stretcherName; - fixed_t goalX = -1, goalY = -1; + double goalX = -1, goalY = -1; int startTime = 0, takeTime = 0; sc.MustGetString (); @@ -732,7 +732,7 @@ void FDecalLib::ParseStretcher (FScanner &sc) void FDecalLib::ParseSlider (FScanner &sc) { FString sliderName; - fixed_t distX = 0, distY = 0; + double distX = 0, distY = 0; int startTime = 0, takeTime = 0; sc.MustGetString (); @@ -773,7 +773,7 @@ void FDecalLib::ParseSlider (FScanner &sc) else if (sc.Compare ("DistY")) { sc.MustGetFloat (); - distY = (fixed_t)(sc.Float * FRACUNIT); + distY = sc.Float; } else { @@ -1046,7 +1046,7 @@ void FDecalTemplate::ApplyToDecal (DBaseDecal *decal, side_t *wall) const decal->ScaleX = ScaleX; decal->ScaleY = ScaleY; decal->PicNum = PicNum; - decal->Alpha = Alpha << 1; + decal->Alpha = Alpha; decal->RenderStyle = RenderStyle; decal->RenderFlags = (RenderFlags & ~(DECAL_RandomFlipX|DECAL_RandomFlipY)) | (decal->RenderFlags & (RF_RELMASK|RF_CLIPMASK|RF_INVISIBLE|RF_ONESIDED)); @@ -1184,7 +1184,7 @@ void DDecalFader::Tick () int distanceToEnd = TimeToEndDecay - level.maptime; int fadeDistance = TimeToEndDecay - TimeToStartDecay; - TheDecal->Alpha = Scale (StartTrans, distanceToEnd, fadeDistance); + TheDecal->Alpha = StartTrans * distanceToEnd / fadeDistance; } } @@ -1278,11 +1278,11 @@ void DDecalStretcher::Tick () int maxDistance = TimeToStop - TimeToStart; if (bStretchX) { - TheDecal->ScaleX = StartX + Scale (GoalX - StartX, distance, maxDistance); + TheDecal->ScaleX = StartX + (GoalX - StartX) * distance / maxDistance; } if (bStretchY) { - TheDecal->ScaleY = StartY + Scale (GoalY - StartY, distance, maxDistance); + TheDecal->ScaleY = StartY + (GoalY - StartY) * distance / maxDistance; } } @@ -1339,8 +1339,8 @@ void DDecalSlider::Tick () int distance = level.maptime - TimeToStart; int maxDistance = TimeToStop - TimeToStart; - /*TheDecal->LeftDistance = StartX + Scale (DistX, distance, maxDistance);*/ - TheDecal->Z = StartY + Scale (DistY, distance, maxDistance); + /*TheDecal->LeftDistance = StartX + DistX * distance / maxDistance);*/ + TheDecal->Z = StartY + DistY * distance / maxDistance; } DThinker *FDecalCombinerAnim::CreateThinker (DBaseDecal *actor, side_t *wall) const @@ -1428,8 +1428,8 @@ DThinker *FDecalColorerAnim::CreateThinker (DBaseDecal *actor, side_t *wall) con return Colorer; } -static fixed_t ReadScale (FScanner &sc) +static double ReadScale (FScanner &sc) { sc.MustGetFloat (); - return fixed_t(clamp (sc.Float * FRACUNIT, 256.0, 256.0*FRACUNIT)); + return clamp (sc.Float, 1/256.0, 256.0); } diff --git a/src/decallib.h b/src/decallib.h index 6375c90ee..5f08bdfd1 100644 --- a/src/decallib.h +++ b/src/decallib.h @@ -74,13 +74,13 @@ public: const FDecalTemplate *GetDecal () const; void ReplaceDecalRef (FDecalBase *from, FDecalBase *to); - fixed_t ScaleX, ScaleY; + double ScaleX, ScaleY; DWORD ShadeColor; DWORD Translation; FRenderStyle RenderStyle; FTextureID PicNum; WORD RenderFlags; - WORD Alpha; // same as (actor->alpha >> 1) + double Alpha; // same as actor->alpha const FDecalAnimator *Animator; const FDecalBase *LowerDecal; diff --git a/src/g_shared/a_bridge.cpp b/src/g_shared/a_bridge.cpp index e874bc58e..d8c2ccc9c 100644 --- a/src/g_shared/a_bridge.cpp +++ b/src/g_shared/a_bridge.cpp @@ -28,8 +28,8 @@ static FRandom pr_orbit ("Orbit"); 233: -30° / seconds 244: -15° / seconds This value only matters if args[2] is not zero. - args[4]: Rotation _f_radius() of bridge balls, in bridge _f_radius() %. - If 0, use Hexen default: ORBIT_RADIUS, regardless of bridge _f_radius(). + args[4]: Rotation radius of bridge balls, in bridge radius %. + If 0, use Hexen default: ORBIT_RADIUS, regardless of bridge radius. This value only matters if args[2] is not zero. */ @@ -102,17 +102,17 @@ DEFINE_ACTION_FUNCTION(AActor, A_BridgeOrbit) // Set default values // Every five tics, Hexen moved the ball 3/256th of a revolution. DAngle rotationspeed = 45./32*3/5; - int rotationradius = ORBIT_RADIUS; + double rotationradius = ORBIT_RADIUS; // If the bridge is custom, set non-default values if any. // Set angular speed; 1--128: counterclockwise rotation ~=1--180°; 129--255: clockwise rotation ~= 180--1° if (self->target->args[3] > 128) rotationspeed = 45./32 * (self->target->args[3]-256) / TICRATE; else if (self->target->args[3] > 0) rotationspeed = 45./32 * (self->target->args[3]) / TICRATE; - // Set rotation _f_radius() - if (self->target->args[4]) rotationradius = ((self->target->args[4] * self->target->_f_radius()) / 100); + // Set rotation radius + if (self->target->args[4]) rotationradius = ((self->target->args[4] * self->target->radius) / 100); self->Angles.Yaw += rotationspeed; - self->SetOrigin(self->target->Vec3Angle(rotationradius*FRACUNIT, self->Angles.Yaw, 0), true); + self->SetOrigin(self->target->Vec3Angle(rotationradius, self->Angles.Yaw, 0), true); self->floorz = self->target->floorz; self->ceilingz = self->target->ceilingz; return 0; diff --git a/src/g_shared/a_camera.cpp b/src/g_shared/a_camera.cpp index 5c2e24444..64868231b 100644 --- a/src/g_shared/a_camera.cpp +++ b/src/g_shared/a_camera.cpp @@ -173,9 +173,8 @@ void AAimingCamera::Tick () } if (MaxPitchChange != 0) { // Aim camera's pitch; use floats for precision - fixedvec2 fv3 = tracer->_f_Vec2To(this); - DVector2 vect(fv3.x, fv3.y); - double dz = _f_Z() - tracer->_f_Z() - tracer->_f_height()/2; + DVector2 vect = tracer->Vec2To(this); + double dz = Z() - tracer->Z() - tracer->Height/2; double dist = vect.Length(); DAngle desiredPitch = dist != 0.f ? VecToAngle(dist, dz) : 0.; DAngle diff = deltaangle(Angles.Pitch, desiredPitch); diff --git a/src/g_shared/a_decals.cpp b/src/g_shared/a_decals.cpp index b480deb99..154347496 100644 --- a/src/g_shared/a_decals.cpp +++ b/src/g_shared/a_decals.cpp @@ -47,8 +47,8 @@ #include "farchive.h" #include "doomdata.h" -static fixed_t DecalWidth, DecalLeft, DecalRight; -static fixed_t SpreadZ; +static double DecalWidth, DecalLeft, DecalRight; +static double SpreadZ; static const DBaseDecal *SpreadSource; static const FDecalTemplate *SpreadTemplate; static TArray SpreadStack; @@ -65,25 +65,25 @@ IMPLEMENT_CLASS (DImpactDecal) DBaseDecal::DBaseDecal () : DThinker(STAT_DECAL), - WallNext(0), WallPrev(0), LeftDistance(0), Z(0), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(OPAQUE), + WallNext(0), WallPrev(0), LeftDistance(0), Z(0), ScaleX(1.), ScaleY(1.), Alpha(1.), AlphaColor(0), Translation(0), RenderFlags(0) { RenderStyle = STYLE_None; PicNum.SetInvalid(); } -DBaseDecal::DBaseDecal (fixed_t z) +DBaseDecal::DBaseDecal (double z) : DThinker(STAT_DECAL), - WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(OPAQUE), + WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(1.), ScaleY(1.), Alpha(1.), AlphaColor(0), Translation(0), RenderFlags(0) { RenderStyle = STYLE_None; PicNum.SetInvalid(); } -DBaseDecal::DBaseDecal (int statnum, fixed_t z) +DBaseDecal::DBaseDecal (int statnum, double z) : DThinker(statnum), - WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(FRACUNIT), ScaleY(FRACUNIT), Alpha(OPAQUE), + WallNext(0), WallPrev(0), LeftDistance(0), Z(z), ScaleX(1.), ScaleY(1.), Alpha(1.), AlphaColor(0), Translation(0), RenderFlags(0) { RenderStyle = STYLE_None; @@ -92,8 +92,8 @@ DBaseDecal::DBaseDecal (int statnum, fixed_t z) DBaseDecal::DBaseDecal (const AActor *basis) : DThinker(STAT_DECAL), - WallNext(0), WallPrev(0), LeftDistance(0), Z(basis->_f_Z()), ScaleX(FLOAT2FIXED(basis->Scale.X)), ScaleY(FLOAT2FIXED(basis->Scale.Y)), - Alpha(FLOAT2FIXED(basis->Alpha)), AlphaColor(basis->fillcolor), Translation(basis->Translation), PicNum(basis->picnum), + WallNext(0), WallPrev(0), LeftDistance(0), Z(basis->Z()), ScaleX(basis->Scale.X), ScaleY(basis->Scale.Y), + Alpha(basis->Alpha), AlphaColor(basis->fillcolor), Translation(basis->Translation), PicNum(basis->picnum), RenderFlags(basis->renderflags), RenderStyle(basis->RenderStyle) { } @@ -101,7 +101,7 @@ DBaseDecal::DBaseDecal (const AActor *basis) DBaseDecal::DBaseDecal (const DBaseDecal *basis) : DThinker(STAT_DECAL), WallNext(0), WallPrev(0), LeftDistance(basis->LeftDistance), Z(basis->Z), ScaleX(basis->ScaleX), - ScaleY(basis->ScaleY), Alpha(basis->Alpha), AlphaColor(basis->AlphaColor), Translation(basis->Translation), + ScaleY(basis->ScaleY), Alpha(basis->Alpha), AlphaColor(basis->AlphaColor), Translation(basis->Translation), PicNum(basis->PicNum), RenderFlags(basis->RenderFlags), RenderStyle(basis->RenderStyle) { } @@ -174,7 +174,7 @@ void DBaseDecal::SerializeChain (FArchive &arc, DBaseDecal **first) } } -void DBaseDecal::GetXY (side_t *wall, fixed_t &ox, fixed_t &oy) const +void DBaseDecal::GetXY (side_t *wall, double &ox, double &oy) const { line_t *line = wall->linedef; vertex_t *v1, *v2; @@ -190,11 +190,11 @@ void DBaseDecal::GetXY (side_t *wall, fixed_t &ox, fixed_t &oy) const v2 = line->v1; } - fixed_t dx = v2->x - v1->x; - fixed_t dy = v2->y - v1->y; + double dx = v2->fX() - v1->fX(); + double dy = v2->fY() - v1->fY(); - ox = v1->x + MulScale30 (LeftDistance, dx); - oy = v1->y + MulScale30 (LeftDistance, dy); + ox = v1->fX() + LeftDistance * dx; + oy = v1->fY() + LeftDistance * dy; } void DBaseDecal::SetShade (DWORD rgb) @@ -209,7 +209,7 @@ void DBaseDecal::SetShade (int r, int g, int b) } // Returns the texture the decal stuck to. -FTextureID DBaseDecal::StickToWall (side_t *wall, fixed_t x, fixed_t y, F3DFloor *ffloor) +FTextureID DBaseDecal::StickToWall (side_t *wall, double x, double y, F3DFloor *ffloor) { // Stick the decal at the end of the chain so it appears on top DBaseDecal *next, **prev; @@ -250,27 +250,27 @@ FTextureID DBaseDecal::StickToWall (side_t *wall, fixed_t x, fixed_t y, F3DFloor { RenderFlags |= RF_RELMID; if (line->flags & ML_DONTPEGBOTTOM) - Z -= front->GetPlaneTexZ(sector_t::floor); + Z -= front->GetPlaneTexZF(sector_t::floor); else - Z -= front->GetPlaneTexZ(sector_t::ceiling); + Z -= front->GetPlaneTexZF(sector_t::ceiling); tex = wall->GetTexture(side_t::mid); } else if (back->floorplane.ZatPoint (x, y) >= Z) { RenderFlags |= RF_RELLOWER|RF_CLIPLOWER; if (line->flags & ML_DONTPEGBOTTOM) - Z -= front->GetPlaneTexZ(sector_t::ceiling); + Z -= front->GetPlaneTexZF(sector_t::ceiling); else - Z -= back->GetPlaneTexZ(sector_t::floor); + Z -= back->GetPlaneTexZF(sector_t::floor); tex = wall->GetTexture(side_t::bottom); } else if (back->ceilingplane.ZatPoint (x, y) <= Z) { RenderFlags |= RF_RELUPPER|RF_CLIPUPPER; if (line->flags & ML_DONTPEGTOP) - Z -= front->GetPlaneTexZ(sector_t::ceiling); + Z -= front->GetPlaneTexZF(sector_t::ceiling); else - Z -= back->GetPlaneTexZ(sector_t::ceiling); + Z -= back->GetPlaneTexZF(sector_t::ceiling); tex = wall->GetTexture(side_t::top); } else if (ffloor) // this is a 3d-floor segment - do this only if we know which one! @@ -278,9 +278,9 @@ FTextureID DBaseDecal::StickToWall (side_t *wall, fixed_t x, fixed_t y, F3DFloor Sector=ffloor->model; RenderFlags |= RF_RELMID|RF_CLIPMID; if (line->flags & ML_DONTPEGBOTTOM) - Z -= Sector->GetPlaneTexZ(sector_t::floor); + Z -= Sector->GetPlaneTexZF(sector_t::floor); else - Z -= Sector->GetPlaneTexZ(sector_t::ceiling); + Z -= Sector->GetPlaneTexZF(sector_t::ceiling); if (ffloor->flags & FF_UPPERTEXTURE) { @@ -308,7 +308,7 @@ FTextureID DBaseDecal::StickToWall (side_t *wall, fixed_t x, fixed_t y, F3DFloor return tex; } -fixed_t DBaseDecal::GetRealZ (const side_t *wall) const +double DBaseDecal::GetRealZ (const side_t *wall) const { const line_t *line = wall->linedef; const sector_t *front, *back; @@ -335,34 +335,34 @@ fixed_t DBaseDecal::GetRealZ (const side_t *wall) const case RF_RELUPPER: if (line->flags & ML_DONTPEGTOP) { - return Z + front->GetPlaneTexZ(sector_t::ceiling); + return Z + front->GetPlaneTexZF(sector_t::ceiling); } else { - return Z + back->GetPlaneTexZ(sector_t::ceiling); + return Z + back->GetPlaneTexZF(sector_t::ceiling); } case RF_RELLOWER: if (line->flags & ML_DONTPEGBOTTOM) { - return Z + front->GetPlaneTexZ(sector_t::ceiling); + return Z + front->GetPlaneTexZF(sector_t::ceiling); } else { - return Z + back->GetPlaneTexZ(sector_t::floor); + return Z + back->GetPlaneTexZF(sector_t::floor); } case RF_RELMID: if (line->flags & ML_DONTPEGBOTTOM) { - return Z + front->GetPlaneTexZ(sector_t::floor); + return Z + front->GetPlaneTexZF(sector_t::floor); } else { - return Z + front->GetPlaneTexZ(sector_t::ceiling); + return Z + front->GetPlaneTexZF(sector_t::ceiling); } } } -void DBaseDecal::CalcFracPos (side_t *wall, fixed_t x, fixed_t y) +void DBaseDecal::CalcFracPos (side_t *wall, double x, double y) { line_t *line = wall->linedef; vertex_t *v1, *v2; @@ -378,16 +378,16 @@ void DBaseDecal::CalcFracPos (side_t *wall, fixed_t x, fixed_t y) v2 = line->v1; } - fixed_t dx = v2->x - v1->x; - fixed_t dy = v2->y - v1->y; + double dx = v2->fX() - v1->fX(); + double dy = v2->fY() - v1->fY(); - if (abs(dx) > abs(dy)) + if (fabs(dx) > fabs(dy)) { - LeftDistance = SafeDivScale30 (x - v1->x, dx); + LeftDistance = (x - v1->fX()) / dx; } else if (dy != 0) { - LeftDistance = SafeDivScale30 (y - v1->y, dy); + LeftDistance = (y - v1->fY()) / dy; } else { @@ -395,26 +395,26 @@ void DBaseDecal::CalcFracPos (side_t *wall, fixed_t x, fixed_t y) } } -static void GetWallStuff (side_t *wall, vertex_t *&v1, fixed_t &ldx, fixed_t &ldy) +static void GetWallStuff (side_t *wall, vertex_t *&v1, double &ldx, double &ldy) { line_t *line = wall->linedef; if (line->sidedef[0] == wall) { v1 = line->v1; - ldx = line->dx; - ldy = line->dy; + ldx = line->Delta().X; + ldy = line->Delta().Y; } else { v1 = line->v2; - ldx = -line->dx; - ldy = -line->dy; + ldx = -line->Delta().X; + ldy = -line->Delta().Y; } } -static fixed_t Length (fixed_t dx, fixed_t dy) +static double Length (double dx, double dy) { - return (fixed_t)g_sqrt ((double)dx*(double)dx+(double)dy*(double)dy); + return DVector2(dx, dy).Length(); } static side_t *NextWall (const side_t *wall) @@ -435,25 +435,25 @@ static side_t *NextWall (const side_t *wall) return NULL; } -void DBaseDecal::SpreadLeft (fixed_t r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor) +void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor) { - fixed_t ldx, ldy; + double ldx, ldy; SpreadStack.Push (feelwall); while (r < 0 && feelwall->LeftSide != NO_SIDE) { - fixed_t startr = r; + double startr = r; - fixed_t x = v1->x; - fixed_t y = v1->y; + double x = v1->fX(); + double y = v1->fY(); feelwall = &sides[feelwall->LeftSide]; GetWallStuff (feelwall, v1, ldx, ldy); - fixed_t wallsize = Length (ldx, ldy); + double wallsize = Length (ldx, ldy); r += DecalLeft; - x += Scale (r, ldx, wallsize); - y += Scale (r, ldy, wallsize); + x += r*ldx / wallsize; + y += r*ldy / wallsize; r = wallsize + startr; SpreadSource->CloneSelf (SpreadTemplate, x, y, SpreadZ, feelwall, ffloor); SpreadStack.Push (feelwall); @@ -479,10 +479,10 @@ void DBaseDecal::SpreadLeft (fixed_t r, vertex_t *v1, side_t *feelwall, F3DFloor } } -void DBaseDecal::SpreadRight (fixed_t r, side_t *feelwall, fixed_t wallsize, F3DFloor *ffloor) +void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFloor *ffloor) { vertex_t *v1; - fixed_t x, y, ldx, ldy; + double x, y, ldx, ldy; SpreadStack.Push (feelwall); @@ -508,25 +508,25 @@ void DBaseDecal::SpreadRight (fixed_t r, side_t *feelwall, fixed_t wallsize, F3D r = DecalWidth - r + wallsize - DecalLeft; GetWallStuff (feelwall, v1, ldx, ldy); - x = v1->x; - y = v1->y; + x = v1->fX(); + y = v1->fY(); wallsize = Length (ldx, ldy); - x -= Scale (r, ldx, wallsize); - y -= Scale (r, ldy, wallsize); + x -= r*ldx / wallsize; + y -= r*ldy / wallsize; r = DecalRight - r; SpreadSource->CloneSelf (SpreadTemplate, x, y, SpreadZ, feelwall, ffloor); SpreadStack.Push (feelwall); } } -void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, fixed_t x, fixed_t y, fixed_t z, F3DFloor * ffloor) +void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor) { FTexture *tex; vertex_t *v1; - fixed_t rorg, ldx, ldy; + double rorg, ldx, ldy; GetWallStuff (wall, v1, ldx, ldy); - rorg = Length (x - v1->x, y - v1->y); + rorg = Length (x - v1->fX(), y - v1->fY()); if ((tex = TexMan[PicNum]) == NULL) { @@ -548,11 +548,11 @@ void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, fixed_t x, fix // Then try spreading right SpreadRight (rorg + DecalRight, wall, - Length (wall->linedef->dx, wall->linedef->dy), ffloor); + Length (wall->linedef->Delta().X, wall->linedef->Delta().Y), ffloor); SpreadStack.Clear (); } -DBaseDecal *DBaseDecal::CloneSelf (const FDecalTemplate *tpl, fixed_t ix, fixed_t iy, fixed_t iz, side_t *wall, F3DFloor * ffloor) const +DBaseDecal *DBaseDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const { DBaseDecal *decal = new DBaseDecal(iz); if (decal != NULL) @@ -615,12 +615,12 @@ void DImpactDecal::Serialize (FArchive &arc) } DImpactDecal::DImpactDecal () -: DBaseDecal (STAT_AUTODECAL, 0) +: DBaseDecal (STAT_AUTODECAL, 0.) { ImpactCount++; } -DImpactDecal::DImpactDecal (fixed_t z) +DImpactDecal::DImpactDecal (double z) : DBaseDecal (STAT_AUTODECAL, z) { ImpactCount++; @@ -638,7 +638,7 @@ void DImpactDecal::CheckMax () } } -DImpactDecal *DImpactDecal::StaticCreate (const char *name, const fixedvec3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) +DImpactDecal *DImpactDecal::StaticCreate (const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) { if (cl_maxdecals > 0) { @@ -652,7 +652,7 @@ DImpactDecal *DImpactDecal::StaticCreate (const char *name, const fixedvec3 &pos return NULL; } -DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const fixedvec3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) +DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color) { DImpactDecal *decal = NULL; if (tpl != NULL && cl_maxdecals > 0 && !(wall->Flags & WALLF_NOAUTODECALS)) @@ -669,13 +669,13 @@ DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const fixed StaticCreate (tpl_low, pos, wall, ffloor, lowercolor); } DImpactDecal::CheckMax(); - decal = new DImpactDecal (pos.z); + decal = new DImpactDecal (pos.Z); if (decal == NULL) { return NULL; } - if (!decal->StickToWall (wall, pos.x, pos.y, ffloor).isValid()) + if (!decal->StickToWall (wall, pos.X, pos.Y, ffloor).isValid()) { return NULL; } @@ -692,12 +692,12 @@ DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const fixed } // Spread decal to nearby walls if it does not all fit on this one - decal->Spread (tpl, wall, pos.x, pos.y, pos.z, ffloor); + decal->Spread (tpl, wall, pos.X, pos.Y, pos.Z, ffloor); } return decal; } -DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, fixed_t ix, fixed_t iy, fixed_t iz, side_t *wall, F3DFloor * ffloor) const +DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, double iy, double iz, side_t *wall, F3DFloor * ffloor) const { if (wall->Flags & WALLF_NOAUTODECALS) { @@ -758,7 +758,7 @@ CCMD (spray) Net_WriteString (argv[1]); } -DBaseDecal *ShootDecal(const FDecalTemplate *tpl, AActor *basisactor, sector_t *sec, fixed_t x, fixed_t y, fixed_t z, angle_t angle, fixed_t tracedist, bool permanent) +DBaseDecal *ShootDecal(const FDecalTemplate *tpl, AActor *basisactor, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent) { if (tpl == NULL || (tpl = tpl->GetDecal()) == NULL) { @@ -769,30 +769,28 @@ DBaseDecal *ShootDecal(const FDecalTemplate *tpl, AActor *basisactor, sector_t * DBaseDecal *decal; side_t *wall; - angle >>= ANGLETOFINESHIFT; - - Trace(x, y, z, sec, - finecosine[angle], finesine[angle], 0, - tracedist, 0, 0, NULL, trace, TRACE_NoSky); + Trace(FLOAT2FIXED(x), FLOAT2FIXED(y), FLOAT2FIXED(z), sec, + FLOAT2FIXED(angle.Cos()), FLOAT2FIXED(angle.Sin()), 0, + FLOAT2FIXED(tracedist), 0, 0, NULL, trace, TRACE_NoSky); if (trace.HitType == TRACE_HitWall) { if (permanent) { - decal = new DBaseDecal(trace.HitPos.z); + decal = new DBaseDecal(FIXED2DBL(trace.HitPos.z)); wall = trace.Line->sidedef[trace.Side]; - decal->StickToWall(wall, trace.HitPos.x, trace.HitPos.y, trace.ffloor); + decal->StickToWall(wall, FIXED2DBL(trace.HitPos.x), FIXED2DBL(trace.HitPos.y), trace.ffloor); tpl->ApplyToDecal(decal, wall); // Spread decal to nearby walls if it does not all fit on this one if (cl_spreaddecals) { - decal->Spread(tpl, wall, trace.HitPos.x, trace.HitPos.y, trace.HitPos.z, trace.ffloor); + decal->Spread(tpl, wall, FIXED2DBL(trace.HitPos.x), FIXED2DBL(trace.HitPos.y), FIXED2DBL(trace.HitPos.z), trace.ffloor); } return decal; } else { - return DImpactDecal::StaticCreate(tpl, trace.HitPos, trace.Line->sidedef[trace.Side], NULL); + return DImpactDecal::StaticCreate(tpl, DVector3(FIXED2DBL(trace.HitPos.x), FIXED2DBL(trace.HitPos.y), FIXED2DBL(trace.HitPos.z)), trace.Line->sidedef[trace.Side], NULL); } } return NULL; @@ -827,7 +825,7 @@ void ADecal::BeginPlay () // Look for a wall within 64 units behind the actor. If none can be // found, then no decal is created, and this actor is destroyed // without effectively doing anything. - if (NULL == ShootDecal(tpl, this, Sector, _f_X(), _f_Y(), _f_Z(), FLOAT2ANGLE(Angles.Yaw.Degrees) + ANGLE_180, 64*FRACUNIT, true)) + if (NULL == ShootDecal(tpl, this, Sector, X(), Y(), Z(), Angles.Yaw + 180, 64., true)) { DPrintf ("Could not find a wall to stick decal to at (%f,%f)\n", X(), Y()); } diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index ff08a04d9..a4f743460 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -8,9 +8,10 @@ class FDecalTemplate; struct vertex_t; struct side_t; struct F3DFloor; +class DBaseDecal; void P_SpawnDirt (AActor *actor, double radius); -class DBaseDecal *ShootDecal(const FDecalTemplate *tpl, AActor *basisactor, sector_t *sec, fixed_t x, fixed_t y, fixed_t z, angle_t angle, fixed_t tracedist, bool permanent); +class DBaseDecal *ShootDecal(const FDecalTemplate *tpl, AActor *basisactor, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent); class DBaseDecal : public DThinker { @@ -18,28 +19,28 @@ class DBaseDecal : public DThinker HAS_OBJECT_POINTERS public: DBaseDecal (); - DBaseDecal (fixed_t z); - DBaseDecal (int statnum, fixed_t z); + DBaseDecal(double z); + DBaseDecal(int statnum, double z); DBaseDecal (const AActor *actor); DBaseDecal (const DBaseDecal *basis); void Serialize (FArchive &arc); void Destroy (); - FTextureID StickToWall (side_t *wall, fixed_t x, fixed_t y, F3DFloor * ffloor); - fixed_t GetRealZ (const side_t *wall) const; + FTextureID StickToWall(side_t *wall, double x, double y, F3DFloor * ffloor); + double GetRealZ (const side_t *wall) const; void SetShade (DWORD rgb); void SetShade (int r, int g, int b); - void Spread (const FDecalTemplate *tpl, side_t *wall, fixed_t x, fixed_t y, fixed_t z, F3DFloor * ffloor); - void GetXY (side_t *side, fixed_t &x, fixed_t &y) const; + 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; static void SerializeChain (FArchive &arc, DBaseDecal **firstptr); DBaseDecal *WallNext, **WallPrev; - fixed_t LeftDistance; - fixed_t Z; - fixed_t ScaleX, ScaleY; - fixed_t Alpha; + double LeftDistance; + double Z; + double ScaleX, ScaleY; + double Alpha; DWORD AlphaColor; int Translation; FTextureID PicNum; @@ -48,23 +49,23 @@ public: sector_t * Sector; // required for 3D floors protected: - virtual DBaseDecal *CloneSelf (const FDecalTemplate *tpl, fixed_t x, fixed_t y, fixed_t z, side_t *wall, F3DFloor * ffloor) const; - void CalcFracPos (side_t *wall, fixed_t x, fixed_t y); + virtual DBaseDecal *CloneSelf(const FDecalTemplate *tpl, double x, double y, double z, side_t *wall, F3DFloor * ffloor) const; + void CalcFracPos(side_t *wall, double x, double y); void Remove (); - static void SpreadLeft (fixed_t r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor); - static void SpreadRight (fixed_t r, side_t *feelwall, fixed_t wallsize, F3DFloor *ffloor); + static void SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor *ffloor); + static void SpreadRight (double r, side_t *feelwall, double wallsize, F3DFloor *ffloor); }; class DImpactDecal : public DBaseDecal { DECLARE_CLASS (DImpactDecal, DBaseDecal) public: - DImpactDecal (fixed_t z); + DImpactDecal(double z); DImpactDecal (side_t *wall, const FDecalTemplate *templ); - static DImpactDecal *StaticCreate (const char *name, const fixedvec3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color=0); - static DImpactDecal *StaticCreate (const FDecalTemplate *tpl, const fixedvec3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color=0); + static DImpactDecal *StaticCreate(const char *name, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0); + static DImpactDecal *StaticCreate(const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0); void BeginPlay (); void Destroy (); @@ -73,7 +74,7 @@ public: static void SerializeTime (FArchive &arc); protected: - DBaseDecal *CloneSelf (const FDecalTemplate *tpl, fixed_t x, fixed_t y, fixed_t z, side_t *wall, F3DFloor * ffloor) const; + DBaseDecal *CloneSelf(const FDecalTemplate *tpl, double x, double y, double z, side_t *wall, F3DFloor * ffloor) const; static void CheckMax (); private: diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 8d6802eae..7a1062975 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4768,9 +4768,9 @@ static bool DoSpawnDecal(AActor *actor, const FDecalTemplate *tpl, int flags, an { angle += actor->_f_angle(); } - return NULL != ShootDecal(tpl, actor, actor->Sector, actor->_f_X(), actor->_f_Y(), - actor->_f_Z() + (actor->_f_height()>>1) - actor->_f_floorclip() + actor->GetBobOffset() + zofs, - angle, distance, !!(flags & SDF_PERMANENT)); + return NULL != ShootDecal(tpl, actor, actor->Sector, actor->X(), actor->Y(), + actor->Center() - actor->Floorclip + actor->GetBobOffset() + FIXED2DBL(zofs), + DAngle(ANGLE2DBL(angle)), FIXED2DBL(distance), !!(flags & SDF_PERMANENT)); } static void SetActorAngle(AActor *activator, int tid, int angle, bool interpolate) diff --git a/src/p_map.cpp b/src/p_map.cpp index b36517507..7e6902697 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -4540,7 +4540,8 @@ void P_TraceBleed(int damage, fixed_t x, fixed_t y, fixed_t z, AActor *actor, an bloodcolor.a = 1; } - DImpactDecal::StaticCreate(bloodType, bleedtrace.HitPos, + DVector3 hp(FIXED2DBL(bleedtrace.HitPos.x), FIXED2DBL(bleedtrace.HitPos.y), FIXED2DBL(bleedtrace.HitPos.z)); + DImpactDecal::StaticCreate(bloodType, hp, bleedtrace.Line->sidedef[bleedtrace.Side], bleedtrace.ffloor, bloodcolor); } } @@ -6418,8 +6419,9 @@ void SpawnShootDecal(AActor *t1, const FTraceResults &trace) } if (decalbase != NULL) { + DVector3 hp(FIXED2DBL(trace.HitPos.x), FIXED2DBL(trace.HitPos.y), FIXED2DBL(trace.HitPos.z)); DImpactDecal::StaticCreate(decalbase->GetDecal(), - trace.HitPos, trace.Line->sidedef[trace.Side], trace.ffloor); + hp, trace.Line->sidedef[trace.Side], trace.ffloor); } } diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index c62498c13..6c3e0adef 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1445,7 +1445,7 @@ void P_ExplodeMissile (AActor *mo, line_t *line, AActor *target) } } - DImpactDecal::StaticCreate(base->GetDecal(), { x, y, z }, line->sidedef[side], ffloor); + DImpactDecal::StaticCreate(base->GetDecal(), DVector3(FIXED2DBL(x), FIXED2DBL(y), FIXED2DBL(z)), line->sidedef[side], ffloor); } } } diff --git a/src/r_defs.h b/src/r_defs.h index 241f66f61..01150afd0 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -95,6 +95,16 @@ struct vertex_t { fixed_t x, y; + double fX() const + { + return FIXED2DBL(x); + } + + double fY() const + { + return FIXED2DBL(y); + } + bool operator== (const vertex_t &other) { return x == other.x && y == other.y; @@ -724,6 +734,11 @@ struct sector_t return planes[pos].TexZ; } + double GetPlaneTexZF(int pos) const + { + return FIXED2DBL(planes[pos].TexZ); + } + void SetPlaneTexZ(int pos, fixed_t val) { planes[pos].TexZ = val; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8d2c3767b..d31c233d5 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -3022,7 +3022,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, fixed_t xscale, yscale; fixed_t topoff; BYTE flipx; - fixed_t zpos; + double zpos; int needrepeat = 0; sector_t *front, *back; bool calclighting; @@ -3044,36 +3044,36 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, case RF_RELUPPER: if (curline->linedef->flags & ML_DONTPEGTOP) { - zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling); + zpos = decal->Z + front->GetPlaneTexZF(sector_t::ceiling); } else { - zpos = decal->Z + back->GetPlaneTexZ(sector_t::ceiling); + zpos = decal->Z + back->GetPlaneTexZF(sector_t::ceiling); } break; case RF_RELLOWER: if (curline->linedef->flags & ML_DONTPEGBOTTOM) { - zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling); + zpos = decal->Z + front->GetPlaneTexZF(sector_t::ceiling); } else { - zpos = decal->Z + back->GetPlaneTexZ(sector_t::floor); + zpos = decal->Z + back->GetPlaneTexZF(sector_t::floor); } break; case RF_RELMID: if (curline->linedef->flags & ML_DONTPEGBOTTOM) { - zpos = decal->Z + front->GetPlaneTexZ(sector_t::floor); + zpos = decal->Z + front->GetPlaneTexZF(sector_t::floor); } else { - zpos = decal->Z + front->GetPlaneTexZ(sector_t::ceiling); + zpos = decal->Z + front->GetPlaneTexZF(sector_t::ceiling); } } - xscale = decal->ScaleX; - yscale = decal->ScaleY; + xscale = FLOAT2FIXED(decal->ScaleX); + yscale = FLOAT2FIXED(decal->ScaleY); WallSpriteTile = TexMan(decal->PicNum, true); flipx = (BYTE)(decal->RenderFlags & RF_XFLIP); @@ -3096,7 +3096,10 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, x1 *= xscale; x2 *= xscale; - decal->GetXY (wall, decalx, decaly); + double dcx, dcy; + decal->GetXY(wall, dcx, dcy); + decalx = FLOAT2FIXED(dcx); + decaly = FLOAT2FIXED(dcy); angle_t ang = R_PointToAngle2 (curline->v1->x, curline->v1->y, curline->v2->x, curline->v2->y) >> ANGLETOFINESHIFT; lx = decalx - FixedMul (x1, finecosine[ang]) - viewx; @@ -3169,8 +3172,9 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, break; } + fixed_t fzpos = FLOAT2FIXED(zpos); topoff = WallSpriteTile->TopOffset << FRACBITS; - dc_texturemid = topoff + FixedDiv (zpos - viewz, yscale); + dc_texturemid = topoff + FixedDiv (fzpos - viewz, yscale); // Clip sprite to drawseg x1 = MAX(clipper->x1, x1); @@ -3235,7 +3239,7 @@ static void R_RenderDecal (side_t *wall, DBaseDecal *decal, drawseg_t *clipper, dc_x = x1; ESPSResult mode; - mode = R_SetPatchStyle (decal->RenderStyle, decal->Alpha, decal->Translation, decal->AlphaColor); + mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor); // R_SetPatchStyle can modify basecolormap. if (rereadcolormap)