Skip to content

Commit

Permalink
optimized branch prediction in api fixed update
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoguangYang committed Dec 9, 2023
1 parent 9d4f4d7 commit c8d73bd
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Assets/Scripts/Api/ApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,30 +590,36 @@ void FixedUpdate()
return;
}

if (ApiLock.IsUnlocked && Time.timeScale != 0.0f)
if (!ApiLock.IsUnlocked || Time.timeScale == 0.0f)
{
if (FrameLimit != 0 && CurrentFrame >= FrameLimit)
return;
}

if (FrameLimit != 0)
{
if (CurrentFrame >= FrameLimit)
{
// pause and notify API
SimulatorManager.SetTimeScale(0.0f);
SendResult();
return;
}
else
{
if (FrameLimit == 0 && !API_Notified)
{
SendResult();
API_Notified = true;
}
CurrentTime += Time.fixedDeltaTime;
CurrentFrame += 1;
}
else if (!API_Notified)
{
SendResult();
API_Notified = true;
}

if (!CurrentSceneId.IsNullOrEmpty())
{
SimulatorManager.Instance.PhysicsUpdate();
}
}
CurrentTime += Time.fixedDeltaTime;
CurrentFrame += 1;

if (CurrentSceneId.IsNullOrEmpty())
{
return;
}

SimulatorManager.Instance.PhysicsUpdate();
}

public void ReceiveMessage(IPeerManager sender, DistributedMessage distributedMessage)
Expand Down

0 comments on commit c8d73bd

Please sign in to comment.