## @esengine/ecs-framework 新增 @sync 装饰器和二进制编解码器,支持基于 Component 的网络状态同步: - `sync` 装饰器标记需要同步的字段 - `ChangeTracker` 组件变更追踪 - 二进制编解码器 (BinaryWriter/BinaryReader) - `encodeSnapshot`/`decodeSnapshot` 批量编解码 - `encodeSpawn`/`decodeSpawn` 实体生成编解码 - `encodeDespawn`/`processDespawn` 实体销毁编解码 将以下方法标记为 @internal,用户应通过 Core.update() 驱动更新: - Scene.update() - SceneManager.update() - WorldManager.updateAll() ## @esengine/network - 新增 ComponentSyncSystem 基于 @sync 自动同步组件状态 - 将 ecs-framework 从 devDependencies 移到 peerDependencies ## @esengine/server 新增 ECSRoom,带有 ECS World 支持的房间基类: - 每个 ECSRoom 在 Core.worldManager 中创建独立的 World - Core.update() 统一更新 Time 和所有 World - onTick() 只处理状态同步逻辑 - 自动创建/销毁玩家实体 - 增量状态广播
180 lines
5.2 KiB
TypeScript
180 lines
5.2 KiB
TypeScript
/**
|
|
* @zh @esengine/network 网络同步模块
|
|
* @en @esengine/network Network synchronization module
|
|
*
|
|
* @zh 基于 @esengine/rpc 的网络同步模块,提供类型安全的多人游戏网络通信
|
|
* @en Network synchronization module based on @esengine/rpc for type-safe multiplayer game communication
|
|
*/
|
|
|
|
// ============================================================================
|
|
// Re-export from RPC | 从 RPC 包重新导出
|
|
// ============================================================================
|
|
|
|
export { rpc } from '@esengine/rpc'
|
|
export type {
|
|
ProtocolDef,
|
|
ApiDef,
|
|
MsgDef,
|
|
ApiInput,
|
|
ApiOutput,
|
|
MsgData,
|
|
ApiNames,
|
|
MsgNames,
|
|
RpcError,
|
|
} from '@esengine/rpc'
|
|
|
|
// ============================================================================
|
|
// Protocol | 协议
|
|
// ============================================================================
|
|
|
|
export {
|
|
gameProtocol,
|
|
type GameProtocol,
|
|
type PlayerInput,
|
|
type EntitySyncState,
|
|
type SyncData,
|
|
type SpawnData,
|
|
type DespawnData,
|
|
type FullStateData,
|
|
type JoinRequest,
|
|
type JoinResponse,
|
|
type ReconnectRequest,
|
|
type ReconnectResponse,
|
|
} from './protocol'
|
|
|
|
// ============================================================================
|
|
// Tokens | 服务令牌
|
|
// ============================================================================
|
|
|
|
export {
|
|
NetworkServiceToken,
|
|
NetworkSyncSystemToken,
|
|
NetworkSpawnSystemToken,
|
|
NetworkInputSystemToken,
|
|
NetworkPredictionSystemToken,
|
|
NetworkAOISystemToken,
|
|
} from './tokens'
|
|
|
|
// ============================================================================
|
|
// Plugin | 插件
|
|
// ============================================================================
|
|
|
|
export { NetworkPlugin } from './NetworkPlugin'
|
|
|
|
// ============================================================================
|
|
// Services | 服务
|
|
// ============================================================================
|
|
|
|
export {
|
|
RpcService,
|
|
GameNetworkService,
|
|
NetworkService,
|
|
NetworkState,
|
|
createNetworkService,
|
|
} from './services/NetworkService'
|
|
export type { NetworkServiceOptions } from './services/NetworkService'
|
|
|
|
// ============================================================================
|
|
// Components | 组件
|
|
// ============================================================================
|
|
|
|
export { NetworkIdentity } from './components/NetworkIdentity'
|
|
export { NetworkTransform } from './components/NetworkTransform'
|
|
|
|
// ============================================================================
|
|
// Systems | 系统
|
|
// ============================================================================
|
|
|
|
export { NetworkSyncSystem } from './systems/NetworkSyncSystem'
|
|
export type { SyncMessage, NetworkSyncConfig } from './systems/NetworkSyncSystem'
|
|
export { NetworkSpawnSystem } from './systems/NetworkSpawnSystem'
|
|
export type { PrefabFactory, SpawnMessage, DespawnMessage } from './systems/NetworkSpawnSystem'
|
|
export { NetworkInputSystem, createNetworkInputSystem } from './systems/NetworkInputSystem'
|
|
export type { NetworkInputConfig } from './systems/NetworkInputSystem'
|
|
export {
|
|
NetworkPredictionSystem,
|
|
createNetworkPredictionSystem,
|
|
} from './systems/NetworkPredictionSystem'
|
|
export type {
|
|
NetworkPredictionConfig,
|
|
MovementInput,
|
|
PredictedTransform,
|
|
} from './systems/NetworkPredictionSystem'
|
|
export {
|
|
NetworkAOISystem,
|
|
createNetworkAOISystem,
|
|
} from './systems/NetworkAOISystem'
|
|
export type {
|
|
NetworkAOIConfig,
|
|
NetworkAOIEvent,
|
|
NetworkAOIEventType,
|
|
NetworkAOIEventListener,
|
|
} from './systems/NetworkAOISystem'
|
|
|
|
// ============================================================================
|
|
// State Sync | 状态同步
|
|
// ============================================================================
|
|
|
|
export type {
|
|
IStateSnapshot,
|
|
ITransformState,
|
|
ITransformStateWithVelocity,
|
|
ISnapshotBufferConfig,
|
|
ISnapshotBuffer,
|
|
} from './sync'
|
|
|
|
export type {
|
|
IInterpolator,
|
|
IExtrapolator,
|
|
IInputSnapshot,
|
|
IPredictedState,
|
|
IPredictor,
|
|
ClientPredictionConfig,
|
|
EntityDeltaState,
|
|
DeltaSyncData,
|
|
DeltaCompressionConfig,
|
|
// Component sync types
|
|
ComponentSyncEventType,
|
|
ComponentSyncEvent,
|
|
ComponentSyncEventListener,
|
|
ComponentSyncConfig,
|
|
} from './sync'
|
|
|
|
export {
|
|
lerp,
|
|
lerpAngle,
|
|
smoothDamp,
|
|
SnapshotBuffer,
|
|
createSnapshotBuffer,
|
|
TransformInterpolator,
|
|
HermiteTransformInterpolator,
|
|
createTransformInterpolator,
|
|
createHermiteTransformInterpolator,
|
|
ClientPrediction,
|
|
createClientPrediction,
|
|
DeltaFlags,
|
|
StateDeltaCompressor,
|
|
createStateDeltaCompressor,
|
|
// Component sync
|
|
ComponentSyncSystem,
|
|
createComponentSyncSystem,
|
|
} from './sync'
|
|
|
|
// ============================================================================
|
|
// Blueprint Nodes | 蓝图节点
|
|
// ============================================================================
|
|
|
|
export {
|
|
IsLocalPlayerTemplate,
|
|
IsServerTemplate,
|
|
HasAuthorityTemplate,
|
|
GetNetworkIdTemplate,
|
|
GetLocalPlayerIdTemplate,
|
|
IsLocalPlayerExecutor,
|
|
IsServerExecutor,
|
|
HasAuthorityExecutor,
|
|
GetNetworkIdExecutor,
|
|
GetLocalPlayerIdExecutor,
|
|
NetworkNodeDefinitions,
|
|
} from './nodes'
|