/// <summary> /// Here we set the first vessel updates. We use the current vessel state as the starting point. /// </summary> /// <param name="update"></param> private bool SetFirstVesselUpdates(VesselUpdate update) { var first = update?.Clone(); if (first != null) { first.SentTime = update.SentTime - DefaultFactor; CurrentVesselUpdate.Add(update.VesselId, first); CurrentVesselUpdate[update.VesselId].Target = update; return(true); } return(false); }
/// <summary> /// Create and send the vessel update /// </summary> /// <param name="checkVessel"></param> private void SendVesselUpdate(Vessel checkVessel) { var update = VesselUpdate.CreateFromVessel(checkVessel); if (update != null) { MessageSender.SendVesselUpdate(update); } else { Debug.LogError("[LMP]: Cannot send vessel update!"); } }
public void SendVesselUpdate(VesselUpdate update) { var msg = new VesselUpdateMsgData { GameSentTime = Time.fixedTime, Stage = update.Stage, PlanetTime = update.PlanetTime, ActiveEngines = update.ActiveEngines, StoppedEngines = update.StoppedEngines, Decouplers = update.Decouplers, AnchoredDecouplers = update.AnchoredDecouplers, Clamps = update.Clamps, Docks = update.Docks, VesselId = update.VesselId, Acceleration = update.Acceleration, ActiongroupControls = update.ActionGrpControls, BodyName = update.BodyName, GearDown = update.FlightState.gearDown, GearUp = update.FlightState.gearUp, Headlight = update.FlightState.headlight, IsSurfaceUpdate = update.IsSurfaceUpdate, KillRot = update.FlightState.killRot, MainThrottle = update.FlightState.mainThrottle, Orbit = update.Orbit, Pitch = update.FlightState.pitch, PitchTrim = update.FlightState.pitchTrim, Position = update.Position, Roll = update.FlightState.roll, RollTrim = update.FlightState.rollTrim, Rotation = update.Rotation, Velocity = update.Velocity, WheelSteer = update.FlightState.wheelSteer, WheelSteerTrim = update.FlightState.wheelSteerTrim, WheelThrottle = update.FlightState.wheelThrottle, WheelThrottleTrim = update.FlightState.wheelThrottleTrim, X = update.FlightState.X, Y = update.FlightState.Y, Yaw = update.FlightState.yaw, YawTrim = update.FlightState.yawTrim, Z = update.FlightState.Z }; SendMessage(msg); }
public static VesselUpdate CreateFromVessel(Vessel vessel) { try { var engines = vessel.FindPartModulesImplementing <ModuleEngines>(); var returnUpdate = new VesselUpdate { VesselId = vessel.id, PlanetTime = Planetarium.GetUniversalTime(), ActiveEngines = engines.Where(e => e.EngineIgnited) .Select(e => e.part.craftID).ToArray(), StoppedEngines = engines.Where(e => !e.EngineIgnited) .Select(e => e.part.craftID).ToArray(), Decouplers = vessel.FindPartModulesImplementing <ModuleDecouple>() .Where(e => !e.isDecoupled) .Select(e => e.part.craftID).ToArray(), AnchoredDecouplers = vessel.FindPartModulesImplementing <ModuleAnchoredDecoupler>() .Where(e => !e.isDecoupled) .Select(e => e.part.craftID).ToArray(), Clamps = vessel.FindPartModulesImplementing <LaunchClamp>() .Select(e => e.part.craftID).ToArray(), Docks = vessel.FindPartModulesImplementing <ModuleDockingNode>() .Where(e => !e.IsDisabled) .Select(e => e.part.craftID).ToArray(), Stage = vessel.currentStage, FlightState = new FlightCtrlState(), BodyName = vessel.mainBody.bodyName, Rotation = new[] { vessel.transform.rotation.x, vessel.transform.rotation.y, vessel.transform.rotation.z, vessel.transform.rotation.w }, ActionGrpControls = new[] { vessel.ActionGroups[KSPActionGroup.Gear], vessel.ActionGroups[KSPActionGroup.Light], vessel.ActionGroups[KSPActionGroup.Brakes], vessel.ActionGroups[KSPActionGroup.SAS], vessel.ActionGroups[KSPActionGroup.RCS] } }; returnUpdate.FlightState.CopyFrom(vessel.ctrlState); if (vessel.altitude < 10000) { //Use surface position under 10k returnUpdate.IsSurfaceUpdate = true; returnUpdate.Position = new double[] { vessel.latitude, vessel.longitude, vessel.altitude, vessel.radarAltitude }; Vector3d srfVel = Quaternion.Inverse(vessel.mainBody.bodyTransform.rotation) * vessel.srf_velocity; returnUpdate.Velocity = new[] { srfVel.x, srfVel.y, srfVel.z }; Vector3d srfAcceleration = Quaternion.Inverse(vessel.mainBody.bodyTransform.rotation) * vessel.acceleration; returnUpdate.Acceleration = new[] { srfAcceleration.x, srfAcceleration.y, srfAcceleration.z }; } else { //Use orbital positioning over 10k returnUpdate.IsSurfaceUpdate = false; returnUpdate.Orbit = new[] { vessel.orbit.inclination, vessel.orbit.eccentricity, vessel.orbit.semiMajorAxis, vessel.orbit.LAN, vessel.orbit.argumentOfPeriapsis, vessel.orbit.meanAnomalyAtEpoch, vessel.orbit.epoch }; } return(returnUpdate); } catch (Exception e) { Debug.Log($"[LMP]: Failed to get vessel update, exception: {e}"); return(null); } }
public void HandleMessage(IMessageData messageData) { var msgData = messageData as VesselUpdateMsgData; if (msgData == null || !System.UpdateSystemBasicReady || VesselCommon.UpdateIsForOwnVessel(msgData.VesselId)) { return; } var update = new VesselUpdate { Id = Guid.NewGuid(), ReceiveTime = Time.fixedTime, PlanetTime = msgData.PlanetTime, Stage = msgData.Stage, SentTime = msgData.GameSentTime, ActiveEngines = msgData.ActiveEngines, StoppedEngines = msgData.StoppedEngines, Decouplers = msgData.Decouplers, AnchoredDecouplers = msgData.AnchoredDecouplers, Clamps = msgData.Clamps, Docks = msgData.Docks, VesselId = msgData.VesselId, BodyName = msgData.BodyName, Rotation = msgData.Rotation, FlightState = new FlightCtrlState { mainThrottle = msgData.MainThrottle, wheelThrottleTrim = msgData.WheelThrottleTrim, X = msgData.X, Y = msgData.Y, Z = msgData.Z, killRot = msgData.KillRot, gearUp = msgData.GearUp, gearDown = msgData.GearDown, headlight = msgData.Headlight, wheelThrottle = msgData.WheelThrottle, roll = msgData.Roll, yaw = msgData.Yaw, pitch = msgData.Pitch, rollTrim = msgData.RollTrim, yawTrim = msgData.YawTrim, pitchTrim = msgData.PitchTrim, wheelSteer = msgData.WheelSteer, wheelSteerTrim = msgData.WheelSteerTrim }, ActionGrpControls = msgData.ActiongroupControls, IsSurfaceUpdate = msgData.IsSurfaceUpdate }; if (update.IsSurfaceUpdate) { update.Position = msgData.Position; update.Velocity = msgData.Velocity; update.Acceleration = msgData.Acceleration; } else { update.Orbit = msgData.Orbit; } if (!System.ReceivedUpdates.ContainsKey(update.VesselId)) { System.ReceivedUpdates.Add(update.VesselId, new Queue <VesselUpdate>()); } if (System.ReceivedUpdates[update.VesselId].Count + 1 > VesselUpdateInterpolationSystem.MaxTotalUpdatesInQueue) { System.ReceivedUpdates[update.VesselId].Dequeue(); } System.ReceivedUpdates[update.VesselId].Enqueue(update); }