move crucial functions out of Tick, so that light custom tick overrides can be done without calling super.Tick for non-moving visualthinkers

This commit is contained in:
Ricardo Luís Vaz Silva 2024-11-12 16:21:26 -03:00
commit d94a596bc2
3 changed files with 46 additions and 12 deletions

View file

@ -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);
@ -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();
}

View file

@ -25,6 +25,7 @@ enum EVisualThinkerFlags
class DVisualThinker : public DThinker
{
DECLARE_CLASS(DVisualThinker, DThinker);
void UpdateSector(subsector_t * newSubsector);
public:
DVector3 Prev;
DVector2 Scale,
@ -54,6 +55,7 @@ public:
void Tick() override;
void UpdateSpriteInfo();
void UpdateSector();
void Serialize(FSerializer& arc) override;
float GetOffset(bool y) const;

View file

@ -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)
{
@ -49,6 +52,8 @@ Class VisualThinker : Thinker native
p.Translation = trans;
p.Flags = flags;
p.VisualThinkerFlags = VisualThinkerFlags;
p.UpdateSector();
p.UpdateSpriteInfo();
}
return p;
}