Esempio n. 1
0
        private void OnPreCull()
        {
            if (!HighLogic.LoadedSceneIsFlight || !MapView.MapIsEnabled || !ARConfiguration.PrettyLines)
            {
                this.Cleanup(!HighLogic.LoadedSceneIsFlight);

                return;
            }

                        #if DEBUG || BENCH
            timer.Restart();
                        #endif

            try
            {
                log.Clear();

                log.AppendFormat("OnPreCull.\n");

/* @ TODO: Fix
 *                              log.AppendFormat("\tMapView: Draw3DLines: {0}\n" +
 *                                      "\tMapView.MapCamera.camera.fieldOfView: {1}\n" +
 *                                      "\tMapView.MapCamera.Distance: {2}\n",
 *                                      MapView.Draw3DLines,
 *                                      MapView.MapCamera.camera.fieldOfView,
 *                                      MapView.MapCamera.Distance
 *                              );
 */
                log.AppendLine("FlightGlobals ready and Vessels list not null.");

                IAntennaRelay relay;

                for (int i = 0; i < ARFlightController.UsefulRelays.Count; i++)
                {
                    relay = ARFlightController.UsefulRelays[i];

                    if (relay == null)
                    {
                        log.AppendFormat("\n\tGot null relay, skipping");
                        continue;
                    }

                    log.AppendFormat("\n\tDrawing pretty lines for useful relay {0}", relay);

                                        #if DEBUG
                    start = timer.ElapsedMilliseconds;
                                        #endif

                    this.SetRelayVertices(relay);

                    log.AppendFormat("\n\tSet relay vertices for {0} in {1}ms",
                                     relay, timer.ElapsedMilliseconds - start);
                }
            }
            catch (Exception ex)
            {
                this.LogError("Caught {0}: {1}\n{2}\n", ex.GetType().Name, ex.ToString(), ex.StackTrace.ToString());
                this.Cleanup(false);
            }
                        #if DEBUG
            finally
            {
                log.AppendFormat("\n\tOnPreCull finished in {0}ms\n", timer.ElapsedMilliseconds);

                log.Print();
            }
                        #endif

                        #if BENCH
            ARMapRenderer.updateCount++;
            ARMapRenderer.updateTimer += (ulong)this.timer.ElapsedTicks;

            if (ARMapRenderer.updateCount >= (ulong)(8d / Time.smoothDeltaTime))
            {
                ARMapRenderer.averager.AddItem((double)ARMapRenderer.updateTimer / (double)ARMapRenderer.updateCount);
                ARMapRenderer.updateTimer      = 0u;
                ARMapRenderer.updateCount      = 0u;
                ARMapRenderer.twiceAverageTime = (long)(ARMapRenderer.averager.Average * 2d);
            }

            if (this.timer.ElapsedTicks > ARMapRenderer.twiceAverageTime)
            {
                this.Log("PreCull took significant longer than usual ({0:S3}s vs {1:S3}s)",
                         (double)this.timer.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency,
                         ARMapRenderer.averager.Average / (double)System.Diagnostics.Stopwatch.Frequency
                         );
            }
                        #endif
        }