Exemple #1
0
        public async Task SendPlayerEventAsync(PlayerEvent playerEvent)
        {
            Func <GameEvent, Task> onGameEventAsync;

            _playerEvents.Enqueue(playerEvent);

            onGameEventAsync = OnGameEventAsync;

            if (onGameEventAsync != null)
            {
                if (_gameEvents.Count == 0)
                {
                    // Always send an empty GameEvent as an ACK.
                    await onGameEventAsync(new GameEvent());
                }
                else
                {
                    while (true)
                    {
                        GameEvent gameEvent;
                        _gameEvents.TryDequeue(out gameEvent);
                        if (gameEvent == null)
                        {
                            break;
                        }
                        await onGameEventAsync(gameEvent);
                    }
                }
            }
        }
Exemple #2
0
        public async Task SendPlayerEventAsync(PlayerEvent playerEvent)
        {
            Func<GameEvent, Task> onGameEventAsync;

            _playerEvents.Enqueue(playerEvent);

            onGameEventAsync = OnGameEventAsync;

            if (onGameEventAsync != null)
            {
                if (_gameEvents.Count == 0)
                {
                    // Always send an empty GameEvent as an ACK.
                    await onGameEventAsync(new GameEvent());
                }
                else
                {
                    while (true)
                    {
                        GameEvent gameEvent;
                        _gameEvents.TryDequeue(out gameEvent);
                        if (gameEvent == null) break;
                        await onGameEventAsync(gameEvent);
                    }
                }
            }
        }
Exemple #3
0
        public async Task SendPlayerEventAsync(PlayerEvent playerEvent)
        {
            if (!_isConnected)
            {
                return;
            }

            await _stream.WriteObjectAsync(playerEvent);
        }
Exemple #4
0
        private void HandlePlayerEvent(Channel channel, PlayerEvent playerEvent)
        {
            if (playerEvent.PositionData != null)
            {
                channel.Player.PositionData = playerEvent.PositionData;
            }

            if (playerEvent.BlockUpdates != null)
            {
                AddBlockUpdates(playerEvent.BlockUpdates);
            }
        }
Exemple #5
0
        public PlayerEvent CreatePlayerEvent()
        {
            var playerEvent = new PlayerEvent();

            playerEvent.PositionData = new PositionComponent
            {
                Placement   = PositionData.Placement,
                Velocity    = PositionData.Velocity,
                IsFalling   = PositionData.IsFalling,
                InternalPos = PositionData.InternalPos,
            };

            if (_blockUpdates.Count > 0)
            {
                playerEvent.BlockUpdates = _blockUpdates;
                _blockUpdates            = new List <BlockUpdateData>();
            }

            return(playerEvent);
        }
Exemple #6
0
        private void HandlePlayerEvent(Channel channel, PlayerEvent playerEvent)
        {
            if (playerEvent.PositionData != null)
            {
                channel.Player.PositionData = playerEvent.PositionData;
            }

            if (playerEvent.BlockUpdates != null)
            {
                AddBlockUpdates(playerEvent.BlockUpdates);
            }
        }