// main thread protected override void Update() { if (onProxyRecv != null) { lock (proxyPackets) { for (int i = 0; i < proxyPackets.Count; ++i) { onProxyRecv.Invoke(proxyPackets[i]); // OPT: pool for received packet } proxyPackets.Clear(); } } Debug.Assert(onRecv != null); // execute commands stacked in players for (int i = 0; i < sessions.Count; ++i) { var sess = sessions[i]; sess.HandleAllPackets(onRecv); } base.Update(); }
// main thread public void Init(Chan chan) { if (onInit != null) { DH.DHExchange(out secretSend, out modpowerSend); DH.DHExchange(out secretRecv, out modpowerRecv); onInit.Invoke(chan, modpowerSend, modpowerRecv); } }
// worker thread void OnProxyConnected(networking.Chan chan) { chan.recvHandler += HandleProxyRecv; #if UNITY_EDITOR chan.recvHandler += OnStatProxyRecv; chan.onSend += OnStatProxySend; #endif utils.TaskManager.PerformOnMainThread( (obj) => { onProxyConnected.Invoke(chan); }); }
// main thread public void HandleAllPackets(lua.LuaFunction onRecv) { lock (receivedPackets) { for (int i = 0; i < receivedPackets.Count; ++i) { var data = receivedPackets[i]; onRecv.Invoke(id, data); // OPT: pool for received packet } receivedPackets.Clear(); } }
protected override void Update() { Debug.Assert(onRecv != null); lock (receivedPackets) { for (int i = 0; i < receivedPackets.Count; ++i) { var data = receivedPackets[i]; Profiler.BeginSample("Client.OnRecv"); onRecv.Invoke(data); Profiler.EndSample(); // OPT: pool for received packet } receivedPackets.Clear(); } base.Update(); }
// called in worker thread void OnConnected(networking.Chan chan) { chan.recvHandler += HandleRecv; #if UNITY_EDITOR chan.recvHandler += OnStatRecv; chan.onSend += OnStatSend; #endif utils.TaskManager.PerformOnMainThread( (obj) => { Debug.Assert(onConnected != null); onConnected.Invoke(chan); #if UNITY_EDITOR bool left = false; if (rect.x < Screen.width * 0.5f) { left = true; } float x; var width = 200; if (left) { x = rect.width + 10; } else { x = rect.x - 10 - width; } var y = rect.y; var height = 80; Editor_AddGraph_Native( "client_send", "kbps", GetSendBandwidth, 10, 0.5f, x, y, width, height, Color.red); y += height + 5; Editor_AddGraph_Native( "client_recv", "kbps", GetRecvBandwidth, 10, 0.5f, x, y, width, height, Color.blue); #endif }); }
public Action <T> GetAction <T>() { return((arg) => func.Invoke(arg)); }