< Summary

Class:GPUSkinning.GPUSkinningThrottler
Assembly:RenderUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Utils/GPUSkinning/GPUSkinningThrottler.cs
Covered lines:26
Uncovered lines:0
Coverable lines:26
Total lines:67
Line coverage:100% (26 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GPUSkinningThrottler()0%110100%
Bind(...)0%110100%
SetThrottling(...)0%110100%
Start()0%330100%
UpdateTask()0%440100%
Stop()0%330100%
Dispose()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Utils/GPUSkinning/GPUSkinningThrottler.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3using Cysharp.Threading.Tasks;
 4
 5namespace GPUSkinning
 6{
 7    public interface IGPUSkinningThrottler : IDisposable
 8    {
 9        void Bind(IGPUSkinning gpuSkinning);
 10        void SetThrottling(int framesBetweenUpdates);
 11        void Start();
 12        void Stop();
 13    }
 14
 15    public class GPUSkinningThrottler : IGPUSkinningThrottler
 16    {
 17        internal static int startingFrame = 0;
 18
 19        internal IGPUSkinning gpuSkinning;
 20        internal int framesBetweenUpdates;
 21        internal int currentFrame;
 66722        internal CancellationTokenSource updateCts = new CancellationTokenSource();
 23
 66724        public GPUSkinningThrottler()
 25        {
 66726            framesBetweenUpdates = 1;
 66727            currentFrame = startingFrame++;
 66728        }
 29
 1030        public void Bind(IGPUSkinning gpuSkinning) { this.gpuSkinning = gpuSkinning; }
 1031        public void SetThrottling(int newFramesBetweenUpdates) { framesBetweenUpdates = newFramesBetweenUpdates; }
 32
 33        public void Start()
 34        {
 535            updateCts?.Cancel();
 536            updateCts?.Dispose();
 537            updateCts = new CancellationTokenSource();
 538            UpdateTask(updateCts.Token);
 539        }
 40
 41        private async UniTaskVoid UpdateTask(CancellationToken ct)
 42        {
 3143            while (true)
 44            {
 3645                ct.ThrowIfCancellationRequested();
 3646                currentFrame++;
 3647                if (currentFrame % framesBetweenUpdates == 0)
 2348                    gpuSkinning.Update();
 49                // AttachExternalCancellation is needed because WaitForEndOfFrame cancellation would take a frame
 10850                await UniTask.DelayFrame(1, PlayerLoopTiming.PostLateUpdate, ct).AttachExternalCancellation(ct);
 51            }
 52        }
 53        public void Stop()
 54        {
 155            updateCts?.Cancel();
 156            updateCts?.Dispose();
 157            updateCts = null;
 158        }
 59
 60        public void Dispose()
 61        {
 67462            updateCts?.Cancel();
 67463            updateCts?.Dispose();
 67464            updateCts = null;
 67465        }
 66    }
 67}