/// <summary> /// Do work on the completion of a job /// </summary> /// <param name="job"></param> public virtual void onJobComplete(IAdjustmentJob job) { #if DEBUG lens.decrementRunningJobCount(job.adjustment.resolution); #endif /// dirty jobs don't effect the chain if (job.adjustment.type == FocusAdjustmentType.Dirty) { return; } /// try to pass along the adjustment to the next aperture in line, up the line if it's in focus, down the line if it's out Chunk.Resolution nextResolutionInLine = resolution + (job.adjustment.type == FocusAdjustmentType.InFocus ? 1 : -1); if (lens.tryToGetAperture(nextResolutionInLine, out IChunkResolutionAperture nextApetureInLine)) { #if DEBUG lens.level.getChunk(job.adjustment.chunkID).recordEvent($"Handing adjustment to next apeture in line: {(nextResolutionInLine, job.adjustment.type)}"); #endif if (nextApetureInLine.tryToGetAdjustmentJobHandle( new Adjustment( job.adjustment.chunkID, job.adjustment.type, nextResolutionInLine, job.adjustment.focusID ), out ApetureJobHandle jobHandle )) { jobHandle.schedule(); #if DEBUG lens.incrementRunningJobCount(nextResolutionInLine); #endif } } }
/// <summary> /// Get the running count results /// </summary> /// <returns></returns> public List <(int count, string apertureType)> getRunningJobCountPerAperture() { List <(int, string)> results = new List <(int, string)>(); for (Chunk.Resolution resolution = Chunk.Resolution.Loaded; resolution < Chunk.Resolution.Count; resolution++) { if (tryToGetAperture(resolution, out IChunkResolutionAperture aperture)) { results.Add((runningJobCounts[(int)resolution], aperture.GetType().Name)); } } return(results); }
/// <summary> /// Default constructor /// </summary> /// <param name="level"></param> /// <param name="managedChunkRadius"></param> /// <param name="managedChunkHeight"></param> protected ChunkResolutionAperture( Chunk.Resolution resolution, IFocusLens lens, int managedChunkRadius, int managedChunkHeight = 0, float yDistanceWeightMultiplier = 5.0f ) { this.resolution = resolution; this.lens = lens; this.managedChunkRadius = managedChunkRadius; YWeightMultiplier = yDistanceWeightMultiplier; managedChunkHeightRadius = managedChunkHeight == 0 ? managedChunkRadius : managedChunkHeight; double distanceSquared = Math.Pow(managedChunkRadius, 2); double distanceHeightSquared = Math.Pow(managedChunkHeightRadius, 2); MaxManagedChunkDistance = (int)Math.Sqrt( // a[a'^2 + b'^2] squared + b squared distanceSquared + distanceSquared + distanceHeightSquared ); }
/// <summary> /// remove a count from the jobs running for a given aperture /// </summary> /// <param name="jobHandle"></param> public void decrementRunningJobCount(Chunk.Resolution forApertureOfResolution) { lock (runningJobCounts) { runningJobCounts[(int)forApertureOfResolution]--; } }
/// <summary> /// Try to get the apeture type from this lens /// </summary> /// <param name="resolution"></param> /// <param name="aperture"></param> /// <returns></returns> public bool tryToGetAperture(Chunk.Resolution resolution, out IChunkResolutionAperture aperture) { return(apeturesByResolution.TryGetValue(resolution, out aperture)); }