public WriteBufferHandle(byte[] value) : base(value) { if (TryValid(value)) { buffer = HandleManager.ByteToBuffer(value, Used); } }
public static WriteBufferHandle Instance(BufferEnum write, int verify, byte[] data) { WriteBufferHandle handle = new WriteBufferHandle(null); handle.buffer = write; handle.verify = verify; handle.data = data; return(handle); }
public static ReadBufferHandle Instance(BufferEnum buffer, int verify, byte[] data = null) { ReadBufferHandle handle = new ReadBufferHandle(null); handle.verify = verify; handle.buffer = buffer; handle.data = data; return(handle); }
//打包请求读取远端数据 public void BunchRequestBuffer(BufferEnum read, IPEndPoint remote, Action <Request, byte[]> succeed, Action <Request> failed) { ReadBufferHandle handle = ReadBufferHandle.Instance(read, RandVerify); //监听请求 BunchRequestAdd(handle, remote, succeed, failed); //Debug.Log("发送请求"); BunchSend(); }
public ScreenBuffer CreateScreenBuffer(BufferEnum id, Vector2i size) { var bufferFound = ScreenBuffers.TryGetValue(id, out ScreenBuffer buffer); if (!bufferFound || size.Area() * 4 != buffer.Data?.Length) { // different size if (bufferFound && buffer.Allocated()) { // free old buffer SDL2.SDL.SDL_FreeSurface(buffer.SdlSurfacePtr); Marshal.FreeHGlobal(buffer.UnmanagedPtr); } // create new buffer buffer = new ScreenBuffer { Data = new byte[size.Area() * 4] }; buffer.UnmanagedPtr = Marshal.AllocHGlobal(buffer.Data.Length); buffer.SdlSurfacePtr = SDL2.SDL.SDL_CreateRGBSurfaceFrom(buffer.UnmanagedPtr, size.X, size.Y, 32, 4 * size.X, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); if (!bufferFound) { ScreenBuffers.Add(id, buffer); } else { ScreenBuffers[id] = buffer; } Log.Add($"Renderer.ScreenBuffer({ id }, { size })"); } return(buffer); }
/// <summary> /// 请求读取远端数据,返回一条操作 /// 需要指定读取的数据缓存区和远端网络地址 /// 返回的数据会缓存在回调函数的参数里 /// </summary> public void SingleRequestBuffer(BufferEnum read, IPEndPoint remote, Action <Request, byte[]> succeed, Action <Request> failed) { ReadBufferHandle handle = ReadBufferHandle.Instance(read, RandVerify); Request request = new Request(handle, remote, succeed, failed); request.isSend = false; request.overtime = 1000 / FRAME; request.timeSend = TickTime; request.timeStart = TickTime; request.verify = handle.verify; //添加请求列表 if (RequestDic.TryAdd(handle.verify, request)) { Netstat netstat = NetstatDic.GetOrAdd(remote, new Netstat()); netstat.request += 1; //注册完成后直接发送 SendTo(handle.ToBytes(), remote, request); //Debug.Log("[注册验证]" + request.verify + "[验证总数]" + RequestDic.Count); } //Console.WriteLine("单独发送数据请求"+remote + "[ReadBufferHandle]"); //HandleManager.OutStr += "单独发送" + handle.verify + "数据请求至" + remote + "[ReadBufferHandle]" + "\n"; }
public byte[] GetWriteBuffer(BufferEnum buffer) { return(WriteBufferDic[buffer]); }
public byte[] GetReadBuffer(BufferEnum buffer) { return(ReadBufferDic[buffer]); }
public void UpdateWriteBuffer(BufferEnum buffer, byte[] value) { WriteBufferDic[buffer] = value; }
//写入本地读取缓存 public void UpdateReadBuffer(BufferEnum buffer, byte[] value) { ReadBufferDic[buffer] = value; }