< Summary

Information
Class: Lattice.ECS.Session.SessionRunnerDefinition
Assembly: Lattice
File(s): /home/runner/work/Sideline/Sideline/godot/scripts/lattice/ECS/Session/SessionRunnerDefinition.cs
Line coverage
92%
Covered lines: 39
Uncovered lines: 3
Coverable lines: 42
Total lines: 117
Line coverage: 92.8%
Branch coverage
75%
Covered branches: 21
Total branches: 28
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)66.66%181895.83%
get_RunnerName()100%11100%
get_RuntimeOptions()100%11100%
get_SystemCount()100%210%
get_ContextConfiguratorCount()100%210%
BuildRuntime()90%1010100%
CreateRunner()100%11100%
get_LifecycleHooks()100%11100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Lattice.ECS.Framework;
 4
 5namespace Lattice.ECS.Session
 6{
 7    /// <summary>
 8    /// SessionRunner 的不可变运行定义。
 9    /// 承载稳定公开的启动参数、运行时工厂以及系统装配信息。
 10    /// </summary>
 11    public sealed class SessionRunnerDefinition
 12    {
 13        private readonly SessionRuntimeFactory _runtimeFactory;
 14        private readonly ISystem[] _systems;
 15        private readonly SessionRuntimeContextConfigurator[] _contextConfigurators;
 16        private readonly SessionRunnerLifecycleHooks _lifecycleHooks;
 17
 2618        internal SessionRunnerDefinition(
 2619            string runnerName,
 2620            SessionRuntimeOptions runtimeOptions,
 2621            SessionRuntimeFactory runtimeFactory,
 2622            IReadOnlyList<ISystem> systems,
 2623            IReadOnlyList<SessionRuntimeContextConfigurator> contextConfigurators,
 2624            SessionRunnerLifecycleHooks lifecycleHooks)
 25        {
 2626            if (string.IsNullOrWhiteSpace(runnerName))
 27            {
 028                throw new ArgumentException("Runner name cannot be null or whitespace.", nameof(runnerName));
 29            }
 30
 2631            RunnerName = runnerName;
 2632            RuntimeOptions = runtimeOptions ?? throw new ArgumentNullException(nameof(runtimeOptions));
 2633            _runtimeFactory = runtimeFactory ?? throw new ArgumentNullException(nameof(runtimeFactory));
 2634            ArgumentNullException.ThrowIfNull(systems);
 2635            ArgumentNullException.ThrowIfNull(contextConfigurators);
 36
 2637            _systems = new ISystem[systems.Count];
 2638            if (_systems.Length > 0)
 39            {
 2440                for (int i = 0; i < _systems.Length; i++)
 41                {
 842                    _systems[i] = systems[i] ?? throw new ArgumentNullException(nameof(systems), "System registration ca
 43                }
 44            }
 45
 2646            _contextConfigurators = new SessionRuntimeContextConfigurator[contextConfigurators.Count];
 6047            for (int i = 0; i < _contextConfigurators.Length; i++)
 48            {
 449                _contextConfigurators[i] = contextConfigurators[i]
 450                    ?? throw new ArgumentNullException(nameof(contextConfigurators), "Context configurator cannot be nul
 51            }
 52
 2653            _lifecycleHooks = (lifecycleHooks ?? throw new ArgumentNullException(nameof(lifecycleHooks))).Clone();
 2654        }
 55
 56        /// <summary>
 57        /// 运行器名称。
 58        /// 用于标识一个稳定的运行入口,而不是具体某一帧状态对象。
 59        /// </summary>
 5060        public string RunnerName { get; }
 61
 62        /// <summary>
 63        /// 稳定公开的运行时参数。
 64        /// </summary>
 9165        public SessionRuntimeOptions RuntimeOptions { get; }
 66
 67        /// <summary>
 68        /// 当前定义中注册的系统数量。
 69        /// </summary>
 070        public int SystemCount => _systems.Length;
 71
 72        /// <summary>
 73        /// 当前定义中注册的上下文配置器数量。
 74        /// </summary>
 075        public int ContextConfiguratorCount => _contextConfigurators.Length;
 76
 77        /// <summary>
 78        /// 按定义创建一个新的运行时实例并完成系统装配。
 79        /// </summary>
 80        public SessionRuntime BuildRuntime()
 81        {
 3082            SessionRuntime runtime = _runtimeFactory(RuntimeOptions)
 3083                ?? throw new InvalidOperationException("Session runtime factory returned null.");
 84
 3085            if (runtime.DeltaTime != RuntimeOptions.DeltaTime ||
 3086                runtime.LocalPlayerId != RuntimeOptions.LocalPlayerId)
 87            {
 188                throw new InvalidOperationException(
 189                    "Session runtime factory returned a runtime whose stable public parameters do not match SessionRunne
 90            }
 91
 2992            runtime.BindContextRunnerName(RunnerName);
 93
 7094            for (int i = 0; i < _contextConfigurators.Length; i++)
 95            {
 696                _contextConfigurators[i](runtime.Context);
 97            }
 98
 7499            for (int i = 0; i < _systems.Length; i++)
 100            {
 8101                runtime.RegisterSystem(_systems[i]);
 102            }
 103
 29104            return runtime;
 105        }
 106
 107        /// <summary>
 108        /// 按定义创建运行器。
 109        /// </summary>
 110        public SessionRunner CreateRunner()
 111        {
 20112            return new SessionRunner(this);
 113        }
 114
 20115        internal SessionRunnerLifecycleHooks LifecycleHooks => _lifecycleHooks;
 116    }
 117}