Example #1
0
    /// <summary>
    /// Recycle the specified message.
    /// </summary>
    public static void Recycle(OscMessage message)
    {
        //Debug.Log( Time.frameCount +  ": OscPool.Recycle: " + message.address + " " + message.GetAddressHash() + "\n" );
        if (message == null)
        {
            return;
        }
        int hash = message.GetAddressHash();
        Stack <OscMessage> stack;

        if (!_messageStacks.TryGetValue(hash, out stack))
        {
            if (_messageStacks.Count >= saftyCapacity)
            {
                return;
            }
            stack = new Stack <OscMessage>();
            _messageStacks.Add(hash, stack);
        }
        if (stack.Count >= saftyCapacity)
        {
            return;
        }
        if (!stack.Contains(message))
        {
            stack.Push(message);
        }
    }
Example #2
0
    void Dispatch(OscMessage message)
    {
        bool anyMessageActivated = _onAnyMessageListenerCount > 0;
        bool messageExposed      = anyMessageActivated;

        // Regular mappings.
        Dictionary <string, OscMapping> mappingLookup;

        if (_regularMappingLookup.TryGetValue(message.GetAddressHash(), out mappingLookup))
        {
            OscMapping mapping;
            if (mappingLookup.TryGetValue(message.address, out mapping))
            {
                InvokeMapping(mapping, message);
                if (!messageExposed)
                {
                    messageExposed = mapping.type == OscMessageType.OscMessage;
                }
            }
        }

        // Special pattern mappings.
        foreach (OscMapping specialMapping in _specialPatternMappings)
        {
            if (specialMapping.IsMatching(message.address))
            {
                InvokeMapping(specialMapping, message);
                if (!messageExposed)
                {
                    messageExposed = specialMapping.type == OscMessageType.OscMessage;
                }
            }
        }

        // Any message handler.
        if (anyMessageActivated)
        {
            _onAnyMessage.Invoke(message);
        }

#if UNITY_EDITOR
        // Editor inspector.
        _inspectorMessageEvent.Invoke(message);
#endif

        // Recycle when possible.
        if (!anyMessageActivated && !messageExposed)
        {
            OscPool.Recycle(message);
        }
    }