| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Lattice.ECS.Framework |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// 当前 `SystemScheduler` 的正式调度模型类型。 |
| | | 7 | | /// </summary> |
| | | 8 | | public enum SystemSchedulerKind |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// 单线程、平面、按注册顺序执行的最小系统调度模型。 |
| | | 12 | | /// </summary> |
| | | 13 | | FlatOrdered = 0, |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// 单线程、平面、按 phase 再按注册顺序执行的轻量系统调度模型。 |
| | | 17 | | /// </summary> |
| | | 18 | | FlatPhasedOrdered = 1 |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// 当前 `SystemScheduler` 公开承诺的调度能力。 |
| | | 23 | | /// </summary> |
| | | 24 | | [Flags] |
| | | 25 | | public enum SystemSchedulerCapability |
| | | 26 | | { |
| | | 27 | | None = 0, |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// 支持按注册顺序稳定执行系统。 |
| | | 31 | | /// </summary> |
| | | 32 | | OrderedExecution = 1 << 0, |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// 支持显式初始化与关闭生命周期。 |
| | | 36 | | /// </summary> |
| | | 37 | | ExplicitLifecycle = 1 << 1, |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// 支持在初始化前静态注册系统集合。 |
| | | 41 | | /// </summary> |
| | | 42 | | StaticRegistrationBeforeInitialize = 1 << 2, |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// 支持轻量 phase 执行语义。 |
| | | 46 | | /// </summary> |
| | | 47 | | PhasedExecution = 1 << 3, |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// 支持对系统作者契约进行显式校验与执行期守卫。 |
| | | 51 | | /// </summary> |
| | | 52 | | AuthoringContractValidation = 1 << 4 |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// 当前 `SystemScheduler` 明确不承诺的调度能力。 |
| | | 57 | | /// </summary> |
| | | 58 | | [Flags] |
| | | 59 | | public enum UnsupportedSystemSchedulerCapability |
| | | 60 | | { |
| | | 61 | | None = 0, |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// 不支持初始化后的动态系统增删。 |
| | | 65 | | /// </summary> |
| | | 66 | | RuntimeMutation = 1 << 0, |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// 不支持 phase / stage 调度。 |
| | | 70 | | /// 该标记保留用于描述旧边界或其他不支持 phase 的调度器。 |
| | | 71 | | /// </summary> |
| | | 72 | | SystemPhase = 1 << 1, |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// 不支持系统 enable / disable 开关。 |
| | | 76 | | /// </summary> |
| | | 77 | | EnableDisable = 1 << 2, |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// 不支持显式依赖排序图。 |
| | | 81 | | /// </summary> |
| | | 82 | | DependencyOrdering = 1 << 3, |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// 不支持 `SystemGroup` 一类的层级分组。 |
| | | 86 | | /// </summary> |
| | | 87 | | HierarchicalGrouping = 1 << 4, |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// 不支持多线程系统调度。 |
| | | 91 | | /// </summary> |
| | | 92 | | ThreadedExecution = 1 << 5 |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <summary> |
| | | 96 | | /// `SystemScheduler` 的正式调度边界描述。 |
| | | 97 | | /// 用于把“当前系统层正式支持什么、不支持什么”显式暴露在代码层。 |
| | | 98 | | /// </summary> |
| | | 99 | | public sealed class SystemSchedulerBoundary |
| | | 100 | | { |
| | 1 | 101 | | public SystemSchedulerBoundary( |
| | 1 | 102 | | SystemSchedulerKind schedulerKind, |
| | 1 | 103 | | SystemSchedulerCapability supportedCapabilities, |
| | 1 | 104 | | UnsupportedSystemSchedulerCapability unsupportedCapabilities) |
| | | 105 | | { |
| | 1 | 106 | | SchedulerKind = schedulerKind; |
| | 1 | 107 | | SupportedCapabilities = supportedCapabilities; |
| | 1 | 108 | | UnsupportedCapabilities = unsupportedCapabilities; |
| | 1 | 109 | | } |
| | | 110 | | |
| | | 111 | | /// <summary> |
| | | 112 | | /// 当前调度模型类型。 |
| | | 113 | | /// </summary> |
| | 1 | 114 | | public SystemSchedulerKind SchedulerKind { get; } |
| | | 115 | | |
| | | 116 | | /// <summary> |
| | | 117 | | /// 当前正式支持的调度能力。 |
| | | 118 | | /// </summary> |
| | 5 | 119 | | public SystemSchedulerCapability SupportedCapabilities { get; } |
| | | 120 | | |
| | | 121 | | /// <summary> |
| | | 122 | | /// 当前明确不承诺的调度能力。 |
| | | 123 | | /// </summary> |
| | 5 | 124 | | public UnsupportedSystemSchedulerCapability UnsupportedCapabilities { get; } |
| | | 125 | | |
| | | 126 | | public bool Supports(SystemSchedulerCapability capability) |
| | | 127 | | { |
| | 5 | 128 | | return (SupportedCapabilities & capability) == capability; |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | public bool ExplicitlyDoesNotSupport(UnsupportedSystemSchedulerCapability capability) |
| | | 132 | | { |
| | 5 | 133 | | return (UnsupportedCapabilities & capability) == capability; |
| | | 134 | | } |
| | | 135 | | } |
| | | 136 | | } |