< Summary

Class:GDX.Core
Assembly:GDX
File(s):D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Core.cs
Covered lines:7
Uncovered lines:0
Coverable lines:7
Total lines:93
Line coverage:100% (7 of 7)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:1
Method coverage:100% (1 of 1)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InitializeOnMainThread()0%220100%

File(s)

D:/BuildAgent/work/GDX-Documentation/Projects/GDX_Development/Packages/com.dotbunny.gdx/GDX/Core.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 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 GDX.Collections.Generic;
 8using GDX.Mathematics.Random;
 9#if UNITY_EDITOR
 10using UnityEditor;
 11#endif
 12
 13namespace GDX
 14{
 15    public static class Core
 16    {
 17        public const string OverrideClass = "CustomConfig";
 18
 19        public const string OverrideMethod = "Init";
 20        public const string PerformanceCategory = "GDX.Performance";
 21        public const string TestCategory = "GDX.Tests";
 22
 23        /// <summary>
 24        ///     An empty <see cref="object"/> array useful when things require it.
 25        /// </summary>
 26        // ReSharper disable once RedundantArrayCreationExpression, HeapView.ObjectAllocation.Evident
 27        public static readonly object[] EmptyObjectArray = new object[] { };
 28
 29        /// <summary>
 30        ///     A pseudorandom number generated seeded with <see cref="StartTicks"/>.
 31        /// </summary>
 32        /// <remarks>Useful for generic randomness where determinism is not required.</remarks>
 33        public static WELL1024a Random;
 34
 35        /// <summary>
 36        ///     The point in tick based time when the core was initialized.
 37        /// </summary>
 38        public static readonly long StartTicks;
 39
 40        /// <summary>
 41        ///     Has the <see cref="Core"/> main thread initialization happened?
 42        /// </summary>
 43        static bool s_InitializedMainThread;
 44
 45        /// <summary>
 46        ///     Static constructor.
 47        /// </summary>
 48        /// <remarks>Nothing in here can reference the Unity engine and must be thread-safe.</remarks>
 49        [ExcludeFromCodeCoverage]
 50        static Core()
 51        {
 52            // Record initialization time.
 53            StartTicks = DateTime.Now.Ticks;
 54
 55            // The assemblies will change between editor time and compile time so we are going to unfortunately pay a
 56            // cost to iterate over them and try to find our settings class
 57            Reflection.InvokeStaticMethod($"GDX.{OverrideClass}", OverrideMethod);
 58
 59            // Initialize a random provider
 60            Random = new WELL1024a((uint)StartTicks);
 61
 62            DictionaryPrimes.SetDefaultPrimes();
 63
 64            // ReSharper disable UnusedParameter.Local
 65            AppDomain.CurrentDomain.DomainUnload += (sender, args) =>
 66            {
 67                Random.Dispose();
 68            };
 69            // ReSharper restore UnusedParameter.Local
 70        }
 71
 72        /// <summary>
 73        ///     Main-thread initializer.
 74        /// </summary>
 75#if UNITY_EDITOR
 76        [InitializeOnLoadMethod]
 77#else
 78        [UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.AfterAssembliesLoaded)]
 79#endif
 80        public static void InitializeOnMainThread()
 281        {
 282            if (s_InitializedMainThread)
 183            {
 184                return;
 85            }
 86
 187            Localization.SetDefaultCulture();
 88
 189            s_InitializedMainThread = true;
 290        }
 91
 92    }
 93}

Methods/Properties

InitializeOnMainThread()