< Summary

Class:GDX.Developer.ManagedUpdateSystem
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ManagedUpdateSystem.cs
Covered lines:0
Uncovered lines:147
Coverable lines:147
Total lines:294
Line coverage:0% (0 of 147)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:25
Method coverage:0% (0 of 25)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ManagedUpdateSystem()0%2100%
RegisterManagedInitialization(...)0%2100%
RemoveManagedInitialization(...)0%2100%
RegisterManagedUpdate(...)0%2100%
UnregisterManagedUpdate(...)0%2100%
RegisterManagedPreUpdate(...)0%2100%
UnregisterManagedPreUpdate(...)0%2100%
Initialization()0%6200%
Update()0%6200%
PreUpdate()0%6200%
RegisterManagedFixedUpdate(...)0%2100%
UnregisterManagedFixedUpdate(...)0%2100%
FixedUpdate()0%6200%
RegisterManagedEarlyUpdate(...)0%2100%
UnregisterManagedEarlyUpdate(...)0%2100%
EarlyUpdate()0%6200%
RegisterManagedPreLateUpdate(...)0%2100%
UnregisterManagedPreLateUpdate(...)0%2100%
PreLateUpdate()0%6200%
RegisterManagedPostLateUpdate(...)0%2100%
UnregisterManagedPostLateUpdate(...)0%2100%
PostLateUpdate()0%6200%
AddToPlayerLoop()0%2100%
RemoveFromPlayerLoop()0%6200%
IsRunning()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ManagedUpdateSystem.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 GDX.Collections.Generic;
 6using UnityEngine;
 7using UnityEngine.LowLevel;
 8using UnityEngine.PlayerLoop;
 9
 10namespace GDX.Developer
 11{
 12    public static class ManagedUpdateSystem
 13    {
 14        const int k_PreAllocatedSystems = 10;
 015        static SimpleList<IManagedInitialization> s_ManagedInitialization =
 16            new SimpleList<IManagedInitialization>(k_PreAllocatedSystems);
 17        static int s_ManagedInitializationCount;
 018        static SimpleList<IManagedUpdate> s_ManagedUpdate = new SimpleList<IManagedUpdate>(k_PreAllocatedSystems);
 19        static int s_ManagedUpdateCount;
 020        static SimpleList<IManagedPreUpdate> s_ManagedPreUpdate = new SimpleList<IManagedPreUpdate>(k_PreAllocatedSystem
 21        static int s_ManagedPreUpdateCount;
 022        static SimpleList<IManagedFixedUpdate> s_ManagedFixedUpdate =
 23            new SimpleList<IManagedFixedUpdate>(k_PreAllocatedSystems);
 24        static int s_ManagedFixedUpdateCount;
 025        static SimpleList<IManagedEarlyUpdate> s_ManagedEarlyUpdate =
 26            new SimpleList<IManagedEarlyUpdate>(k_PreAllocatedSystems);
 27        static int s_ManagedEarlyUpdateCount;
 028        static SimpleList<IManagedPreLateUpdate> s_ManagedPreLateUpdate =
 29            new SimpleList<IManagedPreLateUpdate>(k_PreAllocatedSystems);
 30        static int s_ManagedPreLateUpdateCount;
 031        static SimpleList<IManagedPostLateUpdate> s_ManagedPostLateUpdate =
 32            new SimpleList<IManagedPostLateUpdate>(k_PreAllocatedSystems);
 33        static int s_ManagedPostLateUpdateCount;
 34
 35        static bool s_AddedToPlayerLoop;
 36
 37        public static void RegisterManagedInitialization(IManagedInitialization managedInitialization)
 038        {
 039            s_ManagedInitialization.AddWithExpandCheck(managedInitialization);
 040            s_ManagedInitializationCount = s_ManagedInitialization.Count;
 041        }
 42        public static void RemoveManagedInitialization(IManagedInitialization managedInitialization)
 043        {
 044            s_ManagedInitialization.RemoveFirstItem(managedInitialization);
 045            s_ManagedInitializationCount = s_ManagedInitialization.Count;
 046        }
 47        public static void RegisterManagedUpdate(IManagedUpdate managedUpdate)
 048        {
 049            s_ManagedUpdate.AddWithExpandCheck(managedUpdate);
 050            s_ManagedUpdateCount = s_ManagedUpdate.Count;
 051        }
 52
 53        public static void UnregisterManagedUpdate(IManagedUpdate managedUpdate)
 054        {
 055            s_ManagedUpdate.RemoveFirstItem(managedUpdate);
 056            s_ManagedUpdateCount = s_ManagedUpdate.Count;
 057        }
 58
 59        public static void RegisterManagedPreUpdate(IManagedPreUpdate managedPreUpdate)
 060        {
 061            s_ManagedPreUpdate.AddWithExpandCheck(managedPreUpdate);
 062            s_ManagedPreUpdateCount = s_ManagedPreUpdate.Count;
 063        }
 64
 65        public static void UnregisterManagedPreUpdate(IManagedPreUpdate managedPreUpdate)
 066        {
 067            s_ManagedPreUpdate.RemoveFirstItem(managedPreUpdate);
 068            s_ManagedPreUpdateCount = s_ManagedPreUpdate.Count;
 069        }
 70
 71        static void Initialization()
 072        {
 073            float deltaTime = Time.deltaTime;
 074            float unscaledDeltaTime = Time.unscaledDeltaTime;
 075            for (int i = 0; i < s_ManagedInitializationCount; i++)
 076            {
 077                s_ManagedInitialization.Array[i].ManagedInitialization(deltaTime, unscaledDeltaTime);
 078            }
 079        }
 80
 81        static void Update()
 082        {
 083            float deltaTime = Time.deltaTime;
 084            float unscaledDeltaTime = Time.unscaledDeltaTime;
 085            for (int i = 0; i < s_ManagedUpdateCount; i++)
 086            {
 087                s_ManagedUpdate.Array[i].ManagedUpdate(deltaTime, unscaledDeltaTime);
 088            }
 089        }
 90
 91        static void PreUpdate()
 092        {
 093            float deltaTime = Time.deltaTime;
 094            float unscaledDeltaTime = Time.unscaledDeltaTime;
 095            for (int i = 0; i < s_ManagedPreUpdateCount; i++)
 096            {
 097                s_ManagedPreUpdate.Array[i].ManagedPreUpdate(deltaTime, unscaledDeltaTime);
 098            }
 099        }
 100
 101        public static void RegisterManagedFixedUpdate(IManagedFixedUpdate managedFixedUpdate)
 0102        {
 0103            s_ManagedFixedUpdate.AddWithExpandCheck(managedFixedUpdate);
 0104            s_ManagedFixedUpdateCount = s_ManagedFixedUpdate.Count;
 0105        }
 106
 107        public static void UnregisterManagedFixedUpdate(IManagedFixedUpdate managedFixedUpdate)
 0108        {
 0109            s_ManagedFixedUpdate.RemoveFirstItem(managedFixedUpdate);
 0110            s_ManagedFixedUpdateCount = s_ManagedFixedUpdate.Count;
 0111        }
 112
 113        static void FixedUpdate()
 0114        {
 0115            float deltaTime = Time.deltaTime;
 0116            float unscaledDeltaTime = Time.unscaledDeltaTime;
 0117            for (int i = 0; i < s_ManagedFixedUpdateCount; i++)
 0118            {
 0119                s_ManagedFixedUpdate.Array[i].ManagedFixedUpdate(deltaTime, unscaledDeltaTime);
 0120            }
 0121        }
 122
 123        public static void RegisterManagedEarlyUpdate(IManagedEarlyUpdate managedEarlyUpdate)
 0124        {
 0125            s_ManagedEarlyUpdate.AddWithExpandCheck(managedEarlyUpdate);
 0126            s_ManagedEarlyUpdateCount = s_ManagedEarlyUpdate.Count;
 0127        }
 128
 129        public static void UnregisterManagedEarlyUpdate(IManagedEarlyUpdate managedEarlyUpdate)
 0130        {
 0131            s_ManagedEarlyUpdate.RemoveFirstItem(managedEarlyUpdate);
 0132            s_ManagedEarlyUpdateCount = s_ManagedEarlyUpdate.Count;
 0133        }
 134
 135        static void EarlyUpdate()
 0136        {
 0137            float deltaTime = Time.deltaTime;
 0138            float unscaledDeltaTime = Time.unscaledDeltaTime;
 0139            for (int i = 0; i < s_ManagedEarlyUpdateCount; i++)
 0140            {
 0141                s_ManagedEarlyUpdate.Array[i].ManagedEarlyUpdate(deltaTime, unscaledDeltaTime);
 0142            }
 0143        }
 144
 145        public static void RegisterManagedPreLateUpdate(IManagedPreLateUpdate managedPreLateUpdate)
 0146        {
 0147            s_ManagedPreLateUpdate.AddWithExpandCheck(managedPreLateUpdate);
 0148            s_ManagedPreLateUpdateCount = s_ManagedPreLateUpdate.Count;
 0149        }
 150
 151        public static void UnregisterManagedPreLateUpdate(IManagedPreLateUpdate managedPreLateUpdate)
 0152        {
 0153            s_ManagedPreLateUpdate.RemoveFirstItem(managedPreLateUpdate);
 0154            s_ManagedPreLateUpdateCount = s_ManagedPreLateUpdate.Count;
 0155        }
 156
 157        static void PreLateUpdate()
 0158        {
 0159            float deltaTime = Time.deltaTime;
 0160            float unscaledDeltaTime = Time.unscaledDeltaTime;
 0161            for (int i = 0; i < s_ManagedPreLateUpdateCount; i++)
 0162            {
 0163                s_ManagedPreLateUpdate.Array[i].ManagedPreLateUpdate(deltaTime, unscaledDeltaTime);
 0164            }
 0165        }
 166
 167        public static void RegisterManagedPostLateUpdate(IManagedPostLateUpdate managedPostLateUpdate)
 0168        {
 0169            s_ManagedPostLateUpdate.AddWithExpandCheck(managedPostLateUpdate);
 0170            s_ManagedPostLateUpdateCount = s_ManagedPostLateUpdate.Count;
 0171        }
 172
 173        public static void UnregisterManagedPostLateUpdate(IManagedPostLateUpdate managedPostLateUpdate)
 0174        {
 0175            s_ManagedPostLateUpdate.RemoveFirstItem(managedPostLateUpdate);
 0176            s_ManagedPostLateUpdateCount = s_ManagedPostLateUpdate.Count;
 0177        }
 178
 179        static void PostLateUpdate()
 0180        {
 0181            float deltaTime = Time.deltaTime;
 0182            float unscaledDeltaTime = Time.unscaledDeltaTime;
 0183            for (int i = 0; i < s_ManagedPostLateUpdateCount; i++)
 0184            {
 0185                s_ManagedPostLateUpdate.Array[i].ManagedPostLateUpdate(deltaTime, unscaledDeltaTime);
 0186            }
 0187        }
 188
 189
 190        public static void AddToPlayerLoop()
 0191        {
 0192            PlayerLoopSystem systemRoot = PlayerLoop.GetCurrentPlayerLoop();
 193
 0194            systemRoot.AddSubSystemToFirstSubSystemOfType(
 195                typeof(Initialization),
 196                typeof(ManagedUpdateSystem), Initialization);
 0197            systemRoot.AddSubSystemToFirstSubSystemOfType(
 198                typeof(EarlyUpdate),
 199                typeof(ManagedUpdateSystem), EarlyUpdate);
 0200            systemRoot.AddSubSystemToFirstSubSystemOfType(
 201                typeof(FixedUpdate),
 202                typeof(ManagedUpdateSystem), FixedUpdate);
 203
 0204            systemRoot.AddSubSystemToFirstSubSystemOfType(
 205                typeof(PreUpdate),
 206                typeof(ManagedUpdateSystem), PreUpdate);
 207
 0208            systemRoot.AddSubSystemToFirstSubSystemOfType(
 209                typeof(Update),
 210                typeof(ManagedUpdateSystem), Update);
 211
 0212            systemRoot.AddSubSystemToFirstSubSystemOfType(
 213                typeof(PreLateUpdate),
 214                typeof(ManagedUpdateSystem), PreLateUpdate);
 215
 0216            systemRoot.AddSubSystemToFirstSubSystemOfType(
 217                typeof(PostLateUpdate),
 218                typeof(ManagedUpdateSystem), PostLateUpdate);
 219
 0220            PlayerLoop.SetPlayerLoop(systemRoot);
 0221            s_AddedToPlayerLoop = true;
 0222        }
 223
 224        public static void RemoveFromPlayerLoop()
 0225        {
 0226            if (!s_AddedToPlayerLoop) return;
 227
 0228            PlayerLoopSystem systemRoot = PlayerLoop.GetCurrentPlayerLoop();
 229
 0230            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(Initialization),
 231                typeof(ManagedUpdateSystem));
 232
 0233            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(EarlyUpdate),
 234                typeof(EarlyUpdate));
 235
 0236            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(FixedUpdate),
 237                typeof(FixedUpdate));
 238
 0239            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(PreUpdate),
 240                typeof(PreUpdate));
 241
 0242            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(Update),
 243                typeof(Update));
 244
 0245            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(PreLateUpdate),
 246                typeof(PreLateUpdate));
 247
 0248            systemRoot.RemoveSubSystemsOfTypeFromFirstSubSystemOfType(typeof(PostLateUpdate),
 249                typeof(PostLateUpdate));
 250
 0251            PlayerLoop.SetPlayerLoop(systemRoot);
 0252            s_AddedToPlayerLoop = false;
 0253        }
 254
 255        public static bool IsRunning()
 0256        {
 0257            return s_AddedToPlayerLoop;
 0258        }
 259
 260        public interface IManagedInitialization
 261        {
 262            void ManagedInitialization(float deltaTime, float unscaledDeltaTime);
 263        }
 264        public interface IManagedUpdate
 265        {
 266            void ManagedUpdate(float deltaTime, float unscaledDeltaTime);
 267        }
 268        public interface IManagedPreUpdate
 269        {
 270            void ManagedPreUpdate(float deltaTime, float unscaledDeltaTime);
 271        }
 272
 273        public interface IManagedFixedUpdate
 274        {
 275            void ManagedFixedUpdate(float deltaTime, float unscaledDeltaTime);
 276        }
 277
 278
 279        public interface IManagedEarlyUpdate
 280        {
 281            void ManagedEarlyUpdate(float deltaTime, float unscaledDeltaTime);
 282        }
 283
 284        public interface IManagedPreLateUpdate
 285        {
 286            void ManagedPreLateUpdate(float deltaTime, float unscaledDeltaTime);
 287        }
 288
 289        public interface IManagedPostLateUpdate
 290        {
 291            void ManagedPostLateUpdate(float deltaTime, float unscaledDeltaTime);
 292        }
 293    }
 294}