Пример #1
0
    private void CheckAxisInputs(string name)
    {
        float axis = InputBuffer.Instance.GetAxis(name);

        //active will be non-null if input was active (non-zero) last frame
        TASInput active;

        activeInputs.TryGetValue(name, out active);

        if (axis != 0.0f)
        {
            if (active != null)
            {
                //if axis is still active and has the same value, increase its duration and time to live
                if (active.Value == axis)
                {
                    active.Duration++;
                    active.TimeToLive++;
                    return;
                }
                //no need to remove input from active dictionary as it will be replaced next
            }

            //create a new input with a duration of 1 frame
            active             = new TASInput(name, axis, 1);
            activeInputs[name] = active;

            //add the input to the input list for this frame
            GetInputListForThisFrame().Inputs.Add(active);
        }
        else if (active != null)
        {
            activeInputs.Remove(name);
        }
    }
Пример #2
0
    private void RemoveDeadInputs()
    {
        List <string> toRemove = new List <string>();

        foreach (string name in activeInputs.Keys)
        {
            if (activeInputs[name].TimeToLive == 0)
            {
                toRemove.Add(name);
            }
        }

        //must use two different for loops to avoid concurrent modification exception
        foreach (string name in toRemove)
        {
            activeInputs.Remove(name);
        }
    }