public override void InvokeAction(MingmingBattleLogic source, MingmingBattleLogic target, CardAlignment cardAlignment)
        {
            OnInvoked?.Invoke();

            if (Constraint.MingmingMeetsConstraint(source))
            {
                Action.InvokeAction(source, target, cardAlignment);
            }
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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;
                }
            }
        }