Example #1
0
        public void SendAsync(EndPoint endPoint, SendData cmd)
        {
            var args = sendArgsPool.Pop();

            if (args == null)
            {
                while (args != null)
                {
                    args = sendArgsPool.Pop();
                }
            }
            if (cmd.Data.Length + checkLenght > args.Buffer.Length)
            {
                throw new Exception("发送的数据大于buffer最大长度");
            }
            else
            {
                args.RemoteEndPoint = endPoint;
                byte[] length = BitConverter.GetBytes(cmd.Data.Length);
                System.Buffer.BlockCopy(length, 0, args.Buffer, 0, length.Length);
                System.Buffer.BlockCopy(cmd.Data, 0, args.Buffer, checkLenght, cmd.Data.Length);
                args.SetBuffer(0, cmd.Data.Length + checkLenght);
                if (!this.ListenerSocket.SendToAsync(args))
                {
                    SendCompleted(null, args);
                }
            }
        }
Example #2
0
        public void SendAsync(EndPoint endPoint, byte[] data, int offset, int count)
        {
            var args = sendArgsPool.Pop();

            args.Completed += SendCompleted;
            if (args == null)
            {
                SpinWait spinWait = new SpinWait();
                while (args != null)
                {
                    args = sendArgsPool.Pop();
                    spinWait.SpinOnce();
                }
            }
            args.RemoteEndPoint = endPoint;
            args.SetBuffer(data, offset, count);
            if (!ListenerSocket.SendToAsync(args))
            {
                SendCompleted(null, args);
            }
        }
        public IController CreateShipFromData(ShipData data)
        {
            var spawnedShip = _providersPool.Pop();

            var shipModel = new ShipModel(
                new ShipData()
            {
                Provider     = spawnedShip,
                Speed        = data.Speed,
                Acceleration = data.Acceleration,
                HP           = data.HP,
                Force        = data.Force
            });

            var moveImplementation     = new AccelerationMove(spawnedShip.transform, shipModel.Speed, shipModel.Acceleration);
            var rotationImplementation = new RotationShip(spawnedShip.transform);

            GetShip = new Ship(moveImplementation, rotationImplementation, _weapon, shipModel);
            spawnedShip.GetComponent <IView>().ProviderDestroyed += GetShip.WatchToProviderDestroyed;

            GetShip.ReloadRequired += ReloadShipController;

            return(GetShip);
        }