Example #1
0
 private async Task WaitForStateChangedAsyncCore(StateWatcher watcher)
 {
     using (watcher.CancellationToken.Register(OnCancellation, watcher))
     {
         await watcher.Tcs.Task.ConfigureAwait(false);
     }
 }
Example #2
0
    public void Start()
    {
        MainMenuEvSys = GetComponentInParent <EventSystem>();

        Watch = new StateWatcher(menuMan, MainMenuAnim, this);

        ThreadPageWatch   = new Thread(new ThreadStart(Watch.TrackPage));
        ThreadButtonWatch = new Thread(new ThreadStart(Watch.TrackButton));

        ThreadPageWatch.Start();
        ThreadButtonWatch.Start();

        //BELOW IMPLIES THAT <<MAX_BUTTONS>> GAMEOBJECTS ALWAYS EXIST
        // Yet are simply not always visible.
        menuTexts = new Text[MenuManager.MAX_BUTTONS];
        for (int i = 0; i < MenuManager.MAX_BUTTONS; i++)
        {
            menuTexts[i] = MenuHolders[i].GetComponentInChildren <Text>();
        }

        //SAME HERE but for the button OBJs not the Text OBJs
        menuButtons = new Button[MenuManager.MAX_BUTTONS];
        for (int i = 0; i < MenuManager.MAX_BUTTONS; i++)
        {
            menuButtons[i] = MenuHolders[i].GetComponentInChildren <Button>();
        }

        DoButtonTextUpdate();
    }
Example #3
0
        internal Task WaitForStateChangedAsync(ConnectivityState lastObservedState, ConnectivityState?waitForState, CancellationToken cancellationToken)
        {
            StateWatcher?watcher;

            lock (_lock)
            {
                if (State != lastObservedState)
                {
                    return(Task.CompletedTask);
                }
                else
                {
                    // Minor optimization to check if we're already waiting for state change
                    // using the specified cancellation token.
                    foreach (var stateWatcher in _stateWatchers)
                    {
                        if (stateWatcher.CancellationToken == cancellationToken &&
                            stateWatcher.WaitForState == waitForState)
                        {
                            return(stateWatcher.Tcs.Task);
                        }
                    }

                    watcher = new StateWatcher(
                        cancellationToken,
                        waitForState,
                        new TaskCompletionSource <object?>(TaskCreationOptions.RunContinuationsAsynchronously));
                    _stateWatchers.Add(watcher);
                }
            }

            return(WaitForStateChangedAsyncCore(watcher));
        }
Example #4
0
 private void OnCancellation(object?s)
 {
     lock (_lock)
     {
         StateWatcher watcher = (StateWatcher)s !;
         if (_stateWatchers.Remove(watcher))
         {
             watcher.Tcs.SetCanceled(watcher.CancellationToken);
         }
     }
 }
Example #5
0
        /// <summary>
        /// Creates new instance of <see cref="MouseDevice"/> with given states count, mouse always attempts
        /// to ensure that there are at least 2 states being recorded.
        /// </summary>
        /// <param name="statesCount"></param>
        public MouseDevice(int statesCount = 0)
        {
            statesCount += 2;

            if (statesCount < 2)
            {
                throw new ArgumentOutOfRangeException(nameof(statesCount));
            }

            StatesCount = statesCount;

            buttonWatcher    = new StateWatcher <MouseButton>();
            mouseStateBuffer = new CircularBuffer <MouseState>(StatesCount);
        }
Example #6
0
        private async Task WaitForStateChangedAsyncCore(StateWatcher watcher, CancellationToken cancellationToken)
        {
            using (cancellationToken.Register(OnCancellation, watcher))
            {
                await watcher.Tcs.Task.ConfigureAwait(false);
            }

            void OnCancellation(object?s)
            {
                lock (_lock)
                {
                    StateWatcher watcher = (StateWatcher)s !;
                    if (_stateWatchers.Remove(watcher))
                    {
                        watcher.Tcs.SetCanceled();
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Creates new instance of <see cref="KeyboardDevice"/> with given states count, keyboard always attempts
        /// to ensure that there are at least 2 states being recorded.
        /// </summary>
        public KeyboardDevice(GameWindow window, int statesCount = 0)
        {
            // Attempt to ensure that at least 2 states get recorded.
            statesCount += 2;

            if (statesCount < 2)
            {
                throw new ArgumentOutOfRangeException(nameof(statesCount));
            }

            StatesCount = statesCount;

            keyWatcher              = new StateWatcher <Keys>();
            keyboardStateBuffer     = new CircularBuffer <KeyboardState>(StatesCount);
            keyboardCharacterBuffer = new CircularBuffer <string>(StatesCount);

            keyboardCharacterFrameBuffer = new StringBuilder();

            window.TextInput += Window_TextInput;
        }
Example #8
0
        /// <summary>
        /// Set state
        /// </summary>
        /// <param name="watcher">watcher</param>
        /// <param name="_pause">pause</param>
        // ----------------------------------------------------------------------------------------------
        public void setState(StateWatcher <PauseState> watcher, bool _pause)
        {
            this.pause = _pause;

            watcher.sendState();
        }
 void Start()
 {
     this.m_refPauseStateWatcher = SimpleReduxManager.Instance.PauseStateWatcher;
 }