protected override byte[] DoEncode() { int numBytes = headerSize + playerStates.Count * bytesPerPlayer; var bytes = new byte[numBytes]; int offset = headerSize; foreach (var p in playerStates) { var ID = Serialization.Encode(p.playerID); Array.Copy(ID, 0, bytes, offset, ID.Length); offset += ID.Length; var pos = Serialization.Encode(p.pos); Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; var tankAngle = Serialization.Encode(p.tankAngle); Array.Copy(tankAngle, 0, bytes, offset, tankAngle.Length); offset += tankAngle.Length; var towerAngle = Serialization.Encode(p.towerAngle); Array.Copy(towerAngle, 0, bytes, offset, towerAngle.Length); offset += towerAngle.Length; var fireCooldown = Serialization.Encode(p.fireCooldown); Array.Copy(fireCooldown, 0, bytes, offset, fireCooldown.Length); offset += fireCooldown.Length; bytes[offset++] = p.currShields; bytes[offset++] = p.currHealth; } return(bytes); }
public static byte[] Encode(ClientUpdate u) { var ID = Serialization.Encode(u.ID); var pID = Serialization.Encode(u.PlayerID); var mAngle = Serialization.Encode(u.MouseAngle); var left = Serialization.Encode(u.LeftMouse); var right = Serialization.Encode(u.RightMouse); var dt = Serialization.Encode(u.DT); var length = ID.Length + pID.Length + mAngle.Length + 1 + left.Length + right.Length + dt.Length; var bytes = new byte[length]; int offset = 0; Array.Copy(ID, 0, bytes, offset, ID.Length); offset += ID.Length; Array.Copy(pID, 0, bytes, offset, pID.Length); offset += pID.Length; bytes[offset] = (byte)u.Keys; offset += 1; Array.Copy(left, 0, bytes, offset, left.Length); offset += left.Length; Array.Copy(right, 0, bytes, offset, right.Length); offset += right.Length; Array.Copy(mAngle, 0, bytes, offset, mAngle.Length); offset += mAngle.Length; Array.Copy(dt, 0, bytes, offset, dt.Length); offset += dt.Length; return(bytes); }
protected override byte[] DoEncode() { var bytes = new byte[headerSize + 4]; var ID = Serialization.Encode(pID); Array.Copy(ID, 0, bytes, headerSize, ID.Length); return(bytes); }
protected override byte[] DoEncode() { var bytes = new byte[headerSize + 4]; int offset = headerSize; var ID = Serialization.Encode(pID); Array.Copy(ID, 0, bytes, offset, ID.Length); offset += 4; return(bytes); }
public static byte[] Encode(ConnectingStaticData c) { var bytes = new byte[4 + c.Arena.Size * c.Arena.Size]; var pID = Serialization.Encode(c.PlayerID); Array.Copy(pID, 0, bytes, 0, pID.Length); for (int y = 0; y < c.Arena.Size; y++) { for (int x = 0; x < c.Arena.Size; x++) { bytes[pID.Length + x + y * c.Arena.Size] = (byte)c.Arena[x, y]; } } return(bytes); }
public static byte[] Encode(ConnectingDynamicData d) { var bytes = new byte[4 + 4 + bytesPerPlayer * d.Players.Count + bytesPerPickup * d.Pickups.Count]; int offset = 0; var numPlayers = Serialization.Encode(d.Players.Count); var numPickups = Serialization.Encode(d.Pickups.Count); Array.Copy(numPlayers, 0, bytes, offset, numPlayers.Length); offset += numPlayers.Length; Array.Copy(numPickups, 0, bytes, offset, numPickups.Length); offset += numPickups.Length; foreach (var p in d.Players.Values) { var pID = Serialization.Encode(p.ID); var pos = Serialization.Encode(p.Position); var col = Serialization.Encode(p.Color); var killCount = Serialization.Encode(p.KillCount); var deathCount = Serialization.Encode(p.DeathCount); Array.Copy(pID, 0, bytes, offset, pID.Length); offset += pID.Length; Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; Array.Copy(col, 0, bytes, offset, col.Length); offset += col.Length; Array.Copy(killCount, 0, bytes, offset, killCount.Length); offset += killCount.Length; Array.Copy(deathCount, 0, bytes, offset, deathCount.Length); offset += deathCount.Length; } foreach (var p in d.Pickups) { var pID = Serialization.Encode(p.Key); var pos = Serialization.Encode(p.Value.pos); var state = Serialization.Encode(p.Value.Active); Array.Copy(pID, 0, bytes, offset, pID.Length); offset += pID.Length; Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; Array.Copy(state, 0, bytes, offset, state.Length); offset += state.Length; } return(bytes); }
protected override byte[] DoEncode() { int offset = headerSize; var ID = Serialization.Encode(pID); var col = Serialization.Encode(pCol); var pos = Serialization.Encode(pPos); var bytes = new byte[offset + ID.Length + col.Length + pos.Length]; Array.Copy(ID, 0, bytes, offset, ID.Length); offset += ID.Length; Array.Copy(col, 0, bytes, offset, col.Length); offset += col.Length; Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; return(bytes); }
protected override byte[] DoEncode() { var bytes = new byte[headerSize + 8 + Vector3.SizeInBytes]; int offset = headerSize; var killed = Serialization.Encode(killedID); Array.Copy(killed, 0, bytes, offset, killed.Length); offset += killed.Length; var killer = Serialization.Encode(killerID); Array.Copy(killer, 0, bytes, offset, killer.Length); offset += killer.Length; var pos = Serialization.Encode(rPos); Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; return(bytes); }
protected override byte[] DoEncode() { var bytes = new byte[headerSize + 4 + 2 * Vector2.SizeInBytes]; int offset = headerSize; var ID = Serialization.Encode(pID); Array.Copy(ID, 0, bytes, offset, ID.Length); offset += ID.Length; var dir = Serialization.Encode(sDir); Array.Copy(dir, 0, bytes, offset, dir.Length); offset += dir.Length; var pos = Serialization.Encode(sPos); Array.Copy(pos, 0, bytes, offset, pos.Length); offset += pos.Length; return(bytes); }