public static void RoomInfo(DataStreamReader stream) { stream.ReadUInt(); Room cRoom = new Room() { possibleDirections = (Direction)stream.ReadByte(), treasureAmount = stream.ReadUShort(), containsMonster = System.Convert.ToBoolean(stream.ReadByte()), containsExit = System.Convert.ToBoolean(stream.ReadByte()), numberOfOtherPlayers = stream.ReadByte() }; List <int> otherPlayerIds = new List <int>(); for (int i = 0; i < cRoom.numberOfOtherPlayers; i++) { otherPlayerIds.Add(stream.ReadInt()); } cRoom.otherPlayerIds = otherPlayerIds.ToArray(); GameManager.Instance.StartCoroutine(LateInvokeRoom(cRoom)); }
public unsafe void Execute(Entity entity, int index, [ReadOnly] ref PlayerStateComponentData playerState) { if (playerState.PlayerShip == Entity.Null) { return; } var buffer = cmdBuffer[entity]; if (buffer.Length == 0) { return; } DataStreamReader reader = DataStreamUnsafeUtility.CreateReaderFromExistingData((byte *)buffer.GetUnsafePtr(), buffer.Length); var ctx = default(DataStreamReader.Context); var inputTick = reader.ReadUInt(ref ctx); var left = reader.ReadByte(ref ctx); var right = reader.ReadByte(ref ctx); var thrust = reader.ReadByte(ref ctx); var shoot = reader.ReadByte(ref ctx); buffer.Clear(); //Debug.Log("Input delay: " + (int)(currentTick - inputTick)); // If ship, store commands in network command buffer var input = shipInput[playerState.PlayerShip]; input.mostRecentPos = (input.mostRecentPos + 1) % 32; input.tick[input.mostRecentPos] = inputTick; input.left[input.mostRecentPos] = left; input.right[input.mostRecentPos] = right; input.thrust[input.mostRecentPos] = thrust; input.shoot[input.mostRecentPos] = shoot; shipInput[playerState.PlayerShip] = input; }
public void Deserialize(uint inputTick, DataStreamReader reader, ref DataStreamReader.Context ctx) { tick = inputTick; left = reader.ReadByte(ref ctx); right = reader.ReadByte(ref ctx); thrust = reader.ReadByte(ref ctx); shoot = reader.ReadByte(ref ctx); }
public void Deserialize(uint inputTick, DataStreamReader reader, ref DataStreamReader.Context ctx) { tick = inputTick; left = reader.ReadByte(ref ctx); right = reader.ReadByte(ref ctx); forward = reader.ReadByte(ref ctx); grenade = reader.ReadByte(ref ctx); }
public void FromStream(DataStreamReader reader, ref DataStreamReader.Context ctx) { Header.FromStream(reader, ref ctx); Version = reader.ReadUShortNetworkByteOrder(ref ctx); CurrentPacket = reader.ReadByte(ref ctx); LastPacket = reader.ReadByte(ref ctx); Length = reader.ReadUShortNetworkByteOrder(ref ctx); }
public void Deserialize(uint inputTick, ref DataStreamReader reader) { tick = inputTick; left = reader.ReadByte(); right = reader.ReadByte(); thrust = reader.ReadByte(); shoot = reader.ReadByte(); }
public void Deserialize(uint tick, ref DataStreamReader reader) { this.tick = tick; keyForwardPressed = reader.ReadByte(); keyBackwardPressed = reader.ReadByte(); keyTurnRightPressed = reader.ReadByte(); keyTurnLeftPressed = reader.ReadByte(); }
public void Deserialize(uint inputTick, ref DataStreamReader reader, ShipCommandData baseline, NetworkCompressionModel compressionModel) { tick = inputTick; left = reader.ReadByte(); right = reader.ReadByte(); thrust = reader.ReadByte(); shoot = reader.ReadByte(); }
public void Deserialize(uint tick, ref DataStreamReader reader) { this.tick = tick; this.horizMove = reader.ReadFloat(); this.vertMove = reader.ReadFloat(); this.targetPitch = reader.ReadFloat(); this.targetYaw = reader.ReadFloat(); this.jump = reader.ReadByte(); this.interact = reader.ReadByte(); this.sprint = reader.ReadByte(); }
public void Deserialize(ref DataStreamReader reader) { moveDirections = (Direction)reader.ReadByte(); treasureInRoom = reader.ReadUShort(); containsMonster = Convert.ToBoolean(reader.ReadByte()); containsExit = Convert.ToBoolean(reader.ReadByte()); numberOfOtherPlayers = reader.ReadByte(); otherPlayerIDs = new int[numberOfOtherPlayers]; for (int i = 0; i < numberOfOtherPlayers; i++) { otherPlayerIDs[i] = reader.ReadInt(); } }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); directions = (Server.Game.Directions)reader.ReadByte(); TreasureInRoom = reader.ReadUShort(); ContainsMonster = reader.ReadByte() > 0; ContainsExit = reader.ReadByte() > 0; NumberofOtherPlayers = reader.ReadByte(); OtherPlayerIDs.Clear(); // to be sure :) for (int i = 0; i < NumberofOtherPlayers; i++) { OtherPlayerIDs.Add(reader.ReadInt()); } }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); MoveDirections = reader.ReadByte(); TreasureInRoom = reader.ReadUShort(); ContainsMonster = reader.ReadByte(); ContainsExit = reader.ReadByte(); NumberOfOtherPlayers = reader.ReadByte(); OtherPlayerIDs.Clear(); for (int i = 0; i < NumberOfOtherPlayers; i++) { OtherPlayerIDs.Add(reader.ReadInt()); } }
public static void Read(ServerBehaviour reader, int connectionID, DataStreamReader stream) { ClientMessage clientMessageType = (ClientMessage)stream.ReadByte(); //Debug.Log(reader.name + " got message of type " + clientMessageType.ToString()); switch (clientMessageType) { case ClientMessage.Pong: reader.ReadPong(connectionID); break; case ClientMessage.PlayerReady: reader.PlayerReady(connectionID); break; case ClientMessage.MovementInput: reader.ReadMovementInput(ExtractVector2(ref stream), connectionID); break; //case ClientMessage.ShootInput: // reader.ShootInput(connectionID, Convert.ToBoolean(stream.ReadByte())); // break; case ClientMessage.PlayerID: int val = stream.ReadInt(); reader.AssignPlayerIDToConnection(connectionID, val); break; default: break; } }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); MoveDirections = reader.ReadByte(); TreasureInRoom = reader.ReadUShort(); ContainsMonster = reader.ReadByte(); ContainsExit = reader.ReadByte(); NumberOfOtherPlayers = reader.ReadByte(); OtherPlayerIDs = new int[NumberOfOtherPlayers]; for (int i = 0; i < NumberOfOtherPlayers; i++) { OtherPlayerIDs[i] = reader.ReadInt(); } //Debug.Log(PlayerName); }
public void ReadingDataFromStreamWithSliceOffset() { var dataStream = new DataStreamWriter(100, Allocator.Temp); dataStream.WriteByte((byte)'a'); dataStream.WriteByte((byte)'b'); dataStream.WriteByte((byte)'c'); dataStream.WriteByte((byte)'d'); dataStream.WriteByte((byte)'e'); dataStream.WriteByte((byte)'f'); var reader = new DataStreamReader(dataStream.AsNativeArray().GetSubArray(3, 3)); Assert.AreEqual('d', reader.ReadByte()); Assert.AreEqual('e', reader.ReadByte()); Assert.AreEqual('f', reader.ReadByte()); }
public void Deserialize(ref DataStreamReader reader) { byte dirtyMask = reader.ReadByte(); Deserialize(ref reader, dirtyMask); SetDirty(dirtyMask); }
public static void Read(DataStreamReader stream, ClientBehaviour reader) { ServerMessage serverMessageType = (ServerMessage)stream.ReadByte(); Debug.Log(reader.name + " got message of type " + serverMessageType.ToString()); switch (serverMessageType) { case ServerMessage.ConnectionID: reader.SaveConnectionID(stream.ReadInt()); break; case ServerMessage.Ping: SendPing(reader.m_Driver, reader.m_Connection); break; //case ServerMessage.Disconnection: // reader.Disconnect((DisconnectionReason)stream.ReadByte()); //break; case ServerMessage.GameStart: reader.GameStart(stream.ReadInt()); break; case ServerMessage.GameOver: reader.GameOver(ref stream); break; case ServerMessage.TurnStart: reader.TurnStart(); break; case ServerMessage.TurnEnd: reader.TurnEnd(); break; case ServerMessage.ScoreUpdate: int score = (int)stream.ReadFloat(); reader.ScoreUpdate(score); break; case ServerMessage.PlayerPositions: reader.UpdatePlayerPositions(ExtractVector3List(ref stream)); break; case ServerMessage.PlayerRotations: reader.UpdatePlayerRotations(ExtractVector3List(ref stream)); break; case ServerMessage.ProjectilePositions: reader.UpdateProjectilePositions(ExtractVector3List(ref stream)); break; case ServerMessage.PlayerTakesDamage: reader.PlayerTakesDamage(ref stream); break; default: break; } }
public void Deserialize(ref DataStreamReader reader) { HasTarget = Convert.ToBoolean(reader.ReadByte()); if (HasTarget) { TargetPlayerId = reader.ReadIntNetworkByteOrder(); } }
public void ReadingDataFromStreamWithSliceOffset() { using (var dataStream = new DataStreamWriter(100, Allocator.Persistent)) { dataStream.Write((byte)'a'); dataStream.Write((byte)'b'); dataStream.Write((byte)'c'); dataStream.Write((byte)'d'); dataStream.Write((byte)'e'); dataStream.Write((byte)'f'); var reader = new DataStreamReader(dataStream, 3, 3); var readerCtx = default(DataStreamReader.Context); Assert.AreEqual('d', reader.ReadByte(ref readerCtx)); Assert.AreEqual('e', reader.ReadByte(ref readerCtx)); Assert.AreEqual('f', reader.ReadByte(ref readerCtx)); } }
public void Deserialize(uint tick, ref DataStreamReader reader) { this.Tick = tick; this.fillType = reader.ReadByte() == 1; this.centerX = reader.ReadFloat(); this.centerY = reader.ReadFloat(); this.radius = reader.ReadFloat(); this.shape = (VoxelShape)reader.ReadInt(); }
public override void Deserialize(DataStreamReader reader) { int uid = reader.ReadInt(); EntityType type = (EntityType)reader.ReadByte(); Entity = new Entity(uid, type); Entity.Dirty = (EntityFlag)reader.ReadByte(); if (Entity.Dirty.HasFlag(EntityFlag.position)) { DeserializePosition(ref reader); } if (Entity.Dirty.HasFlag(EntityFlag.visual)) { DeserializeVisual(ref reader); } }
public void Deserialize(ref DataStreamReader reader) { numberOfScores = reader.ReadByte(); highScores = new KeyValuePair <int, ushort> [numberOfScores]; for (int i = 0; i < numberOfScores; i++) { highScores[i] = new KeyValuePair <int, ushort>(reader.ReadInt(), reader.ReadUShort()); } }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); NumberOfScores = reader.ReadByte(); for (int i = 0; i < NumberOfScores; i++) { PlayerID.Add(reader.ReadInt()); HighScores.Add(reader.ReadUShort()); } }
public void Deserialize(uint tick, ref DataStreamReader reader, VoxelStencilInput baseline, NetworkCompressionModel compressionModel) { this.Tick = tick; this.fillType = reader.ReadByte() == 1; this.centerX = reader.ReadPackedFloat(compressionModel); this.centerY = reader.ReadPackedFloat(compressionModel); this.radius = reader.ReadPackedFloat(compressionModel); this.shape = (VoxelShape)reader.ReadPackedInt(compressionModel); Deserialize(tick, ref reader); }
unsafe public static string ReadString(this DataStreamReader reader, ref DataStreamReader.Context ctx, Encoding encoding) { var length = reader.ReadByte(ref ctx); fixed(byte *buf = buffer) { reader.ReadBytes(ref ctx, buf, length); } return(encoding.GetString(buffer, 0, length)); }
internal void OnRecieveRpcPacket(ushort senderPlayerId, ref DataStreamReader rpcPacket, ref DataStreamReader.Context ctx) { if (!isSyncComplete) { return; } byte componentIndex = rpcPacket.ReadByte(ref ctx); byte methodId = rpcPacket.ReadByte(ref ctx); if (componentIndex < m_recordableBehaviourList.Count) { var behaviour = m_recordableBehaviourList[componentIndex]; if (behaviour == null) { return; } behaviour.OnRecieveRpcPacket(senderPlayerId, methodId, rpcPacket, ctx); } }
public override void DeserializeObject(ref DataStreamReader reader) { base.DeserializeObject(ref reader); NumberOfScores = reader.ReadByte(); PlayerIDHighscorePairs = new HighScorePair[NumberOfScores]; for (int i = 0; i < NumberOfScores; i++) { PlayerIDHighscorePairs[i].playerID = reader.ReadInt(); PlayerIDHighscorePairs[i].score = reader.ReadUShort(); } }
unsafe string ReadString(DataStreamReader reader, ref DataStreamReader.Context ctx) { var length = reader.ReadByte(ref ctx); var buffer = new byte[byte.MaxValue]; fixed(byte *bufferPtr = &buffer[0]) { reader.ReadBytes(ref ctx, bufferPtr, length); } return(encoding.GetString(buffer, 0, length)); }
public void CreateStreamWithPartOfSourceByteArray() { byte[] byteArray = { (byte)'s', (byte)'o', (byte)'m', (byte)'e', (byte)' ', (byte)'d', (byte)'a', (byte)'t', (byte)'a' }; DataStreamWriter dataStream; dataStream = new DataStreamWriter(4, Allocator.Temp); dataStream.WriteBytes(new NativeArray <byte>(byteArray, Allocator.Temp).GetSubArray(0, 4)); Assert.AreEqual(dataStream.Length, 4); var reader = new DataStreamReader(dataStream.AsNativeArray()); for (int i = 0; i < dataStream.Length; ++i) { Assert.AreEqual(byteArray[i], reader.ReadByte()); } Assert.Throws <ArgumentOutOfRangeException>(() => { reader.ReadByte(); }); }
public void OnMessageReceived(DataStreamReader reader) { uint opCodeValue = reader.ReadByte(); OpCode code = (OpCode)Enum.Parse(typeof(OpCode), opCodeValue.ToString()); if (netMessagesActions.ContainsKey(code)) { netMessagesActions[code]?.Invoke(reader); } else { Debug.Log($"Received unknown OPCODE: {code}"); } }