XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
namespace XFEEDToolBox.Core.Navigation;

public sealed record OriginalCruiseCycleIdentity(string Owner,string StartRequestId,ulong SelectionGeneration,ulong Entity,ulong World);
public sealed record OriginalCruiseCycleEvidence(OriginalCruiseCycleIdentity Identity,int ActiveSamples,ulong EnableAt,ulong LastActiveAt,string StopRequestId,ulong StopAt,ulong OffAt);

/// <summary>A native qualification belongs to one original enable, five distinct updates and an explicit original stop.</summary>
public sealed class OriginalCruiseCycleQualification
{
    private OriginalCruiseCycleIdentity? current;
    private ulong enableAt,lastActiveAt,stopAt;
    private string stopRequestId="";
    public int ActiveSamples{get;private set;}
    public OriginalCruiseCycleEvidence? Completed{get;private set;}
    public bool Qualified=>Completed is not null;
    private static bool Key(string value)=>value.Length==32&&value.All(c=>c is >= '0' and <= '9' or >= 'a' and <= 'f');
    public void ForgetCurrent(){current=null;enableAt=lastActiveAt=stopAt=0;stopRequestId="";ActiveSamples=0;}
    public bool Begin(OriginalCruiseCycleIdentity identity,ulong at,bool originalCalled,int stateAfter)
    {
        ForgetCurrent();
        if(!originalCalled||stateAfter is not(1 or 2)||at==0||!Key(identity.Owner)||!Key(identity.StartRequestId)
            ||identity.SelectionGeneration==0||identity.Entity==0||identity.World==0)return false;
        current=identity;enableAt=at;return true;
    }
    public bool Stop(OriginalCruiseCycleIdentity identity,string requestId,ulong at,bool originalCalled,int stateBefore,int stateAfter,bool explicitlyReleased)
    {
        stopAt=0;stopRequestId="";
        if(current!=identity||!originalCalled||!explicitlyReleased||!Key(requestId)||stateBefore is not(1 or 2)||stateAfter is not(0 or 3)
            ||at<enableAt||at<lastActiveAt||ActiveSamples<5)return false;
        stopRequestId=requestId;stopAt=at;return true;
    }
    public void Observe(ulong entity,ulong world,ulong at,int actualState)
    {
        if(current is null||entity!=current.Entity||world!=current.World||at<enableAt)return;
        if(stopAt==0)
        {
            if(actualState==2&&at>lastActiveAt){lastActiveAt=at;ActiveSamples++;}
            return;
        }
        if(actualState is 0 or 3&&at>stopAt)
            Completed=new(current,ActiveSamples,enableAt,lastActiveAt,stopRequestId,stopAt,at);
    }
}