Files
esengine/packages/runtime-core/src/IPlatformAdapter.ts

164 lines
3.9 KiB
TypeScript
Raw Normal View History

/**
* Platform Adapter Interface
*
*
*
* Defines the adapter interface that different platforms need to implement
*/
feat(engine-core): 添加统一输入系统 (#282) * perf(core): 优化 EntitySystem 迭代性能,添加 CommandBuffer 延迟命令 ReactiveQuery 快照优化: - 添加快照机制,避免每帧拷贝数组 - 只在实体列表变化时创建新快照 - 静态场景下多个系统共享同一快照 CommandBuffer 延迟命令系统: - 支持延迟添加/移除组件、销毁实体、设置实体激活状态 - 每个系统拥有独立的 commands 属性 - 命令在帧末统一执行,避免迭代过程中修改实体列表 Scene 更新: - 在 lateUpdate 后自动刷新所有系统的命令缓冲区 文档: - 更新系统文档,添加 CommandBuffer 使用说明 * fix(ci): upgrade first-interaction action to v1.3.0 Fix Docker build failure in welcome workflow. * fix(ci): upgrade pnpm/action-setup to v4 and fix unused import - Upgrade pnpm/action-setup@v2 to v4 in all workflow files - Remove unused CommandType import in CommandBuffer.test.ts * fix(ci): remove duplicate pnpm version specification * feat(engine-core): 添加统一输入系统 添加完整的输入系统,支持平台抽象: - IPlatformInputSubsystem: 扩展接口支持键盘/鼠标/滚轮事件 - WebInputSubsystem: 浏览器实现,支持事件绑定/解绑 - InputManager: 全局输入状态管理器(键盘、鼠标、触摸) - InputSystem: ECS 系统,连接平台事件到 InputManager - GameRuntime 集成: 自动创建 InputSystem 并绑定平台子系统 使用方式: ```typescript import { Input, MouseButton } from '@esengine/engine-core'; if (Input.isKeyDown('KeyW')) { /* 移动 */ } if (Input.isKeyJustPressed('Space')) { /* 跳跃 */ } if (Input.isMouseButtonDown(MouseButton.Left)) { /* 射击 */ } ``` * fix(runtime-core): 添加缺失的 platform-common 依赖 * fix(runtime-core): 移除 platform-web 依赖避免循环依赖 * fix(runtime-core): 使用工厂函数注入 InputSubsystem 避免循环依赖 - BrowserPlatformAdapter 通过 inputSubsystemFactory 配置接收输入子系统 - 在 IPlatformInputSubsystem 接口添加可选的 dispose 方法 - 移除对 @esengine/platform-web 的直接依赖
2025-12-05 18:15:50 +08:00
import type { IPlatformInputSubsystem } from '@esengine/platform-common';
/**
*
* Asset path resolver
*/
export interface IPathResolver {
/**
* URL
* Resolve asset path to a loadable URL
*/
resolve(path: string): string;
}
/**
*
* Platform capability flags
*/
export interface PlatformCapabilities {
/** 是否支持文件系统访问 / Supports file system access */
fileSystem: boolean;
/** 是否支持热重载 / Supports hot reload */
hotReload: boolean;
/** 是否支持 Gizmo 显示 / Supports gizmo display */
gizmos: boolean;
/** 是否支持网格显示 / Supports grid display */
grid: boolean;
/** 是否支持场景编辑 / Supports scene editing */
sceneEditing: boolean;
}
/**
*
* Platform adapter configuration
*/
export interface PlatformAdapterConfig {
/** Canvas 元素 ID */
canvasId: string;
/** 初始宽度 */
width?: number;
/** 初始高度 */
height?: number;
/** 是否为编辑器模式 */
isEditor?: boolean;
}
/**
*
* Platform adapter interface
*
*
* Different platforms implement this interface to provide platform-specific functionality
*/
export interface IPlatformAdapter {
/**
*
* Platform name
*/
readonly name: string;
/**
*
* Platform capabilities
*/
readonly capabilities: PlatformCapabilities;
/**
*
* Path resolver
*/
readonly pathResolver: IPathResolver;
/**
*
* Initialize platform
*/
initialize(config: PlatformAdapterConfig): Promise<void>;
/**
* WASM
* Get WASM module
*
* WASM
* Different platforms may load WASM in different ways
*/
getWasmModule(): Promise<any>;
/**
* Canvas
* Get canvas element
*/
getCanvas(): HTMLCanvasElement | null;
/**
*
* Resize viewport
*/
resize(width: number, height: number): void;
/**
*
* Get current viewport size
*/
getViewportSize(): { width: number; height: number };
/**
*
* Whether in editor mode
*/
isEditorMode(): boolean;
/**
*
* Set whether to show grid (only effective in editor mode)
*/
setShowGrid?(show: boolean): void;
/**
* Gizmos
* Set whether to show gizmos (only effective in editor mode)
*/
setShowGizmos?(show: boolean): void;
feat(engine-core): 添加统一输入系统 (#282) * perf(core): 优化 EntitySystem 迭代性能,添加 CommandBuffer 延迟命令 ReactiveQuery 快照优化: - 添加快照机制,避免每帧拷贝数组 - 只在实体列表变化时创建新快照 - 静态场景下多个系统共享同一快照 CommandBuffer 延迟命令系统: - 支持延迟添加/移除组件、销毁实体、设置实体激活状态 - 每个系统拥有独立的 commands 属性 - 命令在帧末统一执行,避免迭代过程中修改实体列表 Scene 更新: - 在 lateUpdate 后自动刷新所有系统的命令缓冲区 文档: - 更新系统文档,添加 CommandBuffer 使用说明 * fix(ci): upgrade first-interaction action to v1.3.0 Fix Docker build failure in welcome workflow. * fix(ci): upgrade pnpm/action-setup to v4 and fix unused import - Upgrade pnpm/action-setup@v2 to v4 in all workflow files - Remove unused CommandType import in CommandBuffer.test.ts * fix(ci): remove duplicate pnpm version specification * feat(engine-core): 添加统一输入系统 添加完整的输入系统,支持平台抽象: - IPlatformInputSubsystem: 扩展接口支持键盘/鼠标/滚轮事件 - WebInputSubsystem: 浏览器实现,支持事件绑定/解绑 - InputManager: 全局输入状态管理器(键盘、鼠标、触摸) - InputSystem: ECS 系统,连接平台事件到 InputManager - GameRuntime 集成: 自动创建 InputSystem 并绑定平台子系统 使用方式: ```typescript import { Input, MouseButton } from '@esengine/engine-core'; if (Input.isKeyDown('KeyW')) { /* 移动 */ } if (Input.isKeyJustPressed('Space')) { /* 跳跃 */ } if (Input.isMouseButtonDown(MouseButton.Left)) { /* 射击 */ } ``` * fix(runtime-core): 添加缺失的 platform-common 依赖 * fix(runtime-core): 移除 platform-web 依赖避免循环依赖 * fix(runtime-core): 使用工厂函数注入 InputSubsystem 避免循环依赖 - BrowserPlatformAdapter 通过 inputSubsystemFactory 配置接收输入子系统 - 在 IPlatformInputSubsystem 接口添加可选的 dispose 方法 - 移除对 @esengine/platform-web 的直接依赖
2025-12-05 18:15:50 +08:00
/**
*
* Get input subsystem
*
*
* Returns platform-specific input subsystem implementation
*/
getInputSubsystem?(): IPlatformInputSubsystem | null;
/**
*
* Dispose resources
*/
dispose(): void;
}
/**
*
* Default path resolver (returns path as-is)
*/
export class DefaultPathResolver implements IPathResolver {
resolve(path: string): string {
// 如果已经是 URL直接返回
if (path.startsWith('http://') ||
path.startsWith('https://') ||
path.startsWith('data:') ||
path.startsWith('blob:')) {
return path;
}
return path;
}
}