/// <summary> /// Starts the asynchronous completion and awaits its completion. /// </summary> /// <param name="completable">The completable instance.</param> /// <returns>The completion task to await.</returns> public static Task CompleteAndAwaitAsync(this IAsyncCompletable completable) { Contracts.Requires.That(completable != null); completable.Complete(); return(completable.Completion); }
public AsyncCompletableChunkFactory(IAsyncFactory <TKey, TChunk> factory, IAsyncCompletable completable) { Contracts.Requires.That(factory != null); Contracts.Requires.That(completable != null); this.factory = factory; this.completable = completable; }
public StageSeed(IStageSeedConfig config, StageSeedOptions options) : base(options?.CancellationToken ?? CancellationToken.None) { Contracts.Requires.That(config != null); Contracts.Requires.That(options != null); this.StageIdentity = config.StageIdentity; this.GeneratingPhases = config.PhasesToGenerate.GetIdentities(); this.phasesToGenerate = config.PhasesToGenerate.AddExceptionFiltering(); this.postGeneration = options.PostGeneration ?? new NullAsyncCompletable(); this.ProgressTotalCount = this.phasesToGenerate.Select(phase => phase.ProgressTotalCount).Sum(); // Enumerable.Aggregate is used to combine all the phases' progresses into a single observable this.Progress = this.phasesToGenerate.Aggregate( Observable.Empty <GenerationPhaseProgress>(), (progress, phase) => progress .Concat(Observable.Return(new GenerationPhaseProgress( phase, $"Initializing {phase.PhaseIdentity.Name}", 0, this.ProgressTotalCount))) .Concat(phase.Progress) .Concat(Observable.Return(new GenerationPhaseProgress( phase, $"Completed {phase.PhaseIdentity.Name}", 0, this.ProgressTotalCount))), progress => progress.Accumulate()); }
private static StreamingStageMeshFactory CreateMeshFactory( NoiseFactory noise, IAsyncChunkPopulator <IVoxelGridChunk> populator, IAsyncCompletable additional = null) { Contracts.Requires.That(noise != null); Contracts.Requires.That(populator != null); var voxelCache = CreateVoxelChunkCache(populator); var meshPool = CreateMeshBuilderPool(); var meshFactory = new ContourMeshFactory <TerrainSurfaceData>( VoxelChunkConfig, voxelCache.AsReadOnly, meshPool, new TerrainDualContourer <TerrainSurfaceData>(noise)); var completable = new AggregateAsyncCompletable(voxelCache, new DisposableAsyncCompletable(meshPool)); if (additional != null) { completable = new AggregateAsyncCompletable(additional, completable); } return(new StreamingStageMeshFactory(meshFactory, completable)); }
public ContainerSubscription(BaseContainer container, IAsyncCompletable subscriber) { _container = container; Subscriber = subscriber; }
public IDisposable Subscribe(IAsyncCompletable subscriber) { AcquireLock(); try { return(DoSubscribe()); } catch (Exception ex) { var message = "Error in ContainerSeries.Subscribe: " + ex; Trace.TraceError(message); ThrowHelper.FailFast(message); throw; } finally { ReleaseLock(); } IDisposable DoSubscribe() { var subscription = new ContainerSubscription(this, subscriber); switch (_subscriptions) { case null: { Interlocked.Exchange(ref _subscriptions, subscription); break; } case ContainerSubscription sub when !ReferenceEquals(_subscriptions, subscription): { var newArr = new[] { sub, subscription }; Interlocked.Exchange(ref _subscriptions, newArr); break; } case ContainerSubscription[] subsArray when Array.IndexOf(subsArray, subscription) < 0: { int i; if ((i = Array.IndexOf(subsArray, null)) >= 0) { Volatile.Write(ref subsArray[i], subscription); } else { var newArr = new ContainerSubscription[subsArray.Length * 2]; subsArray.CopyTo(newArr, 0); Interlocked.Exchange(ref _subscriptions, newArr); } break; } default: { // ignoring repeated subscription but it will be caught here ThrowHelper.FailFast("_subscriptions could be either null, a single element or an array. (or repeated subscription)"); break; } } return(subscription); } }
private StreamingStageMeshFactory( IAsyncFactory <ChunkKey, IDisposableValue <IDivisibleMesh <NormalColorTextureVertex> > > factory, IAsyncCompletable completable) : base(factory, completable) { }