public virtual Session OnAccept(AChannel channel) { Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
public long NewOnceTimer(long tillTime, Action action) { OnceTimer timer = EntityFactory.CreateWithParent <OnceTimer, Action>(this, action); timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(timer.Id); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(string address) { AChannel channel = this.Service.ConnectChannel(address); Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
/// <summary> /// 创建一个新Session /// </summary> public Session Create(IPEndPoint ipEndPoint) { AChannel channel = this.Service.ConnectChannel(ipEndPoint); Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel); this.Sessions.Add(session.Id, session); channel.Start(); return(session); }
public Task WaitAsync(long time) { long tillTime = TimeHelper.CurrentLocalMilliseconds() + time; var tcs = new TaskCompletionSource <bool>(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, TaskCompletionSource <bool> >(this, tcs); timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(tcs.Task); }
/// <summary> /// 创建一个RepeatedTimer /// </summary> /// <param name="time"></param> /// <param name="action"></param> /// <returns></returns> public long NewRepeatedTimer(long time, Action action) { if (time < 30) { throw new Exception($"repeated time < 30"); } long tillTime = TimeHelper.CurrentLocalMilliseconds() + time; RepeatedTimer timer = EntityFactory.CreateWithParent <RepeatedTimer, long, Action>(this, time, action); timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); return(timer.Id); }
public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken) { if (TimeHelper.CurrentLocalMilliseconds() > tillTime) { return(Task.CompletedTask); } var tcs = new TaskCompletionSource <bool>(); OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, TaskCompletionSource <bool> >(this, tcs); timers[timer.Id] = timer; AddToTimeId(tillTime, timer.Id); cancellationToken.Register(() => { Remove(timer.Id); }); return(tcs.Task); }
public Task <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key) { CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { queue = EntityFactory.Create <CoroutineLockQueue>(this.Domain); coroutineLockQueueType.Add(key, queue); return(Task.FromResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key))); } TaskCompletionSource <CoroutineLock> tcs = new TaskCompletionSource <CoroutineLock>(); queue.Enqueue(tcs); return(tcs.Task); }
public void Notify(CoroutineLockType coroutineLockType, long key) { CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { throw new Exception($"first work notify not find queue"); } if (queue.Count == 0) { coroutineLockQueueType.Remove(key); queue.Dispose(); return; } TaskCompletionSource <CoroutineLock> tcs = queue.Dequeue(); tcs.SetResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key)); }
public async Task LoadOneBundleAsync(string assetBundleName) { ABInfo abInfo; if (bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (Define.IsAsync) { string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); AssetBundle assetBundle = null; if (!File.Exists(p)) { p = Path.Combine(PathHelper.AppResPath, assetBundleName); } using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.Create <AssetsBundleLoaderAsync>(Domain)) { assetBundle = await assetsBundleLoaderAsync.LoadAsync(p); } if (assetBundle == null) { throw new Exception($"assets bundle not found: {assetBundleName}"); } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets; using (AssetsLoaderAsync assetsLoaderAsync = EntityFactory.Create <AssetsLoaderAsync, AssetBundle>(Domain, assetBundle)) { assets = await assetsLoaderAsync.LoadAllAssetsAsync(); } foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); bundles[assetBundleName] = abInfo; } else { var assetPaths = AssetDatabaseHelper.GetAssetPathsFromAssetBundle(assetBundleName); if (assetPaths != null) { foreach (string s in assetPaths) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = AssetDatabaseHelper.LoadAssetAtPath(s); AddResource(assetBundleName, assetName, resource); } } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); bundles[assetBundleName] = abInfo; } }
public void LoadOneBundle(string assetBundleName) { //Log.Debug($"---------------load one bundle {assetBundleName}"); ABInfo abInfo; if (bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (Define.IsAsync) { string p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName); AssetBundle assetBundle; if (File.Exists(p)) { assetBundle = AssetBundle.LoadFromFile(p); } else { p = Path.Combine(PathHelper.AppResPath, assetBundleName); assetBundle = AssetBundle.LoadFromFile(p); } if (assetBundle == null) { throw new Exception($"assets bundle not found: {assetBundleName}"); } if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle); bundles[assetBundleName] = abInfo; } else { var assetPaths = AssetDatabaseHelper.GetAssetPathsFromAssetBundle(assetBundleName); if (assetPaths != null) { foreach (string s in assetPaths) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = AssetDatabaseHelper.LoadAssetAtPath(s); AddResource(assetBundleName, assetName, resource); } } abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); bundles[assetBundleName] = abInfo; } }