< Summary

Information
Class: Lattice.ECS.Session.SessionRunnerBuilder
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Session/SessionRunnerBuilder.cs
Line coverage
90%
Covered lines: 30
Uncovered lines: 3
Coverable lines: 33
Total lines: 155
Line coverage: 90.9%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
WithRunnerName(...)100%22100%
WithDeltaTime(...)100%11100%
WithLocalPlayerId(...)100%11100%
WithRuntimeOptions(...)100%22100%
WithRuntimeFactory(...)100%22100%
WithSessionFactory(...)100%210%
AddSystem(...)100%11100%
ConfigureContext(...)100%11100%
ConfigureLifecycle(...)100%11100%
BuildDefinition()100%22100%
BuildRuntime()100%11100%
BuildSession()100%210%
Build()100%11100%

File(s)

/home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Session/SessionRunnerBuilder.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using Lattice.ECS.Framework;
 5using Lattice.Math;
 6
 7namespace Lattice.ECS.Session
 8{
 9    /// <summary>
 10    /// 会话运行器构建器。
 11    /// 为代码侧提供最小但正式的运行时装配入口。
 12    /// 当前构建目标是 `SessionRuntime`,默认实例为 `MinimalPredictionSession`。
 13    /// </summary>
 14    public sealed class SessionRunnerBuilder
 15    {
 3016        private readonly List<ISystem> _systems = new();
 3017        private readonly List<SessionRuntimeContextConfigurator> _contextConfigurators = new();
 3018        private readonly SessionRunnerLifecycleHooks _lifecycleHooks = new();
 19        private SessionRuntimeFactory? _runtimeFactory;
 3020        private SessionRuntimeOptions _runtimeOptions = SessionRuntimeOptions.Default;
 3021        private string _runnerName = "Default";
 22
 23        /// <summary>
 24        /// 设置运行器名称。
 25        /// </summary>
 26        public SessionRunnerBuilder WithRunnerName(string runnerName)
 27        {
 1228            if (string.IsNullOrWhiteSpace(runnerName))
 29            {
 230                throw new ArgumentException("Runner name cannot be null or whitespace.", nameof(runnerName));
 31            }
 32
 1033            _runnerName = runnerName;
 1034            return this;
 35        }
 36
 37        /// <summary>
 38        /// 设置固定时间步长。
 39        /// </summary>
 40        public SessionRunnerBuilder WithDeltaTime(FP deltaTime)
 41        {
 942            _runtimeOptions = _runtimeOptions.WithDeltaTime(deltaTime);
 943            return this;
 44        }
 45
 46        /// <summary>
 47        /// 设置本地玩家 ID。
 48        /// </summary>
 49        public SessionRunnerBuilder WithLocalPlayerId(int localPlayerId)
 50        {
 451            _runtimeOptions = _runtimeOptions.WithLocalPlayerId(localPlayerId);
 452            return this;
 53        }
 54
 55        /// <summary>
 56        /// 设置运行时基础配置。
 57        /// 当前仅承载稳定公开的基础参数,不提前暴露历史窗口和采样策略等内部实现细节。
 58        /// </summary>
 59        public SessionRunnerBuilder WithRuntimeOptions(SessionRuntimeOptions runtimeOptions)
 60        {
 961            _runtimeOptions = runtimeOptions ?? throw new ArgumentNullException(nameof(runtimeOptions));
 862            return this;
 63        }
 64
 65        /// <summary>
 66        /// 设置自定义运行时工厂。
 67        /// </summary>
 68        public SessionRunnerBuilder WithRuntimeFactory(SessionRuntimeFactory runtimeFactory)
 69        {
 1070            _runtimeFactory = runtimeFactory ?? throw new ArgumentNullException(nameof(runtimeFactory));
 971            return this;
 72        }
 73
 74        /// <summary>
 75        /// 设置自定义运行时工厂。
 76        /// 该重载保留旧的 `(deltaTime, localPlayerId)` 形式,内部会适配到 `SessionRuntimeOptions` 工厂。
 77        /// </summary>
 78        [Obsolete("请改用 WithRuntimeFactory(SessionRuntimeFactory)。WithSessionFactory 仅保留为兼容入口。", false)]
 79        [EditorBrowsable(EditorBrowsableState.Never)]
 80        public SessionRunnerBuilder WithSessionFactory(Func<FP, int, SessionRuntime> sessionFactory)
 81        {
 082            ArgumentNullException.ThrowIfNull(sessionFactory);
 083            return WithRuntimeFactory(options => sessionFactory(options.DeltaTime, options.LocalPlayerId));
 84        }
 85
 86        /// <summary>
 87        /// 注册系统。
 88        /// </summary>
 89        public SessionRunnerBuilder AddSystem(ISystem system)
 90        {
 991            ArgumentNullException.ThrowIfNull(system);
 892            _systems.Add(system);
 893            return this;
 94        }
 95
 96        /// <summary>
 97        /// 配置运行时上下文。
 98        /// 用于挂载显式声明的 runtime shared service,
 99        /// 而不是继续侵入 `Frame` / `SessionRuntime` 或把 Context 当成万能对象包。
 100        /// </summary>
 101        public SessionRunnerBuilder ConfigureContext(SessionRuntimeContextConfigurator configurator)
 102        {
 4103            ArgumentNullException.ThrowIfNull(configurator);
 4104            _contextConfigurators.Add(configurator);
 4105            return this;
 106        }
 107
 108        /// <summary>
 109        /// 配置宿主生命周期钩子。
 110        /// 用于在 runtime 创建、启动、停止、重建与失败收敛时补齐明确的宿主责任边界。
 111        /// </summary>
 112        public SessionRunnerBuilder ConfigureLifecycle(Action<SessionRunnerLifecycleHooks> configurator)
 113        {
 7114            ArgumentNullException.ThrowIfNull(configurator);
 6115            configurator(_lifecycleHooks);
 6116            return this;
 117        }
 118
 119        /// <summary>
 120        /// 构建不可变运行定义。
 121        /// </summary>
 122        public SessionRunnerDefinition BuildDefinition()
 123        {
 47124            SessionRuntimeFactory runtimeFactory = _runtimeFactory ?? (options => new MinimalPredictionSession(options))
 26125            return new SessionRunnerDefinition(_runnerName, _runtimeOptions, runtimeFactory, _systems, _contextConfigura
 126        }
 127
 128        /// <summary>
 129        /// 构建运行时实例。
 130        /// </summary>
 131        public SessionRuntime BuildRuntime()
 132        {
 2133            return BuildDefinition().BuildRuntime();
 134        }
 135
 136        /// <summary>
 137        /// 构建运行时实例。
 138        /// 保留 `BuildSession()` 名称作为兼容入口。
 139        /// </summary>
 140        [Obsolete("请改用 BuildRuntime()。BuildSession 仅保留为兼容入口。", false)]
 141        [EditorBrowsable(EditorBrowsableState.Never)]
 142        public SessionRuntime BuildSession()
 143        {
 0144            return BuildRuntime();
 145        }
 146
 147        /// <summary>
 148        /// 构建运行器。
 149        /// </summary>
 150        public SessionRunner Build()
 151        {
 13152            return BuildDefinition().CreateRunner();
 153        }
 154    }
 155}