public static ClientUpdate Decode(byte[] bytes, int offset = 0) { int ID = Serialization.DecodeInt(bytes, offset); offset += 4; int pID = Serialization.DecodeInt(bytes, offset); offset += 4; PressedKeys keys = (PressedKeys)bytes[offset]; offset += 1; bool left = Serialization.DecodeBool(bytes, offset); offset += 1; bool right = Serialization.DecodeBool(bytes, offset); offset += 1; float mAngle = Serialization.DecodeFloat(bytes, offset); offset += 4; double dt = Serialization.DecodeDouble(bytes, offset); offset += 8; return(new ClientUpdate(ID, pID, keys, mAngle, left, right, dt)); }
public static ConnectingDynamicData Decode(byte[] bytes, int startIndex) { int offset = startIndex; var numPlayers = Serialization.DecodeInt(bytes, offset); offset += 4; var numPickups = Serialization.DecodeInt(bytes, offset); offset += 4; var players = new Dictionary <int, Engine.Player>(numPlayers); for (int i = 0; i < numPlayers; ++i) { var pID = Serialization.DecodeInt(bytes, offset); offset += 4; var pos = Serialization.DecodeVec3(bytes, offset); offset += OpenTK.Vector3.SizeInBytes; var col = Serialization.DecodeVec3(bytes, offset); offset += OpenTK.Vector3.SizeInBytes; var killCount = Serialization.DecodeInt(bytes, offset); offset += 4; var deathCount = Serialization.DecodeInt(bytes, offset); offset += 4; players.Add(pID, new Engine.Player(pID, pos, col, killCount, deathCount)); } var pickups = new Dictionary <int, Engine.ShieldPickup>(numPickups); for (int i = 0; i < numPickups; ++i) { var pID = Serialization.DecodeInt(bytes, offset); offset += 4; var pos = Serialization.DecodeVec3(bytes, offset); offset += OpenTK.Vector3.SizeInBytes; var state = Serialization.DecodeBool(bytes, offset); offset += 1; pickups.Add(pID, new Engine.ShieldPickup(pos, state)); } return(new ConnectingDynamicData(players, pickups)); }