public InputSourceRewired(int playerId, InputActionDefs possibleActions)
    {
        if (playerId == -1)
        {
            player = RE.ReInput.players.SystemPlayer;
            player.controllers.hasKeyboard = true;
            player.controllers.hasMouse    = true;
        }
        else
        {
            player = RE.ReInput.players.GetPlayer(playerId);
        }

        List <InputActionDef> defs = possibleActions.values;

        actions       = new ActionPair[defs.Count];
        actionToIndex = new Dictionary <InputActionDef, int>();
        for (int i = 0; i < defs.Count; i++)
        {
            var def = defs[i];

            actions[i] = new ActionPair
            {
                def    = def,
                action = new InputAction(def.kind),
            };
            actionToIndex[def] = i;
        }
    }
Exemple #2
0
        /// <summary>
        /// Attempts to lock the gate. The action is run once the gate becomes free.
        /// Queued actions are run in order.
        /// </summary>
        public virtual void TryLock(IAction onAvailable, Needle needle = null, bool autoUnlock = true)
        {
            // replace action to unlock once task has run
            if (autoUnlock)
            {
                onAvailable = new ActionPair(onAvailable, Release);
            }

            // try get the lock
            if (TryTake)
            {
                // replace needle reference if needed
                if (needle == null)
                {
                    ManagerUpdate.Control.AddSingle(onAvailable);
                }
                else
                {
                    needle.AddSingle(onAvailable);
                }
                return;
            }

            // add to queue
            _queue.Enqueue(new Act(onAvailable));
        }
    public override void DoUpdate()
    {
        for (int i = 0; i < actions.Length; i++)
        {
            ActionPair pair = actions[i];

            switch (pair.def.kind)
            {
            case InputAction.Kind.Button:
            {
                // Fix something here! Is called for 5/6 Frames
                bool held    = player.GetButton(pair.def.rewiredAction1);
                bool oldHeld = pair.action.buttonHeld;
                var  change  =
                    held == oldHeld ? InputAction.ValueChange.None :
                    held ? InputAction.ValueChange.NotZero :
                    InputAction.ValueChange.Zero
                ;
                pair.action = new InputAction(held, change);
                break;
            }

            case InputAction.Kind.Axis:
            {
                float value    = player.GetAxis(pair.def.rewiredAction1);
                float oldValue = pair.action.axis;
                var   change   =
                    value == oldValue ? InputAction.ValueChange.None :
                    Math.Abs(value) > 0.0f ? InputAction.ValueChange.NotZero :
                    InputAction.ValueChange.Zero
                ;
                pair.action = new InputAction(value, change);
                break;
            }

            case InputAction.Kind.Axis2D:
            {
                Vector2 value    = player.GetAxis2D(pair.def.rewiredAction1, pair.def.rewiredAction2);
                Vector2 oldValue = pair.action.axis2D;
                var     change   =
                    value.sqrMagnitude == oldValue.sqrMagnitude ? InputAction.ValueChange.None :
                    value.sqrMagnitude > 0.0f ? InputAction.ValueChange.NotZero :
                    InputAction.ValueChange.Zero
                ;
                pair.action = new InputAction(value, change);
                break;
            }
            }
        }
    }
Exemple #4
0
 void PerformPush(Board moveBoard, ActionPair move)
 {
     moveBoard.Pieces [moveBoard.Squares [move.fromLoc.x, move.fromLoc.y]]
         .Push.Push (moveBoard.Squares [move.toLoc.x, move.toLoc.y]);
 }
        private void NotifyCaller(ActionPair action, object data)
        {
            if (action.Key == long.MinValue) // A catastrophic failure occurred, clear the queue and log the error.
            {
                foreach (var item in queuedActions)
                {
                    ActionCompleted(item.Key, null);
                }

                evMan.CallListeners(EventType.InternalException, new Exception("An unknown error has occurred; all queued actions have been cleared."));
            }
            else
            {
                ActionCompleted(action.Key, data);
            }
        }
        private void ProcessQueue()
        {
            while (!disposed)
            {
                Thread.Sleep(50);

                if (queuedActions.IsEmpty) { continue; }

                var action = new ActionPair(long.MinValue, null);
                object data = null;
                try
                {
                    action = GetNextAction();
                    data = action.Value.Action.DynamicInvoke();
                }
                catch (Exception ex)
                {
                    evMan.CallListeners(EventType.InternalException, ex);
                }
                finally
                {
                    NotifyCaller(action, data);
                }
            }

            consumerClosed.Set();
        }