コード例 #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;
                }
            }
        }
コード例 #5
0
ファイル: Intercom.cs プロジェクト: popcron/intercom
        /// <summary>
        /// This should be done very frequently.
        /// </summary>
        public void Poll(OnInvoked callback = null)
        {
            SetCurrentFrame(MySide, GetCurrentFrame(MySide) + 1);
            MemoryMappedViewAccessor input = Input;

            if (input == null)
            {
                return;
            }

            //the other application finished polling all messages
            if (GetReadingState(OtherSide) == ReadingState.Finished)
            {
                SetReadingState(OtherSide, ReadingState.Reading);

                //send out the next batch of messages
                if (queue.Count > 0)
                {
                    SendQueue();
                }
            }

            int position = 0;

            //read the next 8 bytes as an id
            long id = input.ReadInt64(position);

            position += sizeof(long);

            //this message was already processed before
            if (pastMessages.Contains(id))
            {
                //so were done then
                SetReadingState(MySide, ReadingState.Finished);
                return;
            }

            //next 4 bytes is how many messages there are
            int messages = input.ReadInt32(position);

            position += sizeof(int);

            if (messages > 0)
            {
                List <Invocation> invokes = new List <Invocation>();
                for (int m = 0; m < messages; m++)
                {
                    //read message length
                    int length = input.ReadInt32(position);
                    position += sizeof(int);

                    //read message data itself
                    byte[] data = new byte[length];
                    for (int i = 0; i < length; i++)
                    {
                        data[i] = input.ReadByte(position);
                        position++;
                    }

                    //process data
                    if (data.Length > 0)
                    {
                        Invocation newInoke = new Invocation(data, Serializer);
                        invokes.Add(newInoke);
                    }
                }

                for (int i = 0; i < invokes.Count; i++)
                {
                    //try and invoke globally
                    InvokeCallbacks(invokes[i], callback);
                }

                SetReadingState(MySide, ReadingState.Finished);
                pastMessages.Add(id);
            }
            else
            {
                SetReadingState(MySide, ReadingState.Finished);
            }
        }