Skip to content

Commit

Permalink
Refactor DotNet System TimeSource
Browse files Browse the repository at this point in the history
  • Loading branch information
szylis committed Jan 24, 2024
1 parent 5086832 commit 61f360e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Assets/AWSIM/Scripts/Clock/Scripts/DotNetSystemTimeSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace AWSIM
{
/// <summary>
/// A thread-safe timesource class that provides the dot net system utc time.
/// </summary>
public class DotNetSystemTimeSource : ITimeSource
{
private DateTime prevDateTime;
Expand All @@ -21,8 +24,9 @@ public void GetTime(out int seconds, out uint nanoseconds)
{
lock (lockObject)
{
TimeSpan timeSpan = DateTime.UtcNow - prevDateTime;
prevDateTime = DateTime.UtcNow;
DateTime currDateTime = DateTime.UtcNow;
TimeSpan timeSpan = currDateTime - prevDateTime;
prevDateTime = currDateTime;

time += timeSpan.TotalMilliseconds * 0.001f * TimeScaleProvider.TimeScale;
TimeUtils.TimeFromTotalSeconds(time, out seconds, out nanoseconds);
Expand Down

0 comments on commit 61f360e

Please sign in to comment.