예제 #1
0
        public void StartPlayback()
        {
            int  messagesLoaded = 0;
            bool firstMessage   = true;

            using (FileStream fs = new FileStream(recordPath, FileMode.Open))
            {
                while (fs.Position < fs.Length)
                {
                    messagesLoaded++;
                    byte[] headerBytes = new byte[8];
                    fs.Read(headerBytes, 0, 8);
                    using (MessageReader mr = new MessageReader(headerBytes))
                    {
                        ClientMessageType messageType = (ClientMessageType)mr.Read <int>();
                        int    length    = mr.Read <int>();
                        byte[] dataBytes = new byte[length];
                        fs.Read(dataBytes, 0, length);
                        using (MessageReader timeReader = new MessageReader(dataBytes))
                        {
                            //Planet time is the first part of the message for the three types we care about here
                            double planetTime = timeReader.Read <double>();
                            lastTime = planetTime;
                            if (firstMessage)
                            {
                                firstTime    = planetTime;
                                firstMessage = false;
                                Planetarium.SetUniversalTime(planetTime - 5d);
                                warpWorker.SendNewSubspace();
                            }
                        }
                        using (MessageReader mrignore = new MessageReader(dataBytes))
                        {
                            //Planet time, don't care here
                            mrignore.Read <double>();
                            string vesselID = mrignore.Read <string>();
                            vesselWorker.IgnoreVessel(new Guid(vesselID));
                        }
                        switch (messageType)
                        {
                        case ClientMessageType.VESSEL_PROTO:
                            HandleProtoUpdate(dataBytes);
                            break;

                        case ClientMessageType.VESSEL_UPDATE:
                            HandleVesselUpdate(dataBytes);
                            break;

                        case ClientMessageType.VESSEL_REMOVE:
                            HandleVesselRemove(dataBytes);
                            break;
                        }
                    }
                }
            }

            ScreenMessages.PostScreenMessage("Loaded " + messagesLoaded + " saved updates.", 5f, ScreenMessageStyle.UPPER_CENTER);
            screenMessage = ScreenMessages.PostScreenMessage("Playback 0 / " + (int)(lastTime - firstTime) + " seconds.", float.MaxValue, ScreenMessageStyle.UPPER_CENTER);
            playback      = true;
        }
예제 #2
0
        public void StartPlayback()
        {
            int       messagesLoaded = 0;
            bool      firstMessage   = true;
            ByteArray headerBytes    = ByteRecycler.GetObject(8);

            using (FileStream fs = new FileStream(recordPath, FileMode.Open))
            {
                while (fs.Position < fs.Length)
                {
                    messagesLoaded++;
                    fs.Read(headerBytes.data, 0, 8);
                    using (MessageReader mr = new MessageReader(headerBytes.data))
                    {
                        ClientMessageType messageType = (ClientMessageType)mr.Read <int>();
                        int       length    = mr.Read <int>();
                        ByteArray dataBytes = ByteRecycler.GetObject(length);
                        fs.Read(dataBytes.data, 0, length);
                        using (MessageReader timeReader = new MessageReader(dataBytes.data))
                        {
                            //Planet time is the first part of the message for the three types we care about here
                            double planetTime = timeReader.Read <double>();
                            lastTime = planetTime;
                            if (firstMessage)
                            {
                                firstTime    = planetTime;
                                firstMessage = false;
                                Planetarium.SetUniversalTime(planetTime - 5d);
                                warpWorker.SendNewSubspace();
                            }
                        }
                        using (MessageReader mrignore = new MessageReader(dataBytes.data))
                        {
                            //Planet time, don't care here
                            mrignore.Read <double>();
                            string vesselID = mrignore.Read <string>();
                            vesselWorker.IgnoreVessel(new Guid(vesselID));
                        }
                        switch (messageType)
                        {
                        case ClientMessageType.VESSEL_PROTO:
                            HandleProtoUpdate(dataBytes);
                            break;

                        case ClientMessageType.VESSEL_UPDATE:
                            HandleVesselUpdate(dataBytes, false);
                            break;

                        case ClientMessageType.VESSEL_REMOVE:
                            HandleVesselRemove(dataBytes);
                            break;

                        default:
                            break;
                        }
                        ByteRecycler.ReleaseObject(dataBytes);
                    }
                }
                ByteRecycler.ReleaseObject(headerBytes);
            }

            playbackQueue = new Queue <VesselUpdate>();
            using (FileStream fs = new FileStream(recordVectorPath, FileMode.Open))
            {
                while (fs.Position < fs.Length)
                {
                    fs.Read(headerBytesInt, 0, 4);
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(headerBytesInt);
                    }
                    int       updateLength = BitConverter.ToInt32(headerBytesInt, 0);
                    ByteArray updateBytes  = ByteRecycler.GetObject(updateLength);
                    fs.Read(updateBytes.data, 0, updateLength);
                    VesselUpdate vu = networkWorker.VeselUpdateFromBytes(updateBytes.data, false);
                    playbackQueue.Enqueue(vu);
                    ByteRecycler.ReleaseObject(updateBytes);
                }
            }

            ScreenMessages.PostScreenMessage("Loaded " + messagesLoaded + " saved updates.", 5f, ScreenMessageStyle.UPPER_CENTER);
            screenMessage = ScreenMessages.PostScreenMessage("Playback 0 / " + (int)(lastTime - firstTime) + " seconds.", float.MaxValue, ScreenMessageStyle.UPPER_CENTER);
            playback      = true;
        }