コード例 #1
0
        public static VesselPositionUpdate CreateFromMessage(IServerMessageBase msg)
        {
            if (!(msg.Data is VesselPositionMsgData msgData))
            {
                return(null);
            }

            var upd = new VesselPositionUpdate
            {
                VesselId          = msgData.VesselId,
                BodyIndex         = msgData.BodyIndex,
                HeightFromTerrain = msgData.HeightFromTerrain,
                TimeStamp         = msgData.TimeStamp
            };

            Array.Copy(msgData.SrfRelRotation, upd.SrfRelRotation, 4);
            Array.Copy(msgData.TransformPosition, upd.TransformPosition, 3);
            Array.Copy(msgData.Velocity, upd.Velocity, 3);
            Array.Copy(msgData.LatLonAlt, upd.LatLonAlt, 3);
            Array.Copy(msgData.Com, upd.Com, 3);
            Array.Copy(msgData.NormalVector, upd.NormalVector, 3);
            Array.Copy(msgData.Orbit, upd.Orbit, 8);

            return(upd);
        }
コード例 #2
0
        public static VesselPositionUpdate UpdateFromMessage(IServerMessageBase msg, VesselPositionUpdate update)
        {
            if (!(msg.Data is VesselPositionMsgData msgData))
            {
                return(null);
            }

            update.VesselId          = msgData.VesselId;
            update.BodyIndex         = msgData.BodyIndex;
            update.HeightFromTerrain = msgData.HeightFromTerrain;
            update.SentTimeStamp     = msgData.TimeStamp;
            update.ReceiveTimeStamp  = msgData.ReceiveTime;
            update.GameTimeStamp     = msgData.GameTime;

            Array.Copy(msgData.SrfRelRotation, update.SrfRelRotation, 4);
            Array.Copy(msgData.TransformPosition, update.TransformPosition, 3);
            Array.Copy(msgData.Velocity, update.Velocity, 3);
            Array.Copy(msgData.OrbitPos, update.OrbitPos, 3);
            Array.Copy(msgData.OrbitVel, update.OrbitVel, 3);
            Array.Copy(msgData.LatLonAlt, update.LatLonAlt, 3);
            Array.Copy(msgData.NormalVector, update.NormalVector, 3);
            Array.Copy(msgData.Orbit, update.Orbit, 8);

            return(update);
        }
