< Summary

Class:GDX.Core
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Core.cs
Covered lines:24
Uncovered lines:3
Coverable lines:27
Total lines:157
Line coverage:88.8% (24 of 27)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:4
Method coverage:75% (3 of 4)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Dispose()0%2100%
InitializeOnMainThread()0%2.062075%
InitializeAtRuntime()0%3.033084.62%
DeveloperConsoleTick()0%110100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Core.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Diagnostics.CodeAnalysis;
 7using System.Threading;
 8using GDX.Mathematics.Random;
 9using UnityEngine;
 10using UnityEngine.LowLevel;
 11using UnityEngine.PlayerLoop;
 12using UnityEngine.Scripting;
 13#if UNITY_EDITOR
 14using UnityEditor;
 15#endif // UNITY_EDITOR
 16
 17namespace GDX
 18{
 19    [Preserve]
 20    public static class Core
 21    {
 22        public const string OverrideClass = "CustomConfig";
 23        public const string OverrideMethod = "Init";
 24        public const string PerformanceCategory = "GDX.Performance";
 25        public const string TestCategory = "GDX.Tests";
 26
 27        /// <summary>
 28        ///     An empty <see cref="object" /> array useful when things require it.
 29        /// </summary>
 30        // ReSharper disable once RedundantArrayCreationExpression, HeapView.ObjectAllocation.Evident
 31        public static readonly object[] EmptyObjectArray = new object[] { };
 32
 33        /// <summary>
 34        ///     The main threads identifier.
 35        /// </summary>
 36        public static int MainThreadID = -1;
 37
 38        /// <summary>
 39        ///     A pseudorandom number generated seeded with <see cref="StartTicks" />.
 40        /// </summary>
 41        /// <remarks>Useful for generic randomness where determinism is not required.</remarks>
 42        public static WELL1024a Random;
 43
 44        /// <summary>
 45        ///     The point in tick based time when the core was initialized.
 46        /// </summary>
 47        public static readonly long StartTicks;
 48
 49        /// <summary>
 50        ///     Has the <see cref="Core" /> main thread initialization happened?
 51        /// </summary>
 52        static bool s_InitializedMainThread;
 53
 54        static bool s_InitializedRuntime;
 55
 56        /// <summary>
 57        ///     Static constructor.
 58        /// </summary>
 59        /// <remarks>Nothing in here can reference the Unity engine and must be thread-safe.</remarks>
 60        [ExcludeFromCodeCoverage]
 61        static Core()
 62        {
 63            // Record initialization time.
 64            StartTicks = DateTime.Now.Ticks;
 65
 66            // The assemblies will change between editor time and compile time so we are going to unfortunately pay a
 67            // cost to iterate over them and try to find our settings class
 68            Reflection.InvokeStaticMethod($"GDX.{OverrideClass}", OverrideMethod);
 69
 70            // Initialize a random provider
 71            Random = new WELL1024a((uint)StartTicks);
 72
 73            // ReSharper disable UnusedParameter.Local
 74#if UNITY_EDITOR
 75            AppDomain.CurrentDomain.DomainUnload += (sender, args) =>
 76            {
 77                Dispose();
 78            };
 79#else
 80            Application.quitting += Dispose;
 81#endif
 82            // ReSharper restore UnusedParameter.Local
 83        }
 84
 85        static void Dispose()
 086        {
 087            Random.Dispose();
 088        }
 89
 90        /// <summary>
 91        ///     Main-thread initializer.
 92        /// </summary>
 93        /// <remarks>
 94        ///     <para>
 95        ///         It might be important to call this function if you are using GDX related configurations inside of
 96        ///         another <see cref="UnityEngine.RuntimeInitializeOnLoadMethod" /> decorated static method.
 97        ///     </para>
 98        ///     <para>
 99        ///         An example of this sort of usage is in the <see cref="GDX.Threading.TaskDirectorSystem" />.
 100        ///     </para>
 101        /// </remarks>
 102#if UNITY_EDITOR
 103        [InitializeOnLoadMethod]
 104#else
 105        [UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.AfterAssembliesLoaded)]
 106#endif // UNITY_EDITOR
 107        public static void InitializeOnMainThread()
 9108        {
 9109            if (s_InitializedMainThread)
 6110            {
 6111                return;
 112            }
 113
 3114            MainThreadID = Thread.CurrentThread.ManagedThreadId;
 115
 3116            Localization.SetDefaultCulture();
 117
 3118            s_InitializedMainThread = true;
 9119        }
 120
 121        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
 122        public static void InitializeAtRuntime()
 5123        {
 5124            if (s_InitializedRuntime)
 4125            {
 4126                return;
 127            }
 128
 1129            PlayerLoopSystem systemRoot = PlayerLoop.GetCurrentPlayerLoop();
 130
 131            // Subscribe our developer console
 132#if UNITY_2022_2_OR_NEWER
 1133            if (Config.EnvironmentDeveloperConsole)
 1134            {
 135                // Disable the built in developer console
 1136                Debug.developerConsoleEnabled = false;
 137
 1138                systemRoot.AddSubSystemToFirstSubSystemOfType(
 139                    typeof(Initialization),
 140                    typeof(Console), DeveloperConsoleTick);
 1141            }
 142#endif // UNITY_2022_2_OR_NEWER
 143
 1144            PlayerLoop.SetPlayerLoop(systemRoot);
 145
 1146            s_InitializedRuntime = true;
 5147        }
 148
 149        static void DeveloperConsoleTick()
 4388150        {
 151#if UNITY_2022_2_OR_NEWER
 152            // We need to feed in the deltaTime, this could be the previous frames if were being honest about it
 4388153            Developer.Console.Tick(Time.deltaTime);
 154#endif // UNITY_2022_2_OR_NEWER
 4388155        }
 156    }
 157}

Coverage by test methods

























Methods/Properties

Dispose()
InitializeOnMainThread()
InitializeAtRuntime()
DeveloperConsoleTick()