/// <summary> /// Call this method to apply a vessel update using interpolation /// </summary> public void ApplyInterpolatedVesselUpdate() { if (Body == null) { return; } if (InterpolationFinished && VesselPositionSystem.TargetVesselUpdateQueue.TryGetValue(VesselId, out var queue) && queue.TryDequeue(out var targetUpdate)) { if (Target == null) //This is the case of first iteration { GameTimeStamp = targetUpdate.GameTimeStamp - TimeSpan.FromMilliseconds(SettingsSystem.ServerSettings.SecondaryVesselUpdatesMsInterval).TotalSeconds; } ProcessRestart(); CurrentFrame = 0; if (Target != null) { Target.CopyFrom(targetUpdate); VesselPositionSystem.TargetVesselUpdateQueue[VesselId].Recycle(targetUpdate); } else { Target = targetUpdate; } AdjustExtraInterpolationTimes(); Vessel?.protoVessel?.UpdatePositionValues(Target); VesselsProtoStore.UpdateVesselProtoPosition(this); KspOrbit = new Orbit(Orbit[0], Orbit[1], Orbit[2], Orbit[3], Orbit[4], Orbit[5], Orbit[6], Body); Target.KspOrbit = new Orbit(Target.Orbit[0], Target.Orbit[1], Target.Orbit[2], Target.Orbit[3], Target.Orbit[4], Target.Orbit[5], Target.Orbit[6], Target.Body); } if (Target == null) { return; } try { Vessel.SetVesselPosition(this, Target, LerpPercentage); } catch (Exception e) { LunaLog.LogError($"ApplyInterpolations: {e}"); } finally { CurrentFrame++; } }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselPositionMsgData msgData)) { return; } var vesselId = msgData.VesselId; //Ignore vessel updates for our own controlled vessel if (LockSystem.LockQuery.ControlLockBelongsToPlayer(vesselId, SettingsSystem.CurrentSettings.PlayerName)) { return; } //Ignore updates if vessel is in kill list if (SystemsContainer.Get <VesselRemoveSystem>().VesselWillBeKilled(vesselId)) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPosition(msgData); if (!VesselPositionSystem.CurrentVesselUpdate.TryGetValue(vesselId, out var existingPositionUpdate)) { VesselPositionSystem.CurrentVesselUpdate.TryAdd(vesselId, MessageToPositionTransfer.CreateFromMessage(msg)); VesselPositionSystem.TargetVesselUpdate.TryAdd(vesselId, MessageToPositionTransfer.CreateFromMessage(msg)); } else { //Here we check that the message timestamp is lower than the message we received. UDP is not reliable and can deliver packets not in order! //Also we only process messages if the interpolation is finished if (existingPositionUpdate.TimeStamp < msgData.TimeStamp && VesselPositionSystem.TargetVesselUpdate.TryGetValue(vesselId, out var existingTargetPositionUpdate) && existingTargetPositionUpdate.TimeStamp < msgData.TimeStamp) { if (SettingsSystem.CurrentSettings.InterpolationEnabled) { //Here we set the start position to the current VESSEL position in order to LERP correctly existingPositionUpdate.Restart(); } else { //Here we just set the interpolation as not started existingPositionUpdate.ResetFields(); } //Overwrite the TARGET data with the data we've received in the message MessageToPositionTransfer.UpdateFromMessage(msg, existingTargetPositionUpdate); } } }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselPositionMsgData msgData)) { return; } var vesselId = msgData.VesselId; if (!VesselCommon.DoVesselChecks(vesselId)) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPosition(msgData); if (!VesselPositionSystem.CurrentVesselUpdate.TryGetValue(vesselId, out var existingPositionUpdate)) { var current = MessageToPositionTransfer.CreateFromMessage(msg); var target = MessageToPositionTransfer.CreateFromMessage(msg); VesselPositionSystem.CurrentVesselUpdate.TryAdd(vesselId, current); VesselPositionSystem.TargetVesselUpdate.TryAdd(vesselId, target); VesselPositionSystem.TargetVesselUpdateQueue.TryAdd(vesselId, new FixedSizedConcurrentQueue <VesselPositionUpdate>(VesselPositionSystem.MaxQueuedUpdates)); current.SetTarget(target); } else { if (SettingsSystem.CurrentSettings.InterpolationEnabled) { if (VesselPositionSystem.TargetVesselUpdateQueue.TryGetValue(vesselId, out var queue)) { queue.Enqueue(MessageToPositionTransfer.CreateFromMessage(msg)); } } else { if (VesselPositionSystem.TargetVesselUpdate.TryGetValue(vesselId, out var existingTargetPositionUpdate)) { //Overwrite the TARGET data with the data we've received in the message MessageToPositionTransfer.UpdateFromMessage(msg, existingTargetPositionUpdate); //Here we just set the interpolation as not started existingPositionUpdate.SetTarget(existingTargetPositionUpdate); } } } }
public void SendVesselPositionUpdate(Vessel vessel) { var msg = MessageToPositionTransfer.CreateMessageFromVessel(vessel); if (msg == null) { return; } msg.GameTime = Planetarium.GetUniversalTime(); //Update our own values in the store aswell as otherwise if we leave the vessel it can still be in the safety bubble VesselsProtoStore.UpdateVesselProtoPosition(msg); SendMessage(msg); }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselPositionMsgData msgData)) { return; } var vesselId = msgData.VesselId; if (!System.DoVesselChecks(vesselId)) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPosition(msgData); if (!VesselPositionSystem.CurrentVesselUpdate.TryGetValue(vesselId, out var existingPositionUpdate)) { var current = MessageToPositionTransfer.CreateFromMessage(msg); var target = MessageToPositionTransfer.CreateFromMessage(msg); VesselPositionSystem.CurrentVesselUpdate.TryAdd(vesselId, current); VesselPositionSystem.TargetVesselUpdate.TryAdd(vesselId, target); current.ResetFields(target); } else { if (VesselPositionSystem.TargetVesselUpdate.TryGetValue(vesselId, out var existingTargetPositionUpdate)) { //Overwrite the TARGET data with the data we've received in the message MessageToPositionTransfer.UpdateFromMessage(msg, existingTargetPositionUpdate); if (SettingsSystem.CurrentSettings.InterpolationEnabled) { //Here we set the start position to the current VESSEL position in order to LERP correctly existingPositionUpdate.Restart(existingTargetPositionUpdate); } else { //Here we just set the interpolation as not started existingPositionUpdate.ResetFields(existingTargetPositionUpdate); } } } }
public void SendVesselPositionUpdate(Vessel vessel) { if (vessel == null) { return; } var msg = CreateMessageFromVessel(vessel); if (msg == null) { return; } //Update our own values in the store aswell as otherwise if we leave the vessel it can still be in the safety bubble VesselsProtoStore.UpdateVesselProtoPosition(msg); UpdateOwnVesselProtoFields(vessel, msg.BodyIndex); SendMessage(msg); }
public void SendVesselPositionUpdate(Vessel vessel) { var msg = MessageToPositionTransfer.CreateMessageFromVessel(vessel); if (msg == null) { return; } msg.GameTime = Planetarium.GetUniversalTime(); if (!vessel.loaded) { vessel.orbit?.UpdateFromStateVectors(vessel.orbit.pos, vessel.orbit.vel, vessel.orbit.referenceBody, Planetarium.GetUniversalTime()); } //Update our own values in the store aswell as otherwise if we leave the vessel it can still be in the safety bubble VesselsProtoStore.UpdateVesselProtoPosition(msg); SendMessage(msg); }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselPositionMsgData msgData)) { return; } var vesselId = msgData.VesselId; if (!VesselCommon.DoVesselChecks(vesselId)) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPosition(msgData); //System is not ready nor in use so just skip the position message if (!System.PositionUpdateSystemBasicReady) { return; } var update = CreatePosUpdateFromMessage(msgData); if (!VesselPositionSystem.CurrentVesselUpdate.ContainsKey(vesselId)) { VesselPositionSystem.CurrentVesselUpdate.TryAdd(vesselId, update); VesselPositionSystem.TargetVesselUpdateQueue.TryAdd(vesselId, new FixedSizedConcurrentQueue <VesselPositionUpdate>(VesselPositionSystem.MaxQueuedUpdates)); } else { if (VesselPositionSystem.TargetVesselUpdateQueue.TryGetValue(vesselId, out var queue)) { queue.Enqueue(update); } } }