/// <summary> /// 从缓冲池里获得一个对象 /// </summary> /// <returns></returns> public static NetTask AcquireContent(ushort packetId) { var ret = TaskPool.AcquireContent(); ret.isRelease = false; ret.TaskProfile = NetTaskProfile.GetNetTaskProfile(packetId); ret.RecvTime = OneServer.NowTime; ret._packetId = packetId; return(ret); }
/// <summary> /// /// </summary> /// <param name="iPacketID"></param> /// <param name="priority"></param> /// <param name="onPacketReceive"></param> public void Register(ushort iPacketID, PacketPriority priority, PacketReceiveCallback onPacketReceive) { if (m_Handlers[iPacketID] != null) { Logs.Warn("Msgid {0} is replace.", iPacketID); } NetTaskProfile.GetNetTaskProfile(iPacketID); m_Handlers[iPacketID] = new PacketHandler(iPacketID, priority, onPacketReceive); }
/// <summary> /// 注册数据包的处理调用者 /// 注意,如果存在相同的消息id,会进行调用方法的替换操作 /// </summary> /// <param name="iPacketID"></param> /// <param name="onPacketReceive"></param> public void Register(ushort iPacketID, PacketReceiveCallback onPacketReceive) { if (m_Handlers[iPacketID] != null) { // 如果有注册相同的消息id,这里只是进行记录,并不干预运行 Logs.Warn("Msgid {0} is replace.", iPacketID); } // 这里在初始化的时候就把对应的性能监视的对象给创建好 NetTaskProfile.GetNetTaskProfile(iPacketID); m_Handlers[iPacketID] = new PacketHandler(iPacketID, PacketPriority.Normal, onPacketReceive); }
/// <summary> /// /// </summary> /// <param name="packageId"></param> /// <returns></returns> public static NetTaskProfile GetNetTaskProfile(ushort packageId) { NetTaskProfile ret; if (Map.TryGetValue(packageId, out ret)) { return(ret); } // 新建一个包处理,然后 ret = new NetTaskProfile(packageId); Map.TryAdd(packageId, ret); profileList = null; return(ret); }
/// <summary> /// /// </summary> /// <param name="packageId"></param> /// <returns></returns> public static NetTaskProfile GetNetTaskProfile(ushort packageId) { NetTaskProfile ret; if (Map.TryGetValue(packageId, out ret)) { return ret; } // 新建一个包处理,然后 ret = new NetTaskProfile(packageId); Map.TryAdd(packageId, ret); profileList = null; return ret; }