提交 f4dd94f7 编写于 作者: T tanghai

继承结构调整,Object->Component->ComponentWithId->Entity 中间加了一层ComponentWithId结构,主要考虑到,大部分组件是不需要Id这一字段的,

但是也有少部分需要,例如玩家的物品背包组件需要单独存数据库,那么这个组件需要Id,需要存数据库的组件都需要继承ComponentWithId
上级 b8f6b57f
......@@ -53,6 +53,7 @@ namespace App
Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
Game.Scene.AddComponent<NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
Game.Scene.AddComponent<AppManagerComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.Realm:
Game.Scene.AddComponent<ActorMessageDispatherComponent>();
......@@ -60,6 +61,7 @@ namespace App
Game.Scene.AddComponent<NetOuterComponent, IPEndPoint>(outerConfig.IPEndPoint);
Game.Scene.AddComponent<LocationProxyComponent>();
Game.Scene.AddComponent<RealmGateAddressComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.Gate:
Game.Scene.AddComponent<PlayerComponent>();
......@@ -69,10 +71,12 @@ namespace App
Game.Scene.AddComponent<LocationProxyComponent>();
Game.Scene.AddComponent<ActorProxyComponent>();
Game.Scene.AddComponent<GateSessionKeyComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.Location:
Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
Game.Scene.AddComponent<LocationComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.Map:
Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(innerConfig.IPEndPoint);
......@@ -81,6 +85,7 @@ namespace App
Game.Scene.AddComponent<ActorProxyComponent>();
Game.Scene.AddComponent<ActorMessageDispatherComponent>();
Game.Scene.AddComponent<ServerFrameComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.AllServer:
Game.Scene.AddComponent<ActorProxyComponent>();
......@@ -99,6 +104,7 @@ namespace App
Game.Scene.AddComponent<GateSessionKeyComponent>();
Game.Scene.AddComponent<ConfigComponent>();
Game.Scene.AddComponent<ServerFrameComponent>();
Game.Scene.AddComponent<ActorManagerComponent>();
break;
case AppType.Benchmark:
Game.Scene.AddComponent<NetOuterComponent>();
......
......@@ -10,7 +10,11 @@ namespace ETHotfix
{
public override void Awake(ActorComponent self)
{
self.Awake();
self.entityActorHandler = new CommonEntityActorHandler();
self.queue = new Queue<ActorMessageInfo>();
Game.Scene.GetComponent<ActorManagerComponent>().Add(self.Entity);
self.HandleAsync();
}
}
......@@ -19,7 +23,11 @@ namespace ETHotfix
{
public override void Awake(ActorComponent self, IEntityActorHandler iEntityActorHandler)
{
self.Awake(iEntityActorHandler);
self.entityActorHandler = iEntityActorHandler;
self.queue = new Queue<ActorMessageInfo>();
Game.Scene.GetComponent<ActorManagerComponent>().Add(self.Entity);
self.HandleAsync();
}
}
......@@ -28,7 +36,16 @@ namespace ETHotfix
{
public override void Load(ActorComponent self)
{
self.Load();
self.entityActorHandler = (IEntityActorHandler)HotfixHelper.Create(self.entityActorHandler);
}
}
[ObjectSystem]
public class ActorComponentDesdroySystem : DestroySystem<ActorComponent>
{
public override void Destroy(ActorComponent self)
{
Game.Scene.GetComponent<ActorManagerComponent>().Remove(self.Entity.Id);
}
}
......@@ -37,34 +54,14 @@ namespace ETHotfix
/// </summary>
public static class ActorComponentEx
{
public static void Awake(this ActorComponent self)
{
self.entityActorHandler = new CommonEntityActorHandler();
self.queue = new Queue<ActorMessageInfo>();
self.HandleAsync();
}
public static void Awake(this ActorComponent self, IEntityActorHandler iEntityActorHandler)
{
self.entityActorHandler = iEntityActorHandler;
self.queue = new Queue<ActorMessageInfo>();
self.HandleAsync();
}
// 热更新要重新创建接口,以便接口也能实现热更新
public static void Load(this ActorComponent self)
{
self.entityActorHandler = (IEntityActorHandler) HotfixHelper.Create(self.entityActorHandler);
}
public static async Task AddLocation(this ActorComponent self)
{
await Game.Scene.GetComponent<LocationProxyComponent>().Add(self.Parent.InstanceId);
await Game.Scene.GetComponent<LocationProxyComponent>().Add(self.Entity.Id);
}
public static async Task RemoveLocation(this ActorComponent self)
{
await Game.Scene.GetComponent<LocationProxyComponent>().Remove(self.Parent.InstanceId);
await Game.Scene.GetComponent<LocationProxyComponent>().Remove(self.Entity.Id);
}
public static void Add(this ActorComponent self, ActorMessageInfo info)
......@@ -92,7 +89,7 @@ namespace ETHotfix
return self.tcs.Task;
}
private static async void HandleAsync(this ActorComponent self)
public static async void HandleAsync(this ActorComponent self)
{
while (true)
{
......
......@@ -13,13 +13,13 @@ namespace ETHotfix
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
List<Component> components = await dbCacheComponent.GetBatch(message.CollectionName, message.IdList);
List<ComponentWithId> components = await dbCacheComponent.GetBatch(message.CollectionName, message.IdList);
response.Components = components;
if (message.NeedCache)
{
foreach (Component component in components)
foreach (ComponentWithId component in components)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
......
......@@ -13,13 +13,13 @@ namespace ETHotfix
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
List<Component> components = await dbCacheComponent.GetJson(message.CollectionName, message.Json);
List<ComponentWithId> components = await dbCacheComponent.GetJson(message.CollectionName, message.Json);
response.Components = components;
if (message.NeedCache)
{
foreach (Component component in components)
foreach (ComponentWithId component in components)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
......
......@@ -12,7 +12,7 @@ namespace ETHotfix
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
Component component = await dbCacheComponent.Get(message.CollectionName, message.Id);
ComponentWithId component = await dbCacheComponent.Get(message.CollectionName, message.Id);
response.Component = component;
......
......@@ -20,7 +20,7 @@ namespace ETHotfix
if (message.NeedCache)
{
foreach (Component component in message.Components)
foreach (ComponentWithId component in message.Components)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
......
......@@ -16,7 +16,7 @@ namespace ETHotfix
// 在map服务器上创建战斗Unit
IPEndPoint mapAddress = Game.Scene.GetComponent<StartConfigComponent>().MapConfigs[0].GetComponent<InnerConfig>().IPEndPoint;
Session mapSession = Game.Scene.GetComponent<NetInnerComponent>().Get(mapAddress);
M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.InstanceId });
M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.Id });
player.UnitId = createUnit.UnitId;
response.UnitId = createUnit.UnitId;
response.Count = createUnit.Count;
......
......@@ -14,7 +14,7 @@ namespace ETHotfix
// 收到actor消息,放入actor队列
if (message is IActorMessage iActorMessage)
{
Entity entity = Game.EventSystem.Get(iActorMessage.ActorId) as Entity;
Entity entity = Game.Scene.GetComponent<ActorManagerComponent>().Get(iActorMessage.ActorId);
if (entity == null)
{
Log.Warning($"not found actor: {iActorMessage.ActorId}");
......
using System.Collections.Generic;
namespace ETModel
{
/// <summary>
/// 用来管理该服务器上所有的Actor对象
/// </summary>
public class ActorManagerComponent : Component
{
private readonly Dictionary<long, Entity> dictionary = new Dictionary<long, Entity>();
public void Add(Entity entity)
{
Log.Info($"add actor: {entity.Id} {entity.GetType().Name}");
dictionary[entity.Id] = entity;
}
public void Remove(long id)
{
Entity entity;
if (!this.dictionary.TryGetValue(id, out entity))
{
return;
}
Log.Info($"remove actor: {entity.Id} {entity.GetType().Name}");
this.dictionary.Remove(id);
}
public Entity Get(long id)
{
Entity entity = null;
this.dictionary.TryGetValue(id, out entity);
return entity;
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
}
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ namespace ETModel
}
}
public sealed class ActorProxy : Component
public sealed class ActorProxy : ComponentWithId
{
// actor的地址
public IPEndPoint Address;
......
......@@ -17,7 +17,7 @@ namespace ETModel
/// </summary>
public class DBCacheComponent : Component
{
public Dictionary<string, Dictionary<long, Component>> cache = new Dictionary<string, Dictionary<long, Component>>();
public Dictionary<string, Dictionary<long, ComponentWithId>> cache = new Dictionary<string, Dictionary<long, ComponentWithId>>();
public const int taskCount = 32;
public List<DBTaskQueue> tasks = new List<DBTaskQueue>(taskCount);
......@@ -31,7 +31,7 @@ namespace ETModel
}
}
public Task<bool> Add(Component component, string collectionName = "")
public Task<bool> Add(ComponentWithId component, string collectionName = "")
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
......@@ -41,43 +41,43 @@ namespace ETModel
{
collectionName = component.GetType().Name;
}
DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, Component, string, TaskCompletionSource<bool>>(component.Id, component, collectionName, tcs);
DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, ComponentWithId, string, TaskCompletionSource<bool>>(component.Id, component, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public Task<bool> AddBatch(List<Component> components, string collectionName)
public Task<bool> AddBatch(List<ComponentWithId> components, string collectionName)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<Component>, string, TaskCompletionSource<bool>>(components, collectionName, tcs);
DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<ComponentWithId>, string, TaskCompletionSource<bool>>(components, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public void AddToCache(Component component, string collectionName = "")
public void AddToCache(ComponentWithId component, string collectionName = "")
{
if (string.IsNullOrEmpty(collectionName))
{
collectionName = component.GetType().Name;
}
Dictionary<long, Component> collection;
Dictionary<long, ComponentWithId> collection;
if (!this.cache.TryGetValue(collectionName, out collection))
{
collection = new Dictionary<long, Component>();
collection = new Dictionary<long, ComponentWithId>();
this.cache.Add(collectionName, collection);
}
collection[component.Id] = component;
}
public Component GetFromCache(string collectionName, long id)
public ComponentWithId GetFromCache(string collectionName, long id)
{
Dictionary<long, Component> d;
Dictionary<long, ComponentWithId> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return null;
}
Component result;
ComponentWithId result;
if (!d.TryGetValue(id, out result))
{
return null;
......@@ -87,7 +87,7 @@ namespace ETModel
public void RemoveFromCache(string collectionName, long id)
{
Dictionary<long, Component> d;
Dictionary<long, ComponentWithId> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return;
......@@ -95,28 +95,28 @@ namespace ETModel
d.Remove(id);
}
public Task<Component> Get(string collectionName, long id)
public Task<ComponentWithId> Get(string collectionName, long id)
{
Component component = GetFromCache(collectionName, id);
ComponentWithId component = GetFromCache(collectionName, id);
if (component != null)
{
return Task.FromResult(component);
}
TaskCompletionSource<Component> tcs = new TaskCompletionSource<Component>();
DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, TaskCompletionSource<Component>>(id, collectionName, tcs);
TaskCompletionSource<ComponentWithId> tcs = new TaskCompletionSource<ComponentWithId>();
DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, TaskCompletionSource<ComponentWithId>>(id, collectionName, tcs);
this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);
return tcs.Task;
}
public Task<List<Component>> GetBatch(string collectionName, List<long> idList)
public Task<List<ComponentWithId>> GetBatch(string collectionName, List<long> idList)
{
List <Component> components = new List<Component>();
List <ComponentWithId> components = new List<ComponentWithId>();
bool isAllInCache = true;
foreach (long id in idList)
{
Component component = this.GetFromCache(collectionName, id);
ComponentWithId component = this.GetFromCache(collectionName, id);
if (component == null)
{
isAllInCache = false;
......@@ -130,18 +130,18 @@ namespace ETModel
return Task.FromResult(components);
}
TaskCompletionSource<List<Component>> tcs = new TaskCompletionSource<List<Component>>();
DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, TaskCompletionSource<List<Component>>>(idList, collectionName, tcs);
TaskCompletionSource<List<ComponentWithId>> tcs = new TaskCompletionSource<List<ComponentWithId>>();
DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, TaskCompletionSource<List<ComponentWithId>>>(idList, collectionName, tcs);
this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
return tcs.Task;
}
public Task<List<Component>> GetJson(string collectionName, string json)
public Task<List<ComponentWithId>> GetJson(string collectionName, string json)
{
TaskCompletionSource<List<Component>> tcs = new TaskCompletionSource<List<Component>>();
TaskCompletionSource<List<ComponentWithId>> tcs = new TaskCompletionSource<List<ComponentWithId>>();
DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, TaskCompletionSource<List<Component>>>(collectionName, json, tcs);
DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, TaskCompletionSource<List<ComponentWithId>>>(collectionName, json, tcs);
this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
return tcs.Task;
......
......@@ -27,9 +27,9 @@ namespace ETModel
//this.database = this.mongoClient.GetDatabase(config.DBName);
}
public IMongoCollection<Component> GetCollection(string name)
public IMongoCollection<ComponentWithId> GetCollection(string name)
{
return this.database.GetCollection<Component>(name);
return this.database.GetCollection<ComponentWithId>(name);
}
}
}
\ No newline at end of file
......@@ -27,55 +27,55 @@ namespace ETModel
dbAddress = dbStartConfig.GetComponent<InnerConfig>().IPEndPoint;
}
public async Task Save(Component component, bool needCache = true)
public async Task Save(ComponentWithId component, bool needCache = true)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache});
}
public async Task SaveBatch(List<Component> components, bool needCache = true)
public async Task SaveBatch(List<ComponentWithId> components, bool needCache = true)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call(new DBSaveBatchRequest { Components = components, NeedCache = needCache});
}
public async Task Save(Component component, bool needCache, CancellationToken cancellationToken)
public async Task Save(ComponentWithId component, bool needCache, CancellationToken cancellationToken)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache}, cancellationToken);
}
public async void SaveLog(Component component)
public async void SaveLog(ComponentWithId component)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = false, CollectionName = "Log" });
}
public async Task<T> Query<T>(long id, bool needCache = true) where T: Component
public async Task<T> Query<T>(long id, bool needCache = true) where T: ComponentWithId
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
return (T)dbQueryResponse.Component;
}
public async Task<List<T>> QueryBatch<T>(List<long> ids, bool needCache = true) where T : Component
public async Task<List<T>> QueryBatch<T>(List<long> ids, bool needCache = true) where T : ComponentWithId
{
List<T> list = new List<T>();
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
foreach (Component component in dbQueryBatchResponse.Components)
foreach (ComponentWithId component in dbQueryBatchResponse.Components)
{
list.Add((T)component);
}
return list;
}
public async Task<List<T>> QueryJson<T>(string json, bool needCache = true) where T : Component
public async Task<List<T>> QueryJson<T>(string json, bool needCache = true) where T : ComponentWithId
{
List<T> list = new List<T>();
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(dbAddress);
DBQueryJsonResponse dbQueryJsonResponse = (DBQueryJsonResponse)await session.Call(new DBQueryJsonRequest { CollectionName = typeof(T).Name, Json = json, NeedCache = needCache});
foreach (Component component in dbQueryJsonResponse.Components)
foreach (ComponentWithId component in dbQueryJsonResponse.Components)
{
list.Add((T)component);
}
......
......@@ -7,9 +7,9 @@ using MongoDB.Driver;
namespace ETModel
{
[ObjectSystem]
public class DbQueryBatchTaskSystem : AwakeSystem<DBQueryBatchTask, List<long>, string, TaskCompletionSource<List<Component>>>
public class DbQueryBatchTaskSystem : AwakeSystem<DBQueryBatchTask, List<long>, string, TaskCompletionSource<List<ComponentWithId>>>
{
public override void Awake(DBQueryBatchTask self, List<long> idList, string collectionName, TaskCompletionSource<List<Component>> tcs)
public override void Awake(DBQueryBatchTask self, List<long> idList, string collectionName, TaskCompletionSource<List<ComponentWithId>> tcs)
{
self.IdList = idList;
self.CollectionName = collectionName;
......@@ -23,20 +23,20 @@ namespace ETModel
public List<long> IdList { get; set; }
public TaskCompletionSource<List<Component>> Tcs { get; set; }
public TaskCompletionSource<List<ComponentWithId>> Tcs { get; set; }
public override async Task Run()
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
List<Component> result = new List<Component>();
List<ComponentWithId> result = new List<ComponentWithId>();
try
{
// 执行查询数据库任务
foreach (long id in IdList)
{
Component component = dbCacheComponent.GetFromCache(this.CollectionName, id);
ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, id);
if (component == null)
{
component = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id).Result.FirstOrDefaultAsync();
......
......@@ -6,9 +6,9 @@ using MongoDB.Driver;
namespace ETModel
{
[ObjectSystem]
public class DBQueryJsonTaskAwakeSystem : AwakeSystem<DBQueryJsonTask, string, string, TaskCompletionSource<List<Component>>>
public class DBQueryJsonTaskAwakeSystem : AwakeSystem<DBQueryJsonTask, string, string, TaskCompletionSource<List<ComponentWithId>>>
{
public override void Awake(DBQueryJsonTask self, string collectionName, string json, TaskCompletionSource<List<Component>> tcs)
public override void Awake(DBQueryJsonTask self, string collectionName, string json, TaskCompletionSource<List<ComponentWithId>> tcs)
{
self.CollectionName = collectionName;
self.Json = json;
......@@ -22,7 +22,7 @@ namespace ETModel
public string Json { get; set; }
public TaskCompletionSource<List<Component>> Tcs { get; set; }
public TaskCompletionSource<List<ComponentWithId>> Tcs { get; set; }
public override async Task Run()
{
......@@ -30,8 +30,8 @@ namespace ETModel
try
{
// 执行查询数据库任务
FilterDefinition<Component> filterDefinition = new JsonFilterDefinition<Component>(this.Json);
List<Component> components = await dbComponent.GetCollection(this.CollectionName).FindAsync(filterDefinition).Result.ToListAsync();
FilterDefinition<ComponentWithId> filterDefinition = new JsonFilterDefinition<ComponentWithId>(this.Json);
List<ComponentWithId> components = await dbComponent.GetCollection(this.CollectionName).FindAsync(filterDefinition).Result.ToListAsync();
this.Tcs.SetResult(components);
}
catch (Exception e)
......
......@@ -25,7 +25,7 @@ namespace ETModel
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
// 执行查询前先看看cache中是否已经存在
Component component = dbCacheComponent.GetFromCache(this.CollectionName, this.Id);
ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, this.Id);
if (component != null)
{
this.Tcs.SetResult(component);
......
......@@ -7,9 +7,9 @@ using MongoDB.Driver;
namespace ETModel
{
[ObjectSystem]
public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<Component>, string, TaskCompletionSource<bool>>
public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<ComponentWithId>, string, TaskCompletionSource<bool>>
{
public override void Awake(DBSaveBatchTask self, List<Component> components, string collectionName, TaskCompletionSource<bool> tcs)
public override void Awake(DBSaveBatchTask self, List<ComponentWithId> components, string collectionName, TaskCompletionSource<bool> tcs)
{
self.Components = components;
self.CollectionName = collectionName;
......@@ -21,7 +21,7 @@ namespace ETModel
{
public string CollectionName { get; set; }
public List<Component> Components;
public List<ComponentWithId> Components;
public TaskCompletionSource<bool> Tcs;
......@@ -29,7 +29,7 @@ namespace ETModel
{
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
foreach (Component component in this.Components)
foreach (ComponentWithId component in this.Components)
{
if (component == null)
{
......
......@@ -6,11 +6,11 @@ namespace ETModel
{
[ObjectSystem]
public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, Component, string, TaskCompletionSource<bool>>
public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, ComponentWithId, string, TaskCompletionSource<bool>>
{
public override void Awake(DBSaveTask self, Component entity, string collectionName, TaskCompletionSource<bool> tcs)
public override void Awake(DBSaveTask self, ComponentWithId component, string collectionName, TaskCompletionSource<bool> tcs)
{
self.Component = entity;
self.Component = component;
self.CollectionName = collectionName;
self.Tcs = tcs;
}
......@@ -18,7 +18,7 @@ namespace ETModel
public sealed class DBSaveTask : DBTask
{
public Component Component;
public ComponentWithId Component;
public string CollectionName { get; set; }
......
......@@ -2,7 +2,7 @@
namespace ETModel
{
public abstract class DBTask : Component
public abstract class DBTask : ComponentWithId
{
public abstract Task Run();
}
......
......@@ -132,7 +132,7 @@ namespace ETModel
public string CollectionName;
[ProtoMember(3, IsRequired = true)]
public Component Component;
public ComponentWithId Component;
}
......@@ -165,7 +165,7 @@ namespace ETModel
public string CollectionName;
[ProtoMember(3)]
public List<Component> Components = new List<Component>();
public List<ComponentWithId> Components = new List<ComponentWithId>();
}
......@@ -216,7 +216,7 @@ namespace ETModel
public string Message { get; set; }
[ProtoMember(1, IsRequired = true)]
public Component Component;
public ComponentWithId Component;
}
......@@ -252,7 +252,7 @@ namespace ETModel
public string Message { get; set; }
[ProtoMember(1)]
public List<Component> Components = new List<Component>();
public List<ComponentWithId> Components = new List<ComponentWithId>();
}
......@@ -288,7 +288,7 @@ namespace ETModel
public string Message { get; set; }
[ProtoMember(1)]
public List<Component> Components = new List<Component>();
public List<ComponentWithId> Components = new List<ComponentWithId>();
}
......
......@@ -43,6 +43,7 @@
<Compile Include="..\..\Unity\Assets\Scripts\Base\MultiMap.cs" Link="Base\MultiMap.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Component.cs" Link="Base\Object\Component.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ComponentFactory.cs" Link="Base\Object\ComponentFactory.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\ComponentWithId.cs" Link="Base\Object\ComponentWithId.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\Entity.cs" Link="Base\Object\Entity.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\EventSystem.cs" Link="Base\Object\EventSystem.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Base\Object\IAwakeSystem.cs" Link="Base\Object\IAwakeSystem.cs" />
......
......@@ -39,14 +39,7 @@ namespace ETModel
return this.InstanceId == 0;
}
}
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
[BsonElement]
[BsonId]
public long Id { get; set; }
[BsonIgnore]
public Component Parent { get; set; }
......@@ -68,13 +61,6 @@ namespace ETModel
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
this.Id = this.InstanceId;
}
protected Component(long instanceId)
{
this.InstanceId = instanceId;
Game.EventSystem.Add(this);
}
public virtual void Dispose()
......
......@@ -72,7 +72,7 @@ namespace ETModel
return component;
}
public static T CreateWithId<T>(long id) where T : Component
public static T CreateWithId<T>(long id) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -80,7 +80,7 @@ namespace ETModel
return component;
}
public static T CreateWithId<T, A>(long id, A a) where T : Component
public static T CreateWithId<T, A>(long id, A a) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -88,7 +88,7 @@ namespace ETModel
return component;
}
public static T CreateWithId<T, A, B>(long id, A a, B b) where T : Component
public static T CreateWithId<T, A, B>(long id, A a, B b) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -96,7 +96,7 @@ namespace ETModel
return component;
}
public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : Component
public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......
using System;
using MongoDB.Bson.Serialization.Attributes;
namespace ETModel
{
[BsonIgnoreExtraElements]
public abstract partial class ComponentWithId : Component
{
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
[BsonElement]
[BsonId]
public long Id { get; set; }
protected ComponentWithId()
{
this.Id = this.InstanceId;
}
protected ComponentWithId(long id)
{
this.Id = id;
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: bba5de837f798c24d82568eb7c0af4b0
timeCreated: 1521510512
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,7 +6,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETModel
{
[BsonIgnoreExtraElements]
public partial class Entity : Component
public partial class Entity : ComponentWithId
{
[BsonElement]
[BsonIgnoreIfNull]
......
......@@ -169,15 +169,15 @@ namespace ETModel
}
}
public void Remove(long instanceId)
public void Remove(long id)
{
this.allComponents.Remove(instanceId);
this.allComponents.Remove(id);
}
public Component Get(long instanceId)
public Component Get(long id)
{
Component component = null;
this.allComponents.TryGetValue(instanceId, out component);
this.allComponents.TryGetValue(id, out component);
return component;
}
......
......@@ -21,7 +21,7 @@ namespace ETModel
Accept,
}
public abstract class AChannel: Component
public abstract class AChannel: ComponentWithId
{
public ChannelType ChannelType { get; }
......@@ -55,7 +55,6 @@ namespace ETModel
protected AChannel(AService service, ChannelType channelType)
{
this.Id = IdGenerater.GenerateId();
this.ChannelType = channelType;
this.service = service;
}
......
......@@ -42,7 +42,6 @@ namespace ILRuntime.Runtime.Generated
VInt3_Binding.Register(app);
ETModel_PlayerComponent_Binding.Register(app);
ETModel_Player_Binding.Register(app);
ETModel_Component_Binding.Register(app);
ETModel_CameraComponent_Binding.Register(app);
System_IDisposable_Binding.Register(app);
ETModel_Actor_Test_Binding.Register(app);
......
......@@ -15,39 +15,6 @@ namespace ILRuntime.Runtime.Generated
{
unsafe class ETModel_Component_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
FieldInfo field;
Type[] args;
Type type = typeof(ETModel.Component);
args = new Type[]{};
method = type.GetMethod("get_Id", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Id_0);
}
static StackObject* get_Id_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
ETModel.Component instance_of_this_method;
instance_of_this_method = (ETModel.Component)typeof(ETModel.Component).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = instance_of_this_method.Id;
__ret->ObjectType = ObjectTypes.Long;
*(long*)&__ret->Value = result_of_this_method;
return __ret + 1;
}
}
}
using System;
using ETModel;
using ETModel;
using MongoDB.Bson.Serialization.Attributes;
namespace ETHotfix
......@@ -41,13 +40,6 @@ namespace ETHotfix
}
}
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
[BsonElement]
[BsonId]
public long Id { get; set; }
[BsonIgnore]
public Component Parent { get; set; }
......@@ -69,13 +61,6 @@ namespace ETHotfix
{
this.InstanceId = IdGenerater.GenerateId();
Game.EventSystem.Add(this);
this.Id = this.InstanceId;
}
protected Component(long instanceId)
{
this.InstanceId = instanceId;
Game.EventSystem.Add(this);
}
public virtual void Dispose()
......@@ -94,7 +79,6 @@ namespace ETHotfix
Game.ObjectPool.Recycle(this);
}
// 触发Desdroy事件
Game.EventSystem.Desdroy(this);
}
......
......@@ -6,7 +6,7 @@ namespace ETHotfix
{
public static Component CreateWithParent(Type type, Component parent)
{
Component component = (Component)Game.ObjectPool.Fetch(type);
Component component = Game.ObjectPool.Fetch(type);
component.Parent = parent;
Game.EventSystem.Awake(component);
return component;
......@@ -72,7 +72,7 @@ namespace ETHotfix
return component;
}
public static T CreateWithId<T>(long id) where T : Component
public static T CreateWithId<T>(long id) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -80,7 +80,7 @@ namespace ETHotfix
return component;
}
public static T CreateWithId<T, A>(long id, A a) where T : Component
public static T CreateWithId<T, A>(long id, A a) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -88,7 +88,7 @@ namespace ETHotfix
return component;
}
public static T CreateWithId<T, A, B>(long id, A a, B b) where T : Component
public static T CreateWithId<T, A, B>(long id, A a, B b) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......@@ -96,7 +96,7 @@ namespace ETHotfix
return component;
}
public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : Component
public static T CreateWithId<T, A, B, C>(long id, A a, B b, C c) where T : ComponentWithId
{
T component = Game.ObjectPool.Fetch<T>();
component.Id = id;
......
using System;
using MongoDB.Bson.Serialization.Attributes;
namespace ETHotfix
{
[BsonIgnoreExtraElements]
public abstract partial class ComponentWithId : Component
{
[BsonIgnoreIfDefault]
[BsonDefaultValue(0L)]
[BsonElement]
[BsonId]
public long Id { get; set; }
protected ComponentWithId()
{
this.Id = this.InstanceId;
}
protected ComponentWithId(long id)
{
this.Id = id;
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ using MongoDB.Bson.Serialization.Attributes;
namespace ETHotfix
{
[BsonIgnoreExtraElements]
public partial class Entity : Component
public partial class Entity : ComponentWithId
{
[BsonElement]
[BsonIgnoreIfNull]
......@@ -59,7 +59,7 @@ namespace ETHotfix
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}");
throw new Exception($"AddComponent, component already exist, component: {type.Name}");
}
if (component is ISerializeToEntity)
......@@ -76,7 +76,7 @@ namespace ETHotfix
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
throw new Exception($"AddComponent, component already exist, component: {typeof(K).Name}");
}
if (component is ISerializeToEntity)
......@@ -93,7 +93,7 @@ namespace ETHotfix
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
throw new Exception($"AddComponent, component already exist, component: {typeof(K).Name}");
}
if (component is ISerializeToEntity)
......@@ -110,7 +110,7 @@ namespace ETHotfix
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
throw new Exception($"AddComponent, component already exist, component: {typeof(K).Name}");
}
if (component is ISerializeToEntity)
......@@ -127,7 +127,7 @@ namespace ETHotfix
if (this.componentDict.ContainsKey(component.GetType()))
{
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
throw new Exception($"AddComponent, component already exist, component: {typeof(K).Name}");
}
if (component is ISerializeToEntity)
......
......@@ -35,7 +35,7 @@ namespace ETHotfix
public override void Dispose()
{
if (Id == 0)
if (this.IsDisposed)
{
return;
}
......
......@@ -56,6 +56,7 @@
<Compile Include="Base\Helper\ExceptionHelper.cs" />
<Compile Include="Base\Helper\JsonHelper.cs" />
<Compile Include="Base\Helper\Log.cs" />
<Compile Include="Base\Object\ComponentWithId.cs" />
<Compile Include="Base\Object\IDestroySystem.cs" />
<Compile Include="Base\Object\IStartSystem.cs" />
<Compile Include="Module\FrameSync\OperaComponent.cs" />
......
......@@ -156,6 +156,7 @@
<Compile Include="Assets\Scripts\Base\Math\VLine.cs" />
<Compile Include="Assets\Scripts\Base\Math\VRect.cs" />
<Compile Include="Assets\Scripts\Base\MultiMap.cs" />
<Compile Include="Assets\Scripts\Base\Object\ComponentWithId.cs" />
<Compile Include="Assets\Scripts\Base\Object\Component.cs" />
<Compile Include="Assets\Scripts\Base\Object\ComponentAttribute.cs" />
<Compile Include="Assets\Scripts\Base\Object\ComponentFactory.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册