コード例 #3
0
        public void HandleMessage(IMessageData messageData)
        {
            var msgData = messageData as VesselPositionMsgData;

            if (msgData == null)
            {
                return;
            }

            var update   = new VesselPositionUpdate(msgData);
            var vesselId = update.VesselId;

            if (!System.CurrentVesselUpdate.TryGetValue(update.VesselId, out var existingPositionUpdate))
            {
                System.CurrentVesselUpdate[vesselId] = update;
                //If we got a position update, add it to the vessel IDs updated and the current vessel dictionary, after we've added it to the CurrentVesselUpdate dictionary
                System.UpdateVesselPositionOnNextFixedUpdate(vesselId);
            }
            else
            {
                if (existingPositionUpdate.SentTime < update.SentTime)
                {
                    //If there's an existing update, copy the body and vessel objects so they don't have to be looked up later.
                    System.SetBodyAndVesselOnNewUpdate(existingPositionUpdate, update);
                    System.CurrentVesselUpdate[vesselId] = update;

                    //If we got a position update, add it to the vessel IDs updated and the current vessel dictionary, after we've added it to the CurrentVesselUpdate dictionary
                    System.UpdateVesselPositionOnNextFixedUpdate(vesselId);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Here we set the first vessel updates. We use the current vessel state as the starting point.
        /// </summary>
        /// <param name="update"></param>
        private void SetFirstVesselUpdates(VesselPositionUpdate update)
        {
            var first = update?.Clone();

            if (first != null)
            {
                first.SentTime = update.SentTime - DefaultFactor;
                CurrentVesselUpdate.Add(update.VesselId, first);
                CurrentVesselUpdate[update.VesselId].Target = update;
            }
        }
コード例 #5
0
 /// <summary>
 /// Performance Improvement: If the body for this position update is the same as the old one, copy the body so that we don't have to look up the
 /// body in the ApplyVesselUpdate() call below (which must run during FixedUpdate)
 /// </summary>
 /// <param name="existingPositionUpdate">The position update currently in the map.  Cannot be null.</param>
 /// <param name="newPositionUpdate">The new position update for the vessel.  Cannot be null.</param>
 public void SetBodyAndVesselOnNewUpdate(VesselPositionUpdate existingPositionUpdate, VesselPositionUpdate newPositionUpdate)
 {
     if (existingPositionUpdate.BodyName == newPositionUpdate.BodyName)
     {
         newPositionUpdate.Body = existingPositionUpdate.Body;
     }
     if (existingPositionUpdate.VesselId == newPositionUpdate.VesselId)
     {
         newPositionUpdate.Vessel = existingPositionUpdate.Vessel;
     }
 }
コード例 #6
0
        public void CopyFrom(VesselPositionUpdate update)
        {
            VesselId          = update.VesselId;
            BodyIndex         = update.BodyIndex;
            SubspaceId        = update.SubspaceId;
            HeightFromTerrain = update.HeightFromTerrain;
            Landed            = update.Landed;
            Splashed          = update.Splashed;
            GameTimeStamp     = update.GameTimeStamp;
            HackingGravity    = update.HackingGravity;

            Array.Copy(update.SrfRelRotation, SrfRelRotation, 4);
            Array.Copy(update.LatLonAlt, LatLonAlt, 3);
            Array.Copy(update.VelocityVector, VelocityVector, 3);
            Array.Copy(update.NormalVector, NormalVector, 3);
            Array.Copy(update.Orbit, Orbit, 8);
        }
コード例 #7
0
        public static VesselPositionUpdate UpdateFromUpdate(VesselPositionUpdate update, VesselPositionUpdate updateToUpdate)
        {
            updateToUpdate.VesselId          = update.VesselId;
            updateToUpdate.BodyIndex         = update.BodyIndex;
            updateToUpdate.HeightFromTerrain = update.HeightFromTerrain;
            updateToUpdate.TimeStamp         = update.TimeStamp;

            Array.Copy(update.SrfRelRotation, updateToUpdate.SrfRelRotation, 4);
            Array.Copy(update.TransformPosition, updateToUpdate.TransformPosition, 3);
            Array.Copy(update.Velocity, updateToUpdate.Velocity, 3);
            Array.Copy(update.LatLonAlt, updateToUpdate.LatLonAlt, 3);
            Array.Copy(update.Com, updateToUpdate.Com, 3);
            Array.Copy(update.NormalVector, updateToUpdate.NormalVector, 3);
            Array.Copy(update.Orbit, updateToUpdate.Orbit, 8);

            return(update);
        }
コード例 #8
0
 public void SendVesselPositionUpdate(VesselPositionUpdate update)
 {
     SendMessage(new VesselPositionMsgData
     {
         GameSentTime = Time.time,
         PlanetTime = update.PlanetTime,
         VesselId = update.VesselId,
         BodyName = update.BodyName,
         Orbit = update.Orbit,
         LatLonAlt = update.LatLonAlt,
         TransformPosition = update.WorldPosition,
         OrbitPosition = update.OrbitPosition,
         TransformRotation = update.TransformRotation,
         Velocity = update.Velocity,
         OrbitVelocity = update.OrbitVelocity,
         Acceleration = update.Acceleration,
     });
 }
コード例 #9
0
        public void HandleMessage(IMessageData messageData)
        {
            var msgData = messageData as VesselPositionMsgData;

            if (msgData == null || !System.PositionUpdateSystemBasicReady || VesselCommon.UpdateIsForOwnVessel(msgData.VesselId))
            {
                return;
            }

            var update = new VesselPositionUpdate(msgData);

            if (!System.ReceivedUpdates.ContainsKey(update.VesselId))
            {
                System.ReceivedUpdates.Add(update.VesselId, new Queue <VesselPositionUpdate>());
            }

            if (System.ReceivedUpdates[update.VesselId].Count + 1 > VesselPositionInterpolationSystem.MaxTotalUpdatesInQueue)
            {
                System.ReceivedUpdates[update.VesselId].Dequeue();
            }

            System.ReceivedUpdates[update.VesselId].Enqueue(update);
        }
コード例 #10
0
        private static VesselPositionUpdate CreatePosUpdateFromMessage(VesselPositionMsgData msgData)
        {
            var update = new VesselPositionUpdate
            {
                VesselId          = msgData.VesselId,
                BodyIndex         = msgData.BodyIndex,
                HeightFromTerrain = msgData.HeightFromTerrain,
                Landed            = msgData.Landed,
                Splashed          = msgData.Splashed,
                GameTimeStamp     = msgData.GameTime,
                UtcSentTime       = msgData.UtcSentTime,
                ReceiveTime       = LunaTime.UtcNow,
                HackingGravity    = msgData.HackingGravity,
            };

            Array.Copy(msgData.SrfRelRotation, update.SrfRelRotation, 4);
            Array.Copy(msgData.Velocity, update.Velocity, 3);
            Array.Copy(msgData.LatLonAlt, update.LatLonAlt, 3);
            Array.Copy(msgData.NormalVector, update.NormalVector, 3);
            Array.Copy(msgData.Orbit, update.Orbit, 8);

            return(update);
        }
コード例 #11
0
 public void SendVesselPositionUpdate(Vessel vessel)
 {
     var update = new VesselPositionUpdate(vessel);
     SendVesselPositionUpdate(update);
 }