コード例 #1
0
        public override void InvokeAction(MingmingBattleLogic source, MingmingBattleLogic target, CardAlignment cardAlignment)
        {
            OnInvoked?.Invoke();

            if (Constraint.MingmingMeetsConstraint(source))
            {
                Action.InvokeAction(source, target, cardAlignment);
            }
        }
コード例 #2
0
ファイル: TinyThreadPool.cs プロジェクト: yswenli/SAEA
        void RunWorkThread()
        {
            _workThread = new Thread(new ThreadStart(() =>
            {
                while (_started)
                {
                    if (_queue != null && _queue.TryDequeue(out Action work))
                    {
                        _maxQueueSemaphore.Release();

                        _maxWorkSemaphore.WaitOne();

                        var th = new Thread(new ThreadStart(() =>
                        {
                            Interlocked.Increment(ref workingThreadCount);
                            try
                            {
                                var result = OnInvoking?.Invoke();

                                if (!result.HasValue || result.Value)
                                {
                                    work.Invoke();

                                    OnInvoked?.Invoke();
                                }
                            }
                            catch (Exception ex)
                            {
                                OnError?.Invoke(new TinyThreadPoolException(ex));
                            }
                            finally
                            {
                                Interlocked.Decrement(ref workingThreadCount);
                                _maxWorkSemaphore.Release();
                            }
                        }));
                        th.Start();
                    }
                    else
                    {
                        _nullProcess.WaitOne(10);
                    }
                }
            }));
            _workThread.IsBackground = true;
            _workThread.Start();
        }
コード例 #3
0
ファイル: Intercom.cs プロジェクト: popcron/intercom
        private void InvokeCallbacks(Invocation inv, OnInvoked callback)
        {
            EnsureMethodsExist();

            //try and do globally first
            for (int i = 0; i < methods.Count; i++)
            {
                if (methods[i].Name == inv.MethodName)
                {
                    ParameterInfo[] parameterInfo = methods[i].GetParameters();
                    if (parameterInfo.Length == inv.Parameters.Length)
                    {
                        //try and match these params
                        bool match = true;
                        for (int p = 0; p < parameterInfo.Length; p++)
                        {
                            Type source   = parameterInfo[p].ParameterType;
                            Type incoming = inv.Parameters[p].GetType();

                            //strictly the same type
                            if (source == incoming)
                            {
                                continue;
                            }

                            //eh close enough through inheritance
                            if (source.IsSubclassOf(incoming))
                            {
                                continue;
                            }

                            match = false;
                            break;
                        }

                        //cool match bro, hit it
                        if (match)
                        {
                            CallMethod(methods[i], inv);
                        }
                    }
                }
            }

            callback?.Invoke(inv);
        }
コード例 #4
0
ファイル: KeySequence.cs プロジェクト: ShawnM427/MonUX
        public void CheckKeys(GameTime gameTime)
        {
            if (gameTime.TotalGameTime - myLastKeyPressTime > myMaxSequenceTime)
            {
                myLastKeyPressTime = gameTime.TotalGameTime;
                myCurrentKey       = 0;
            }

            if (KeyboardManager.GetDelta(myKeyList[myCurrentKey]) == ButtonDelta.Pressed)
            {
                myCurrentKey++;
                if (myCurrentKey >= myKeyList.Count)
                {
                    OnInvoked?.Invoke(this, EventArgs.Empty);
                    myCurrentKey = 0;
                }
            }
        }