Skip to content

Commit

Permalink
Switch VisualThinker's bools to flags
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 committed Feb 25, 2024
1 parent da5bdb8 commit b323162
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
28 changes: 9 additions & 19 deletions src/playsim/p_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ int DVisualThinker::GetLightLevel(sector_t* rendersector) const
{
int lightlevel = rendersector->GetSpriteLight();

if (bAddLightLevel)
if (flags & VTF_AddLightLevel)
{
lightlevel += LightLevel;
}
Expand All @@ -1242,7 +1242,7 @@ int DVisualThinker::GetLightLevel(sector_t* rendersector) const

FVector3 DVisualThinker::InterpolatedPosition(double ticFrac) const
{
if (bDontInterpolate) return FVector3(PT.Pos);
if (flags & VTF_DontInterpolate) return FVector3(PT.Pos);

DVector3 proc = Prev + (ticFrac * (PT.Pos - Prev));
return FVector3(proc);
Expand All @@ -1251,7 +1251,7 @@ FVector3 DVisualThinker::InterpolatedPosition(double ticFrac) const

float DVisualThinker::InterpolatedRoll(double ticFrac) const
{
if (bDontInterpolate) return PT.Roll;
if (flags & VTF_DontInterpolate) return PT.Roll;

return float(PrevRoll + (PT.Roll - PrevRoll) * ticFrac);
}
Expand Down Expand Up @@ -1331,9 +1331,9 @@ int DVisualThinker::GetRenderStyle()
float DVisualThinker::GetOffset(bool y) const // Needed for the renderer.
{
if (y)
return (float)(bFlipOffsetY ? Offset.Y : -Offset.Y);
return (float)((flags & VTF_FlipOffsetY) ? Offset.Y : -Offset.Y);
else
return (float)(bFlipOffsetX ? Offset.X : -Offset.X);
return (float)((flags & VTF_FlipOffsetX) ? Offset.X : -Offset.X);
}

void DVisualThinker::Serialize(FSerializer& arc)
Expand All @@ -1354,14 +1354,9 @@ void DVisualThinker::Serialize(FSerializer& arc)
("translation", Translation)
("cursector", cursector)
("scolor", PT.color)
("flipx", bXFlip)
("flipy", bYFlip)
("dontinterpolate", bDontInterpolate)
("addlightlevel", bAddLightLevel)
("flipoffsetx", bFlipOffsetX)
("flipoffsetY", bFlipOffsetY)
("lightlevel", LightLevel)
("flags", PT.flags);
("flags", PT.flags)
("visualThinkerFlags", flags);

}

Expand All @@ -1372,7 +1367,8 @@ DEFINE_FIELD_NAMED(DVisualThinker, PT.Vel, Vel);
DEFINE_FIELD_NAMED(DVisualThinker, PT.Roll, Roll);
DEFINE_FIELD_NAMED(DVisualThinker, PT.alpha, Alpha);
DEFINE_FIELD_NAMED(DVisualThinker, PT.texture, Texture);
DEFINE_FIELD_NAMED(DVisualThinker, PT.flags, Flags);
DEFINE_FIELD_NAMED(DVisualThinker, PT.flags, ParticleFlags);
DEFINE_FIELD_NAMED(DVisualThinker, flags, VisualThinkerFlags);

DEFINE_FIELD(DVisualThinker, Prev);
DEFINE_FIELD(DVisualThinker, Scale);
Expand All @@ -1381,9 +1377,3 @@ DEFINE_FIELD(DVisualThinker, PrevRoll);
DEFINE_FIELD(DVisualThinker, Translation);
DEFINE_FIELD(DVisualThinker, LightLevel);
DEFINE_FIELD(DVisualThinker, cursector);
DEFINE_FIELD(DVisualThinker, bXFlip);
DEFINE_FIELD(DVisualThinker, bYFlip);
DEFINE_FIELD(DVisualThinker, bDontInterpolate);
DEFINE_FIELD(DVisualThinker, bAddLightLevel);
DEFINE_FIELD(DVisualThinker, bFlipOffsetX);
DEFINE_FIELD(DVisualThinker, bFlipOffsetY);
17 changes: 11 additions & 6 deletions src/playsim/p_effect_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
//
//===========================================================================

enum EVisualThinkerFlags
{
VTF_FlipOffsetX = 1 << 0,
VTF_FlipOffsetY = 1 << 1,
VTF_FlipX = 1 << 2,
VTF_FlipY = 1 << 3, // flip the sprite on the x/y axis.
VTF_DontInterpolate = 1 << 4, // disable all interpolation
VTF_AddLightLevel = 1 << 5, // adds sector light level to 'LightLevel'
};

class DVisualThinker : public DThinker
{
DECLARE_CLASS(DVisualThinker, DThinker);
Expand All @@ -25,12 +35,7 @@ class DVisualThinker : public DThinker
FTextureID AnimatedTexture;
sector_t *cursector;

bool bFlipOffsetX,
bFlipOffsetY,
bXFlip,
bYFlip, // flip the sprite on the x/y axis.
bDontInterpolate, // disable all interpolation
bAddLightLevel; // adds sector light level to 'LightLevel'
int flags;

// internal only variables
particle_t PT;
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t
? TexAnim.UpdateStandaloneAnimation(spr->PT.animData, di->Level->maptime + timefrac)
: spr->PT.texture, !custom_anim);

if (spr->bDontInterpolate)
if (spr->flags & VTF_DontInterpolate)
timefrac = 0.;

FVector3 interp = spr->InterpolatedPosition(timefrac);
Expand All @@ -1528,12 +1528,12 @@ void HWSprite::AdjustVisualThinker(HWDrawInfo* di, DVisualThinker* spr, sector_t
auto r = spi.GetSpriteRect();
r.Scale(spr->Scale.X, spr->Scale.Y);

if (spr->bXFlip)
if (spr->flags & VTF_FlipX)
{
std::swap(ul,ur);
r.left = -r.width - r.left; // mirror the sprite's x-offset
}
if (spr->bYFlip) std::swap(vt,vb);
if (spr->flags & VTF_FlipY) std::swap(vt,vb);

float viewvecX = vp.ViewVector.X;
float viewvecY = vp.ViewVector.Y;
Expand Down
10 changes: 10 additions & 0 deletions wadsrc/static/zscript/constants.zs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,4 +1492,14 @@ enum EModelFlags
MDL_MODELSAREATTACHMENTS = 1<<12, // any model index after 0 is treated as an attachment, and therefore will use the bone results of index 0
MDL_CORRECTPIXELSTRETCH = 1<<13, // ensure model does not distort with pixel stretch when pitch/roll is applied
MDL_FORCECULLBACKFACES = 1<<14,
};

enum EVisualThinkerFlags
{
VTF_FlipOffsetX = 1 << 0,
VTF_FlipOffsetY = 1 << 1,
VTF_FlipX = 1 << 2,
VTF_FlipY = 1 << 3, // flip the sprite on the x/y axis.
VTF_DontInterpolate = 1 << 4, // disable all interpolation
VTF_AddLightLevel = 1 << 5, // adds sector light level to 'LightLevel'
};
13 changes: 5 additions & 8 deletions wadsrc/static/zscript/visualthinker.zs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ Class VisualThinker : Thinker native
Alpha;
native TextureID Texture;
native TranslationID Translation;
native uint16 Flags;
native int16 LightLevel;
native bool bFlipOffsetX,
bFlipOffsetY,
bXFlip,
bYFlip,
bDontInterpolate,
bAddLightLevel;

native uint16 ParticleFlags;
native int VisualThinkerFlags;

native Color scolor;

native Sector CurSector; // can be null!
Expand All @@ -43,7 +40,7 @@ Class VisualThinker : Thinker native
p.Offset = offset;
p.SetRenderStyle(style);
p.Translation = trans;
p.Flags = flags;
p.ParticleFlags = flags;
}
return p;
}
Expand Down

0 comments on commit b323162

Please sign in to comment.