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); } }
public void AddLife(WorldTask Life) { lock (this.SyncRoot) { this._storage.Add(Life, null); this._wait.Set(); } }
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); } }
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); } }
//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); }