Exemplo n.º 1
0
        private void CaptureLoads()
        {
            if (timerStarted)
            {
                framesSinceLastManualSplit++;
                //Console.WriteLine("TIME NOW: {0}", DateTime.Now - lastTime);
                //Console.WriteLine("TIME DIFF START: {0}", DateTime.Now - lastTime);
                lastTime = DateTime.Now;
                //Capture image using the settings defined for the component
                //Bitmap capture = settings.CaptureImage();

                //Feed the image to the feature detection

                bool wasLoading = isLoading;
                isLoading = settings.CaptureAndDetectLoads();

                timer.CurrentState.IsGameTimePaused = isLoading;

                if (isLoading && !wasLoading)
                {
                    segmentTimeStart = DateTime.Now;
                }

                if (isLoading)
                {
                    pausedFramesSegment++;
                }

                if (wasLoading && !isLoading)
                {
                    TimeSpan delta = (DateTime.Now - segmentTimeStart);
                    framesSum += delta.TotalSeconds * 60.0f;
                    int framesRounded = Convert.ToInt32(delta.TotalSeconds * 60.0f);
                    framesSumRounded += framesRounded;
                    Console.WriteLine("SEGMENT FRAMES: {0}, fromTime (@60fps) {1}, timeDelta {2}, totalFrames {3}, fromTime(int) {4}, totalFrames(int) {5}",
                                      pausedFramesSegment, delta.TotalSeconds,
                                      delta.TotalSeconds * 60.0f, framesSum, framesRounded, framesSumRounded);
                    pausedFramesSegment = 0;
                }


                if (settings.AutoSplitterEnabled && !(settings.AutoSplitterDisableOnSkipUntilSplit && LastSplitSkip))
                {
                    //This is just so that if the detection is not correct by a single frame, it still only splits if a few successive frames are loading
                    if (isLoading && NSTState == CrashNSTState.RUNNING)
                    {
                        pausedFrames++;
                        runningFrames = 0;
                    }
                    else if (!isLoading && NSTState == CrashNSTState.LOADING)
                    {
                        runningFrames++;
                        pausedFrames = 0;
                    }

                    if (NSTState == CrashNSTState.RUNNING && pausedFrames >= settings.AutoSplitterJitterToleranceFrames)
                    {
                        runningFrames = 0;
                        pausedFrames  = 0;
                        //We enter pause.
                        NSTState = CrashNSTState.LOADING;
                        if (framesSinceLastManualSplit >= settings.AutoSplitterManualSplitDelayFrames)
                        {
                            NumberOfLoadsPerSplit[liveSplitState.CurrentSplitIndex]++;

                            if (CumulativeNumberOfLoadsForSplitIndex(liveSplitState.CurrentSplitIndex) >= settings.GetCumulativeNumberOfLoadsForSplit(liveSplitState.CurrentSplit.Name))
                            {
                                timer.Split();
                            }
                        }
                    }
                    else if (NSTState == CrashNSTState.LOADING && runningFrames >= settings.AutoSplitterJitterToleranceFrames)
                    {
                        runningFrames = 0;
                        pausedFrames  = 0;
                        //We enter runnning.
                        NSTState = CrashNSTState.RUNNING;
                    }
                }


                //Console.WriteLine("TIME TAKEN FOR DETECTION: {0}", DateTime.Now - lastTime);
            }
        }
        private void CaptureLoads()
        {
            try
            {
                if (timerStarted)
                {
                    framesSinceLastManualSplit++;
                    //Console.WriteLine("TIME NOW: {0}", DateTime.Now - lastTime);
                    //Console.WriteLine("TIME DIFF START: {0}", DateTime.Now - lastTime);
                    lastTime = DateTime.Now;

                    //Capture image using the settings defined for the component
                    Bitmap     capture = settings.CaptureImage();
                    List <int> max_per_patch;
                    List <int> min_per_patch;
                    //Feed the image to the feature detection
                    int black_level = 0;

                    var features = FeatureDetector.featuresFromBitmap(capture, out max_per_patch, out black_level, out min_per_patch);

                    int  tempMatchingBins = 0;
                    bool wasLoading       = isLoading;
                    bool wasTransition    = isTransition;

                    //TODO: should we "learn" the black level automatically? we could do this during the first few transitions, by keeping track of the minimum histogram values, and dynamically adjusting the number of black bins?

                    float new_avg_transition_max = 0.0f;
                    try
                    {
                        //DateTime current_time = DateTime.Now;
                        isLoading = FeatureDetector.compareFeatureVectorTransition(features.ToArray(), FeatureDetector.listOfFeatureVectorsEng, max_per_patch, min_per_patch, -1.0f, out new_avg_transition_max, out tempMatchingBins, 0.8f, false, settings.BlackLevel);                        //FeatureDetector.isGameTransition(capture, 30);
                        //Console.WriteLine("Timing for detection: {0}", (DateTime.Now - current_time).TotalSeconds);
                    }
                    catch (Exception ex)
                    {
                        isLoading = false;
                        Console.WriteLine("Error: " + ex.ToString());
                        throw ex;
                    }


                    matchingBins = tempMatchingBins;

                    //timer.CurrentState.IsGameTimePaused = isLoading;

                    /*if (settings.RemoveFadeins || settings.RemoveFadeouts)
                     * {
                     *      try
                     *      {
                     *              isTransition = FeatureDetector.compareFeatureVectorTransition(features.ToArray(), FeatureDetector.listOfFeatureVectorsEng, max_per_patch, min_per_patch, -1.0f, out new_avg_transition_max, out tempMatchingBins, 0.8f, false);//FeatureDetector.isGameTransition(capture, 30);
                     *      }
                     *      catch (Exception ex)
                     *      {
                     *              isTransition = false;
                     *              Console.WriteLine("Error: " + ex.ToString());
                     *              throw ex;
                     *      }
                     *      //Console.WriteLine("Transition: {0}", isTransition);
                     *      if (wasLoading && isTransition && settings.RemoveFadeins)
                     *      {
                     *              postLoadTransition = true;
                     *              transitionStart = DateTime.Now;
                     *      }
                     *
                     *      if (wasTransition == false && isTransition && settings.RemoveFadeouts)
                     *      {
                     *              //This could be a pre-load transition, start timing it
                     *              transitionStart = DateTime.Now;
                     *      }
                     *
                     *
                     *      //Console.WriteLine("GAMETIMEPAUSETIME: {0}", timer.CurrentState.GameTimePauseTime);
                     *
                     *
                     *      if (wasTransition && isLoading)
                     *      {
                     *              // This was a pre-load transition, subtract the gametime
                     *              TimeSpan delta = (DateTime.Now - transitionStart);
                     *
                     *              if (settings.RemoveFadeouts)
                     *              {
                     *                      if (delta.TotalSeconds > numSecondsTransitionMax)
                     *                      {
                     *                              Console.WriteLine("{2}: Transition longer than {0} seconds, doesn't count! (Took {1} seconds)", numSecondsTransitionMax, delta.TotalSeconds, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *                      }
                     *                      else
                     *                      {
                     *                              timer.CurrentState.SetGameTime(timer.CurrentState.GameTimePauseTime - delta);
                     *
                     *                              total_paused_time += delta.TotalSeconds;
                     *                              Console.WriteLine("PRE-LOAD TRANSITION {2} seconds: {0}, totalPausedTime: {1}", delta.TotalSeconds, total_paused_time, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *                      }
                     *
                     *              }
                     *
                     *      }
                     *
                     *      if (settings.RemoveFadeins)
                     *      {
                     *              if (postLoadTransition && isTransition == false)
                     *              {
                     *                      TimeSpan delta = (DateTime.Now - transitionStart);
                     *
                     *                      total_paused_time += delta.TotalSeconds;
                     *                      Console.WriteLine("POST-LOAD TRANSITION {2} seconds: {0}, totalPausedTime: {1}", delta.TotalSeconds, total_paused_time, SplitNames[Math.Max(Math.Min(liveSplitState.CurrentSplitIndex, SplitNames.Count - 1), 0)]);
                     *              }
                     *
                     *
                     *              if (postLoadTransition == true && isTransition)
                     *              {
                     *                      // We are transitioning after a load screen, this stops the timer, and actually increases the load time
                     *                      timer.CurrentState.IsGameTimePaused = true;
                     *
                     *
                     *              }
                     *              else
                     *              {
                     *                      postLoadTransition = false;
                     *              }
                     *
                     *      }
                     *
                     * }
                     */

                    if (!isLoading)
                    {
                        black_screen_started = false;
                    }
                    else
                    {
                        // We start a segment. Record the starting time
                        if (black_screen_started == false && black_screen_active == false)
                        {
                            black_screen_started = true;
                            black_screen_start   = DateTime.Now;

                            //Console.WriteLine("Timer GameTime at start: " + timer.CurrentState.GameTimePauseTime);
                        }
                    }

                    var duration_since_black_screen_start = DateTime.Now - black_screen_start;

                    if (black_screen_started && duration_since_black_screen_start.TotalSeconds > settings.MinimumBlackLength)
                    {
                        black_screen_started = false;

                        // now we can subtract the duration since the start and set the black screen active (which pauses the timer)

                        //Console.WriteLine("Duration since black start: " + duration_since_black_screen_start);

                        //Console.WriteLine("Timer GameTime at active: " + timer.CurrentState.GameTimePauseTime);


                        timer.CurrentState.LoadingTimes += duration_since_black_screen_start;

                        black_screen_active = true;
                    }


                    if (black_screen_active == true)
                    {
                        timer.CurrentState.IsGameTimePaused = true;

                        if (!isLoading)
                        {
                            timer.CurrentState.IsGameTimePaused = false;
                            black_screen_active = false;
                        }
                    }

                    //Console.WriteLine("Timer GameTime at frame: " + timer.CurrentState.GameTimePauseTime);


                    if (settings.AutoSplitterEnabled && !(settings.AutoSplitterDisableOnSkipUntilSplit && LastSplitSkip))
                    {
                        //This is just so that if the detection is not correct by a single frame, it still only splits if a few successive frames are loading
                        if (timer.CurrentState.IsGameTimePaused && NSTState == CrashNSTState.RUNNING)
                        {
                            pausedFrames++;
                            runningFrames = 0;
                        }
                        else if (!timer.CurrentState.IsGameTimePaused && NSTState == CrashNSTState.LOADING)
                        {
                            runningFrames++;
                            pausedFrames = 0;
                        }

                        if (NSTState == CrashNSTState.RUNNING && pausedFrames >= settings.AutoSplitterJitterToleranceFrames)
                        {
                            runningFrames = 0;
                            pausedFrames  = 0;
                            //We enter pause.
                            NSTState = CrashNSTState.LOADING;
                            if (framesSinceLastManualSplit >= settings.AutoSplitterManualSplitDelayFrames)
                            {
                                NumberOfLoadsPerSplit[liveSplitState.CurrentSplitIndex]++;

                                if (CumulativeNumberOfLoadsForSplitIndex(liveSplitState.CurrentSplitIndex) >= settings.GetCumulativeNumberOfLoadsForSplit(liveSplitState.CurrentSplit.Name))
                                {
                                    timer.Split();
                                }
                            }
                        }
                        else if (NSTState == CrashNSTState.LOADING && runningFrames >= settings.AutoSplitterJitterToleranceFrames)
                        {
                            runningFrames = 0;
                            pausedFrames  = 0;
                            //We enter runnning.
                            NSTState = CrashNSTState.RUNNING;
                        }
                    }


                    //Console.WriteLine("TIME TAKEN FOR DETECTION: {0}", DateTime.Now - lastTime);
                }
            }
            catch (Exception ex)
            {
                isTransition = false;
                isLoading    = false;
                Console.WriteLine("Error: " + ex.ToString());
            }
        }