void Update() { _messageCount = 0; if (_mappings == null || !isOpen) { return; } // As little work as possible while we touch the locked buffers. //Debug.Log( "UNITY THREAD: " + DateTime.Now.Second + ":" + DateTime.Now.Millisecond ); lock ( _lock ) { // Parse messages and put them in a queue. for (int i = 0; i < _lockedBufferCount; i++) { TempBuffer buffer = _lockedBufferList[i]; OscPacket packet; int index = 0; if (OscPacket.TryReadFrom(buffer.content, ref index, buffer.count, out packet)) { _packetQueue.Enqueue(packet); } //Debug.Log( "Frame: " + Time.frameCount + ", buffer index: " + i + ", size :" + buffer.count ); } _lockedBufferCount = 0; } // If no messages, job done. if (_packetQueue.Count == 0) { return; } // Update mappings. if (_regularMappingLookup == null || _dirtyMappings) { UpdateMappings(); } // Now we can take our time, go through the queue and dispatch the messages. while (_packetQueue.Count > 0) { UnpackRecursivelyAndDispatch(_packetQueue.Dequeue()); } if (_filterDuplicates) { _uniqueAddresses.Clear(); } }
void Update() { _messageCountLastFrame = 0; _byteCountLastFrame = 0; if (_mappings == null || !isOpen) { return; } // As little work as possible while we touch the locked buffers. lock ( _lock ) { if (_lockedReceiveBuffer != null) { if (_safeReceiveBuffer == null || _safeReceiveBuffer.Length < _lockedReceiveBuffer.Length) { _safeReceiveBuffer = new byte[_lockedReceiveBuffer.Length]; } if (_lockedReceiveBufferCount > 0) { Array.Copy(_lockedReceiveBuffer, 0, _safeReceiveBuffer, 0, _lockedReceiveBufferByteCount); } } // Update and reset counters. _safeReceiveBufferByteCount = _lockedReceiveBufferByteCount; // Including zero padding. _byteCountLastFrame = _lockedReceiveBufferCount == 0 ? 0 : _safeReceiveBufferByteCount - (4 * (_lockedReceiveBufferCount - 1)); // Excluding zero padding. _lockedReceiveBufferByteCount = 0; _lockedReceiveBufferCount = 0; } // If no data, job done. if (_safeReceiveBufferByteCount == 0) { return; } // Parse packets and put them in a queue. int index = 0; while (index < _safeReceiveBufferByteCount) { OscPacket packet; if (OscPacket.TryReadFrom(_safeReceiveBuffer, ref index, _safeReceiveBufferByteCount, out packet)) { _packetQueue.Enqueue(packet); } } // If no messages, job done. if (_packetQueue.Count == 0) { return; } // Update mappings. if (_dirtyMappings) { UpdateMappings(); } // Dispatch messages. while (_packetQueue.Count > 0) { UnpackRecursivelyAndDispatch(_packetQueue.Dequeue()); } if (_filterDuplicates) { _uniqueAddresses.Clear(); } }