Skip to content

Commit

Permalink
move crucial functions out of Tick, so that light custom tick overrid…
Browse files Browse the repository at this point in the history
…es can be done without calling super.Tick for non-moving visualthinkers
  • Loading branch information
RicardoLuis0 committed Nov 12, 2024
1 parent 2d0f0c8 commit b66eba6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
51 changes: 39 additions & 12 deletions src/playsim/p_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,33 @@ static DVisualThinker* SpawnVisualThinker(FLevelLocals* Level, PClass* type)
return DVisualThinker::NewVisualThinker(Level, type);
}

void DVisualThinker::UpdateSector(subsector_t * newSubsector)
{
assert(newSubsector);
if(PT.subsector != newSubsector)
{
PT.subsector = newSubsector;
cursector = newSubsector->sector;
}
}

void DVisualThinker::UpdateSector()
{
UpdateSector(Level->PointInRenderSubsector(PT.Pos));
}

static void UpdateSector(DVisualThinker * self)
{
self->UpdateSector();
}

DEFINE_ACTION_FUNCTION_NATIVE(DVisualThinker, UpdateSector, UpdateSector)
{
PARAM_SELF_PROLOGUE(DVisualThinker);
self->UpdateSector();
return 0;
}

DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, SpawnVisualThinker, SpawnVisualThinker)
{
PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
Expand Down Expand Up @@ -1092,27 +1119,27 @@ void DVisualThinker::Tick()
PT.Pos.Y = newxy.Y;
PT.Pos.Z += PT.Vel.Z;

PT.subsector = Level->PointInRenderSubsector(PT.Pos);
cursector = PT.subsector->sector;
subsector_t * ss = Level->PointInRenderSubsector(PT.Pos);

// Handle crossing a sector portal.
if (!cursector->PortalBlocksMovement(sector_t::ceiling))
if (!ss->sector->PortalBlocksMovement(sector_t::ceiling))
{
if (PT.Pos.Z > cursector->GetPortalPlaneZ(sector_t::ceiling))
if (PT.Pos.Z > ss->sector->GetPortalPlaneZ(sector_t::ceiling))
{
PT.Pos += cursector->GetPortalDisplacement(sector_t::ceiling);
PT.subsector = Level->PointInRenderSubsector(PT.Pos);
cursector = PT.subsector->sector;
PT.Pos += ss->sector->GetPortalDisplacement(sector_t::ceiling);
ss = Level->PointInRenderSubsector(PT.Pos);
}
}
else if (!cursector->PortalBlocksMovement(sector_t::floor))
else if (!ss->sector->PortalBlocksMovement(sector_t::floor))
{
if (PT.Pos.Z < cursector->GetPortalPlaneZ(sector_t::floor))
if (PT.Pos.Z < ss->sector->GetPortalPlaneZ(sector_t::floor))
{
PT.Pos += cursector->GetPortalDisplacement(sector_t::floor);
PT.subsector = Level->PointInRenderSubsector(PT.Pos);
cursector = PT.subsector->sector;
PT.Pos += ss->sector->GetPortalDisplacement(sector_t::floor);
ss = Level->PointInRenderSubsector(PT.Pos);
}
}

UpdateSector(ss);
UpdateSpriteInfo();
}

Expand Down
2 changes: 2 additions & 0 deletions src/playsim/p_visualthinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum EVisualThinkerFlags
class DVisualThinker : public DThinker
{
DECLARE_CLASS(DVisualThinker, DThinker);
void UpdateSector(subsector_t * newSubsector);
public:
DVector3 Prev;
DVector2 Scale,
Expand Down Expand Up @@ -54,6 +55,7 @@ class DVisualThinker : public DThinker

void Tick() override;
void UpdateSpriteInfo();
void UpdateSector();
void Serialize(FSerializer& arc) override;

float GetOffset(bool y) const;
Expand Down
5 changes: 5 additions & 0 deletions wadsrc/static/zscript/visualthinker.zs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Class VisualThinker : Thinker native
native void SetRenderStyle(int mode); // see ERenderStyle
native bool IsFrozen();

native protected void UpdateSector(); // needs to be called if the thinker is set to a non-ticking statnum and the position is modified (or if Tick is overriden and doesn't call Super.Tick())
native protected void UpdateSpriteInfo(); // needs to be called every time the texture is updated if the thinker uses SPF_LOCAL_ANIM and is set to a non-ticking statnum (or if Tick is overriden and doesn't call Super.Tick())

static VisualThinker Spawn(Class<VisualThinker> type, TextureID tex, Vector3 pos, Vector3 vel, double alpha = 1.0, int flags = 0,
double roll = 0.0, Vector2 scale = (1,1), Vector2 offset = (0,0), int style = STYLE_Normal, TranslationID trans = 0, int VisualThinkerFlags = 0)
{
Expand All @@ -49,6 +52,8 @@ Class VisualThinker : Thinker native
p.Translation = trans;
p.Flags = flags;
p.VisualThinkerFlags = VisualThinkerFlags;
p.UpdateSector();
p.UpdateSpriteInfo();
}
return p;
}
Expand Down

0 comments on commit b66eba6

Please sign in to comment.