| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Lattice.ECS.Session |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// 当前运行时的输入存取策略类型。 |
| | | 7 | | /// </summary> |
| | | 8 | | public enum SessionInputStorageKind |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// 按 `(playerId, tick)` 访问的固定窗口输入存储。 |
| | | 12 | | /// </summary> |
| | | 13 | | PlayerTickFixedWindow = 0 |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// 当前运行时的历史帧策略类型。 |
| | | 18 | | /// </summary> |
| | | 19 | | public enum SessionHistoryStorageKind |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// 保留有限 live frame,并通过 sampled snapshot 按需重建更早历史。 |
| | | 23 | | /// </summary> |
| | | 24 | | BoundedLiveFramesWithSampledSnapshots = 0 |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// 当前运行时的 checkpoint 存储策略类型。 |
| | | 29 | | /// </summary> |
| | | 30 | | public enum SessionCheckpointStorageKind |
| | | 31 | | { |
| | | 32 | | /// <summary> |
| | | 33 | | /// 使用 packed frame snapshot 作为 checkpoint 主格式。 |
| | | 34 | | /// </summary> |
| | | 35 | | PackedSnapshot = 0 |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// 当前运行时公开承诺的数据策略能力。 |
| | | 40 | | /// </summary> |
| | | 41 | | [Flags] |
| | | 42 | | public enum SessionRuntimeDataCapability |
| | | 43 | | { |
| | | 44 | | None = 0, |
| | | 45 | | PlayerTickInputLookup = 1 << 0, |
| | | 46 | | BoundedInputRetention = 1 << 1, |
| | | 47 | | TickAddressableHistory = 1 << 2, |
| | | 48 | | SampledHistoryMaterialization = 1 << 3, |
| | | 49 | | ExplicitCheckpointRestore = 1 << 4, |
| | | 50 | | PackedCheckpointStorage = 1 << 5 |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// 当前运行时明确不承诺的数据策略能力。 |
| | | 55 | | /// </summary> |
| | | 56 | | [Flags] |
| | | 57 | | public enum UnsupportedSessionRuntimeDataCapability |
| | | 58 | | { |
| | | 59 | | None = 0, |
| | | 60 | | ConfigurableInputRetention = 1 << 0, |
| | | 61 | | ConfigurableHistoryRetention = 1 << 1, |
| | | 62 | | ConfigurableSnapshotSampling = 1 << 2, |
| | | 63 | | PluggableHistoryStore = 1 << 3, |
| | | 64 | | AlternativeCheckpointFormats = 1 << 4, |
| | | 65 | | UnboundedPerTickRetention = 1 << 5 |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Session 运行时的数据策略边界描述。 |
| | | 70 | | /// 用于把“输入 / 历史 / checkpoint 的稳定公开契约”和“内部 sizing 策略”分开。 |
| | | 71 | | /// </summary> |
| | | 72 | | public sealed class SessionRuntimeDataBoundary |
| | | 73 | | { |
| | 1 | 74 | | public SessionRuntimeDataBoundary( |
| | 1 | 75 | | SessionInputStorageKind inputStorageKind, |
| | 1 | 76 | | SessionHistoryStorageKind historyStorageKind, |
| | 1 | 77 | | SessionCheckpointStorageKind checkpointStorageKind, |
| | 1 | 78 | | SessionRuntimeDataCapability supportedCapabilities, |
| | 1 | 79 | | UnsupportedSessionRuntimeDataCapability unsupportedCapabilities) |
| | | 80 | | { |
| | 1 | 81 | | InputStorageKind = inputStorageKind; |
| | 1 | 82 | | HistoryStorageKind = historyStorageKind; |
| | 1 | 83 | | CheckpointStorageKind = checkpointStorageKind; |
| | 1 | 84 | | SupportedCapabilities = supportedCapabilities; |
| | 1 | 85 | | UnsupportedCapabilities = unsupportedCapabilities; |
| | 1 | 86 | | } |
| | | 87 | | |
| | 1 | 88 | | public SessionInputStorageKind InputStorageKind { get; } |
| | | 89 | | |
| | 1 | 90 | | public SessionHistoryStorageKind HistoryStorageKind { get; } |
| | | 91 | | |
| | 32 | 92 | | public SessionCheckpointStorageKind CheckpointStorageKind { get; } |
| | | 93 | | |
| | 6 | 94 | | public SessionRuntimeDataCapability SupportedCapabilities { get; } |
| | | 95 | | |
| | 6 | 96 | | public UnsupportedSessionRuntimeDataCapability UnsupportedCapabilities { get; } |
| | | 97 | | |
| | | 98 | | public bool Supports(SessionRuntimeDataCapability capability) |
| | | 99 | | { |
| | 6 | 100 | | return (SupportedCapabilities & capability) == capability; |
| | | 101 | | } |
| | | 102 | | |
| | | 103 | | public bool ExplicitlyDoesNotSupport(UnsupportedSessionRuntimeDataCapability capability) |
| | | 104 | | { |
| | 6 | 105 | | return (UnsupportedCapabilities & capability) == capability; |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | /// <summary> |
| | | 110 | | /// 当前运行时内部使用的输入 / 历史策略默认 sizing。 |
| | | 111 | | /// 这些值用于实现调优,不属于稳定公开 API。 |
| | | 112 | | /// </summary> |
| | | 113 | | internal static class SessionRuntimeDataDefaults |
| | | 114 | | { |
| | | 115 | | internal const int MaxPredictionFrames = 8; |
| | | 116 | | internal const int HistorySize = 128; |
| | | 117 | | internal const int LiveHistorySize = MaxPredictionFrames + 4; |
| | | 118 | | internal const int HistorySnapshotInterval = 4; |
| | | 119 | | internal const int MaterializedHistoryCacheSize = 4; |
| | | 120 | | internal const int RecycledFrameLimit = LiveHistorySize + 4; |
| | | 121 | | } |
| | | 122 | | } |