//清空 static public void Dispose() { //idToCallback.Clear(); try { Monitor.Enter(_waitingForRun); //Utils.LogSys.Log("Start to Call"); _waitingForRun.Clear(); Monitor.Pulse(_waitingForRun); } finally { Monitor.Exit(_waitingForRun); } LuaStreamCache.ClearAll(); }
public static void ProcessCaches() { if (_luaStreamCaches.Count > 0) { for (var index = 0; index < _luaStreamCaches.Count; index++) { LuaStreamCache cache = _luaStreamCaches[index]; ProtoID pID = cache.id; MemoryStream mem = cache.stream; //Debug.LogWarning("发送缓存LUA消息:" + pID); sluaAux.luaProtobuf.getInstance().receiveMsg((int)pID, mem); cache.Release(); } _luaStreamCaches.Clear(); } }
public static void PushStreamCache(ProtoID pid, MemoryStream stream) { LuaStreamCache cache = new LuaStreamCache(pid, stream); PushStreamCache(cache); }
/// <summary> /// 执行count条存储的消息 /// </summary> /// <param name="count">取出n条执行(默认取出全部)</param> public static void Run(int count = 0) { if (_waitingForRun.Count > 0) { try { Monitor.Enter(_waitingForRun); //Utils.LogSys.Log("Start to Call"); if (count == 0 || count > _waitingForRun.Count) { count = _waitingForRun.Count; } while (count-- > 0) { //Utils.LogSys.LogError("Duel " + _waitingForRun[0]._protoType); NetThreadMsgPackage msgPkg = _waitingForRun.Dequeue(); //C#消息处理 if (idToCallback.ContainsKey(msgPkg.id)) { object protoMsg = ProtoSerializer.ParseFrom(msgPkg.id, msgPkg.stream); MsgObject msgObj = new MsgObject(msgPkg.id, protoMsg); RunCallback(msgObj._protoType, msgObj._proto); } else { //Debug.LogWarning("处理LUA消息:" + msgPkg.id); } msgPkg.stream.Seek(0, SeekOrigin.Begin); //Lua消息处理 if (sluaAux.luaSvrManager.getInstance().IsLoaded) { Utils.LogSys.Log("处理LUA消息:" + msgPkg.id); sluaAux.luaProtobuf.getInstance().receiveMsg((int)msgPkg.id, msgPkg.stream); } else { LuaStreamCache.PushStreamCache(msgPkg.id, msgPkg.stream); } //释放(对应于接收消息线程创建的memorystream) msgPkg.Dispose(); //_waitingForRun[0].RunCallback(); } Monitor.Pulse(_waitingForRun); } finally { Monitor.Exit(_waitingForRun); } } else { ClientNetwork.Instance.CheckIsLostConnect(); } }
public static void PushStreamCache(LuaStreamCache cache) { _luaStreamCaches.Add(cache); }