Skip to content

Commit

Permalink
chore: sdk7 improve tween SBC update (#6002)
Browse files Browse the repository at this point in the history
* moved sbc check in tween component to an early stage to cover every case
* improved a couple of tests
  • Loading branch information
pravusjif authored Dec 5, 2023
1 parent 63b9155 commit 2e9345e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ private void UpdateTweenComponentModel(KeyValueSetTriplet<IParcelScene, long, EC

long entityId = tweenComponentGroup.key2;
InternalTween model = tweenComponentGroup.value.model;
scene.entities.TryGetValue(entityId, out IDCLEntity entity);

switch (model.tweenMode)
{
case PBTween.ModeOneofCase.Move:
sbcInternalComponent.SetPosition(scene, entity, model.transform.position);
break;
case PBTween.ModeOneofCase.Rotate:
case PBTween.ModeOneofCase.Scale:
sbcInternalComponent.OnTransformScaleRotationChanged(scene, entity);
break;
}

if (model.removed)
{
Expand All @@ -66,12 +78,10 @@ private void UpdateTweenComponentModel(KeyValueSetTriplet<IParcelScene, long, EC
if (currentTime.Equals(1f) && model.currentTime.Equals(1f))
return;

scene.entities.TryGetValue(entityId, out IDCLEntity entity);

if (model.playing)
{
tweenStateComponentModel.State = currentTime.Equals(1f) ? TweenStateStatus.TsCompleted : TweenStateStatus.TsActive;
UpdatePlayingTweenComponentModel(tweenStateComponentModel, currentTime, scene, entity, model);
tweenStateComponentModel.CurrentTime = currentTime;
}
else
{
Expand All @@ -86,22 +96,6 @@ private void UpdateTweenComponentModel(KeyValueSetTriplet<IParcelScene, long, EC
tweenInternalComponent.PutFor(scene, entityId, model);
}

private void UpdatePlayingTweenComponentModel(PBTweenState tweenStateComponentModel, float currentTime,
IParcelScene scene, IDCLEntity entity, InternalTween model)
{
tweenStateComponentModel.CurrentTime = currentTime;
switch (model.tweenMode)
{
case PBTween.ModeOneofCase.Move:
sbcInternalComponent.SetPosition(scene, entity, model.transform.position);
break;
case PBTween.ModeOneofCase.Rotate:
case PBTween.ModeOneofCase.Scale:
sbcInternalComponent.OnTransformScaleRotationChanged(scene, entity);
break;
}
}

private void UpdateTransformComponent(IParcelScene scene, IDCLEntity entity, Transform entityTransform, ComponentWriter writer)
{
var transformComponent = transformComponentPool.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public void UpdateTransformComponentCorrectly()
{
entity.parentId = 6966;
float currentTime = 0.666f;
float duration = 9f;
Transform entityTransform = entity.gameObject.transform;

// Stuff that the handler does
Tweener tweener = entityTransform.DOLocalMove(Vector3.up, 9);
tweener.Goto(9 * currentTime);
Tweener tweener = entityTransform.DOLocalMove(Vector3.up, duration);
internalComponents.TweenComponent.PutFor(scene, entity, new InternalTween()
{
transform = entityTransform,
Expand All @@ -115,26 +115,39 @@ public void UpdateTransformComponentCorrectly()
playing = true,
});

tweener.Goto(duration * currentTime);
systemUpdate();
outgoingMessages.Put_Called<ECSTransform>(
entity.entityId,
ComponentID.TRANSFORM,
componentModel =>
componentModel.position == entityTransform.localPosition
&& componentModel.parentId == entity.parentId
);
Vector3 midPosition = entityTransform.localPosition;

currentTime = 1f;
tweener.Goto(duration * currentTime);
systemUpdate();
outgoingMessages.Put_Called<ECSTransform>(
entity.entityId,
ComponentID.TRANSFORM,
componentModel =>
componentModel.position == entityTransform.localPosition
&& componentModel.parentId == entity.parentId
);
Assert.AreNotEqual(midPosition, entityTransform.localPosition);
}

[Test]
public void UpdateInternalSBCComponent()
{
float currentTime = 0.666f;
float duration = 9f;
Transform entityTransform = entity.gameObject.transform;

// Stuff that the handler does
Tweener tweener = entityTransform.DOLocalMove(Vector3.up, 9);
tweener.Goto(9 * currentTime);
Tweener tweener = entityTransform.DOLocalMove(Vector3.up, duration);
internalComponents.TweenComponent.PutFor(scene, entity, new InternalTween()
{
transform = entityTransform,
Expand All @@ -144,10 +157,16 @@ public void UpdateInternalSBCComponent()
playing = true,
});

tweener.Goto(duration * currentTime);
systemUpdate();

var sbcModel = internalComponents.sceneBoundsCheckComponent.GetFor(scene, entity).Value.model;
Assert.AreEqual(entityTransform.position, sbcModel.entityPosition);

currentTime = 1f;
tweener.Goto(duration * currentTime);
systemUpdate();
sbcModel = internalComponents.sceneBoundsCheckComponent.GetFor(scene, entity).Value.model;
Assert.AreEqual(entityTransform.position, sbcModel.entityPosition);
}
}
}

0 comments on commit 2e9345e

Please sign in to comment.