예제 #1
0
        public void StartRecord()
        {
            active          = true;
            recording       = new MemoryStream();
            recordingVector = new MemoryStream();
            VesselUpdate update = Recycler <VesselUpdate> .GetObject();

            update.SetVesselWorker(vesselWorker);
            update.CopyFromVessel(FlightGlobals.fetch.activeVessel);
            networkWorker.SendVesselUpdate(update);
            Recycler <VesselUpdate> .ReleaseObject(update);
        }
예제 #2
0
        public void DisplayUpdateVesselOffset()
        {
            double interpolatorDelay = 0;

            if (dmpSettings.interpolatorType == InterpolatorType.INTERPOLATE1S)
            {
                interpolatorDelay = 1;
            }
            if (dmpSettings.interpolatorType == InterpolatorType.INTERPOLATE3S)
            {
                interpolatorDelay = 3;
            }

            while (playbackQueue.Count > 0 && Planetarium.GetUniversalTime() > (playbackQueue.Peek().planetTime + interpolatorDelay))
            {
                if (lastUpdate != null)
                {
                    Recycler <VesselUpdate> .ReleaseObject(lastUpdate);
                }
                lastUpdate = playbackQueue.Dequeue();
                playbackID = lastUpdate.vesselID;
            }
            if (playbackQueue.Count > 0)
            {
                VesselUpdate vu = playbackQueue.Peek();
                if (lastUpdate != null && vu != null && lastUpdate.isSurfaceUpdate && vu.isSurfaceUpdate)
                {
                    Vessel av = FlightGlobals.fetch.vessels.Find(v => v.id == vu.vesselID);
                    if (av != null)
                    {
                        double   scaling       = (Planetarium.GetUniversalTime() - interpolatorDelay - lastUpdate.planetTime) / (vu.planetTime - lastUpdate.planetTime);
                        Vector3d orgPos        = new Vector3d(lastUpdate.position[0], lastUpdate.position[1], lastUpdate.position[2]);
                        Vector3d nextPos       = new Vector3d(vu.position[0], vu.position[1], vu.position[2]);
                        Vector3d updatePos     = Vector3d.Lerp(orgPos, nextPos, scaling);
                        Vector3d distanceInPos = av.mainBody.GetWorldSurfacePosition(av.latitude, av.longitude, av.altitude) - av.mainBody.GetWorldSurfacePosition(updatePos.x, updatePos.y, updatePos.z);
                        double   timeDiff      = Planetarium.GetUniversalTime() - interpolatorDelay - lastUpdate.planetTime;
                        DarkLog.Debug("Difference in position: " + Math.Round(distanceInPos.magnitude, 3) + ", scaling: " + Math.Round(scaling, 3));
                    }
                }
            }
            else
            {
                //Free the last update too!
                if (lastUpdate != null)
                {
                    Recycler <VesselUpdate> .ReleaseObject(lastUpdate);

                    lastUpdate = null;
                }
            }
        }
예제 #3
0
 public override void OnMessageReceived(ClientObject client, ClientMessage messageData)
 {
     if (!inited)
     {
         return;
     }
     if (messageData.type == ClientMessageType.VESSEL_PROTO)
     {
         using (MessageReader mr = new MessageReader(messageData.data))
         {
             double planetTime              = mr.Read <double>();
             bool   vesselIdOK              = Guid.TryParse(mr.Read <string>(), out Guid vesselID);
             bool   isDockingUpdate         = mr.Read <bool>();
             bool   isFlyingUpdate          = mr.Read <bool>();
             byte[] possibleCompressedBytes = mr.Read <byte[]>();
             byte[] vesselData              = Compression.DecompressIfNeeded(possibleCompressedBytes);
             if (vesselIdOK)
             {
                 UpdateVessel(client, vesselID, vesselData);
             }
         }
     }
     if (messageData.type == ClientMessageType.VESSEL_UPDATE)
     {
         VesselUpdate vu = VesselUpdate.VeselUpdateFromBytes(messageData.data);
         PositionVessel(client, vu);
         Recycler <VesselUpdate> .ReleaseObject(vu);
     }
     if (messageData.type == ClientMessageType.VESSEL_REMOVE)
     {
         using (MessageReader mr = new MessageReader(messageData.data))
         {
             double planetTime = mr.Read <double>();
             if (Guid.TryParse(mr.Read <string>(), out Guid vesselID))
             {
                 RemoveVessel(client, vesselID);
             }
         }
     }
 }
예제 #4
0
        public void Update()
        {
            if (playback)
            {
                DisplayUpdateVesselOffset();
                if (Planetarium.GetUniversalTime() > (lastTime))
                {
                    playback = false;
                    ScreenMessages.RemoveMessage(screenMessage);
                    screenMessage = null;
                }
                else
                {
                    int timeLeft = (int)(lastTime - Planetarium.GetUniversalTime());
                    ScreenMessages.RemoveMessage(screenMessage);
                    screenMessage = ScreenMessages.PostScreenMessage("Playback time left: " + timeLeft + " / " + (int)(lastTime - firstTime) + " seconds", float.MaxValue, ScreenMessageStyle.UPPER_CENTER);
                }
            }

            if (active)
            {
                VesselUpdate vu = Recycler <VesselUpdate> .GetObject();

                vu.SetVesselWorker(vesselWorker);
                vu.CopyFromVessel(FlightGlobals.fetch.activeVessel);
                ClientMessage updateBytes = networkWorker.GetVesselUpdateMessage(vu);
                byte[]        lengthBytes = BitConverter.GetBytes(updateBytes.data.Length);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(lengthBytes);
                }
                recordingVector.Write(lengthBytes, 0, lengthBytes.Length);
                recordingVector.Write(updateBytes.data.data, 0, updateBytes.data.Length);
                ByteRecycler.ReleaseObject(updateBytes.data);
                Recycler <VesselUpdate> .ReleaseObject(vu);
            }
        }