Skip to content

Commit

Permalink
When server is physics warping, just set rate to 1x and live with the…
Browse files Browse the repository at this point in the history
… jitteryness. Fixes #1
  • Loading branch information
DanielKinsman committed Apr 16, 2014
1 parent 917d616 commit 3371602
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client/flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ public static void UpdateTime(comms.Time timeUpdate)
if(Math.Abs(Planetarium.GetUniversalTime() - timeUpdate.UniversalTime) > maxTimeDelta)
Planetarium.SetUniversalTime(timeUpdate.UniversalTime);

if(timeUpdate.TimeWarpRate > 1.0f && timeUpdate.TimeWarpRate <= 4.0f)
{
// Server most likely physics warping. We can't do that, so just set it to 1x.
if(TimeWarp.CurrentRateIndex != 0)
TimeWarp.SetRate(0, false);
return;
}

if(TimeWarp.CurrentRateIndex != timeUpdate.TimeWarpRateIndex)
TimeWarp.SetRate(timeUpdate.TimeWarpRateIndex, false);
}
Expand Down
6 changes: 5 additions & 1 deletion comms/time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ public class Time
[ProtoMember(2)]
public int TimeWarpRateIndex {get;set;}

[ProtoMember(3)]
public float TimeWarpRate {get;set;}

public Time()
{
}

public Time(double universalTime, int timeWarpRateIndex)
public Time(double universalTime, int timeWarpRateIndex, float timeWarpRate)
{
this.UniversalTime = universalTime;
this.TimeWarpRateIndex = timeWarpRateIndex;
this.TimeWarpRate = timeWarpRate;
}
}
}
2 changes: 1 addition & 1 deletion server/server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void UnityWorker()
try
{
var packet = new comms.Packet();
packet.Time = new comms.Time(Planetarium.GetUniversalTime(), TimeWarp.CurrentRateIndex);
packet.Time = new comms.Time(Planetarium.GetUniversalTime(), TimeWarp.CurrentRateIndex, TimeWarp.CurrentRate);

if(FlightGlobals.ActiveVessel != null)
packet.Vessel = new comms.Vessel(FlightGlobals.ActiveVessel);
Expand Down

0 comments on commit 3371602

Please sign in to comment.