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) { 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); }