Exemple #1
0
        protected void LoadModulesOfType <U>()
        {
            using (PooledDebugLogger sb = PooledDebugLogger.New(this))
            {
                sb.AppendLine("Loading modules...");

                AssemblyLoader.LoadedAssembly assy;
                for (int aIdx = 0; aIdx < AssemblyLoader.loadedAssemblies.Count; aIdx++)
                {
                    assy = AssemblyLoader.loadedAssemblies[aIdx];

                    Type[] loadedTypes = assy.assembly.GetExportedTypes();
                    Type   loadedType;
                    for (int tIdx = 0; tIdx < loadedTypes.Length; tIdx++)
                    {
                        loadedType = loadedTypes[tIdx];

                        if (
                            loadedType.IsInterface ||
                            loadedType.IsAbstract ||
                            !typeof(U).IsAssignableFrom(loadedType) ||
                            typeof(VOIDCore).IsAssignableFrom(loadedType))
                        {
                            continue;
                        }

                        sb.AppendFormat("Checking IVOID_Module type {0}...", loadedType.Name);

                        try
                        {
                            this.LoadModule(loadedType);
                            sb.AppendLine("Success.");
                        }
                        catch (Exception ex)
                        {
                            sb.AppendFormat("Failed, caught {0}\n", ex.GetType().Name);

                                                        #if DEBUG
                            Debug.LogException(ex);
                                                        #endif
                        }
                    }
                }

                this.LoadConfig();

                this.modulesLoaded = true;

                sb.AppendFormat("Loaded {0} modules.\n", this.Modules.Count);

                sb.Print();
            }
        }
        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
        }