public void Add(Feature feature) { var featureType = feature.GetType(); if (feature is CompiledFeature) { if (ConfiguredFeatures.Any(f => f.Name == feature.Name)) { throw new ArgumentException(string.Format(FeatureNameConflictTemplate, feature.Name, nameof(ConfiguredFeature))); } CompiledFeatures.Add((CompiledFeature)feature); } else if (feature is ConfiguredFeature) { if (CompiledFeatures.Any(f => f.Name == feature.Name)) { throw new ArgumentException(string.Format(FeatureNameConflictTemplate, feature.Name, nameof(CompiledFeature))); } ConfiguredFeatures.Add((ConfiguredFeature)feature); } else { throw new NotImplementedException($"Support for {featureType} features in {nameof(FeatureSet)} has not been implemented."); } }
public static void UpdateCropGeometry() { _NeedExtent = null; _TrueCropGeometry = Geometry.Blank; if (GameProfile != null) { // TO REMOVE // I'm afraid that removing it will break things so that'll happen later. int i = 0; foreach (var wz in GameProfile.Screens[0].WatchZones) { var g = wz.Geometry; g.RemoveAnchor(wz.Screen.Geometry); g.ResizeTo(CropGeometry, GameProfile.Screens[0].Geometry); g.Update(CropGeometry.X, CropGeometry.Y); wz.CropGeometry = g; foreach (var wi in wz.WatchImages) { wi.SetMagickImage(ExtremePrecision); wi.Index = i; i++; } } foreach (var s in GameProfile.Screens) { s.CropGeometry = Scanner.CropGeometry; } CompiledFeatures.Compile(GameProfile, false); } }
// Todo: prevFile isn't necessary. Instead store the features of the current scan to be used on the next. // That could cause sync problems so it needs to be investigated. private void NewRun(Scan scan, int index) { var deltas = new double[CompiledFeatures.FeatureCount]; var benchmarks = new double[CompiledFeatures.FeatureCount]; var now = scan.CurrentFrame.DateTime; var fileImageBase = scan.CurrentFrame.Bitmap; var prevFileImageBase = CompiledFeatures.UsesDupeCheck(now) ? scan.PreviousFrame.Bitmap : null; try { foreach (var cWatchZone in CompiledFeatures.CWatchZones) { CropScan(ref deltas, ref benchmarks, now, fileImageBase, prevFileImageBase, cWatchZone); } } catch (Exception e) { scan.Dispose(); Log.Error(e, "Error scanning frame."); if (IsVideoSourceRunning() && !IsScannerLocked) { ScanningCount--; } } var scanEnd = TimeStamp.CurrentDateTime.Time; try { DeltaManager?.AddResult(index, scan, scanEnd, deltas, benchmarks); NewResult(this, new DeltaOutput(DeltaManager, index, CurrentFPS)); ScanningCount--; if (ScanFinished != null) { ScanFinished(this, scan); } //scan.Dispose(); // It's on its own thread so running it here should be okay. if (index % Math.Ceiling(AverageFPS) == 0) { RefreshBenchmarks(); } if (index >= DeltaManager.History.Count && AverageFPS > 70d) { Log.Warning("Framerate is abnormally high, usually an indicator the video feed is not active."); Restart(); } } catch (Exception e) { Log.Error(e, "Unknown Scanner Error."); } }
public void UpdateCropGeometry() { _TrueCropGeometry = Geometry.Blank; if (_Component.IsScriptLoaded() && _GameProfile != null) { Log.Info("Adjusting profile to set dimensions..."); IsScannerLocked = true; CompiledFeatures = new CompiledFeatures(_GameProfile, CropGeometry); IsScannerLocked = false; Log.Info("Profile adjusted."); } else { Log.Verbose("Game Profile is not set or script is not loaded. UpdateCropGeometry() failed."); } }
public void HandleNewFrame(object sender, NewFrameEventArgs e) { var now = TimeStamp.CurrentDateTime.Time; InitCount++; if (!IsScannerLocked && (InitCount > 255 || InitCount % 10 == 0) && !CompiledFeatures.IsPaused(now) && ScanningCount < 12) { ScanningCount++; var currentFrame = new Frame(now, (Bitmap)e.Frame.Clone()); var previousFrame = CurrentFrame; CurrentFrame = currentFrame; var newScan = new Scan(currentFrame, previousFrame, CompiledFeatures.UsesDupeCheck(now)); var index = CurrentIndex; CurrentIndex++; Task.Factory.StartNew(() => NewRun(newScan, index)); } else if (ScanningCount >= 12) { OverloadCount++; if (OverloadCount > 50) { Log.Warning("Frame handler is too overloaded, restarting scanner..."); Restart(); } else { Log.Warning("Frame handler is overloaded!!!"); } } }
} = 100; // 100 milliseconds. public DeltaManager(CompiledFeatures compiledFeatures, int capacity) { CompiledFeatures = compiledFeatures; History = new DeltaHistory(capacity); }