using System; using System.Collections.Generic; using System.Text; using CommonLang.Protocol; using CommonAI.ZoneClient; using CommonAI.Zone; using RoomService.Net.BsServer; using CommonLang; using CommonAI.RTS; using CommonLang.Vector; using CommonAI.Zone.ZoneEditor; using CommonAI; using CommonLang.Concurrent; namespace CommonAIClient.Client { public abstract class AbstractBattle : Disposable, ILayerClient { private static AtomicInteger s_alloc_object_count = new AtomicInteger(0); private static AtomicInteger s_active_object_count = new AtomicInteger(0); /// /// 未释放实例数量 /// public static int ActiveZoneLayerCount { get { return s_active_object_count.Value; } } /// /// 分配实例数量 /// public static int AllocZoneLayerCount { get { return s_alloc_object_count.Value; } } private ZoneLayer layer; //private SyncMessageQueue task_queue = new SyncMessageQueue(); private List task_queue = new List(); public ZoneLayer Layer { get { return layer; } } public ZoneActor Actor { get { return layer.Actor; } } public EditorTemplates DataRoot { get; private set; } public AbstractBattle(EditorTemplates datas) { s_alloc_object_count++; s_active_object_count++; this.DataRoot = datas; this.layer = TemplateManager.Factory.CreateClientZoneLayer(datas, this); } ~AbstractBattle() { s_alloc_object_count--; } protected override void Disposing() { //lock (task_queue) { this.task_queue.Clear(); } this.layer.Dispose(); s_active_object_count--; } // public virtual ZoneLayer GenLayer() // { // return new ZoneLayer(DataRoot, this); // } public abstract bool IsNet { get; } public abstract int CurrentPing { get; } public abstract long RecvPackages { get; } public abstract long SendPackages { get; } public abstract KickedByServerNotifyB2C KickMessage { get; } public virtual void BeginUpdate(int intervalMS) { this.layer.BeginUpdate(intervalMS); } public virtual void Update() { //this.task_queue.ProcessMessages(doTask); //lock (task_queue) { var num = task_queue.Count; for (int i = 0; i < num; i++) { doTask(task_queue[i]); } task_queue.RemoveRange(0, num); } this.layer.Update(); } //------------------------------------------------------------------- public abstract void SendAction(CommonAI.Zone.Action action); public virtual void BattleReady(bool bok) { } //------------------------------------------------------------------- public void QueueTask(Task task) { //task_queue.Enqueue(task); //lock (task_queue) { task_queue.Add(task); } } private void doTask(Task task) { task(this); } public delegate void Task(AbstractBattle bc); } }