Skip to content

Commit

Permalink
[World] Fix interpolation for multitile objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Jun 23, 2019
1 parent 3eb45b8 commit d4a04ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion TSOClient/tso.simantics/primitives/VMSnap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOpe
if (obj == context.Caller)
{
obj.MovedSelf = true;
if (obj is VMGameObject) obj.WorldUI?.PrepareSnapInterpolation();
if (obj is VMGameObject)
{
if (VM.UseWorld)
{
foreach (var obj2 in obj.MultitileGroup.Objects)
obj2.WorldUI.PrepareSnapInterpolation(obj.WorldUI);
}
}
}

if (operand.OriginOnly) { } //origin only. unused?
Expand Down
4 changes: 3 additions & 1 deletion TSOClient/tso.world/components/EntityComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public override Vector3 Position
}

protected int _IdleFrames;
protected EntityComponent InterpolationOwner;
protected float _IdleFramesPct;
public int IdleFrames
{
Expand All @@ -116,10 +117,11 @@ public int IdleFrames
}
public Vector3 SnapSelfPrevious;

public void PrepareSnapInterpolation()
public void PrepareSnapInterpolation(EntityComponent ent)
{
if (_Position != SnapSelfPrevious)
{
InterpolationOwner = ent;
_IdleFramesPct = 1f;
SnapSelfPrevious = _Position;
PreviousSlotOffset = null;
Expand Down
6 changes: 4 additions & 2 deletions TSOClient/tso.world/components/ObjectComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public ObjectComponent(GameObject obj) {
dgrp = new DGRPRenderer(this.DrawGroup);
dgrp.DynamicSpriteBaseID = obj.OBJ.DynamicSpriteBaseId;
dgrp.NumDynamicSprites = obj.OBJ.NumDynamicSprites;
InterpolationOwner = this;
}

public virtual DGRP DGRP
Expand Down Expand Up @@ -294,11 +295,12 @@ public override void Update(GraphicsDevice device, WorldState world)
DynamicCounter = 0; //keep windows and doors on the top floor on the dynamic layer.
}

if (IdleFrames > 0)
var idleFrames = InterpolationOwner.IdleFrames;
if (idleFrames > 0)
{
if (_IdleFramesPct > -3)
{
_IdleFramesPct -= world.FramePerDraw / IdleFrames;
_IdleFramesPct -= world.FramePerDraw / idleFrames;
_WorldDirty = true;
}
}
Expand Down

0 comments on commit d4a04ec

Please sign in to comment.