コード例 #1
0
        public static VesselUpdate VeselUpdateFromBytes(byte[] messageData)
        {
            VesselUpdate update = Recycler <VesselUpdate> .GetObject();

            using (MessageReader mr = new MessageReader(messageData))
            {
                update.planetTime      = mr.Read <double>();
                update.vesselID        = new Guid(mr.Read <string>());
                update.bodyName        = mr.Read <string>();
                update.rotation        = mr.Read <float[]>();
                update.angularVelocity = mr.Read <float[]>();
                //FlightState variables
                update.flightState = new FlightCtrlState();
                update.flightState.mainThrottle      = mr.Read <float>();
                update.flightState.wheelThrottleTrim = mr.Read <float>();
                update.flightState.X              = mr.Read <float>();
                update.flightState.Y              = mr.Read <float>();
                update.flightState.Z              = mr.Read <float>();
                update.flightState.killRot        = mr.Read <bool>();
                update.flightState.gearUp         = mr.Read <bool>();
                update.flightState.gearDown       = mr.Read <bool>();
                update.flightState.headlight      = mr.Read <bool>();
                update.flightState.wheelThrottle  = mr.Read <float>();
                update.flightState.roll           = mr.Read <float>();
                update.flightState.yaw            = mr.Read <float>();
                update.flightState.pitch          = mr.Read <float>();
                update.flightState.rollTrim       = mr.Read <float>();
                update.flightState.yawTrim        = mr.Read <float>();
                update.flightState.pitchTrim      = mr.Read <float>();
                update.flightState.wheelSteer     = mr.Read <float>();
                update.flightState.wheelSteerTrim = mr.Read <float>();
                //Action group controls
                update.actiongroupControls = mr.Read <bool[]>();
                //Position/velocity
                update.isSurfaceUpdate = mr.Read <bool>();
                if (update.isSurfaceUpdate)
                {
                    update.position      = mr.Read <double[]>();
                    update.velocity      = mr.Read <double[]>();
                    update.acceleration  = mr.Read <double[]>();
                    update.terrainNormal = mr.Read <float[]>();
                }
                else
                {
                    update.orbit = mr.Read <double[]>();
                }
                update.sasEnabled = mr.Read <bool>();
                if (update.sasEnabled)
                {
                    update.autopilotMode  = mr.Read <int>();
                    update.lockedRotation = mr.Read <float[]>();
                }
                return(update);
            }
        }
コード例 #2
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);
        }
コード例 #3
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);
            }
        }