From 2acb485121e9414cb6da197b15ad4a2d27f00986 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Wed, 3 May 2017 13:47:27 -0400 Subject: [PATCH] - Added +SPRITEFLIP which reverses a sprite's left-rightness. --- src/actor.h | 1 + src/r_data/sprites.cpp | 12 ++++++++++-- src/r_data/sprites.h | 2 +- src/scripting/thingdef_data.cpp | 1 + src/swrenderer/scene/r_opaque_pass.cpp | 3 ++- src/swrenderer/things/r_sprite.cpp | 4 ++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/actor.h b/src/actor.h index ff9e27af9..17a7a6a8a 100644 --- a/src/actor.h +++ b/src/actor.h @@ -396,6 +396,7 @@ enum ActorFlag7 MF7_FORCEZERORADIUSDMG = 0x10000000, // passes zero radius damage on to P_DamageMobj, this is necessary in some cases where DoSpecialDamage gets overrideen. MF7_NOINFIGHTSPECIES = 0x20000000, // don't start infights with one's own species. MF7_FORCEINFIGHTING = 0x40000000, // overrides a map setting of 'no infighting'. + MF7_SPRITEFLIP = 0x80000000, // sprite flipped on x-axis }; // --- mobj.renderflags --- diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index aab36109a..9b2da567b 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -64,7 +64,7 @@ PalEntry OtherGameSkinPalette[256]; // //=========================================================================== -FTextureID spritedef_t::GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror) +FTextureID spritedef_t::GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror, bool flipagain) { if ((unsigned)frame >= numframes) { @@ -77,10 +77,18 @@ FTextureID spritedef_t::GetSpriteFrame(int frame, int rot, DAngle ang, bool *mir spriteframe_t *sprframe = &SpriteFrames[spriteframes + frame]; if (rot == -1) { - if (sprframe->Texture[0] == sprframe->Texture[1]) + if ((sprframe->Texture[0] == sprframe->Texture[1]) && flipagain) + { + rot = (360.0 - ang + 45.0 / 2 * 9).BAMs() >> 28; + } + else if (sprframe->Texture[0] == sprframe->Texture[1]) { rot = (ang + 45.0 / 2 * 9).BAMs() >> 28; } + else if (flipagain) + { + rot = (360.0 - ang + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; + } else { rot = (ang + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; diff --git a/src/r_data/sprites.h b/src/r_data/sprites.h index aec0a246d..37c608986 100644 --- a/src/r_data/sprites.h +++ b/src/r_data/sprites.h @@ -37,7 +37,7 @@ struct spritedef_t uint8_t numframes; uint16_t spriteframes; - FTextureID GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror); + FTextureID GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror, bool flipagain = false); }; extern TArray SpriteFrames; diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index be8726b06..0c3962c7d 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -322,6 +322,7 @@ static FFlagDef ActorFlagDefs[]= DEFINE_FLAG(MF7, FORCEZERORADIUSDMG, AActor, flags7), DEFINE_FLAG(MF7, NOINFIGHTSPECIES, AActor, flags7), DEFINE_FLAG(MF7, FORCEINFIGHTING, AActor, flags7), + DEFINE_FLAG(MF7, SPRITEFLIP, AActor, flags7), // Effect flags DEFINE_FLAG(FX, VISIBILITYPULSE, AActor, effects), diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 2ce071f2b..3d0e9a08a 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -1006,7 +1006,8 @@ namespace swrenderer auto &viewpoint = Thread->Viewport->viewpoint; DAngle sprangle = thing->GetSpriteAngle((sprite.pos - viewpoint.Pos).Angle(), viewpoint.TicFrac); bool flipX; - FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX); + + FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX, !!(thing->flags7 & MF7_SPRITEFLIP)); if (!tex.isValid()) return false; if (flipX) diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index a34902560..889430004 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -145,6 +145,10 @@ namespace swrenderer // [RH] Flip for mirrors renderflags ^= renderportal->MirrorFlags & RF_XFLIP; + // [SP] SpriteFlip + if (thing->flags7 & MF7_SPRITEFLIP) + renderflags ^= RF_XFLIP; + // calculate edges of the shape const double thingxscalemul = spriteScale.X / tex->Scale.X;