Ejemplo n.º 1
0
        public void Update()
        {
            var mouseState = Mouse.GetState();
            var mousePoint = new Point(mouseState.X, mouseState.Y);

            for (var i = 0; i < _containers.Length; i++)
            {
                if (_containers[i].Position.Contains(mousePoint))
                {
                    _containers[i].OnFocus = true;
                    _containersOnFocus.Add(_containers[i]);


                    if (mouseState.LeftButton != ButtonState.Pressed ||
                        _prevMouseState.LeftButton == ButtonState.Pressed)
                    {
                        continue;
                    }

                    _indexOnFocus = i;

                    SwapContainer.Swap(_containers[i]);
                }
            }
            _prevContainersOnFocus.ToList().Where(container => !_containersOnFocus.Contains(container)).ToList().ForEach(container => container.OnFocus = false);

            _prevMouseState        = mouseState;
            _prevContainersOnFocus = _containersOnFocus;
            _containersOnFocus     = new HashSet <Container>();
        }
Ejemplo n.º 2
0
        private void RefreshClientList()
        {
            // accept client connection
            if (waitClientQueue.Out.Count == 0)
            {
                waitClientQueue.Swap();
                foreach (var clientConnection in waitClientQueue.Out)
                {
                    if (clientDict.ContainsKey(clientConnection.connectionId))
                    {
                        Logger.Error("ServerNetwork.RefreshClientList connector exist id={0}", clientConnection.connectionId);
                        return;
                    }

                    clientDict.Add(clientConnection.connectionId, clientConnection);
                    OnClientConnected?.Invoke(clientConnection);
                    clientConnection.BeginReceive();
                }
                waitClientQueue.Out.Clear();
            }

            // close client connection
            if (closeClientQueue.Out.Count == 0)
            {
                closeClientQueue.Swap();
                foreach (var clientConnection in closeClientQueue.Out)
                {
                    if (clientDict.ContainsKey(clientConnection.connectionId))
                    {
                        clientDict.Remove(clientConnection.connectionId);
                        clientConnection.Close();
                        OnClientDisconnected?.Invoke(clientConnection);
                    }
                }
                closeClientQueue.Out.Clear();
            }

            foreach (var client in clientDict.Values)
            {
                client.Send();
                if (client.DefferedClose)
                {
                    // close client deffered close
                    CloseClient(client, NetworkCloseMode.DefferedClose);
                }
            }
        }
Ejemplo n.º 3
0
        public void ProcessMessageQueue(MessageHandler messageHandler)
        {
            if (!Connected)
            {
                return;
            }

            if (messageQueue.Out.Count == 0)
            {
                messageQueue.Swap();
            }

            while (messageQueue.Out.Count > 0)
            {
                var msg = messageQueue.Out.Dequeue();
                messageHandler(this, msg);
            }
        }