예제 #1
0
        public void Run(System.Action action)
        {
            // add to any waiting threads
            for (int i = maxThreads; i < _threads.Count; ++i)
            {
                if (_threads[i].state == FogOfWarThreadState.Running && _threads[i].isWaiting)
                {
                    _threads[i].Run(action);
                    return;
                }
            }

            // create thread
            if (_threads.Count < maxThreads)
            {
                FogOfWarThread newthread = new FogOfWarThread(this);
                _threads.Add(newthread);
                newthread.Run(action);
                return;
            }

            // no available threads, so just add it to the queue
            lock (_actionQueue)
                _actionQueue.Add(action);
        }
예제 #2
0
 internal System.Action RequestNewAction(FogOfWarThread thread)
 {
     lock (_actionQueue)
     {
         if (_actionQueue.Count > 0)
         {
             System.Action newaction = _actionQueue[_actionQueue.Count - 1];
             _actionQueue.RemoveAt(_actionQueue.Count - 1);
             return(newaction);
         }
     }
     return(null);
 }