Exemple #1
0
        // 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.");
            }
        }
        // Sorry for the nersts mess.
        public void Start()
        {
            try
            {
                Log.Verbose("Initializing start.");
                UpdateCropGeometry();
                Log.Info("Trying to start scanner.");
                if (_GameProfile != null && IsVideoSourceValid() && CompiledFeatures != null)
                {
                    Log.Info("Starting scanner...");
                    CurrentIndex  = 0;
                    OverloadCount = 0;
                    DeltaManager  = new DeltaManager(CompiledFeatures, 256); // Todo: Unhardcode?
                    InitCount     = 0;

                    Log.Verbose("Hooking events onto Accord.");
                    _VideoSource.NewFrame         += _NewFrameEventHandler;
                    _VideoSource.VideoSourceError += _VideoSourceErrorEventHandler;
                    Log.Info("Scanner hooked onto video source.");

                    var moniker = DeviceMoniker;
                    if (!string.IsNullOrWhiteSpace(moniker))
                    {
                        try
                        {
                            _VideoSource.Source = moniker;
                            _VideoSource.Start();
                            Log.Info("Scanner started.");
                        }
                        catch (Exception e)
                        {
                            Log.Error(e, "Video source failed to start.");
                        }
                    }
                    else
                    {
                        Log.Warning("How did you manage to change the selected device in a few milliseconds?");
                    }
                }
                else
                {
                    var str = "Scanner start failed because:";

                    if (_GameProfile == null)
                    {
                        str += " The game profile was empty.";
                    }
                    if (!IsVideoSourceValid())
                    {
                        str += " The script was not loaded.";
                    }
                    if (CompiledFeatures == null)
                    {
                        str += " CompiledFeatures was blank.";
                    }

                    Log.Verbose(str);
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Unknown Scanner.Start() error, please show this to the component developers.");
            }
        }