Skip to content

Commit c8d73bd

Browse files
committed
optimized branch prediction in api fixed update
1 parent 9d4f4d7 commit c8d73bd

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

Assets/Scripts/Api/ApiManager.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -590,30 +590,36 @@ void FixedUpdate()
590590
return;
591591
}
592592

593-
if (ApiLock.IsUnlocked && Time.timeScale != 0.0f)
593+
if (!ApiLock.IsUnlocked || Time.timeScale == 0.0f)
594594
{
595-
if (FrameLimit != 0 && CurrentFrame >= FrameLimit)
595+
return;
596+
}
597+
598+
if (FrameLimit != 0)
599+
{
600+
if (CurrentFrame >= FrameLimit)
596601
{
597602
// pause and notify API
598603
SimulatorManager.SetTimeScale(0.0f);
599604
SendResult();
605+
return;
600606
}
601-
else
602-
{
603-
if (FrameLimit == 0 && !API_Notified)
604-
{
605-
SendResult();
606-
API_Notified = true;
607-
}
608-
CurrentTime += Time.fixedDeltaTime;
609-
CurrentFrame += 1;
607+
}
608+
else if (!API_Notified)
609+
{
610+
SendResult();
611+
API_Notified = true;
612+
}
610613

611-
if (!CurrentSceneId.IsNullOrEmpty())
612-
{
613-
SimulatorManager.Instance.PhysicsUpdate();
614-
}
615-
}
614+
CurrentTime += Time.fixedDeltaTime;
615+
CurrentFrame += 1;
616+
617+
if (CurrentSceneId.IsNullOrEmpty())
618+
{
619+
return;
616620
}
621+
622+
SimulatorManager.Instance.PhysicsUpdate();
617623
}
618624

619625
public void ReceiveMessage(IPeerManager sender, DistributedMessage distributedMessage)

0 commit comments

Comments
 (0)