private void LateUpdate() { _webClient.ProcessMessageQueue(this); if (_webClient.ConnectionState == ClientState.Connected && Time.time >= _timeToSendNextUpdate) { _timeToSendNextUpdate = Time.time + (1f / Constants.CLIENT_TICKRATE); // GUARD, DONT SEND POSITION IF WE DIDN'T MOVE if (!_overrideDirtySendRule && (_previousPlayerPosition - LocalPlayerTransform.position).magnitude < 0.1f) { return; } // Send our position to server _bitBuffer.Clear(); _bitBuffer.AddByte(1); QuantizedVector3 qPosition = BoundedRange.Quantize(LocalPlayerTransform.position, Constants.WORLD_BOUNDS); _bitBuffer.AddUInt(qPosition.x); _bitBuffer.AddUInt(qPosition.y); _bitBuffer.ToArray(_buffer); _webClient.Send(new ArraySegment <byte>(_buffer, 0, 9)); _previousPlayerPosition = LocalPlayerTransform.position; _overrideDirtySendRule = false; } }
void LateUpdate() { _ws.ProcessMessageQueue(this); if (_ws.ConnectionState == ClientState.Connected) { if (Time.time - _timeSinceLastSend > SendInterval) { _timeSinceLastSend = Time.time; QuantizedVector3 qPosition = BoundedRange.Quantize(_modelTransform.position, Constants.WORLD_BOUNDS); QuantizedQuaternion qRotation = SmallestThree.Quantize(_modelTransform.rotation); ushort qBestTime = HalfPrecision.Quantize(GameTimer.BestTime); _bitBuffer.Clear(); _bitBuffer.AddUInt(qPosition.x) .AddUInt(qPosition.y) .AddUInt(qPosition.z) .AddUInt(qRotation.m) .AddUInt(qRotation.a) .AddUInt(qRotation.b) .AddUInt(qRotation.c) .AddUShort(qBestTime) .ToArray(_byteBuffer); _ws.Send(new ArraySegment <byte>(_byteBuffer, 0, 28)); } } }