Пример #1
0
    public override void Process(GameTime gameTime, int entityId)
    {
        var state = playerMapper.Get(entityId);
        var input = inputMapper.Get(entityId);

        input.CurrentFrame = sharedContext.FrameCounter;

        state.LocalPlayerIndex.IfSome(playerIndex => {
            var currentFrame = sharedContext.FrameCounter + sharedContext.FrameOffset;

            if (input.PlayerKeysByFrame.Count >= PlayerInput.InitialFrameBuffer)
            {
                input.PlayerKeysByFrame.Remove(currentFrame - PlayerInput.InitialFrameBuffer);
            }

            if (input.DirectionalInputsByFrame.Count >= PlayerInput.InitialFrameBuffer)
            {
                input.DirectionalInputsByFrame.Remove(currentFrame - PlayerInput.InitialFrameBuffer);
            }

            var playerPressedKeys = pressedKeys[playerIndex];


            if (!input.PlayerKeysByFrame.ContainsKey(currentFrame))
            {
                input.PlayerKeysByFrame[currentFrame] =
                    UpdatePlayerKeys(input.PlayerKeysByFrame.TryGetValue(currentFrame - 1, out var keys) ? keys : PlayerInput.DefaultPlayerKeys(),
                                     playerPressedKeys);
            }


            if (!input.DirectionalInputsByFrame.ContainsKey(currentFrame))
            {
                input.DirectionalInputsByFrame[currentFrame] = GetDirectionalInputs(playerIndex, input, currentFrame);
            }
        });

        debugLogger.AddObject(input);


        if (!input.IsUpToDate())
        {
            sharedContext.IsPaused  = true;
            sharedContext.IsSyncing = true;
        }
    }