< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GPUSkinningThrottler()0%110100%
Bind(...)0%2100%
SetThrottling(...)0%2100%
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;
 130922        internal CancellationTokenSource updateCts = new CancellationTokenSource();
 23
 130924        public GPUSkinningThrottler()
 25        {
 130926            framesBetweenUpdates = 1;
 130927            currentFrame = startingFrame++;
 130928        }
 29
 030        public void Bind(IGPUSkinning gpuSkinning) { this.gpuSkinning = gpuSkinning; }
 031        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        {
 141162            updateCts?.Cancel();
 141163            updateCts?.Dispose();
 141164            updateCts = null;
 141165        }
 66    }
 67}