123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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);
- /// <summary>
- /// 未释放实例数量
- /// </summary>
- public static int ActiveZoneLayerCount { get { return s_active_object_count.Value; } }
- /// <summary>
- /// 分配实例数量
- /// </summary>
- public static int AllocZoneLayerCount { get { return s_alloc_object_count.Value; } }
- private ZoneLayer layer;
- //private SyncMessageQueue<Task> task_queue = new SyncMessageQueue<Task>();
- private List<Task> task_queue = new List<Task>();
- 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);
- }
- }
|