| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Lattice.ECS.Session |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// 当前运行时上下文正式推荐的归属模型。 |
| | | 7 | | /// </summary> |
| | | 8 | | public enum SessionRuntimeContextKind |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// 以类型为键挂载显式声明的运行时共享服务。 |
| | | 12 | | /// </summary> |
| | | 13 | | TypedRuntimeSharedServices = 0 |
| | | 14 | | } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// 当前运行时上下文正式承诺的能力。 |
| | | 18 | | /// </summary> |
| | | 19 | | [Flags] |
| | | 20 | | public enum SessionRuntimeContextCapability |
| | | 21 | | { |
| | | 22 | | None = 0, |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// 运行时共享对象按类型注册和读取。 |
| | | 26 | | /// </summary> |
| | | 27 | | TypedSharedLookup = 1 << 0, |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// 共享对象必须显式声明为 runtime shared service。 |
| | | 31 | | /// </summary> |
| | | 32 | | ExplicitRuntimeSharedServiceRegistration = 1 << 1, |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// 共享对象可以由上下文托管释放。 |
| | | 36 | | /// </summary> |
| | | 37 | | OwnedSharedObjectLifetime = 1 << 2, |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// 上下文稳定暴露运行时元信息。 |
| | | 41 | | /// </summary> |
| | | 42 | | RuntimeMetadataExposure = 1 << 3 |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// 当前运行时上下文明确不承诺的能力。 |
| | | 47 | | /// </summary> |
| | | 48 | | [Flags] |
| | | 49 | | public enum UnsupportedSessionRuntimeContextCapability |
| | | 50 | | { |
| | | 51 | | None = 0, |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// 不允许把上下文当成任意对象包。 |
| | | 55 | | /// </summary> |
| | | 56 | | ArbitraryObjectBag = 1 << 0, |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// 不允许把可回滚状态或历史载体塞进上下文。 |
| | | 60 | | /// </summary> |
| | | 61 | | RollbackStateStorage = 1 << 1, |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// 不允许把 gameplay 状态通信主链路挂到上下文。 |
| | | 65 | | /// </summary> |
| | | 66 | | GameplayStateExchange = 1 << 2, |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// 不提供 string key / 名字查找式 service locator。 |
| | | 70 | | /// </summary> |
| | | 71 | | StringKeyedServiceLocator = 1 << 3 |
| | | 72 | | } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// SessionRuntimeContext 的正式边界描述。 |
| | | 76 | | /// </summary> |
| | | 77 | | public sealed class SessionRuntimeContextBoundary |
| | | 78 | | { |
| | 1 | 79 | | public SessionRuntimeContextBoundary( |
| | 1 | 80 | | SessionRuntimeContextKind contextKind, |
| | 1 | 81 | | SessionRuntimeContextCapability supportedCapabilities, |
| | 1 | 82 | | UnsupportedSessionRuntimeContextCapability unsupportedCapabilities) |
| | | 83 | | { |
| | 1 | 84 | | ContextKind = contextKind; |
| | 1 | 85 | | SupportedCapabilities = supportedCapabilities; |
| | 1 | 86 | | UnsupportedCapabilities = unsupportedCapabilities; |
| | 1 | 87 | | } |
| | | 88 | | |
| | | 89 | | /// <summary> |
| | | 90 | | /// 当前上下文归属模型。 |
| | | 91 | | /// </summary> |
| | 1 | 92 | | public SessionRuntimeContextKind ContextKind { get; } |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// 当前正式支持的上下文能力。 |
| | | 96 | | /// </summary> |
| | 4 | 97 | | public SessionRuntimeContextCapability SupportedCapabilities { get; } |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// 当前明确不承诺的上下文能力。 |
| | | 101 | | /// </summary> |
| | 4 | 102 | | public UnsupportedSessionRuntimeContextCapability UnsupportedCapabilities { get; } |
| | | 103 | | |
| | | 104 | | public bool Supports(SessionRuntimeContextCapability capability) |
| | | 105 | | { |
| | 4 | 106 | | return (SupportedCapabilities & capability) == capability; |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | public bool ExplicitlyDoesNotSupport(UnsupportedSessionRuntimeContextCapability capability) |
| | | 110 | | { |
| | 4 | 111 | | return (UnsupportedCapabilities & capability) == capability; |
| | | 112 | | } |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | /// <summary> |
| | | 116 | | /// 允许挂入 SessionRuntimeContext 的正式运行时共享服务标记。 |
| | | 117 | | /// 该标记用于把上下文约束在 runtime service 归属面,而不是任意对象包。 |
| | | 118 | | /// </summary> |
| | | 119 | | public interface ISessionRuntimeSharedService |
| | | 120 | | { |
| | | 121 | | } |
| | | 122 | | } |