public void ReadNetworkPacket(PacketReader packetReader, GameTime gameTime, TimeSpan latency) { float packetSendTime = packetReader.ReadSingle(); bool pIsAlive = packetReader.ReadBoolean(); if (pIsAlive) { float px = packetReader.ReadSingle(); float py = packetReader.ReadSingle(); float vx = packetReader.ReadSingle(); float vy = packetReader.ReadSingle(); rawPostion = new Vector2(px, py); rawVelocity = new Vector2(vx, vy); } //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); //} }
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); }
/// <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); } }
public static void updateInputFromNetwork(this CarActor carActor, PacketReader reader) { // read values and apply to carActor: // accleration carActor.Acceleration = reader.ReadSingle(); }