/// <summary> /// Calls TinyDeserialize in all Components that we received updates for. /// </summary> /// <param name="netMsg">A wrapper for a <see cref="TinyNetMsgType.StateUpdate"/> message.</param> void OnStateUpdateMessage(TinyNetMessageReader netMsg) { LastServerTick = netMsg.reader.GetUShort(); if (TinyNetLogLevel.logDev) { TinyLogger.Log("TinyNetClient::OnStateUpdateMessage frame: " + LastServerTick + " channel: " + netMsg.channelId); } while (netMsg.reader.AvailableBytes > 0) { int networkID = netMsg.reader.GetInt(); int rSize = netMsg.reader.GetInt(); _stateUpdateReader.Clear(); //Debug.Log("OnStateUpdate: RawDataSize: " + netMsg.reader.RawDataSize + ", Position: " + netMsg.reader.Position + ", rSize: " + rSize); _stateUpdateReader.SetSource(netMsg.reader.RawData, netMsg.reader.Position, rSize + netMsg.reader.Position); _stateUpdateReader.SetFrameTick(LastServerTick); //Debug.Log("OnStateUpdate: _stateUpdateReader " + _stateUpdateReader.RawDataSize + ", Position: " + _stateUpdateReader.Position); TinyNetIdentity localObject = GetTinyNetIdentityByNetworkID(networkID); if (localObject != null) { localObject.TinyDeserialize(_stateUpdateReader, false); } else { if (TinyNetLogLevel.logWarn) { TinyLogger.LogWarning("Did not find target for sync message for " + networkID); } } // We jump the reader position to the amount of data we read. //netMsg.reader.SetSource(netMsg.reader.RawData, netMsg.reader.Position + rSize, netMsg.reader.RawDataSize); netMsg.reader.SkipBytes(rSize); } foreach (TinyNetIdentity tinyNetId in LocalIdentityObjects.Values) { tinyNetId.OnStateUpdate(); } }
/// <summary> /// Deserializes all <see cref="ITinyNetComponent"/> data. /// </summary> /// <param name="reader">The reader.</param> /// <param name="bInitialState">if set to <c>true</c> [b initial state].</param> public virtual void TinyDeserialize(TinyNetStateReader reader, bool firstStateUpdate) { if (firstStateUpdate && _tinyNetComponents == null) { if (TinyNetLogLevel.logWarn) { TinyLogger.LogWarning("TinyNetIdentity::TinyDeserialize called with firstStateUpdate true, but _tinyNetComponents is null."); } CacheTinyNetObjects(); } if (firstStateUpdate) { for (int i = 0; i < _tinyNetComponents.Length; i++) { _tinyNetComponents[i].ReceiveNetworkID(new TinyNetworkID(TinyInstanceID.NetworkID, (byte)(i + 1))); _recycleReader.Clear(); int rSize = reader.GetInt(); _recycleReader.SetSource(reader.RawData, reader.Position, rSize); _recycleReader.SetFrameTick(reader.FrameTick); _tinyNetComponents[i].TinyDeserialize(_recycleReader, firstStateUpdate); // We jump the reader position to the amount of data we read. reader.SkipBytes(rSize); } return; } switch (_dirtyFlag.Length) { case 8: TinyBitArrayUtil.U64ToBitArray(reader.GetByte(), _dirtyFlag); break; case 16: TinyBitArrayUtil.U64ToBitArray(reader.GetUShort(), _dirtyFlag); break; case 32: TinyBitArrayUtil.U64ToBitArray(reader.GetUInt(), _dirtyFlag); break; case 64: TinyBitArrayUtil.U64ToBitArray(reader.GetULong(), _dirtyFlag); break; } for (int i = 0; i < _tinyNetComponents.Length; i++) { if (_dirtyFlag[i] == true) { _recycleReader.Clear(); int rSize = reader.GetInt(); _recycleReader.SetSource(reader.RawData, reader.Position, rSize); _recycleReader.SetFrameTick(reader.FrameTick); //Debug.Log("[Deserialize] Size: " + rSize + ", DirtyFlag: " + TinyBitArrayUtil.Display(_recycleReader.PeekByte())); _tinyNetComponents[i].TinyDeserialize(_recycleReader, firstStateUpdate); // We jump the reader position to the amount of data we read. reader.SkipBytes(rSize); } } }