|
@@ -250,24 +250,30 @@ namespace PeerToPeer
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Helper for updating a locally controlled gamer.
|
|
/// Helper for updating a locally controlled gamer.
|
|
/// </summary>
|
|
/// </summary>
|
|
- void UpdateLocalGamer(LocalNetworkGamer gamer)
|
|
|
|
|
|
+ void UpdateLocalGamer(LocalNetworkGamer localNetworkGamer)
|
|
{
|
|
{
|
|
// Look up what tank is associated with this local player.
|
|
// Look up what tank is associated with this local player.
|
|
- if (gamer.Tag is Tank localTank)
|
|
|
|
|
|
+ if (localNetworkGamer.Tag is Tank localTank)
|
|
{
|
|
{
|
|
|
|
|
|
// Update the tank.
|
|
// Update the tank.
|
|
- ReadTankInputs(localTank, (PlayerIndex)gamer.SignedInGamer.PlayerIndex);
|
|
|
|
|
|
+ ReadTankInputs(localTank, (PlayerIndex)localNetworkGamer.SignedInGamer.PlayerIndex);
|
|
|
|
|
|
localTank.Update();
|
|
localTank.Update();
|
|
|
|
|
|
|
|
+ // Reset the writer so we don't append across frames
|
|
|
|
+ packetWriter.Position = 0; // or: packetWriter.Reset();
|
|
|
|
+
|
|
// Write the tank state into a network packet.
|
|
// Write the tank state into a network packet.
|
|
packetWriter.Write(localTank.Position);
|
|
packetWriter.Write(localTank.Position);
|
|
packetWriter.Write(localTank.TankRotation);
|
|
packetWriter.Write(localTank.TankRotation);
|
|
packetWriter.Write(localTank.TurretRotation);
|
|
packetWriter.Write(localTank.TurretRotation);
|
|
|
|
|
|
// Send the data to everyone in the session.
|
|
// Send the data to everyone in the session.
|
|
- gamer.SendData(packetWriter, SendDataOptions.InOrder);
|
|
|
|
|
|
+ localNetworkGamer.SendData(packetWriter, SendDataOptions.InOrder);
|
|
|
|
+
|
|
|
|
+ // Reset after send, to be extra safe
|
|
|
|
+ packetWriter.Position = 0; // or: packetWriter.Reset();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|