public static MsgHandleObj Allocate(int mId, ulong uId, CsMessageBus.MessageHandle h, string type) { MsgHandleObj tmp; if (recircleObj.Count > 0) { tmp = recircleObj.Pop(); tmp.msgId = mId; tmp.uid = uId; tmp.handle = h; tmp.msgType = type; ReCounter++; } else { tmp = new MsgHandleObj() { msgId = mId, uid = uId, handle = h, msgType = type }; newCounter++; } tmp.removed = false; //Debug.LogError("newCounter " + newCounter + " ReCounter " + ReCounter); return(tmp); }
public static void PreInit() { for (int i = 0; i < _intSize; i++) { var o = new MsgHandleObj(); recircleObj.Push(o); } }
public static void Release(MsgHandleObj b) { if (isMaxSize) { return; } recircleObj.Push(b); }
public void ClearDicByType(string type) { if (_msgDic.ContainsKey(type)) { _msgDic[type].ForEach(x => { MsgHandleObj.Release(x); }); _msgDic[type].Clear(); _msgDic.Remove(type); } //else // Debug.LogError( type +" not exit ? " ); }
int RegMsg(string messageType, MessageHandle handle, ulong id = UInt64.MinValue) { int _hid = ++handleCounter; List <MsgHandleObj> list = null; if (!_msgDic.TryGetValue(messageType, out list)) { list = new List <MsgHandleObj>(); _msgDic.Add(messageType, list); } _msgRef.Add(_hid, messageType); if (handle == null) { // ? null ? Debug.LogError("RegMsg " + messageType); } else { MsgHandleObj obj = MsgHandleObj.Allocate(_hid, id, handle, messageType); if (list.Contains(obj) == false) { if (list.Count > 0) { var o = list[list.Count - 1]; // todo, 可以针对 plato trigger In 高频 事件 优化 插入 if (o.removed) { list[list.Count - 1] = obj; } else { list.Add(obj); } } else { list.Add(obj); } } } return(_hid); }
public void Init() { MsgHandleObj.PreInit(); }