aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs
blob: 0853459990a97e7c80f5cc5a6fcbaf2a2f1d7dd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using ARMeilleure.Translation.PTC;
using System;

namespace Ryujinx.Cpu.Jit
{
    public class JitDiskCacheLoadState : IDiskCacheLoadState
    {
        /// <inheritdoc/>
        public event Action<LoadState, int, int> StateChanged;

        private readonly IPtcLoadState _loadState;

        public JitDiskCacheLoadState(IPtcLoadState loadState)
        {
            loadState.PtcStateChanged += LoadStateChanged;
            _loadState = loadState;
        }

        private void LoadStateChanged(PtcLoadingState newState, int current, int total)
        {
            LoadState state = newState switch
            {
                PtcLoadingState.Start => LoadState.Unloaded,
                PtcLoadingState.Loading => LoadState.Loading,
                PtcLoadingState.Loaded => LoadState.Loaded,
                _ => throw new ArgumentException($"Invalid load state \"{newState}\"."),
            };

            StateChanged?.Invoke(state, current, total);
        }

        /// <inheritdoc/>
        public void Cancel()
        {
            _loadState.Continue();
        }
    }
}