示例#1
0
    /// <summary>
    /// 派发消息
    /// </summary>
    public void dispatch(int type, T data = default(T))
    {
        IntObjectMap <BaseEventAction> dic = _listenerDic.get(type);

        if (dic == null)
        {
            return;
        }

        int[]             keys   = dic.getKeys();
        BaseEventAction[] values = dic.getValues();
        int fv = dic.getFreeValue();
        int k;
        int safeIndex = dic.getLastFreeIndex();

        for (int i = safeIndex - 1; i != safeIndex; --i)
        {
            if (i < 0)
            {
                i = values.Length;
            }
            else if ((k = keys[i]) != fv)
            {
                values[i].execute(data);

                if (k != keys[i])
                {
                    ++i;
                }
            }
        }

        if (data != null && data is IEvt)
        {
            ((IEvt)data).clear();
        }
    }