Exemple #1
0
        internal WorldTask GetNextWorldTask()
        {
            if (this.CurrentWorld == null)
            {
                return(null);
            }

            if (this._enum.MoveNext() == true)
            {
                return(new WorldTask(
                           DateTime.Now.Add(this._enum.Current),
                           delegate()
                {
                    WorldTask task = this.GetNextWorldTask();
                    if (task != null)
                    {
                        this.CurrentWorld.AddWorldTask(task);
                    }
                }));
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
 public void AddLife(WorldTask Life)
 {
     lock (this.SyncRoot)
     {
         this._storage.Add(Life, null);
         this._wait.Set();
     }
 }
Exemple #3
0
 private void Running()
 {
     while (this._Disposed == false)
     {
         WorldTask item = _cq.GetNextLife();
         TimeSpan  idle = item.ExecuteTime - DateTime.Now;
         if (idle > TimeSpan.Zero)
         {
             // 時間還沒到,發呆一下等到時間到為止
             Thread.Sleep(idle);
         }
         ThreadPool.QueueUserWorkItem(item.ExecuteTask);
         //ThreadPool.QueueUserWorkItem(RunLifeNextStateChange, item);
     }
 }
Exemple #4
0
        public WorldTask GetNextLife()
        {
            WorldTask item = null;

            while ((item = this.CheckNextLife()) == null)
            {
                //Thread.Sleep(0);
                this._wait.WaitOne();
            }

            lock (this.SyncRoot)
            {
                this._storage.Remove(item);
                //System.Diagnostics.Trace.WriteLine(string.Format("Life({0},{1},{2})", item.PosX, item.PosY, item.NextWakeUpTime));
                return(item);
            }
        }
Exemple #5
0
        //public void MovePosition(Life item, int moveX, int moveY)
        //{
        //}

        //public IEnumerable<Life> FindLivies(int posX, int posY)
        //{
        //    if (this._map[posX, posY] == null) yield break;
        //    return this._map[posX, posY];
        //}

        internal void AddWorldTask(WorldTask task)
        {
            this._cq.AddLife(task);
        }