Exemple #1
0
        public void ReadNetworkPacket(PacketReader packetReader, GameTime gameTime, TimeSpan latency,
					      bool enablePrediction, bool enableSmoothing, float packetSendTime)
        {
            if (enableSmoothing) {
                previousState = displayState;
                _currentSmoothing = 1;
            } else
                _currentSmoothing = 0;

            //float packetSendTime = packetReader.ReadSingle();

            simulationState.Position = packetReader.ReadVector3();
            simulationState.Velocity = packetReader.ReadVector2();
            simulationState.Rotation = packetReader.ReadSingle();

            PositionInput = packetReader.ReadVector2();
            RotationInput = packetReader.ReadVector4();

            if (enablePrediction)
                ApplyPrediction(gameTime, latency, packetSendTime);
        }
Exemple #2
0
        /// <summary>
        /// Reads the state of a remotely controlled tank from a network packet.
        /// </summary>
        public void ReadNetworkPacket(PacketReader packetReader,
                                      GameTime gameTime, TimeSpan latency,
                                      bool enablePrediction, bool enableSmoothing)
        {
            if (enableSmoothing)
            {
                // Start a new smoothing interpolation from our current
                // state toward this new state we just received.
                previousState = displayState;
                currentSmoothing = 1;
            }
            else
            {
                currentSmoothing = 0;
            }

            // Read what time this packet was sent.
            float packetSendTime = packetReader.ReadSingle();

            // Read simulation state from the network packet.
            simulationState.Position = packetReader.ReadVector2();
            simulationState.Velocity = packetReader.ReadVector2();
            simulationState.TankRotation = packetReader.ReadSingle();
            simulationState.TurretRotation = packetReader.ReadSingle();

            // Read remote inputs from the network packet.
            tankInput = packetReader.ReadVector2();
            turretInput = packetReader.ReadVector2();

            // Optionally apply prediction to compensate for
            // how long it took this packet to reach us.
            if (enablePrediction)
            {
                ApplyPrediction(gameTime, latency, packetSendTime);
            }
        }
Exemple #3
0
 public void ReadInputFromClient(PacketReader packetReader, GameTime gameTime)
 {
     PositionInput = packetReader.ReadVector2();
     RotationInput = packetReader.ReadVector4();
 }
Exemple #4
0
        /// <summary>
        /// Create a new ShipInput object based on the data in the packet.
        /// </summary>
        /// <param name="packetReader">The packet with the data.</param>
        public ShipInput(PacketReader packetReader)
        {
            // safety-check the parameters, as they must be valid
            if (packetReader == null)
            {
                throw new ArgumentNullException("packetReader");
            }

            // read the data
            LeftStick = packetReader.ReadVector2();
            RightStick = packetReader.ReadVector2();
            MineFired = packetReader.ReadBoolean();
        }