提交 eb5dcc50 编写于 作者: T tanghai

1.db cache这个功能比较鸡肋,实在需要cache可以自己搞个进程来cache

2.TaskCompletionSource是没有非泛型实现的,导致之前必须使用TaskCompletionSource<bool>,ETTask有非泛型实现,所以不需要这个bool了
上级 67e4883c
......@@ -60,9 +60,8 @@
{
int32 RpcId = 90;
bool NeedCache = 1;
string CollectionName = 2;
ComponentWithId Component = 3;
string CollectionName = 1;
ComponentWithId Component = 2;
}
......@@ -77,9 +76,8 @@
{
int32 RpcId = 90;
bool NeedCache = 1;
string CollectionName = 2;
repeated ComponentWithId Components = 3;
string CollectionName = 1;
repeated ComponentWithId Components = 2;
}
message DBSaveResponse // IResponse
......@@ -94,7 +92,6 @@
int32 RpcId = 90;
int64 Id = 1;
string CollectionName = 2;
bool NeedCache = 3;
}
message DBQueryResponse // IResponse
......@@ -111,7 +108,6 @@
int32 RpcId = 90;
string CollectionName = 1;
repeated int64 IdList = 2;
bool NeedCache = 3;
}
message DBQueryBatchResponse // IResponse
......
......@@ -92,7 +92,6 @@ namespace App
//Game.Scene.AddComponent<DBComponent>();
//Game.Scene.AddComponent<DBProxyComponent>();
//Game.Scene.AddComponent<DBCacheComponent>();
// location server需要的组件
Game.Scene.AddComponent<LocationComponent>();
......
using System.Threading.Tasks;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using System;
using System.Net;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System.Threading.Tasks;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using System;
using System.Net;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......@@ -54,14 +52,14 @@ namespace ETHotfix
}
}
private static ETTask<bool> WaitLock(this LockComponent self)
private static ETTask WaitLock(this LockComponent self)
{
if (self.status == LockStatus.Locked)
{
return ETTask.FromResult(true);
}
ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
ETTaskCompletionSource tcs = new ETTaskCompletionSource();
self.queue.Enqueue(tcs);
return tcs.Task;
}
......@@ -77,9 +75,9 @@ namespace ETHotfix
self.status = LockStatus.Locked;
foreach (ETTaskCompletionSource<bool> taskCompletionSource in self.queue)
foreach (ETTaskCompletionSource taskCompletionSource in self.queue)
{
taskCompletionSource.SetResult(true);
taskCompletionSource.SetResult();
}
self.queue.Clear();
}
......
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using System.Net;
using ETModel;
namespace ETHotfix
......@@ -17,7 +15,7 @@ namespace ETHotfix
self.ghostsAddress.Remove(address);
}
public static ETTask<bool> Lock(this MasterComponent self, IPEndPoint address)
public static ETTask Lock(this MasterComponent self, IPEndPoint address)
{
if (self.lockedAddress == null)
{
......@@ -25,7 +23,7 @@ namespace ETHotfix
return ETTask.FromResult(true);
}
ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
ETTaskCompletionSource tcs = new ETTaskCompletionSource();
LockInfo lockInfo = new LockInfo(address, tcs);
self.queue.Enqueue(lockInfo);
return tcs.Task;
......@@ -45,7 +43,7 @@ namespace ETHotfix
}
LockInfo lockInfo = self.queue.Dequeue();
self.lockedAddress = lockInfo.Address;
lockInfo.Tcs.SetResult(true);
lockInfo.Tcs.SetResult();
}
}
}
\ No newline at end of file
......@@ -2,11 +2,9 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using ETModel;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
namespace ETHotfix
......@@ -31,34 +29,34 @@ namespace ETHotfix
self.dbAddress = dbStartConfig.GetComponent<InnerConfig>().IPEndPoint;
}
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, bool needCache = true)
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache});
await session.Call(new DBSaveRequest { Component = component });
}
public static async ETTask SaveBatch(this DBProxyComponent self, List<ComponentWithId> components, bool needCache = true)
public static async ETTask SaveBatch(this DBProxyComponent self, List<ComponentWithId> components)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
await session.Call(new DBSaveBatchRequest { Components = components, NeedCache = needCache});
await session.Call(new DBSaveBatchRequest { Components = components });
}
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, bool needCache, CancellationToken cancellationToken)
public static async ETTask Save(this DBProxyComponent self, ComponentWithId component, CancellationToken cancellationToken)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = needCache}, cancellationToken);
await session.Call(new DBSaveRequest { Component = component }, cancellationToken);
}
public static async ETVoid SaveLog(this DBProxyComponent self, ComponentWithId component)
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
await session.Call(new DBSaveRequest { Component = component, NeedCache = false, CollectionName = "Log" });
await session.Call(new DBSaveRequest { Component = component, CollectionName = "Log" });
}
public static async ETTask<T> Query<T>(this DBProxyComponent self, long id, bool needCache = true) where T: ComponentWithId
public static async ETTask<T> Query<T>(this DBProxyComponent self, long id) where T: ComponentWithId
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id, NeedCache = needCache });
DBQueryResponse dbQueryResponse = (DBQueryResponse)await session.Call(new DBQueryRequest { CollectionName = typeof(T).Name, Id = id });
return (T)dbQueryResponse.Component;
}
......@@ -78,10 +76,10 @@ namespace ETHotfix
return await self.Query<T>(json);
}
public static async ETTask<List<ComponentWithId>> Query<T>(this DBProxyComponent self, List<long> ids, bool needCache = true) where T : ComponentWithId
public static async ETTask<List<ComponentWithId>> Query<T>(this DBProxyComponent self, List<long> ids) where T : ComponentWithId
{
Session session = Game.Scene.GetComponent<NetInnerComponent>().Get(self.dbAddress);
DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids, NeedCache = needCache});
DBQueryBatchResponse dbQueryBatchResponse = (DBQueryBatchResponse)await session.Call(new DBQueryBatchRequest { CollectionName = typeof(T).Name, IdList = ids });
return dbQueryBatchResponse.Components;
}
......
using System;
using System.Collections.Generic;
using ETModel;
namespace ETHotfix
......@@ -17,18 +16,8 @@ namespace ETHotfix
DBQueryBatchResponse response = new DBQueryBatchResponse();
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
List<ComponentWithId> components = await dbCacheComponent.GetBatch(message.CollectionName, message.IdList);
response.Components = components;
if (message.NeedCache)
{
foreach (ComponentWithId component in components)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
}
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
response.Components = await dbComponent.GetBatch(message.CollectionName, message.IdList);
reply(response);
}
......
......@@ -17,8 +17,7 @@ namespace ETHotfix
DBQueryJsonResponse response = new DBQueryJsonResponse();
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
List<ComponentWithId> components = await dbCacheComponent.GetJson(message.CollectionName, message.Json);
List<ComponentWithId> components = await Game.Scene.GetComponent<DBComponent>().GetJson(message.CollectionName, message.Json);
response.Components = components;
reply(response);
......
......@@ -16,16 +16,10 @@ namespace ETHotfix
DBQueryResponse response = new DBQueryResponse();
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
ComponentWithId component = await dbCacheComponent.Get(message.CollectionName, message.Id);
ComponentWithId component = await Game.Scene.GetComponent<DBComponent>().Get(message.CollectionName, message.Id);
response.Component = component;
if (message.NeedCache && component != null)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
reply(response);
}
catch (Exception e)
......
......@@ -16,22 +16,14 @@ namespace ETHotfix
DBSaveBatchResponse response = new DBSaveBatchResponse();
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
if (string.IsNullOrEmpty(message.CollectionName))
{
message.CollectionName = message.Components[0].GetType().Name;
}
if (message.NeedCache)
{
foreach (ComponentWithId component in message.Components)
{
dbCacheComponent.AddToCache(component, message.CollectionName);
}
}
await dbCacheComponent.AddBatch(message.Components, message.CollectionName);
await dbComponent.AddBatch(message.Components, message.CollectionName);
reply(response);
}
......
......@@ -16,17 +16,13 @@ namespace ETHotfix
DBSaveResponse response = new DBSaveResponse();
try
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
if (string.IsNullOrEmpty(message.CollectionName))
{
message.CollectionName = message.Component.GetType().Name;
}
if (message.NeedCache)
{
dbCacheComponent.AddToCache(message.Component, message.CollectionName);
}
await dbCacheComponent.Add(message.Component, message.CollectionName);
await dbComponent.Add(message.Component, message.CollectionName);
reply(response);
}
catch (Exception e)
......
using System;
using System.Threading.Tasks;
using ETModel;
namespace ETHotfix
......
using System;
using System.Net;
using ETModel;
using MongoDB.Bson;
namespace ETHotfix
{
......
using ETModel;
using PF;
using ABPath = ETModel.ABPath;
namespace ETHotfix
{
......
using System;
using System.Threading.Tasks;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ETModel;
using PF;
......
using System;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using System.Net;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using System;
using ETModel;
using Google.Protobuf;
namespace ETHotfix
{
......
......@@ -18,6 +18,6 @@ namespace ETModel
public LockStatus status = LockStatus.LockedNot;
public IPEndPoint address;
public int lockCount;
public readonly Queue<ETTaskCompletionSource<bool>> queue = new Queue<ETTaskCompletionSource<bool>>();
public readonly Queue<ETTaskCompletionSource> queue = new Queue<ETTaskCompletionSource>();
}
}
\ No newline at end of file
......@@ -6,9 +6,9 @@ namespace ETModel
public class LockInfo
{
public IPEndPoint Address;
public ETTaskCompletionSource<bool> Tcs;
public ETTaskCompletionSource Tcs;
public LockInfo(IPEndPoint address, ETTaskCompletionSource<bool> tcs)
public LockInfo(IPEndPoint address, ETTaskCompletionSource tcs)
{
this.Address = address;
this.Tcs = tcs;
......
using System.Collections.Generic;
namespace ETModel
{
[ObjectSystem]
public class DbCacheComponentSystem : AwakeSystem<DBCacheComponent>
{
public override void Awake(DBCacheComponent self)
{
self.Awake();
}
}
/// <summary>
/// 用来缓存数据
/// </summary>
public class DBCacheComponent : 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);
public void Awake()
{
for (int i = 0; i < taskCount; ++i)
{
DBTaskQueue taskQueue = ComponentFactory.Create<DBTaskQueue>();
this.tasks.Add(taskQueue);
}
}
public ETTask<bool> Add(ComponentWithId component, string collectionName = "")
{
ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
if (string.IsNullOrEmpty(collectionName))
{
collectionName = component.GetType().Name;
}
DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource<bool>>(component.Id, component, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public ETTask<bool> AddBatch(List<ComponentWithId> components, string collectionName)
{
ETTaskCompletionSource<bool> tcs = new ETTaskCompletionSource<bool>();
DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource<bool>>(components, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public void AddToCache(ComponentWithId component, string collectionName = "")
{
if (string.IsNullOrEmpty(collectionName))
{
collectionName = component.GetType().Name;
}
Dictionary<long, ComponentWithId> collection;
if (!this.cache.TryGetValue(collectionName, out collection))
{
collection = new Dictionary<long, ComponentWithId>();
this.cache.Add(collectionName, collection);
}
collection[component.Id] = component;
}
public ComponentWithId GetFromCache(string collectionName, long id)
{
Dictionary<long, ComponentWithId> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return null;
}
ComponentWithId result;
if (!d.TryGetValue(id, out result))
{
return null;
}
return result;
}
public void RemoveFromCache(string collectionName, long id)
{
Dictionary<long, ComponentWithId> d;
if (!this.cache.TryGetValue(collectionName, out d))
{
return;
}
d.Remove(id);
}
public ETTask<ComponentWithId> Get(string collectionName, long id)
{
ComponentWithId component = GetFromCache(collectionName, id);
if (component != null)
{
return ETTask.FromResult(component);
}
ETTaskCompletionSource<ComponentWithId> tcs = new ETTaskCompletionSource<ComponentWithId>();
DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, ETTaskCompletionSource<ComponentWithId>>(id, collectionName, tcs);
this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);
return tcs.Task;
}
public ETTask<List<ComponentWithId>> GetBatch(string collectionName, List<long> idList)
{
List <ComponentWithId> components = new List<ComponentWithId>();
bool isAllInCache = true;
foreach (long id in idList)
{
ComponentWithId component = this.GetFromCache(collectionName, id);
if (component == null)
{
isAllInCache = false;
break;
}
components.Add(component);
}
if (isAllInCache)
{
return ETTask.FromResult(components);
}
ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, ETTaskCompletionSource<List<ComponentWithId>>>(idList, collectionName, tcs);
this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
return tcs.Task;
}
public ETTask<List<ComponentWithId>> GetJson(string collectionName, string json)
{
ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, ETTaskCompletionSource<List<ComponentWithId>>>(collectionName, json, tcs);
this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
return tcs.Task;
}
}
}
using MongoDB.Driver;
using System.Collections.Generic;
using MongoDB.Driver;
namespace ETModel
{
......@@ -12,24 +13,83 @@ namespace ETModel
}
/// <summary>
/// 连接mongodb
/// 用来缓存数据
/// </summary>
public class DBComponent : Component
{
public MongoClient mongoClient;
public IMongoDatabase database;
public const int taskCount = 32;
public List<DBTaskQueue> tasks = new List<DBTaskQueue>(taskCount);
public void Awake()
{
DBConfig config = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.GetComponent<DBConfig>();
DBConfig config = StartConfigComponent.Instance.StartConfig.GetComponent<DBConfig>();
string connectionString = config.ConnectionString;
mongoClient = new MongoClient(connectionString);
this.database = this.mongoClient.GetDatabase(config.DBName);
for (int i = 0; i < taskCount; ++i)
{
DBTaskQueue taskQueue = ComponentFactory.Create<DBTaskQueue>();
this.tasks.Add(taskQueue);
}
}
public IMongoCollection<ComponentWithId> GetCollection(string name)
{
return this.database.GetCollection<ComponentWithId>(name);
}
public ETTask Add(ComponentWithId component, string collectionName = "")
{
ETTaskCompletionSource tcs = new ETTaskCompletionSource();
if (string.IsNullOrEmpty(collectionName))
{
collectionName = component.GetType().Name;
}
DBSaveTask task = ComponentFactory.CreateWithId<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource>(component.Id, component, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public ETTask AddBatch(List<ComponentWithId> components, string collectionName)
{
ETTaskCompletionSource tcs = new ETTaskCompletionSource();
DBSaveBatchTask task = ComponentFactory.Create<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource>(components, collectionName, tcs);
this.tasks[(int)((ulong)task.Id % taskCount)].Add(task);
return tcs.Task;
}
public ETTask<ComponentWithId> Get(string collectionName, long id)
{
ETTaskCompletionSource<ComponentWithId> tcs = new ETTaskCompletionSource<ComponentWithId>();
DBQueryTask dbQueryTask = ComponentFactory.CreateWithId<DBQueryTask, string, ETTaskCompletionSource<ComponentWithId>>(id, collectionName, tcs);
this.tasks[(int)((ulong)id % taskCount)].Add(dbQueryTask);
return tcs.Task;
}
public ETTask<List<ComponentWithId>> GetBatch(string collectionName, List<long> idList)
{
ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
DBQueryBatchTask dbQueryBatchTask = ComponentFactory.Create<DBQueryBatchTask, List<long>, string, ETTaskCompletionSource<List<ComponentWithId>>>(idList, collectionName, tcs);
this.tasks[(int)((ulong)dbQueryBatchTask.Id % taskCount)].Add(dbQueryBatchTask);
return tcs.Task;
}
public ETTask<List<ComponentWithId>> GetJson(string collectionName, string json)
{
ETTaskCompletionSource<List<ComponentWithId>> tcs = new ETTaskCompletionSource<List<ComponentWithId>>();
DBQueryJsonTask dbQueryJsonTask = ComponentFactory.Create<DBQueryJsonTask, string, string, ETTaskCompletionSource<List<ComponentWithId>>>(collectionName, json, tcs);
this.tasks[(int)((ulong)dbQueryJsonTask.Id % taskCount)].Add(dbQueryJsonTask);
return tcs.Task;
}
}
}
\ No newline at end of file
}
......@@ -25,7 +25,6 @@ namespace ETModel
public override async ETTask Run()
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
List<ComponentWithId> result = new List<ComponentWithId>();
......@@ -34,12 +33,8 @@ namespace ETModel
// 执行查询数据库任务
foreach (long id in IdList)
{
ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, id);
if (component == null)
{
IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id);
component = await cursor.FirstOrDefaultAsync();
}
IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == id);
ComponentWithId component = await cursor.FirstOrDefaultAsync();
if (component == null)
{
......
......@@ -21,20 +21,12 @@ namespace ETModel
public override async ETTask Run()
{
DBCacheComponent dbCacheComponent = Game.Scene.GetComponent<DBCacheComponent>();
DBComponent dbComponent = Game.Scene.GetComponent<DBComponent>();
// 执行查询前先看看cache中是否已经存在
ComponentWithId component = dbCacheComponent.GetFromCache(this.CollectionName, this.Id);
if (component != null)
{
this.Tcs.SetResult(component);
return;
}
try
{
// 执行查询数据库任务
IAsyncCursor<ComponentWithId> cursor = await dbComponent.GetCollection(this.CollectionName).FindAsync((s) => s.Id == this.Id);
component = await cursor.FirstOrDefaultAsync();
ComponentWithId component = await cursor.FirstOrDefaultAsync();
this.Tcs.SetResult(component);
}
catch (Exception e)
......
......@@ -6,9 +6,9 @@ using MongoDB.Driver;
namespace ETModel
{
[ObjectSystem]
public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource<bool>>
public class DbSaveBatchTaskSystem : AwakeSystem<DBSaveBatchTask, List<ComponentWithId>, string, ETTaskCompletionSource>
{
public override void Awake(DBSaveBatchTask self, List<ComponentWithId> components, string collectionName, ETTaskCompletionSource<bool> tcs)
public override void Awake(DBSaveBatchTask self, List<ComponentWithId> components, string collectionName, ETTaskCompletionSource tcs)
{
self.Components = components;
self.CollectionName = collectionName;
......@@ -22,7 +22,7 @@ namespace ETModel
public List<ComponentWithId> Components;
public ETTaskCompletionSource<bool> Tcs;
public ETTaskCompletionSource Tcs;
public override async ETTask Run()
{
......@@ -46,7 +46,7 @@ namespace ETModel
this.Tcs.SetException(new Exception($"保存数据失败! {CollectionName} {this.Components.ListToString()}", e));
}
}
this.Tcs.SetResult(true);
this.Tcs.SetResult();
}
}
}
\ No newline at end of file
......@@ -5,9 +5,9 @@ namespace ETModel
{
[ObjectSystem]
public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource<bool>>
public class DbSaveTaskAwakeSystem : AwakeSystem<DBSaveTask, ComponentWithId, string, ETTaskCompletionSource>
{
public override void Awake(DBSaveTask self, ComponentWithId component, string collectionName, ETTaskCompletionSource<bool> tcs)
public override void Awake(DBSaveTask self, ComponentWithId component, string collectionName, ETTaskCompletionSource tcs)
{
self.Component = component;
self.CollectionName = collectionName;
......@@ -21,7 +21,7 @@ namespace ETModel
public string CollectionName { get; set; }
public ETTaskCompletionSource<bool> Tcs;
public ETTaskCompletionSource Tcs;
public override async ETTask Run()
{
......@@ -31,7 +31,7 @@ namespace ETModel
{
// 执行保存数据库任务
await dbComponent.GetCollection(this.CollectionName).ReplaceOneAsync(s => s.Id == this.Component.Id, this.Component, new UpdateOptions {IsUpsert = true});
this.Tcs.SetResult(true);
this.Tcs.SetResult();
}
catch (Exception e)
{
......
using ETModel;
using System.Collections.Generic;
namespace ETModel
{
......@@ -93,8 +94,6 @@ namespace ETModel
{
public int RpcId { get; set; }
public bool NeedCache { get; set; }
public string CollectionName { get; set; }
public ComponentWithId Component { get; set; }
......@@ -117,8 +116,6 @@ namespace ETModel
{
public int RpcId { get; set; }
public bool NeedCache { get; set; }
public string CollectionName { get; set; }
public List<ComponentWithId> Components = new List<ComponentWithId>();
......@@ -145,8 +142,6 @@ namespace ETModel
public string CollectionName { get; set; }
public bool NeedCache { get; set; }
}
[Message(InnerOpcode.DBQueryResponse)]
......@@ -171,8 +166,6 @@ namespace ETModel
public List<long> IdList = new List<long>();
public bool NeedCache { get; set; }
}
[Message(InnerOpcode.DBQueryBatchResponse)]
......
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace ETModel
......@@ -11,7 +10,7 @@ namespace ETModel
{
if (self.loadMapOperation.isDone)
{
self.tcs.SetResult(true);
self.tcs.SetResult();
}
}
}
......@@ -19,13 +18,13 @@ namespace ETModel
public class SceneChangeComponent: Component
{
public AsyncOperation loadMapOperation;
public ETTaskCompletionSource<bool> tcs;
public ETTaskCompletionSource tcs;
public float deltaTime;
public int lastProgress = 0;
public ETTask<bool> ChangeSceneAsync(string sceneName)
public ETTask ChangeSceneAsync(string sceneName)
{
this.tcs = new ETTaskCompletionSource<bool>();
this.tcs = new ETTaskCompletionSource();
// 加载map
this.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);
return this.tcs.Task;
......@@ -45,7 +44,7 @@ namespace ETModel
public void Finish()
{
this.tcs.SetResult(true);
this.tcs.SetResult();
}
public override void Dispose()
......
......@@ -21,7 +21,7 @@ namespace ETModel
public bool isCancel;
public ETTaskCompletionSource<bool> tcs;
public ETTaskCompletionSource tcs;
public override void Dispose()
{
......@@ -65,7 +65,7 @@ namespace ETModel
{
if (this.isCancel)
{
this.tcs.SetResult(false);
this.tcs.SetException(new Exception($"request error: {this.Request.error}"));
return;
}
......@@ -79,12 +79,12 @@ namespace ETModel
return;
}
this.tcs.SetResult(true);
this.tcs.SetResult();
}
public ETTask<bool> DownloadAsync(string url)
public ETTask DownloadAsync(string url)
{
this.tcs = new ETTaskCompletionSource<bool>();
this.tcs = new ETTaskCompletionSource();
url = url.Replace(" ", "%20");
this.Request = UnityWebRequest.Get(url);
......
......@@ -28,7 +28,7 @@ namespace ETModel
private AssetBundleRequest request;
private ETTaskCompletionSource<bool> tcs;
private ETTaskCompletionSource tcs;
public void Awake(AssetBundle ab)
{
......@@ -42,8 +42,8 @@ namespace ETModel
return;
}
ETTaskCompletionSource<bool> t = tcs;
t.SetResult(true);
ETTaskCompletionSource t = tcs;
t.SetResult();
}
public override void Dispose()
......@@ -64,9 +64,9 @@ namespace ETModel
return this.request.allAssets;
}
private ETTask<bool> InnerLoadAllAssetsAsync()
private ETTask InnerLoadAllAssetsAsync()
{
this.tcs = new ETTaskCompletionSource<bool>();
this.tcs = new ETTaskCompletionSource();
this.request = assetBundle.LoadAllAssetsAsync();
return this.tcs.Task;
}
......
using System.Collections.Generic;
using System.Net;
using ETModel;
using ETModel;
namespace ETHotfix
{
......
using ETModel;
namespace ETModel
{
[Message(OuterOpcode.Actor_Test)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册