예제 #1
0
 private void writeIntToStream(KSP.IO.FileStream stream, Int32 val)
 {
     stream.Write(KMPCommon.intToBytes(val), 0, 4);
 }
예제 #2
0
        private void writeVesselUpdateToFile(KSP.IO.FileStream out_stream, Vessel vessel)
        {
            if (!vessel || !vessel.mainBody)
                return;

            //Create a KLFVesselUpdate from the vessel data
            KLFVesselUpdate update = new KLFVesselUpdate();

            update.vesselName = vessel.vesselName;
            update.ownerName = playerName;
            update.id = vessel.id;

            Vector3 pos = vessel.mainBody.transform.InverseTransformPoint(vessel.GetWorldPos3D());
            Vector3 dir = vessel.mainBody.transform.InverseTransformDirection(vessel.transform.up);
            Vector3 vel = vessel.mainBody.transform.InverseTransformDirection(vessel.GetObtVelocity());

            for (int i = 0; i < 3; i++)
            {
                update.localPosition[i] = pos[i];
                update.localDirection[i] = dir[i];
                update.localVelocity[i] = vel[i];
            }

            update.situation = vessel.situation;

            if (vessel == FlightGlobals.ActiveVessel)
                update.state = Vessel.State.ACTIVE;
            else if (vessel.isCommandable)
                update.state = Vessel.State.INACTIVE;
            else
                update.state = Vessel.State.DEAD;

            update.timeScale = Planetarium.TimeScale;
            update.bodyName = vessel.mainBody.bodyName;

            //Serialize the update
            byte[] update_bytes = KSP.IO.IOUtils.SerializeToBinary(update);

            //Write the length of the serialized to the stream
            writeIntToStream(out_stream, update_bytes.Length);

            //Write the serialized update to the stream
            out_stream.Write(update_bytes, 0, update_bytes.Length);
        }