@craft_eco/craft-mcp 0.1.18 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -8
- package/bin/craft-mcp.mjs +14 -1
- package/dist-server/core/connector-auth.mjs +3 -3
- package/dist-server/game-workflow/asset-formats.mjs +25 -64
- package/dist-server/game-workflow/asset-import.mjs +83 -67
- package/dist-server/game-workflow/assets.mjs +81 -9
- package/dist-server/game-workflow/capture-worker.mjs +1 -1
- package/dist-server/game-workflow/check.mjs +1 -1
- package/dist-server/game-workflow/draft-archive.mjs +53 -53
- package/dist-server/game-workflow/draft-bindings.mjs +35 -35
- package/dist-server/game-workflow/draft-uploads.mjs +207 -207
- package/dist-server/game-workflow/engines.mjs +2 -2
- package/dist-server/game-workflow/library-assets.mjs +16 -5
- package/dist-server/game-workflow/library-candidates.mjs +2 -1
- package/dist-server/game-workflow/library-catalog.mjs +2 -2
- package/dist-server/game-workflow/publication-materials.mjs +67 -67
- package/dist-server/game-workflow/publications.mjs +148 -148
- package/dist-server/game-workflow/publish-capture-worker.mjs +57 -57
- package/dist-server/game-workflow/publish-capture.mjs +75 -75
- package/dist-server/game-workflow/resource-catalog.mjs +16 -13
- package/dist-server/mcp/control-panel.html +2 -2
- package/dist-server/mcp/control-panel.mjs +59 -59
- package/dist-server/mcp/publication-page.html +85 -86
- package/dist-server/mcp/publication-page.mjs +346 -347
- package/dist-server/mcp/publication-preview.mjs +62 -48
- package/dist-server/mcp/publication-tools.mjs +22 -22
- package/dist-server/mcp/publish-panel.mjs +191 -191
- package/dist-server/mcp/server.mjs +312 -312
- package/dist-server/upstream/craft-aigc.mjs +182 -169
- package/dist-server/upstream/library-url.mjs +3 -5
- package/dist-server/upstream/publication-transport.mjs +81 -81
- package/dist-server/upstream/resource-path.mjs +17 -0
- package/package.json +2 -2
- package/resources/craft-game-maker/SKILL.md +71 -69
- package/resources/craft-game-maker/js.md +6 -5
- package/resources/craft-game-maker/js3d.md +6 -5
- package/resources/game_visual_qa.mjs +9 -3
- package/resources/js/context/.role/AGENTS_DESIGN.md +9 -0
- package/resources/js/context/AGENTS.md +112 -0
- package/resources/js/context/agents/aigc-asset.md +168 -0
- package/resources/js/context/hooks/hooks.json +14 -20
- package/resources/js/context/knowledge/AigcEnabled.md +49 -41
- package/resources/js/context/knowledge/AigcWiring.md +200 -200
- package/resources/js/context/knowledge/AssetUrl.md +24 -24
- package/resources/js/context/knowledge/FrontendComponents.md +17 -23
- package/resources/js/context/knowledge/Lifecycle.md +32 -27
- package/resources/js/context/knowledge/MobileAdaptation.md +73 -0
- package/resources/js/context/knowledge/MobileAdapted.md +36 -0
- package/resources/js/context/knowledge/Multiplayer/GameplaySystemKnowledge.md +114 -114
- package/resources/js/context/knowledge/Multiplayer/OverviewKnowledge.md +115 -115
- package/resources/js/context/knowledge/Multiplayer/StateSyncKnowledge.md +392 -392
- package/resources/js/context/knowledge/PlatformServices.md +190 -184
- package/resources/js/context/knowledge/ProjectDisplayConfig.md +35 -0
- package/resources/js/context/knowledge/Subsystems/Optional/MultiplayerManagerKnowledge.md +242 -242
- package/resources/js/context/knowledge/Ui.md +11 -11
- package/resources/js/context/knowledge/UiEditorCompat.md +21 -21
- package/resources/js/context/rules/MultiplayerCapability.md +23 -23
- package/resources/js/context/rules/MultiplayerRoomEntryUX.md +63 -63
- package/resources/js/context/rules/PlatformBoundaryModules.md +44 -43
- package/resources/js/context/rules/preview_ready.md +8 -0
- package/resources/js/context/skills/aigc-generate/SKILL.md +149 -301
- package/resources/js/context/skills/aigc-generate/knowledge/audio.md +39 -39
- package/resources/js/context/skills/aigc-generate/knowledge/batch-replace.md +26 -14
- package/resources/js/context/skills/aigc-generate/knowledge/character2d.md +132 -129
- package/resources/js/context/skills/aigc-generate/knowledge/non-stepwise-aigc.md +53 -54
- package/resources/js/context/skills/aigc-generate/knowledge/texture-prop.md +52 -50
- package/resources/js/context/skills/aigc-generate/knowledge/texture-scene.md +191 -201
- package/resources/js/context/skills/aigc-generate/knowledge/texture-ui.md +55 -53
- package/resources/js/context/skills/asset-search/SKILL.md +69 -73
- package/resources/js/context/skills/asset-search/scripts/asset_display.mjs +62 -62
- package/resources/js/context/skills/asset-search/scripts/config.json +5 -5
- package/resources/js/context/skills/asset-search/scripts/provided_assets.mjs +125 -125
- package/resources/js/context/skills/asset-search/scripts/search.mjs +760 -749
- package/resources/js/context/skills/asset-search/scripts/sprite_source_materializer.mjs +657 -723
- package/resources/js/context/skills/asset-search/strategies/anim2d.md +42 -0
- package/resources/js/context/skills/asset-search/strategies/audio.md +34 -34
- package/resources/js/context/skills/asset-search/strategies/effect2d.md +31 -31
- package/resources/js/context/skills/asset-search/strategies/texture-prop.md +22 -22
- package/resources/js/context/skills/asset-search/strategies/ui-common.md +40 -40
- package/resources/js/context/skills/asset-search/strategies/ui-style.md +28 -28
- package/resources/js/context/skills/export-config/SKILL.md +28 -20
- package/resources/js/context/skills/export-config/assets/tooling/cli.mjs +20 -0
- package/resources/js/context/skills/{lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform → export-config/assets/tooling}/config.d.mts +19 -19
- package/resources/js/context/skills/{lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform → export-config/assets/tooling}/config.mjs +1 -1
- package/resources/js/context/skills/export-config/assets/tooling/project.d.mts +6 -0
- package/resources/js/context/skills/export-config/assets/tooling/project.mjs +77 -0
- package/resources/js/context/skills/export-config/assets/tooling/vite.d.mts +2 -0
- package/resources/js/context/skills/export-config/assets/tooling/vite.mjs +34 -0
- package/resources/js/context/skills/export-config/scripts/assert-asset-wiring.mjs +72 -72
- package/resources/js/context/skills/export-config/scripts/export-config.mjs +46 -43
- package/resources/js/context/skills/export-config/scripts/install.mjs +89 -0
- package/resources/js/context/skills/export-config/scripts/panel-resource-path.mjs +106 -106
- package/resources/js/context/skills/export-config/scripts/sync-asset-controls.mjs +352 -351
- package/resources/js/context/skills/export-config/scripts/translate-asset-titles.mjs +161 -163
- package/resources/js/context/skills/lightgame-runtime-adapt/SKILL.md +93 -92
- package/resources/js/context/skills/lightgame-runtime-adapt/project/game-runtime.json +7 -7
- package/resources/js/context/skills/lightgame-runtime-adapt/project/package.json +22 -22
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform-capture-video.mjs +227 -227
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform-service.d.mts +31 -25
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform.d.mts +79 -79
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform.mjs +29 -29
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/release.json +22 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/assets.d.mts +24 -24
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/assets.mjs +2 -2
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/astc.d.mts +10 -10
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/astc.mjs +1 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/config-export.mjs +37 -32
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/refresh-runtime.mjs +50 -50
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/cli.mjs +20 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/config.d.mts +19 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/config.mjs +1 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/installed.json +6 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/project.d.mts +6 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/project.mjs +77 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/vite.mjs +34 -0
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/display/ui-stage.ts +156 -121
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/display/viewport.ts +249 -254
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/main.ts +87 -99
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/platform.ts +2 -14
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/screenUi.ts +185 -172
- package/resources/js/context/skills/lightgame-runtime-adapt/project/src/style.css +294 -165
- package/resources/js/context/skills/lightgame-runtime-adapt/project/tsconfig.json +20 -20
- package/resources/js/context/skills/lightgame-runtime-adapt/project/vite.config.ts +5 -4
- package/resources/js/context/skills/lightgame-runtime-adapt/scripts/install-template.mjs +159 -109
- package/resources/js/context/skills/mobile-adaptation/SKILL.md +277 -260
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-config.json +50 -50
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-layer.ts +862 -881
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-platform.ts +92 -92
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-primitives.ts +254 -0
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/look-pad.ts +245 -245
- package/resources/js/context/skills/mobile-adaptation/assets/example/src/ui/touch-controls.css +135 -134
- package/resources/js/context/skills/mobile-adaptation/references/input-config.md +342 -311
- package/resources/js/context/skills/mobile-adaptation/references/verification.md +140 -106
- package/resources/js/context/skills/mobile-adaptation/references/web-audio.md +11 -0
- package/resources/js/context/skills/mobile-compat-qa/SKILL.md +53 -0
- package/resources/js/context/skills/mobile-compat-qa/references/startup-diagnosis.md +23 -0
- package/resources/js/context/skills/mobile-compat-qa/references/web-lifecycle.md +20 -0
- package/resources/js/context/skills/mobile-compat-qa/references/web-performance.md +19 -0
- package/resources/js/context/skills/optimization-suggestions/SKILL.md +89 -89
- package/resources/js/context/skills/platform-services/SKILL.md +101 -94
- package/resources/js/context/skills/platform-services/assets/modules/MultiplayerManager.ts +465 -783
- package/resources/js/context/skills/platform-services/assets/modules/eventBus.ts +57 -57
- package/resources/js/context/skills/platform-services/assets/modules/identity/qq-ai-game-sdk.min.js +5 -0
- package/resources/js/context/skills/platform-services/assets/modules/identity/qq-session.mjs +208 -0
- package/resources/js/context/skills/platform-services/assets/modules/identity/shared.mjs +37 -0
- package/resources/js/context/skills/platform-services/assets/modules/leaderboard.d.mts +39 -39
- package/resources/js/context/skills/platform-services/assets/modules/leaderboard.mjs +1 -1
- package/resources/js/context/skills/platform-services/assets/modules/log.ts +35 -35
- package/resources/js/context/skills/platform-services/assets/modules/multiplayer/clockSync.ts +61 -0
- package/resources/js/context/skills/platform-services/assets/modules/multiplayer/dsClient.ts +52 -0
- package/resources/js/context/skills/platform-services/assets/modules/multiplayer/payloadCodec.ts +30 -0
- package/resources/js/context/skills/platform-services/assets/modules/multiplayer/roomHttp.ts +89 -0
- package/resources/js/context/skills/platform-services/assets/modules/multiplayer/types.ts +47 -0
- package/resources/js/context/skills/platform-services/assets/modules/platform-service.d.mts +31 -25
- package/resources/js/context/skills/platform-services/assets/modules/platform-service.mjs +272 -1
- package/resources/js/context/skills/platform-services/assets/modules/save.d.mts +49 -49
- package/resources/js/context/skills/platform-services/assets/modules/save.mjs +1 -1
- package/resources/js/context/skills/platform-services/assets/scaffold/ds/main.mjs +7 -7
- package/resources/js/context/skills/platform-services/assets/scaffold/ds/rooms/SyncRoom.mjs +264 -264
- package/resources/js/context/skills/platform-services/assets/scaffold/ds/rooms/syncSchema.mjs +39 -39
- package/resources/js/context/skills/platform-services/references/SERVER_GUIDE.md +139 -139
- package/resources/js/context/skills/platform-services/references/api_reference.md +18 -18
- package/resources/js/context/skills/platform-services/references/leaderboard_playbook.md +96 -0
- package/resources/js/context/skills/platform-services/scripts/install.mjs +148 -134
- package/resources/js/context/skills/resolution-adaptation/SKILL.md +47 -202
- package/resources/js/context/skills/resolution-adaptation/assets/display/ui-stage.ts +156 -121
- package/resources/js/context/skills/resolution-adaptation/assets/display/viewport.ts +249 -254
- package/resources/js/context/skills/resolution-adaptation/assets/example/main.ts +98 -98
- package/resources/js/context/skills/resolution-adaptation/assets/example/ui-tokens.css +200 -200
- package/resources/js/context/skills/resolution-adaptation/references/audit.md +31 -0
- package/resources/js/context/skills/resolution-adaptation/references/device-safe-area.md +40 -0
- package/resources/js/context/skills/resolution-adaptation/references/game-ui-occlusion.md +18 -0
- package/resources/js/context/skills/resolution-adaptation/references/layout-rules.md +15 -134
- package/resources/js/context/skills/resolution-adaptation/references/troubleshooting.md +34 -0
- package/resources/js/context/skills/resolution-adaptation/references/viewport-api.md +38 -119
- package/resources/js/context/skills/resolution-adaptation/references/world-resize.md +55 -0
- package/resources/js/context/skills/resolution-adaptation/scripts/aspect_audit.mjs +448 -338
- package/resources/js/context/skills/scene-editor-compat/SKILL.md +94 -94
- package/resources/js/context/skills/scene-editor-compat/assets/example/localcraft.assets.json +13 -13
- package/resources/js/context/skills/scene-editor-compat/assets/example/localcraft.scene-editor.json +6 -6
- package/resources/js/context/skills/scene-editor-compat/assets/example/src/game/sceneAdapter.ts +25 -25
- package/resources/js/context/skills/scene-editor-compat/assets/example/src/scenes/main.scene.json +18 -18
- package/resources/js/context/skills/scene-editor-compat/assets/runtime/release.json +7 -7
- package/resources/js/context/skills/scene-editor-compat/assets/runtime/scene.d.mts +42 -42
- package/resources/js/context/skills/scene-editor-compat/assets/runtime/scene.mjs +144 -144
- package/resources/js/context/skills/scene-editor-compat/docs/contract.md +330 -330
- package/resources/js/context/skills/scene-editor-compat/docs/resource-sync.md +64 -64
- package/resources/js/context/skills/scene-editor-compat/docs/runtime-state.md +28 -28
- package/resources/js/context/skills/scene-editor-compat/docs/terrain-contract.md +47 -47
- package/resources/js/context/skills/scene-editor-compat/docs/visual-contract.md +64 -64
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/localcraft.assets.json +38 -38
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/localcraft.scene-editor.json +9 -9
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneAdapter.ts +59 -59
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneBlockers.ts +30 -30
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneFileAssets.ts +66 -66
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/scenes/Main.Scene.ts +20 -20
- package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/scenes/SceneTypes.ts +26 -26
- package/resources/js/context/skills/scene-editor-compat/references/contract.md +73 -73
- package/resources/js/context/skills/scene-editor-compat/scripts/apply_scene_marker.py +162 -162
- package/resources/js/context/skills/scene-editor-compat/scripts/check_scene_contract.py +853 -853
- package/resources/js/context/skills/scene-editor-compat/scripts/check_scene_resource_urls.py +173 -173
- package/resources/js/context/skills/scene-editor-compat/scripts/scene-editor.mjs +427 -427
- package/resources/js/context/skills/scene-editor-compat/version.json +1 -1
- package/resources/js/context/skills/ui-editor-compat/SKILL.md +48 -48
- package/resources/js/context/skills/ui-editor-compat/assets/example/hud/WidgetLayout_Hud.ts +35 -35
- package/resources/js/context/skills/ui-editor-compat/assets/example/hud/WidgetLogic_Hud.ts +74 -74
- package/resources/js/context/skills/ui-editor-compat/assets/example/hud/hud.css +60 -60
- package/resources/js/context/skills/ui-editor-compat/assets/runtime/dom-ui.d.mts +45 -45
- package/resources/js/context/skills/ui-editor-compat/assets/runtime/dom-ui.mjs +265 -265
- package/resources/js/context/skills/ui-editor-compat/assets/runtime/release.json +7 -7
- package/resources/js/context/skills/ui-editor-compat/references/contract.md +132 -132
- package/resources/js/context/skills/ui-editor-compat/scripts/editor-contract.mjs +327 -327
- package/resources/js/context/skills/ui-editor-compat/scripts/project-files.mjs +80 -80
- package/resources/js/context/skills/ui-editor-compat/scripts/ui-editor.mjs +84 -84
- package/resources/js/context/skills/version-update/SKILL.md +192 -192
- package/resources/js/context/skills/version-update/scripts/check_runtime_refs.mjs +129 -129
- package/resources/js/context/skills/version-update/scripts/feature_snapshot.mjs +159 -159
- package/resources/js/context/skills/version-update/scripts/update_feature_version.mjs +157 -157
- package/resources/js/context/skills/visual-qa/SKILL.md +36 -36
- package/resources/js/context/version/version.json +1 -1
- package/resources/js/project/README.md +99 -99
- package/resources/js/project/SPEC/readme.md +6 -6
- package/resources/js/project/configs/assets.json +1 -1
- package/resources/js/project/configs/game.controls.json +3 -3
- package/resources/js/project/configs/game.json +3 -3
- package/resources/js/project/game-runtime.json +2 -2
- package/resources/js/project/{projectDisplayInfo.json → game.config.json} +7 -7
- package/resources/js/project/index.html +20 -20
- package/resources/js/project/package.json +23 -23
- package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-capture-video.mjs +227 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-service.d.mts +31 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/platform.d.mts +79 -0
- package/resources/js/project/runtime/lightgame/1.1.0/platform/platform.mjs +29 -0
- package/resources/js/project/runtime/lightgame/1.1.0/release.json +22 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tools/assets.d.mts +24 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tools/assets.mjs +2 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tools/astc.d.mts +10 -0
- package/resources/js/project/runtime/lightgame/1.1.0/tools/astc.mjs +1 -0
- package/resources/js/project/scripts/config-export.mjs +37 -32
- package/resources/js/project/scripts/refresh-runtime.mjs +50 -50
- package/resources/js/project/scripts/skill-modules/export-config/cli.mjs +20 -0
- package/resources/js/project/scripts/skill-modules/export-config/config.d.mts +19 -0
- package/resources/js/project/scripts/skill-modules/export-config/config.mjs +1 -0
- package/resources/js/project/scripts/skill-modules/export-config/installed.json +6 -0
- package/resources/js/project/scripts/skill-modules/export-config/project.d.mts +6 -0
- package/resources/js/project/scripts/skill-modules/export-config/project.mjs +77 -0
- package/resources/js/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
- package/resources/js/project/scripts/skill-modules/export-config/vite.mjs +34 -0
- package/resources/js/project/scripts/write-preview-ready.mjs +22 -0
- package/resources/js/project/src/display/ui-stage.ts +156 -121
- package/resources/js/project/src/display/viewport.ts +249 -254
- package/resources/js/project/src/main.ts +87 -99
- package/resources/js/project/src/platform.ts +2 -14
- package/resources/js/project/src/scenes/LoadScene.ts +89 -89
- package/resources/js/project/src/scenes/PlayScene.ts +17 -17
- package/resources/js/project/src/screenUi.ts +185 -172
- package/resources/js/project/src/style.css +294 -165
- package/resources/js/project/tsconfig.json +20 -20
- package/resources/js/project/unified_data_control_config.json +20 -20
- package/resources/js/project/vendor/core-manager-js/src/.versions.json +42 -42
- package/resources/js/project/vendor/core-manager-js/src/CoreManagerPlugin.ts +41 -41
- package/resources/js/project/vendor/core-manager-js/src/assetManager/AssetRef.ts +93 -90
- package/resources/js/project/vendor/core-manager-js/src/assetManager/AstcFirstImageFile.ts +203 -203
- package/resources/js/project/vendor/core-manager-js/src/assetManager/AstcTextureLoader.ts +106 -106
- package/resources/js/project/vendor/core-manager-js/src/assetManager/resolveAssetUrl.test.ts +25 -25
- package/resources/js/project/vendor/core-manager-js/src/assetManager/resolveAssetUrl.ts +21 -21
- package/resources/js/project/vendor/core-manager-js/src/audioManager/AudioManager.test.ts +65 -65
- package/resources/js/project/vendor/core-manager-js/src/audioManager/AudioManager.ts +340 -340
- package/resources/js/project/vendor/core-manager-js/src/configManager/FeatureConfig.ts +87 -87
- package/resources/js/project/vendor/core-manager-js/src/configManager/tuneRuntime.d.mts +92 -92
- package/resources/js/project/vendor/core-manager-js/src/configManager/tuneRuntime.mjs +271 -271
- package/resources/js/project/vendor/core-manager-js/src/index.ts +31 -31
- package/resources/js/project/vendor/core-manager-js/src/inputManager/InputConfig.ts +81 -81
- package/resources/js/project/vendor/core-manager-js/src/inputManager/InputManager.test.ts +43 -43
- package/resources/js/project/vendor/core-manager-js/src/inputManager/InputManager.ts +32 -32
- package/resources/js/project/vendor/core-manager-js/src/inputManager/InputRuntime.test.ts +141 -141
- package/resources/js/project/vendor/core-manager-js/src/inputManager/InputRuntime.ts +20 -20
- package/resources/js/project/vendor/core-manager-js/src/inputManager/KeyboardProvider.ts +183 -183
- package/resources/js/project/vendor/core-manager-js/src/inputManager/TouchProvider.ts +304 -304
- package/resources/js/project/vendor/core-manager-js/src/inputManager/VirtualJoystick.ts +351 -351
- package/resources/js/project/vendor/core-manager-js/src/inputManager/_internal/InputManagerImpl.ts +180 -180
- package/resources/js/project/vendor/core-manager-js/src/inputManager/icons.b64 +13 -13
- package/resources/js/project/vendor/core-manager-js/src/inputManager/icons.b64.d.ts +14 -14
- package/resources/js/project/vendor/core-manager-js/src/inputManager/input_config.example.json +68 -68
- package/resources/js/project/vendor/core-manager-js/src/logManager/DebugConsole.ts +433 -433
- package/resources/js/project/vendor/core-manager-js/src/logManager/LogCapture.ts +118 -118
- package/resources/js/project/vendor/core-manager-js/src/logManager/LogManager.ts +444 -444
- package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCapture.ts +485 -485
- package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCaptureVideo.test.ts +66 -66
- package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCaptureVideo.ts +149 -149
- package/resources/js/project/vendor/core-manager-js/src/logManager/icons.b64 +9 -9
- package/resources/js/project/vendor/core-manager-js/src/resourceManager/AssetUrlResolver.ts +29 -29
- package/resources/js/project/vendor/core-manager-js/src/resourceManager/ResourceManager.test.ts +88 -88
- package/resources/js/project/vendor/core-manager-js/src/resourceManager/ResourceManager.ts +122 -122
- package/resources/js/project/vendor/core-manager-js/src/runtime.ts +24 -24
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterEntity.ts +318 -318
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterPhysicsBinding.test.ts +151 -151
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterPhysicsBinding.ts +235 -235
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectComposite.test.ts +98 -98
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectComposite.ts +94 -94
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectEntity.ts +209 -209
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxManager.test.ts +106 -106
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxManager.ts +341 -341
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxRecipe.test.ts +68 -68
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxRecipe.ts +236 -236
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteAnimManager.test.ts +22 -22
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteAnimManager.ts +29 -29
- package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteEntity.test.ts +197 -197
- package/resources/js/project/vendor/core-manager-js/src/uiManager/DomUiContracts.ts +9 -9
- package/resources/js/project/vendor/core-manager-js/src/uiManager/DomUiKit.ts +555 -555
- package/resources/js/project/vendor/core-manager-js/src/uiManager/UIFacadePlugin.test.ts +112 -112
- package/resources/js/project/vendor/core-manager-js/src/uiManager/UIFacadePlugin.ts +178 -178
- package/resources/js/project/vendor/core-manager-js/src/uiManager/ui-base.css +246 -246
- package/resources/js/project/vendor/core-manager-js/src/videoManager/VideoManager.ts +139 -139
- package/resources/js/project/vendor/core-manager-js/tsconfig.json +15 -15
- package/resources/js/project/vendor/run.sh +4 -107
- package/resources/js/project/version/craft_feature_version.json +42 -42
- package/resources/js/project/version/project_feature_version.json +11 -11
- package/resources/js/project/vite.config.ts +5 -4
- package/resources/js3d/context/.role/AGENTS_DESIGN.md +9 -0
- package/resources/js3d/context/AGENTS.md +95 -0
- package/resources/js3d/context/hooks/hooks.json +14 -20
- package/resources/js3d/context/knowledge/3D/PoseInterpolationKnowledge.md +75 -87
- package/resources/js3d/context/knowledge/CodingGuide/Pitfalls.md +69 -69
- package/resources/js3d/context/knowledge/CodingGuide/SceneEditableGuide.md +42 -42
- package/resources/js3d/context/knowledge/FrontendComponents.md +19 -23
- package/resources/js3d/context/knowledge/MobileAdaptation.md +73 -0
- package/resources/js3d/context/knowledge/MobileAdapted.md +36 -0
- package/resources/js3d/context/knowledge/Multiplayer/GameplaySystemKnowledge.md +114 -114
- package/resources/js3d/context/knowledge/Multiplayer/OverviewKnowledge.md +117 -117
- package/resources/js3d/context/knowledge/Multiplayer/StateSyncKnowledge.md +430 -430
- package/resources/js3d/context/knowledge/PlatformServices.md +190 -162
- package/resources/js3d/context/knowledge/ProjectDisplayConfig.md +35 -0
- package/resources/js3d/context/knowledge/Runtime.md +34 -30
- package/resources/js3d/context/knowledge/SceneEditorCompat.md +35 -34
- package/resources/js3d/context/knowledge/StepByStep.md +21 -21
- package/resources/js3d/context/knowledge/Subsystems/Optional/MultiplayerManagerKnowledge.md +242 -242
- package/resources/js3d/context/knowledge/UiEditorCompat.md +21 -21
- package/resources/js3d/context/rules/MultiplayerCapability.md +27 -27
- package/resources/js3d/context/rules/MultiplayerRoomEntryUX.md +63 -63
- package/resources/js3d/context/rules/PlatformBoundaryModules.md +44 -43
- package/resources/js3d/context/rules/preview_ready.md +8 -0
- package/resources/js3d/context/skills/aigc-integration/SKILL.md +172 -176
- package/resources/js3d/context/skills/aigc-integration/assets/sprite-sheet-player.mjs +70 -0
- package/resources/js3d/context/skills/aigc-integration/callback.md +77 -56
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/README.md +23 -22
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/audio-aigc-knowledge.md +38 -38
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/character2d-aigc-knowledge.md +72 -0
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/staticmesh-aigc-knowledge.md +33 -33
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-prop-aigc-knowledge.md +36 -36
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-scene-aigc-knowledge.md +37 -37
- package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-ui-aigc-knowledge.md +35 -35
- package/resources/js3d/context/skills/asset-search/SKILL.md +178 -159
- package/resources/js3d/context/skills/asset-search/references/resource-config.md +99 -56
- package/resources/js3d/context/skills/asset-search/references/sprite-sheets.md +58 -0
- package/resources/js3d/context/skills/asset-search/scripts/asset_display.mjs +62 -62
- package/resources/js3d/context/skills/asset-search/scripts/config.json +235 -213
- package/resources/js3d/context/skills/asset-search/scripts/manifest_pipeline.mjs +905 -885
- package/resources/js3d/context/skills/asset-search/scripts/preflight.mjs +79 -79
- package/resources/js3d/context/skills/asset-search/scripts/provided_assets.mjs +74 -74
- package/resources/js3d/context/skills/asset-search/scripts/search.mjs +637 -597
- package/resources/js3d/context/skills/asset-search/scripts/sprite_source_materializer.mjs +667 -0
- package/resources/js3d/context/skills/asset-search/strategies/anim2d.md +42 -0
- package/resources/js3d/context/skills/asset-search/strategies/effect2d.md +31 -0
- package/resources/js3d/context/skills/asset-usage-audit/SKILL.md +92 -0
- package/resources/js3d/context/skills/asset-usage-audit/references/case-tidewater-zoo.md +89 -0
- package/resources/js3d/context/skills/asset-usage-audit/references/optimization-playbook.md +143 -0
- package/resources/js3d/context/skills/asset-usage-audit/references/usage-model.md +90 -0
- package/resources/js3d/context/skills/asset-usage-audit/scripts/compare-animations.mjs +48 -0
- package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/anim.mjs +266 -0
- package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/glb.mjs +241 -0
- package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/scan.mjs +455 -0
- package/resources/js3d/context/skills/asset-usage-audit/scripts/scan-assets.mjs +77 -0
- package/resources/js3d/context/skills/export-config/SKILL.md +20 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/cli.mjs +20 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/config.d.mts +19 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/config.mjs +1 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/project.d.mts +6 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/project.mjs +77 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/vite.d.mts +2 -0
- package/resources/js3d/context/skills/export-config/assets/tooling/vite.mjs +34 -0
- package/resources/js3d/context/skills/export-config/scripts/assert-asset-wiring.mjs +97 -83
- package/resources/js3d/context/skills/export-config/scripts/export-config.mjs +56 -53
- package/resources/js3d/context/skills/export-config/scripts/install.mjs +89 -0
- package/resources/js3d/context/skills/export-config/scripts/panel-resource-path.mjs +106 -106
- package/resources/js3d/context/skills/export-config/scripts/sync-asset-controls.mjs +327 -325
- package/resources/js3d/context/skills/export-config/scripts/sync-scene-assets.mjs +216 -181
- package/resources/js3d/context/skills/export-config/scripts/translate-asset-titles.mjs +161 -163
- package/resources/js3d/context/skills/game-art-style/SKILL.md +60 -60
- package/resources/js3d/context/skills/game-art-style/references/art-parameters-lite.md +38 -38
- package/resources/js3d/context/skills/game-art-style/references/construction.md +111 -111
- package/resources/js3d/context/skills/game-art-style/references/materials-textures.md +105 -105
- package/resources/js3d/context/skills/game-art-style/references/sources.md +25 -25
- package/resources/js3d/context/skills/game-art-style/references/styles/cartoon.md +175 -175
- package/resources/js3d/context/skills/game-art-style/references/styles/comic.md +168 -168
- package/resources/js3d/context/skills/game-art-style/references/styles/cozy.md +191 -191
- package/resources/js3d/context/skills/game-art-style/references/styles/cyber.md +165 -165
- package/resources/js3d/context/skills/game-art-style/references/styles/horror.md +173 -173
- package/resources/js3d/context/skills/game-art-style/references/styles/lowpoly.md +185 -185
- package/resources/js3d/context/skills/game-art-style/references/styles/paper.md +181 -181
- package/resources/js3d/context/skills/game-art-style/references/styles/voxel.md +189 -189
- package/resources/js3d/context/skills/game-art-style/references/user-style-document.md +88 -88
- package/resources/js3d/context/skills/mobile-adaptation/SKILL.md +301 -284
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-config.json +104 -104
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-layer.ts +933 -952
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-platform.ts +92 -92
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-primitives.ts +254 -0
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/look-pad.ts +245 -245
- package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/ui/touch-controls.css +257 -256
- package/resources/js3d/context/skills/mobile-adaptation/references/input-config.md +342 -311
- package/resources/js3d/context/skills/mobile-adaptation/references/verification.md +140 -106
- package/resources/js3d/context/skills/mobile-adaptation/references/web-audio.md +11 -0
- package/resources/js3d/context/skills/mobile-compat-qa/SKILL.md +53 -0
- package/resources/js3d/context/skills/mobile-compat-qa/references/startup-diagnosis.md +23 -0
- package/resources/js3d/context/skills/mobile-compat-qa/references/web-form-input.md +10 -0
- package/resources/js3d/context/skills/mobile-compat-qa/references/web-lifecycle.md +20 -0
- package/resources/js3d/context/skills/mobile-compat-qa/references/web-performance.md +19 -0
- package/resources/js3d/context/skills/optimization-suggestions/SKILL.md +74 -74
- package/resources/js3d/context/skills/performance-audit/SKILL.md +166 -0
- package/resources/js3d/context/skills/performance-audit/references/case-notes.md +93 -0
- package/resources/js3d/context/skills/performance-audit/references/rules.md +183 -0
- package/resources/js3d/context/skills/performance-audit/scripts/lib/rules.mjs +470 -0
- package/resources/js3d/context/skills/performance-audit/scripts/lib/scan.mjs +387 -0
- package/resources/js3d/context/skills/performance-audit/scripts/lib/source.mjs +398 -0
- package/resources/js3d/context/skills/performance-audit/scripts/scan-perf.mjs +130 -0
- package/resources/js3d/context/skills/platform-services/SKILL.md +101 -94
- package/resources/js3d/context/skills/platform-services/assets/modules/MultiplayerManager.ts +465 -783
- package/resources/js3d/context/skills/platform-services/assets/modules/eventBus.ts +57 -57
- package/resources/js3d/context/skills/platform-services/assets/modules/identity/qq-ai-game-sdk.min.js +5 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/identity/qq-session.mjs +208 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/identity/shared.mjs +37 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/leaderboard.d.mts +39 -39
- package/resources/js3d/context/skills/platform-services/assets/modules/leaderboard.mjs +1 -1
- package/resources/js3d/context/skills/platform-services/assets/modules/log.ts +35 -35
- package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/clockSync.ts +61 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/dsClient.ts +52 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/payloadCodec.ts +30 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/roomHttp.ts +89 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/types.ts +47 -0
- package/resources/js3d/context/skills/platform-services/assets/modules/platform-service.d.mts +31 -25
- package/resources/js3d/context/skills/platform-services/assets/modules/platform-service.mjs +272 -1
- package/resources/js3d/context/skills/platform-services/assets/modules/save.d.mts +49 -49
- package/resources/js3d/context/skills/platform-services/assets/modules/save.mjs +1 -1
- package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/main.mjs +7 -7
- package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/rooms/SyncRoom.mjs +264 -264
- package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/rooms/syncSchema.mjs +39 -39
- package/resources/js3d/context/skills/platform-services/references/SERVER_GUIDE.md +139 -139
- package/resources/js3d/context/skills/platform-services/references/api_reference.md +18 -18
- package/resources/js3d/context/skills/platform-services/references/leaderboard_playbook.md +96 -0
- package/resources/js3d/context/skills/platform-services/scripts/install.mjs +148 -134
- package/resources/js3d/context/skills/resolution-adaptation/SKILL.md +46 -170
- package/resources/js3d/context/skills/resolution-adaptation/assets/display/ui-stage.ts +156 -121
- package/resources/js3d/context/skills/resolution-adaptation/assets/display/viewport.ts +239 -244
- package/resources/js3d/context/skills/resolution-adaptation/assets/example/main.ts +129 -127
- package/resources/js3d/context/skills/resolution-adaptation/assets/example/ui-tokens.css +188 -188
- package/resources/js3d/context/skills/resolution-adaptation/references/audit.md +31 -0
- package/resources/js3d/context/skills/resolution-adaptation/references/device-safe-area.md +40 -0
- package/resources/js3d/context/skills/resolution-adaptation/references/game-ui-occlusion.md +18 -0
- package/resources/js3d/context/skills/resolution-adaptation/references/layout-rules.md +15 -124
- package/resources/js3d/context/skills/resolution-adaptation/references/troubleshooting.md +34 -0
- package/resources/js3d/context/skills/resolution-adaptation/references/viewport-api.md +38 -117
- package/resources/js3d/context/skills/resolution-adaptation/scripts/aspect_audit.mjs +448 -338
- package/resources/js3d/context/skills/scene-editor-compat/SKILL.md +599 -599
- package/resources/js3d/context/skills/scene-editor-compat/references/bundle-contract.md +141 -141
- package/resources/js3d/context/skills/scene-editor-compat/references/editor-integration.md +92 -92
- package/resources/js3d/context/skills/scene-editor-compat/references/scene-data-format.md +125 -125
- package/resources/js3d/context/skills/scene-editor-compat/references/slots-rules.md +113 -113
- package/resources/js3d/context/skills/scene-editor-compat/scripts/scene-editor.mjs +1187 -1187
- package/resources/js3d/context/skills/threejs-game-quality/SKILL.md +53 -52
- package/resources/js3d/context/skills/threejs-game-quality/agents/openai.yaml +4 -4
- package/resources/js3d/context/skills/threejs-game-quality/references/01-build.md +94 -94
- package/resources/js3d/context/skills/threejs-game-quality/references/02-avoid.md +50 -50
- package/resources/js3d/context/skills/threejs-game-quality/references/03-detect.md +105 -105
- package/resources/js3d/context/skills/threejs-game-quality/references/camera-by-genre.md +147 -147
- package/resources/js3d/context/skills/threejs-game-quality/references/camera-distance.md +79 -79
- package/resources/js3d/context/skills/threejs-game-quality/references/camera-sources.md +56 -56
- package/resources/js3d/context/skills/threejs-game-quality/references/character-motion-face.md +51 -51
- package/resources/js3d/context/skills/threejs-game-quality/references/parameter-contract.md +55 -55
- package/resources/js3d/context/skills/threejs-game-quality/references/refine-existing.md +78 -78
- package/resources/js3d/context/skills/threejs-game-quality/references/rendering-stability.md +84 -84
- package/resources/js3d/context/skills/threejs-game-quality/references/runtime-tools.md +117 -117
- package/resources/js3d/context/skills/threejs-game-quality/scripts/package.json +4 -4
- package/resources/js3d/context/skills/threejs-game-quality/scripts/runtime-audit.js +238 -238
- package/resources/js3d/context/skills/ui-editor-compat/SKILL.md +59 -59
- package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/WidgetLayout_Hud.ts +35 -35
- package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/WidgetLogic_Hud.ts +61 -61
- package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/hud.css +60 -60
- package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/dom-ui.d.mts +45 -45
- package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/dom-ui.mjs +265 -265
- package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/release.json +7 -7
- package/resources/js3d/context/skills/ui-editor-compat/references/contract.md +110 -110
- package/resources/js3d/context/skills/ui-editor-compat/scripts/editor-contract.mjs +327 -327
- package/resources/js3d/context/skills/ui-editor-compat/scripts/project-files.mjs +80 -80
- package/resources/js3d/context/skills/ui-editor-compat/scripts/ui-editor.mjs +84 -84
- package/resources/js3d/context/skills/version-update/SKILL.md +191 -191
- package/resources/js3d/context/skills/version-update/scripts/check_runtime_refs.mjs +129 -129
- package/resources/js3d/context/skills/version-update/scripts/feature_snapshot.mjs +159 -159
- package/resources/js3d/context/skills/version-update/scripts/update_feature_version.mjs +157 -157
- package/resources/js3d/context/version/version.json +1 -1
- package/resources/js3d/project/README.md +106 -100
- package/resources/js3d/project/configs/game.controls.json +3 -3
- package/resources/js3d/project/configs/game.json +3 -3
- package/resources/js3d/project/game-runtime.json +2 -2
- package/resources/js3d/project/{projectDisplayInfo.json → game.config.json} +7 -7
- package/resources/js3d/project/index.html +12 -12
- package/resources/js3d/project/package.json +24 -24
- package/resources/js3d/project/runtime/lightgame/1.0.0/release.json +2 -2
- package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.d.mts +2 -12
- package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.mjs +21 -29
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-capture-video.mjs +227 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-service.d.mts +31 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform.d.mts +79 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform.mjs +30 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/release.json +24 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/assets.d.mts +24 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/assets.mjs +2 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/astc.d.mts +10 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/astc.mjs +1 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/glb.d.mts +26 -0
- package/resources/js3d/project/runtime/lightgame/1.1.0/tools/glb.mjs +351 -0
- package/resources/js3d/project/scripts/config-export.mjs +37 -32
- package/resources/js3d/project/scripts/refresh-runtime.mjs +50 -50
- package/resources/js3d/project/scripts/skill-modules/export-config/cli.mjs +20 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/config.d.mts +19 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/config.mjs +1 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/installed.json +6 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/project.d.mts +6 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/project.mjs +77 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
- package/resources/js3d/project/scripts/skill-modules/export-config/vite.mjs +34 -0
- package/resources/js3d/project/scripts/write-preview-ready.mjs +22 -0
- package/resources/js3d/project/src/display/ui-stage.ts +156 -121
- package/resources/js3d/project/src/display/viewport.ts +239 -244
- package/resources/js3d/project/src/main.ts +85 -83
- package/resources/js3d/project/src/platform.ts +2 -14
- package/resources/js3d/project/src/style.css +83 -17
- package/resources/js3d/project/tsconfig.json +20 -20
- package/resources/js3d/project/unified_data_control_config.json +20 -20
- package/resources/js3d/project/vendor/core-manager-three/package.json +12 -12
- package/resources/js3d/project/vendor/core-manager-three/src/index.ts +2 -2
- package/resources/js3d/project/vendor/run.sh +4 -4
- package/resources/js3d/project/version/craft_feature_version.json +42 -42
- package/resources/js3d/project/version/project_feature_version.json +11 -11
- package/resources/js3d/project/vite.config.ts +5 -4
- package/vendor/agent-cli/dist/runtime-tools/ue/blender-cook-assets.cjs +19 -19
- package/vendor/agent-cli/dist/runtime-tools/ue/tool-manifest.json +1 -1
- package/vendor/agent-cli/dist/src/artifacts/context-finalize.d.ts +1 -1
- package/vendor/agent-cli/dist/src/artifacts/context-finalize.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/context-finalize.js +15 -6
- package/vendor/agent-cli/dist/src/artifacts/context-finalize.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/native-source.d.ts +3 -0
- package/vendor/agent-cli/dist/src/artifacts/native-source.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/native-source.js +13 -0
- package/vendor/agent-cli/dist/src/artifacts/native-source.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.d.ts +13 -0
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js +300 -0
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/prepare.d.ts +4 -0
- package/vendor/agent-cli/dist/src/artifacts/prepare.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/prepare.js +20 -7
- package/vendor/agent-cli/dist/src/artifacts/prepare.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.d.ts +8 -1
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js +59 -37
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/restore-permissions.d.ts +27 -0
- package/vendor/agent-cli/dist/src/artifacts/restore-permissions.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/restore-permissions.js +112 -0
- package/vendor/agent-cli/dist/src/artifacts/restore-permissions.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/restore.d.ts +9 -0
- package/vendor/agent-cli/dist/src/artifacts/restore.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/restore.js +137 -57
- package/vendor/agent-cli/dist/src/artifacts/restore.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/static.d.ts +6 -2
- package/vendor/agent-cli/dist/src/artifacts/static.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/static.js +100 -28
- package/vendor/agent-cli/dist/src/artifacts/static.js.map +1 -1
- package/vendor/agent-cli/dist/src/cli/process-protocol.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/cli/process-protocol.js +6 -3
- package/vendor/agent-cli/dist/src/cli/process-protocol.js.map +1 -1
- package/vendor/agent-cli/dist/src/component/browser-queue.d.ts +55 -0
- package/vendor/agent-cli/dist/src/component/browser-queue.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/browser-queue.js +63 -0
- package/vendor/agent-cli/dist/src/component/browser-queue.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/execution.d.ts +4 -0
- package/vendor/agent-cli/dist/src/component/execution.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/component/execution.js +16 -4
- package/vendor/agent-cli/dist/src/component/execution.js.map +1 -1
- package/vendor/agent-cli/dist/src/component/isolated-launcher.d.ts +2 -0
- package/vendor/agent-cli/dist/src/component/isolated-launcher.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/isolated-launcher.js +76 -0
- package/vendor/agent-cli/dist/src/component/isolated-launcher.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/isolated-preload.d.ts +2 -0
- package/vendor/agent-cli/dist/src/component/isolated-preload.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/isolated-preload.js +27 -0
- package/vendor/agent-cli/dist/src/component/isolated-preload.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/platform-access/server.d.ts +0 -5
- package/vendor/agent-cli/dist/src/component/platform-access/server.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/component/platform-access/server.js +9 -3
- package/vendor/agent-cli/dist/src/component/platform-access/server.js.map +1 -1
- package/vendor/agent-cli/dist/src/component/preparation-diagnostics.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/component/preparation-diagnostics.js +5 -0
- package/vendor/agent-cli/dist/src/component/preparation-diagnostics.js.map +1 -1
- package/vendor/agent-cli/dist/src/component/process-diagnostics.d.ts +25 -0
- package/vendor/agent-cli/dist/src/component/process-diagnostics.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/process-diagnostics.js +137 -0
- package/vendor/agent-cli/dist/src/component/process-diagnostics.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/process-isolation.d.ts +10 -0
- package/vendor/agent-cli/dist/src/component/process-isolation.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/process-isolation.js +59 -0
- package/vendor/agent-cli/dist/src/component/process-isolation.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/proxied-fetch.d.ts +2 -0
- package/vendor/agent-cli/dist/src/component/proxied-fetch.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/proxied-fetch.js +46 -0
- package/vendor/agent-cli/dist/src/component/proxied-fetch.js.map +1 -0
- package/vendor/agent-cli/dist/src/component/public-egress.d.ts +17 -0
- package/vendor/agent-cli/dist/src/component/public-egress.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/component/public-egress.js +246 -0
- package/vendor/agent-cli/dist/src/component/public-egress.js.map +1 -0
- package/vendor/agent-cli/dist/src/context/cache-publication-lock.d.ts +3 -0
- package/vendor/agent-cli/dist/src/context/cache-publication-lock.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/context/cache-publication-lock.js +68 -0
- package/vendor/agent-cli/dist/src/context/cache-publication-lock.js.map +1 -0
- package/vendor/agent-cli/dist/src/context/cache-publication.d.ts +1 -1
- package/vendor/agent-cli/dist/src/context/cache-publication.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/cache-publication.js +8 -4
- package/vendor/agent-cli/dist/src/context/cache-publication.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-cache.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-cache.js +5 -2
- package/vendor/agent-cli/dist/src/context/context-cache.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-project.d.ts +45 -4
- package/vendor/agent-cli/dist/src/context/context-project.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-project.js +157 -16
- package/vendor/agent-cli/dist/src/context/context-project.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-scoped-source.d.ts +13 -0
- package/vendor/agent-cli/dist/src/context/context-scoped-source.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/context/context-scoped-source.js +78 -0
- package/vendor/agent-cli/dist/src/context/context-scoped-source.js.map +1 -0
- package/vendor/agent-cli/dist/src/context/context-snapshot-cache.d.ts +14 -0
- package/vendor/agent-cli/dist/src/context/context-snapshot-cache.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/context-snapshot-cache.js +110 -44
- package/vendor/agent-cli/dist/src/context/context-snapshot-cache.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/local-skills.d.ts +2 -0
- package/vendor/agent-cli/dist/src/context/local-skills.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/local-skills.js +36 -19
- package/vendor/agent-cli/dist/src/context/local-skills.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/member-context.d.ts +2 -1
- package/vendor/agent-cli/dist/src/context/member-context.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/member-context.js +17 -9
- package/vendor/agent-cli/dist/src/context/member-context.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/script-dependencies.d.ts +9 -1
- package/vendor/agent-cli/dist/src/context/script-dependencies.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/script-dependencies.js +22 -6
- package/vendor/agent-cli/dist/src/context/script-dependencies.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/shared-cache-build.d.ts +1 -1
- package/vendor/agent-cli/dist/src/context/shared-cache-build.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/shared-cache-build.js +1 -0
- package/vendor/agent-cli/dist/src/context/shared-cache-build.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/team-knowledge.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/team-knowledge.js +11 -2
- package/vendor/agent-cli/dist/src/context/team-knowledge.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-cache.js +2 -2
- package/vendor/agent-cli/dist/src/context/template-cache.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-seed.d.ts +3 -0
- package/vendor/agent-cli/dist/src/context/template-seed.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-seed.js +50 -16
- package/vendor/agent-cli/dist/src/context/template-seed.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/user-skill-context.d.ts +3 -1
- package/vendor/agent-cli/dist/src/context/user-skill-context.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/user-skill-context.js +41 -2
- package/vendor/agent-cli/dist/src/context/user-skill-context.js.map +1 -1
- package/vendor/agent-cli/dist/src/index.d.ts +4 -1
- package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/index.js +4 -1
- package/vendor/agent-cli/dist/src/index.js.map +1 -1
- package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.d.ts +2 -2
- package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.js +4 -2
- package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.js.map +1 -1
- package/vendor/agent-cli/dist/src/lifecycle/hook-command.js +1 -1
- package/vendor/agent-cli/dist/src/lifecycle/hook-command.js.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.d.ts +24 -0
- package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.js +6 -0
- package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.js.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts +71 -4
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js +13 -1
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js.map +1 -1
- package/vendor/agent-cli/dist/src/security/command-translate.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/security/command-translate.js +4 -0
- package/vendor/agent-cli/dist/src/security/command-translate.js.map +1 -1
- package/vendor/agent-cli/dist/src/security/guard.d.ts +4 -0
- package/vendor/agent-cli/dist/src/security/guard.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/security/guard.js +17 -5
- package/vendor/agent-cli/dist/src/security/guard.js.map +1 -1
- package/vendor/agent-cli/dist/src/security/mount-table.d.ts +11 -2
- package/vendor/agent-cli/dist/src/security/mount-table.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/security/mount-table.js +92 -5
- package/vendor/agent-cli/dist/src/security/mount-table.js.map +1 -1
- package/vendor/agent-cli/dist/src/security/tool-scope.d.ts +4 -1
- package/vendor/agent-cli/dist/src/security/tool-scope.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/security/tool-scope.js +38 -4
- package/vendor/agent-cli/dist/src/security/tool-scope.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/client.d.ts +20 -0
- package/vendor/agent-cli/dist/src/session/client.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/client.js +26 -4
- package/vendor/agent-cli/dist/src/session/client.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/custom-context.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/custom-context.js +12 -6
- package/vendor/agent-cli/dist/src/session/custom-context.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/execution-recovery.d.ts +9 -0
- package/vendor/agent-cli/dist/src/session/execution-recovery.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/execution-recovery.js +49 -0
- package/vendor/agent-cli/dist/src/session/execution-recovery.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/expert-definition.d.ts +4 -0
- package/vendor/agent-cli/dist/src/session/expert-definition.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/expert-definition.js +20 -0
- package/vendor/agent-cli/dist/src/session/expert-definition.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/link-config.js +1 -1
- package/vendor/agent-cli/dist/src/session/link-config.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/link-session.d.ts +1 -0
- package/vendor/agent-cli/dist/src/session/link-session.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/link-session.js +19 -2
- package/vendor/agent-cli/dist/src/session/link-session.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-lifecycle.d.ts +5 -0
- package/vendor/agent-cli/dist/src/session/process-lifecycle.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-lifecycle.js +18 -0
- package/vendor/agent-cli/dist/src/session/process-lifecycle.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-observability.d.ts +4 -0
- package/vendor/agent-cli/dist/src/session/process-observability.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-observability.js +14 -0
- package/vendor/agent-cli/dist/src/session/process-observability.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-request.d.ts +6 -6
- package/vendor/agent-cli/dist/src/session/process-request.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-request.js +55 -60
- package/vendor/agent-cli/dist/src/session/process-request.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-restore.d.ts +4 -0
- package/vendor/agent-cli/dist/src/session/process-restore.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-restore.js +21 -0
- package/vendor/agent-cli/dist/src/session/process-restore.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-workspace.d.ts +3 -0
- package/vendor/agent-cli/dist/src/session/process-workspace.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-workspace.js +21 -0
- package/vendor/agent-cli/dist/src/session/process-workspace.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/reference-tools.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/reference-tools.js +3 -2
- package/vendor/agent-cli/dist/src/session/reference-tools.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-setup.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-setup.js +33 -14
- package/vendor/agent-cli/dist/src/session/run-setup.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-start-body.d.ts +5 -0
- package/vendor/agent-cli/dist/src/session/run-start-body.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-start-body.js +13 -1
- package/vendor/agent-cli/dist/src/session/run-start-body.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/team-persistence.js +1 -1
- package/vendor/agent-cli/dist/src/session/team-persistence.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/tool-scheduler.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/tool-scheduler.js +32 -23
- package/vendor/agent-cli/dist/src/session/tool-scheduler.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/user-skill-compatibility.d.ts +4 -0
- package/vendor/agent-cli/dist/src/session/user-skill-compatibility.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/user-skill-compatibility.js +25 -0
- package/vendor/agent-cli/dist/src/session/user-skill-compatibility.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/user-skill-loaded.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/user-skill-loaded.js +2 -1
- package/vendor/agent-cli/dist/src/session/user-skill-loaded.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/user-skill-prompt.d.ts +4 -0
- package/vendor/agent-cli/dist/src/session/user-skill-prompt.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/user-skill-prompt.js +15 -0
- package/vendor/agent-cli/dist/src/session/user-skill-prompt.js.map +1 -0
- package/vendor/agent-cli/dist/src/shared/types.d.ts +50 -3
- package/vendor/agent-cli/dist/src/shared/types.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/command-executor.d.ts +3 -0
- package/vendor/agent-cli/dist/src/tools/command-executor.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/command-executor.js +42 -5
- package/vendor/agent-cli/dist/src/tools/command-executor.js.map +1 -1
- package/vendor/agent-cli/dist/src/tools/context-program.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/context-program.js +46 -20
- package/vendor/agent-cli/dist/src/tools/context-program.js.map +1 -1
- package/vendor/agent-cli/dist/src/tools/file-ops.d.ts +10 -19
- package/vendor/agent-cli/dist/src/tools/file-ops.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/file-ops.js +11 -85
- package/vendor/agent-cli/dist/src/tools/file-ops.js.map +1 -1
- package/vendor/agent-cli/dist/src/tools/file-search.d.ts +29 -0
- package/vendor/agent-cli/dist/src/tools/file-search.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/tools/file-search.js +98 -0
- package/vendor/agent-cli/dist/src/tools/file-search.js.map +1 -0
- package/vendor/agent-cli/dist/src/tools/file-stat.d.ts +9 -0
- package/vendor/agent-cli/dist/src/tools/file-stat.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/tools/file-stat.js +29 -0
- package/vendor/agent-cli/dist/src/tools/file-stat.js.map +1 -0
- package/vendor/agent-cli/dist/src/tools/local-hands.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/local-hands.js +10 -2
- package/vendor/agent-cli/dist/src/tools/local-hands.js.map +1 -1
- package/vendor/agent-cli/dist/src/tools/tool-contract.gen.d.ts +3 -0
- package/vendor/agent-cli/dist/src/tools/tool-contract.gen.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/tools/tool-contract.gen.js +3 -0
- package/vendor/agent-cli/dist/src/tools/tool-contract.gen.js.map +1 -1
- package/resources/js/context/CLAUDE.md +0 -54
- package/resources/js/context/agents/aigc-manager.md +0 -91
- package/resources/js/context/knowledge/GameProbe.md +0 -74
- package/resources/js/context/skills/aigc-generate/scripts/apply-results.mjs +0 -83
- package/resources/js/context/skills/aigc-generate/scripts/config.json +0 -29
- package/resources/js/context/skills/aigc-generate/scripts/generate.mjs +0 -1016
- package/resources/js/context/skills/aigc-generate/scripts/lib/client.mjs +0 -228
- package/resources/js/context/skills/aigc-generate/scripts/lib/ledger.mjs +0 -119
- package/resources/js/context/skills/aigc-generate/scripts/lib/nstep-handoff.mjs +0 -100
- package/resources/js/context/skills/aigc-generate/scripts/lib/pipelines.mjs +0 -441
- package/resources/js/context/skills/aigc-generate/scripts/lib/queue.mjs +0 -283
- package/resources/js/context/skills/aigc-generate/scripts/lib/submit.mjs +0 -122
- package/resources/js/context/skills/aigc-generate/scripts/worker.mjs +0 -171
- package/resources/js/context/skills/asset-search/scripts/recalled_sprite_paths.mjs +0 -47
- package/resources/js/context/skills/asset-search/strategies/character2d.md +0 -33
- package/resources/js/context/skills/asset-search/strategies/texture-ui.md +0 -35
- package/resources/js/context/skills/display-info-setup/SKILL.md +0 -32
- package/resources/js/context/skills/display-info-setup/scripts/init_project.mjs +0 -38
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/leaderboard.d.mts +0 -39
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/leaderboard.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/platform-service.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/save.d.mts +0 -49
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/save.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/release.json +0 -37
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/cli.mjs +0 -2
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/project.d.mts +0 -8
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/project.mjs +0 -2
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/vite.d.mts +0 -3
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/vite.mjs +0 -8
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/audio.d.mts +0 -20
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/audio.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/canvas.d.mts +0 -21
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/canvas.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/input.d.mts +0 -17
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/input.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/three.d.mts +0 -40
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/three.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/ui.d.mts +0 -10
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/ui.mjs +0 -1
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/video.d.mts +0 -8
- package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/video.mjs +0 -1
- package/resources/js/context/skills/platform-services/assets/release.json +0 -44
- package/resources/js/project/.gitattributes +0 -2
- package/resources/js/project/gameplay-probe.json +0 -37
- package/resources/js/project/package-lock.json +0 -1155
- package/resources/js3d/context/CLAUDE.md +0 -50
- package/resources/js3d/context/skills/aigc-integration/scripts/config.json +0 -3
- package/resources/js3d/context/skills/aigc-integration/scripts/lib/submit.mjs +0 -344
- package/resources/js3d/context/skills/aigc-integration/scripts/query-music.mjs +0 -53
- package/resources/js3d/context/skills/aigc-integration/scripts/query-results.mjs +0 -53
- package/resources/js3d/context/skills/aigc-integration/scripts/submit-cover.mjs +0 -44
- package/resources/js3d/context/skills/aigc-integration/scripts/submit-image.mjs +0 -48
- package/resources/js3d/context/skills/aigc-integration/scripts/submit-music.mjs +0 -34
- package/resources/js3d/context/skills/aigc-integration/scripts/submit-staticmesh.mjs +0 -39
- package/resources/js3d/context/skills/platform-services/assets/release.json +0 -44
- package/resources/js3d/project/.gitattributes +0 -2
- package/resources/js3d/project/gameplay-probe.json +0 -38
- package/resources/js3d/project/package-lock.json +0 -1204
- package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.test.mjs +0 -25
|
@@ -1,430 +1,430 @@
|
|
|
1
|
-
# 联网状态、同步与权威边界
|
|
2
|
-
|
|
3
|
-
> 仅在设计联网契约或排查“一端更新、另一端不一致”时读取。
|
|
4
|
-
> 本文提供跨玩法的判断方法,不提供任何具体游戏的字段、事件或服务端实现。
|
|
5
|
-
> 前半部分(owner / 通道 / 权威 / 恢复 / 频率)与维度无关,2D、3D 完全一致;3D 的唯一实质差异集中在末尾「3D 位姿与朝向同步」一节。
|
|
6
|
-
|
|
7
|
-
## 先确定 owner,再选通道
|
|
8
|
-
|
|
9
|
-
不要从“发什么消息”开始设计。先判断状态由谁拥有、丢失后是否必须恢复,再选择传输通道。
|
|
10
|
-
|
|
11
|
-
| 数据性质 | owner | 传输位置 | 客户端收口 | 典型特征 |
|
|
12
|
-
|---|---|---|---|---|
|
|
13
|
-
| 本机即时状态 | 玩法 System | 不需要绕 DS 回传 | System getter / 本机事件 | 本机已经知道,等待网络回声反而增加延迟 |
|
|
14
|
-
| 每名玩家各自的连续态 | 对应玩家上报,DS 存槽位 | `players[sessionId].data` | `mp-peer-pose` | 高频、每人一份、偶尔丢一帧仍可继续 |
|
|
15
|
-
| 房间唯一且必须恢复的权威状态 | DS | state 根字段 | `onStateField` / `mp-state-field` | 阶段、行动权、局面、比分、胜负等全房唯一事实 |
|
|
16
|
-
| 一次性表现通知 | DS 或玩家事件经 DS 转发 | `evt` | `onEvent` / `mp-event` | 错过不影响当前局面,可由现有状态重新渲染 |
|
|
17
|
-
|
|
18
|
-
关键事实:
|
|
19
|
-
|
|
20
|
-
- state 根字段在连接时携带当前值,适合后加入与重连恢复。
|
|
21
|
-
- `evt` 只投递发生时在线的连接。必须恢复的数据若使用 `evt`,DS 必须在 `onJoin` 定向补当前快照;能放根字段时优先放根字段。
|
|
22
|
-
- `players[sessionId].data` 不回推给发送者自己。本机状态由玩法 System 自己保存。
|
|
23
|
-
- `sessionId` 是一条 DS 连接内的实体 key;不要用 `player_id` 替代,同账号双开是两个实体。
|
|
24
|
-
- ⚠️ **根字段有两种形态,客户端收口不同**:上表把 root → `onStateField` 一概而论,**仅对标量根字段**(string/number/boolean)成立——`onStateField` 底层是 `$(room.state).listen(field)`,对 **MapSchema / ArraySchema 容器**只在整个引用被替换时触发,**收不到条目增删与嵌套字段变化**。容器型根字段要么在 `src/skill-modules/platform-services/MultiplayerManager.ts` 的 `_attachRoom()` 里补容器监听(写法见 `${
|
|
25
|
-
|
|
26
|
-
## 客户端提交意图,DS 产生结果
|
|
27
|
-
|
|
28
|
-
客户端输入不能直接成为权威结果。DS 收到 `pub` 后至少按实际玩法检查:
|
|
29
|
-
|
|
30
|
-
1. **发送者归属**:操作对象是否属于 `client.sessionId`,禁止相信 payload 自报的 player/session id。
|
|
31
|
-
2. **阶段与顺序**:当前阶段是否允许该操作,是否轮到该玩家。
|
|
32
|
-
3. **对象存在性**:目标、道具、格子或实体是否仍存在且可操作。
|
|
33
|
-
4. **空间与数值合法性**:位置、距离、速度、资源消耗和取值范围是否合理。
|
|
34
|
-
5. **幂等与竞态**:重复消息、同时争抢或迟到消息只能产生一次结果。
|
|
35
|
-
6. **频率与体积**:拒绝异常高频和超预算的**上行** payload(4KB 上限只卡上行,见「频率与包体」节)。拒绝时要打日志说明原因,不要静默丢弃;此检查仅针对客户端上行,**不要挪用到 DS 的下行发送路径**。
|
|
36
|
-
|
|
37
|
-
DS 校验后再修改根状态或广播事件。不得直接采信客户端提交的得分、奖励、胜负、死亡、命中、资源生成等结果。
|
|
38
|
-
|
|
39
|
-
不是所有实时玩法都要做完整服务端模拟,但应明确“客户端预测什么、DS 最终裁决什么”。无法权威模拟时,也要对结果做最小可验证约束,并在架构文档声明风险边界。
|
|
40
|
-
|
|
41
|
-
### 抢唯一资源用乐观并发(CAS)
|
|
42
|
-
|
|
43
|
-
多个客户端同时争抢**唯一资源**(首杀奖励、唯一道具、唯一座位、唯一击杀判定)时,用「期望值匹配才更新」的乐观并发,避免加锁:
|
|
44
|
-
|
|
45
|
-
- DS 是唯一写入者,天然是校验点。收到抢占意图时:读当前根状态字段 → 检查是否仍为期望值(尚未被占)→ 是才写入占有者并广播、否则拒绝并回一条失败事件。
|
|
46
|
-
- 客户端提交的是「我想抢,我看到的当前值是 X」,不是「我已经抢到了」;是否成功由 DS 依据它自己 state 的**当前**值裁定,迟到的第二个请求读到的已是被占值,自然失败。
|
|
47
|
-
- 这套判定只在 DS 里做,客户端不做本地占有假设(可做乐观 UI,但以 DS 结果为准回滚)。
|
|
48
|
-
|
|
49
|
-
## 私密态:按角色定向下发,禁进根字段
|
|
50
|
-
|
|
51
|
-
有些状态只该给**部分玩家**看。这类**私密态**的传输规则和公开态相反,单独一节。
|
|
52
|
-
|
|
53
|
-
**举例(帮助理解,非规则规定)**:狼人杀里各人的身份、军棋的暗子、你画我猜发给画者的题目、只发给本人的手牌——都是「每人看到的内容不同、且不能让别人看到」的私密态。这些例子**只用于说明「什么是私密态」**,不代表本引擎固化了某一款玩法的具体规则链;具体怎么分配、何时揭示、揭示给谁,由各项目的策划案和玩法 System 自己定,本节只给通用机制。
|
|
54
|
-
|
|
55
|
-
### 铁律:私密态禁放 state 根字段
|
|
56
|
-
|
|
57
|
-
根字段是**全房广播**的——任何客户端都能在本地读到完整 state,哪怕 UI 不渲染它。把私密内容(如身份)写进根字段,等于把答案发给了所有人,改 UI 藏不住,**必然泄漏**。私密态一律不进根字段。
|
|
58
|
-
|
|
59
|
-
判断口径:一份数据**是否对全房所有人是同一份**。是 → 根字段(棋盘、比分、阶段);否(每人内容不同、或只给本人)→ 私密态,走定向 `evt`。
|
|
60
|
-
|
|
61
|
-
### 通道:DS 侧按 sessionId 定向 send
|
|
62
|
-
|
|
63
|
-
私密态走**定向事件**——DS 只对目标那一条连接发,不广播:
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
// DS 侧:只发给某一个玩家(client 是该玩家的连接)
|
|
67
|
-
client.send("evt", { type: "secret_state", data: { /* 该玩家专属内容 */ } });
|
|
68
|
-
|
|
69
|
-
// 对照:room.broadcast 是全房,私密态绝不能用它
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
- 发给谁由 DS 决定,接收方从 `onEvent`(`mp-event`)收,和公开事件同一个收口,靠 `type` 区分。
|
|
73
|
-
- 客户端**不自报私密内容**:发什么由 DS 裁定并只发给本人;客户端收到什么就是什么。
|
|
74
|
-
|
|
75
|
-
### 安全口径:目标身份以 DS 侧绑定为准,不信客户端自报
|
|
76
|
-
|
|
77
|
-
`player_id` 是**进房时由 DS 分配、并锁定到该条 sessionId** 的。私密下发要发给谁、重连认领谁的席位,**目标一律以 DS 侧的这份绑定为准**,不能每次从客户端 `options` 里读它自报的 id——否则 A 只要在自报里填 B 的 id,就能冒领 B 的暗子 / 席位。
|
|
78
|
-
|
|
79
|
-
```js
|
|
80
|
-
// DS 侧:进房时分配并锁定绑定,后续只认这份绑定
|
|
81
|
-
onJoin(client, options) {
|
|
82
|
-
// player_id 由 DS 分配 / 校验后锁定到 sessionId,不直接采信 options 里的自报值
|
|
83
|
-
const playerId = this._bindPlayer(client.sessionId, options);
|
|
84
|
-
// ...后续私密下发、席位认领都用 playerId(来自绑定表),不用 options.player_id
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
> 这条①②共用:凡「发给某人」「认领某人的东西」,目标都从 DS 绑定表取,不从客户端当次自报取。①违背它 → 冒领暗子;②违背它 → 冒领席位。
|
|
89
|
-
|
|
90
|
-
### 私密态在后进房 / 重连必须 onJoin 定向重发
|
|
91
|
-
|
|
92
|
-
`evt` 是一次性的、**只投递发送时在线的连接**。私密态若只在开局广播一次,**后进房或断线重连的玩家永远收不到自己的那份**——它不像根字段会在握手时自动携带当前值。
|
|
93
|
-
|
|
94
|
-
所以私密态由 DS **同时**维护在**服务端内存**(不是根字段,客户端读不到),并在 `onJoin` 里对刚进来的这条 client 按其绑定的 `playerId` 定向重发一次:
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
// DS 侧 Room
|
|
98
|
-
onCreate() {
|
|
99
|
-
this._secrets = new Map(); // playerId -> 私密内容,仅存 DS 内存,不进 state
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 某时机把私密内容分配给某人(playerId 来自 DS 绑定,不来自客户端自报)
|
|
103
|
-
setSecret(playerId, client, content) {
|
|
104
|
-
this._secrets.set(playerId, content);
|
|
105
|
-
client.send("evt", { type: "secret_state", data: content });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 后进房 / 重连:按绑定表取 playerId,把这条 client 的私密态定向补一次
|
|
109
|
-
onJoin(client, options) {
|
|
110
|
-
const playerId = this._bindPlayer(client.sessionId, options);
|
|
111
|
-
const secret = this._secrets.get(playerId);
|
|
112
|
-
if (secret) client.send("evt", { type: "secret_state", data: secret });
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
> 私密态存 DS 内存 + onJoin 定向重发,是「私密」和「可恢复」的唯一并存方式:放根字段可恢复但泄漏,只广播一次不泄漏但重连即丢。二者都不行。
|
|
117
|
-
|
|
118
|
-
### 私密 → 公开的单向转换(通用机制)
|
|
119
|
-
|
|
120
|
-
原本只发给某人的私密态,可能在**某个时机**变成「对某人 / 对所有人公开」。本节只给**通用机制**,不写任何具体玩法的转换规则:
|
|
121
|
-
|
|
122
|
-
- **由 DS 判定转换时机**:何时从私密转公开,由服务端按玩法裁决触发,客户端不自行揭示。
|
|
123
|
-
- **按目标定向「提升」下发**:转换是 DS 主动向**指定目标**(某个人、某几个人、或全房)重新下发这份内容。⚠️ 注意:即便揭示给多人,**这仍是「对特定目标定向提升」,不是把它写进根字段做全房广播**——目标集合由 DS 决定并逐一 `client.send`。
|
|
124
|
-
- **转换前存 DS 内存**:未转换时内容始终只在 DS 内存的私密表里,不进根字段;转换只改变 DS「发给谁」,不改变「私密态不落根字段」这条铁律。
|
|
125
|
-
- ⚠️ **转换那一刻下行包会明显变大,这是正常的、且不受上行 4KB 限制**:原本只发给 1 人的一小份私密态,转换后要向指定目标(某人 / 某几人 / 全房逐一)重新下发,内容可能是**一整个局面级**的大对象;这是 **DS→客户端的下行**,浏览器端不设 4KB 接收上限,不会触发 code 1009。**绝不要在这条下发路径上套上行的包体预算检查**(如 `if (overBudget(data)) return`)——那属于把「上行 4KB」误当成全局规则,会把这份本该送达的大包**静默吞掉**(下行不受限的完整说明见「频率与包体」节)。此处下发只管发全、发对目标,不做体积裁切。
|
|
126
|
-
|
|
127
|
-
可举一例帮助理解(**仅示意,非规则**):棋类玩法中「一方出局后,向其揭示全场剩余局面」即属此类——出局那一刻由 DS 判定,把原先各自私密的局面定向提升下发给该玩家。它仍是定向提升,不是全房广播;这份「全场剩余局面」下发时体积会陡增,属上面说的正常情形,不要在此处拦截。
|
|
128
|
-
|
|
129
|
-
### 本地标注不属于状态同步范畴
|
|
130
|
-
|
|
131
|
-
玩家给己方 / 对方棋子贴的本地便签、标记、备注,是**纯客户端本地**的辅助显示:不上报 DS、不进任何同步通道、对手不可见、断线重连也不需要恢复。它属于 UI 层,**不属于状态同步范畴**,本上下文不展开。
|
|
132
|
-
|
|
133
|
-
### 完成检查(私密态)
|
|
134
|
-
|
|
135
|
-
- 私密态**不在**任何 state 根字段里;grep 根字段 Schema 确认无身份 / 暗子 / 手牌等私密字段。
|
|
136
|
-
- 私密态走 `client.send`(定向),不走 `room.broadcast`(全房);私密→公开转换后**仍是定向提升**,未退化成根字段广播。
|
|
137
|
-
- 私密→公开转换的**下行发送路径上没有任何包体预算检查 / 裸 `return`**:转换时下行包变大是正常的、且不受 4KB 限制,不得在此静默拦截(4KB 只卡上行)。
|
|
138
|
-
- 私密下发 / 重连认领的目标**取自 DS 绑定表**,不取自客户端 `options` 自报的 id。
|
|
139
|
-
- DS 在内存保有私密态,`onJoin` 对新连接 / 重连按绑定 `playerId` 定向重发;后进房玩家能拿到自己的那份。
|
|
140
|
-
- 本地标注类数据未进任何同步通道。
|
|
141
|
-
|
|
142
|
-
## 后加入与重连
|
|
143
|
-
|
|
144
|
-
对每类数据回答:“错过此前全部消息,只看当前 state,能否继续?”
|
|
145
|
-
|
|
146
|
-
- 能:当前状态足以恢复,事件只用于表现。
|
|
147
|
-
- 不能:把必要事实移到根状态,或在 `onJoin` 定向发送一份完整快照。
|
|
148
|
-
- 玩家连续态:新连接通过当前 `players` Map 获得;不要依赖历史 pose。
|
|
149
|
-
- 断线重连会得到新的 `sessionId`。需要跨连接保留的业务身份只能由玩法明确映射,不能默认沿用旧 session。
|
|
150
|
-
|
|
151
|
-
三种结束路径必须分开:
|
|
152
|
-
|
|
153
|
-
- `mp-disconnect`:网络异常,用事件里的 `roomId` 或 `getLastRoomId()` 重走 `joinRoom()`。禁止在 detach 之后读 `getRoomId()`。
|
|
154
|
-
- `mp-room-closed`:本局已结束或进程回收,不重连。
|
|
155
|
-
- 主动 `leaveRoom()`:正常退出,不触发自动重连。
|
|
156
|
-
|
|
157
|
-
### 权威恒在 DS,不存在客户端切主
|
|
158
|
-
|
|
159
|
-
本子系统是**服务端权威**:权威逻辑跑在 DS,不跑在任何客户端。房主玩家掉线只是少一名玩家,DS 进程还在、裁决照常,**不存在“主逻辑无人计算”,因此不需要、也不实现“切主 / MasterClient 切换”**。遇到房主制、客户端权威、MasterClient 那套资料(房主端算逻辑、掉线抢切网络最好的玩家)不要套用——那是没有权威服务端的架构的补救,与本架构无关。我们对应的机制只是**某玩家断线后按原 `roomId` 重连**(重连得到新 `sessionId`,业务身份靠玩法自己映射),这与“切主”是两码事。
|
|
160
|
-
|
|
161
|
-
### 重连保席位:DS 用席位表认领旧 slot
|
|
162
|
-
|
|
163
|
-
上面说的「业务身份靠玩法自己映射」,落地范式是 **DS 在根字段维护一张席位表**,把「对局里的槽位」和「玩家身份」绑定,断线重连能认回原 slot。
|
|
164
|
-
|
|
165
|
-
- **根字段维护 `seats`**:`seats: { player_id -> { slot, hp, score, alive, ... } }`。这是全房可读的权威(谁占几号位、血量分、存活),不是私密态。
|
|
166
|
-
- **onJoin 用 DS 绑定后的 `playerId` 查表**:命中的 = 重连认领原席位,把**新 sessionId 绑回旧 slot**(旧 session 已失效,按新连接重建该 slot 的 `players[sessionId].data` 连续态);未命中 = 新玩家,占下一个新 slot。⚠️ `playerId` 取自 DS 侧绑定表(见上面「安全口径」),**不是每次从客户端 `options` 读自报值**。
|
|
167
|
-
|
|
168
|
-
> **⚠️ 席位表是容器,别用下标 / 别用 `{}`**:`seats` 是「按 player_id 索引的映射」。**绝不能写成 `this.state.seats = {}`**(普通对象不能当 Colyseus 根字段,`seats` 从未在 `defineTypes` 里声明的话,这行是往 Schema 实例挂未声明字段——不报错、能跑,但 `seats` **从头到尾不进编码**,客户端 `state` 里根本没这个字段,100% 不同步);也**不能对容器用下标读写**(`state.seats[k] = v` / `state.seats[k]` / `delete state.seats[k]` 在 `@colyseus/schema@4.0.30` 下**静默失效**:名下标只挂一个普通 JS 属性,**读得回来**所以按 key 取的路径全正常,但 `.size` 恒 0、`.forEach`/`for...of` 遍历不到、**完全不进编码,客户端永远收不到**——「一半路径能跑、一半静默空」正是本次双端不同步的最难定位形态)。详见 `${
|
|
169
|
-
|
|
170
|
-
**席位表有两种合法形态,按下面判据选,不能只写一种**:
|
|
171
|
-
|
|
172
|
-
| 形态 | 声明 | 客户端收口 | 适用 |
|
|
173
|
-
|---|---|---|---|
|
|
174
|
-
| **JSON 字符串根字段**(默认推荐) | `seats: "string"` | 现成 `onStateField('seats')`,握手自带当前值,零客户端改动 | 整表 ≤ 约 1KB,且**低频**写(回合结算、偶发扣血)。席位表天然低频,默认走这个 |
|
|
175
|
-
| **MapSchema 根字段** | `seats: { map: SeatState }` | `onStateField` **收不到条目增删与嵌套字段变化**,须在 `MultiplayerManager.ts` 的 `_attachRoom()` 补容器监听(见 `${
|
|
176
|
-
|
|
177
|
-
> **判据优先级**(不能只看高频低频):① **owner**——DS 裁决的 → 根字段(高低频都一样);玩家自报的连续态 → `players[sid].data`(那是客户端上报通道、DS 只存不改,且**不回推给发起者自己**,把 DS 裁决的`hp` 塞进去会让本机另存一份、两份必分叉)。② **整表全量多大**——`patchRate` 已把下发频率锁在 20Hz,成本上限 = 全量 × 20Hz,与写入频率无关;≤ 约 1KB 字符串够用,≥ 几 KB 用 MapSchema。③ **客户端要什么粒度**——整表刷新即可 → 字符串;「只有 hp 变了才更新这一个血条」→ MapSchema。**默认走 JSON 字符串根字段**;确需字段级增量才扩到 MapSchema。
|
|
178
|
-
|
|
179
|
-
```js
|
|
180
|
-
// ds/rooms/xxxSchema.mjs —— 席位表作为 JSON 字符串根字段(默认形态)
|
|
181
|
-
defineTypes(RoomState, {
|
|
182
|
-
players: { map: PlayerState }, // 连续态槽位,模板已有,勿改
|
|
183
|
-
phase: "string",
|
|
184
|
-
seats: "string", // player_id -> { slot, hp, score, alive } 的 JSON
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// ds/rooms/xxxRoom.mjs
|
|
188
|
-
onCreate() {
|
|
189
|
-
this._bindings = new Map(); // sessionId -> player_id(DS 分配的锁定绑定,JS 原生 Map)
|
|
190
|
-
this._nextSlot = 1;
|
|
191
|
-
}
|
|
192
|
-
_seats() { try { return JSON.parse(this.state.seats || "{}"); } catch { return {}; } }
|
|
193
|
-
_writeSeats(o) { this.state.seats = JSON.stringify(o); } // 必须整体赋值才触发同步
|
|
194
|
-
|
|
195
|
-
onJoin(client, options) {
|
|
196
|
-
// _bindPlayer 意图:首次进房由 DS 分配一个 player_id 并锁定到该 sessionId(存 _bindings),
|
|
197
|
-
// 之后"认领谁的席位 / 私密发给谁"都从 _bindings 取,不读客户端 options 里的自报 id ——
|
|
198
|
-
// 否则 A 在自报里填 B 的 id 就能冒领 B 的席位(见"安全口径"节)。
|
|
199
|
-
// ⚠️ player_id 是认领 key;sessionId 才是权限校验对象,两者别混用。
|
|
200
|
-
const playerId = this._bindPlayer(client, options);
|
|
201
|
-
const seats = this._seats();
|
|
202
|
-
if (seats[playerId]) {
|
|
203
|
-
// 重连:认回旧 slot,把新 sessionId 绑回旧席位
|
|
204
|
-
seats[playerId].sessionId = client.sessionId;
|
|
205
|
-
this._restoreContinuousState(seats[playerId]); // 重建该 slot 的 players[sid].data
|
|
206
|
-
} else {
|
|
207
|
-
// 新玩家:占新 slot
|
|
208
|
-
seats[playerId] = { slot: this._nextSlot++, hp: 100, score: 0, alive: true, sessionId: client.sessionId };
|
|
209
|
-
}
|
|
210
|
-
this._writeSeats(seats); // 改完必须整体写回,只改 seats 对象本身不会同步
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
- **字符串形态唯一的坑**:`_seats()` 返回的是**快照副本**,直接改它不会同步,**必须 `_writeSeats()` 整体写回**。
|
|
215
|
-
- **`player_id` 的权威在 DS 侧绑定**:首次进房由 DS 分配并锁定到该 sessionId(`_bindings`),后续认领 / 下发一律从绑定表取。客户端若把 id 带回 `options`,只当**定位 key** 用(DS 查绑定表能否命中),不当授权凭证;「这条消息是不是本人发的」仍由 sessionId 判定(见「客户端提交意图」节)。要更硬可叠加平台下发可信身份,但「主管目标以 DS 绑定为准」这条不变。
|
|
216
|
-
- 和传输层**不矛盾**:传输层**禁用 `allowReconnection`**(见 `${
|
|
217
|
-
|
|
218
|
-
### 最小骨架
|
|
219
|
-
|
|
220
|
-
**回合制桌牌**:`seats.pid` 存槽位 + 当前积分;玩家掉线,`mp-disconnect` 后业务按其 `player_id` 等待若干秒;重连 `joinRoom` 时 `onJoin` 命中即认回槽位、积分、当前手牌(手牌若私密则按上面私密态节补发)。超时未回则标记 `alive=false` 或让席位进入托管/弃权。
|
|
221
|
-
|
|
222
|
-
**实时对战**:`seats.pid` 存 `{ slot, hp, alive, score }`;掉线者尸体保留原地(位姿停更),重连认回后在宽限期内恢复原血量/比分。宽限期结束仍未回,服务端判定出局或由 AI 托管(取决于玩法策略),并广播事件。
|
|
223
|
-
|
|
224
|
-
### 完成检查(重连保席位)
|
|
225
|
-
|
|
226
|
-
- 席位表在**根字段**,全房可读、DS 单点写;不依赖客户端各自记忆。
|
|
227
|
-
- `onJoin` 用 **DS 绑定后的 `playerId`** 查表:命中 → 认回原 slot 并重建连续态;未命中 → 新玩家占新 slot;**不从 `options` 直接读自报 id 作主管目标**(防冒领席位,见「安全口径」)。
|
|
228
|
-
- 明确区分:`player_id` 是认领 key、`sessionId` 是权限校验对象;二者不被混用。
|
|
229
|
-
- 和「禁用 `allowReconnection`」不冲突:传输层新建连接,业务层靠席位表跨连接认回——写清二者分工。
|
|
230
|
-
- **可机检**:`ds/` 全文 grep 不到 `this.state.<字段>[` 形式的下标访问;所有 **MapSchema / ArraySchema** 容器走 `.set/.get/.has/.delete/.forEach`(JS 原生 `Map`、JSON 解析出的普通对象用下标/方法访问是正常的,不要误伤——只查 `state.` 开的容器字段)。每个 state 根字段都能说出它是**标量还是容器**,以及**客户端从哪个收口拿到它**(标量 → `onStateField`;容器 → `MultiplayerManager.ts` 的 `_attachRoom()` 里补的容器监听,见 `${
|
|
231
|
-
|
|
232
|
-
## 阶段 / 回合状态机:根字段单点迁移,客户端只读
|
|
233
|
-
|
|
234
|
-
回合制与阶段驱动玩法(场景一的轮转、场景三的出题→作答→投票→揭晓)需要**阶段状态机**。它也是**全房唯一权威事实**,归 DS 单点迁移。
|
|
235
|
-
|
|
236
|
-
### 哪些放根字段
|
|
237
|
-
|
|
238
|
-
- **阶段**(`phase`: `prepare/playing/voting/reveal`…)、**当前行动者**(`turn_player` 或 `turn_sessionId`)、**回合序号**(`round`)——三者**都放根字段**。
|
|
239
|
-
- 客户端**只读根字段渲染**当前阶段,**只发意图**(落子、提交答案、投票),不自行推进阶段。
|
|
240
|
-
|
|
241
|
-
### DS 单点迁移
|
|
242
|
-
|
|
243
|
-
阶段迁移、行动权轮换**只在 DS 里算**,DS 改根字段后全房经 `onStateField` 自动同步。客户端无权改阶段、也无权广播「轮到我了」:
|
|
244
|
-
|
|
245
|
-
```js
|
|
246
|
-
// DS 侧:轮转到下一个玩家(回合制)
|
|
247
|
-
nextTurn() {
|
|
248
|
-
const next = this._players[(this._turnIndex + 1) % this._players.length];
|
|
249
|
-
this.state.phase = "playing";
|
|
250
|
-
this.state.turn_sessionId = next.sessionId;
|
|
251
|
-
this.state.round += 1;
|
|
252
|
-
// 改根字段后,全房客户端经 onStateField 自动收到
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// 多阶段机:出题 -> 作答 -> 投票 -> 揭晓
|
|
256
|
-
advancePhase() {
|
|
257
|
-
const order = ["pitch", "answer", "vote", "reveal"];
|
|
258
|
-
this.state.phase = order[(order.indexOf(this.state.phase) + 1) % order.length];
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### 倒计时用 DS 时间戳,不用客户端各自计
|
|
263
|
-
|
|
264
|
-
- 倒计时起始/截止**时间戳放根字段**(如 `phase_deadline: <ds 时间戳 ms>`),客户端用它**算剩余**——不是每个客户端各自开 `setInterval` 计一段本地时长。
|
|
265
|
-
- 客户端本地计时的起点误差会累积、掉帧会漂移;极端情况各端看到的「还剩 3 秒、2 秒、1 秒」不一致,导致不同玩家同时看到不同阶段。
|
|
266
|
-
- DS 是唯一时钟源:到 `phase_deadline` 后由 DS 触发迁移(轮转或进下一阶段),不是靠某客户端喊「时间到了」。
|
|
267
|
-
|
|
268
|
-
### 最小骨架
|
|
269
|
-
|
|
270
|
-
**回合轮转(切下一个 sessionId)**:根字段 `turn_sessionId` + `round`;DS 在收到当前行动者有效落子 / 或用尽时限后 `advancePhase` 切下家;客户端只读 `turn_sessionId` 判断「现在轮到我发意图」,不发「我来切轮次」的消息。
|
|
271
|
-
|
|
272
|
-
**多阶段机(出题→作答→投票→揭晓)**:根字段 `phase` + `phase_deadline`;DS 依次迁移;每个阶段客户端只发对应阶段允许的意图(作答期才收答案、投票期才收投票),DS 校验「当前 phase 是否允许此操作」(见「客户端提交意图」节的阶段与顺序检查)。私密部分(如画者的题)按上面私密态节单独收发。
|
|
273
|
-
|
|
274
|
-
### 完成检查(状态机)
|
|
275
|
-
|
|
276
|
-
- 阶段 / 行动者 / 回合序号都在**根字段**,DS 单点迁移;客户端只读渲染、只发意图。
|
|
277
|
-
- 倒计时用 DS 时间戳派生剩余,不在客户端各自本地计时。
|
|
278
|
-
- DS 校验「当前阶段是否允许该操作」,防止客户端跨阶段发指令。
|
|
279
|
-
- 私密阶段的内容(身份/题)不走根字段,按私密态节定向下发。
|
|
280
|
-
|
|
281
|
-
## 频率与包体
|
|
282
|
-
|
|
283
|
-
- 上行连续态不超过 20Hz;更高频率不会提高服务端 patch 频率。
|
|
284
|
-
- **单包 4KB 上限只约束上行(客户端 → DS),下行(DS → 客户端)不受此限**:
|
|
285
|
-
- **上行**:客户端发给 DS 的单包 ≤ 4KB UTF-8 字节,发送前用 `TextEncoder` 计算。这个 4KB 来自传输层 `@colyseus/ws-transport` 的默认 `maxPayload`(`4 * 1024`),且默认**无压缩**(`perMessageDeflate = false`)。它是 **DS 作为接收方**能收下的最大消息字节——所以只卡「客户端往 DS 发」这一向。超限的代价是**连接以 code 1009 被断开、`onMessage` 根本不执行**(是断连,不是丢这一包),所以有效检查必须在**客户端发送前**做。
|
|
286
|
-
- **下行**:DS 发给客户端的包**没有对应的 4KB 大小上限**——浏览器端不设等价的接收字节限制,下行大包不会触发 1009、不会被断连。**因此绝不要把上行那套「超预算就裁 / 就 return」的逻辑套到下行发送路径上**:下行包该多大就多大(私密→公开转换、onJoin 定向补全整局面等场景下行本就会明显偏大),在下行处做体积拦截会**静默吞掉本应送达的消息**。
|
|
287
|
-
- ⚠️ **下行「没有大小上限」不等于「怎么发都行」——它仍受带宽与延迟约束**:下行大包**必须是低频、事件驱动的**(`onJoin` 补全、私密→公开转换、阶段切换等**一次性时机**)。**不要**因为「下行不受 4KB 限制」就在**每帧 / 定时器 / `setSimulationInterval` 路径**上 `broadcast` 全量局面——大包不会断连,但会在 WebSocket 上**队头阻塞**后续消息,DS 又是一局一进程、按容量调度,结果是延迟飙升、甚至心跳超时被强杀、整房掉线。持续态仍走 **state 增量**(`patchRate` 默认 50ms / 20Hz,框架自动 diff),不要用整包广播替代增量。**判据**:这条下发属于「一次性时机」还是「周期性」?后者不该发全量。
|
|
288
|
-
- 优先减少字段、降低精度、发送头部或关键采样点;不要用拆包规避单个逻辑状态过大。**(此条针对上行——下行不受包体大小预算约束,无需为下行拆包或裁字段;下行的约束是「低频事件驱动」,见上。)**
|
|
289
|
-
- **禁止静默丢弃消息**:任何方向的消息,凡因预算 / 校验被拒绝,**必须打日志**(方向 + 字节数 + 拒绝原因),**绝不裸 `return`**。静默丢弃会伪装成「消息发了但对方没收到」,是排查成本最高的一类故障;尤其下行本就不该做体积拦截,若真在下行处写了 `if (over) return` 之类,等于凭空丢包且无任何痕迹。
|
|
290
|
-
- 一次性事件只带裁决所需的最小意图,当前完整局面放 state。
|
|
291
|
-
- `max_players`、DS `maxClients`、玩法人数三者必须相同。
|
|
292
|
-
|
|
293
|
-
## 回放边界:局末一次性落盘,不进状态同步
|
|
294
|
-
|
|
295
|
-
状态同步**不承载回放 / 历史留存**:各通道只保「当前值」,不保「过去发生了什么」。回放不是状态同步的职责,是另一条独立路径。
|
|
296
|
-
|
|
297
|
-
- **根字段只保当前值**:`phase`、`score`、棋盘都是「此刻是什么」,没有历史数组、没有操作日志、没有上一帧的副本。
|
|
298
|
-
- **回放的独立路径**(只写方向,不写完整 DS-log 实现):DS 在对局过程中**累积全知动作日志**(谁在何时做了什么、DS 的裁决结果)→ **局末一次性写入已有的云存储**(局外数据,不走同步通道)→ **回放时前端读这条日志重演**,按日志逐条重建局面。
|
|
299
|
-
- **禁止用状态同步 / 根字段存历史**:不要把操作序列、撤销栈、每回合快照放进根字段或 `evt`。根字段体积按字节受控(见「频率与包体」),塞历史会直接挤压当前态的可用空间;且根字段是实时权威态,不是存档。
|
|
300
|
-
- **对局内的「上一动作」**(如「最后一步棋」「上一个喊话」)若玩法需要展示,属**当前值**而非历史:作为当前状态的一个字段随根字段同步,不进回放日志。
|
|
301
|
-
|
|
302
|
-
## 项目契约记录格式
|
|
303
|
-
|
|
304
|
-
每个联网玩法在架构文档的模块与耦合表中记录 owner 和依赖;精确线上字段在玩法 System / Room 的契约注释中维护,避免架构文档膨胀为 API 手册。
|
|
305
|
-
|
|
306
|
-
每类数据至少记录:
|
|
307
|
-
|
|
308
|
-
- 语义与 owner;
|
|
309
|
-
- 使用的通道及字段/事件名;
|
|
310
|
-
- 客户端上报内容与 DS 校验;
|
|
311
|
-
- 后加入/重连恢复方式;
|
|
312
|
-
- 更新频率与最大体积;
|
|
313
|
-
- 本机状态是否需要本地镜像。
|
|
314
|
-
|
|
315
|
-
字段和事件只属于当前项目,不得因某个实现成功或失败而写入全局 Knowledge。
|
|
316
|
-
|
|
317
|
-
## 3D 位姿与朝向同步(3D 相对 2D 的唯一实质差异)
|
|
318
|
-
|
|
319
|
-
同步层本身与维度无关:`players[sessionId].data` 通道只搬运一段 JSON,DS 不感知有没有 z 轴。3D 相对 2D 只在**连续态 pose 的内容**与**收端处理**两点不同,其余(owner 判定、权威裁决、恢复、频率、包体)一字不改。
|
|
320
|
-
|
|
321
|
-
### 一、pose 多带 z + 朝向用四元数
|
|
322
|
-
|
|
323
|
-
- 位置从 `{x, y}` 扩到 `{x, y, z}`。
|
|
324
|
-
- 朝向**用四元数,不用欧拉角**:欧拉角有万向锁、且不便平滑插值;四元数可直接 `slerp`。
|
|
325
|
-
- 连续态字段范式(走 `players[sid].data` 通道,`sendPose` 上报):
|
|
326
|
-
|
|
327
|
-
```js
|
|
328
|
-
// 3D 连续态:一个物体一份
|
|
329
|
-
{ x, y, z, // 位置,建议 toFixed(2)
|
|
330
|
-
qx, qy, qz, qw } // 朝向四元数,建议 toFixed(3)
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
- 精度即带宽:位置两位小数、四元数三位小数通常足够;抖动明显时先降频、再考虑升精度,不要无脑全精度。
|
|
334
|
-
|
|
335
|
-
### 二、收端基本必须插值
|
|
336
|
-
|
|
337
|
-
**总命题**:表现层的更新节奏,不得由同步 / 帧到达的节奏决定。同步是 10~20Hz 的离散输入,渲染是 60fps 的连续输出,收端必须自己把离散摊成连续。这条对 **2D 与 3D 一样致命**——不是「3D 才明显」:2D 同样会每同步周期瞬移一次(曾有 2D io 工程正因此卡顿)。按**「是否有连续运动的实体」**判要不要做,不按维度、不按品类;有连续运动的(io / 射击 / 竞速 / 体育,2D3D 皆然)必做,纯回合 / 棋牌不涉及。
|
|
338
|
-
|
|
339
|
-
> **这三种收端形态与维度无关,2D 同样适用**——放在这条 3D 专属大节下,只因 3D 首次踩到(球类/弹道的本地模拟纠偏在 3D 项目里先炸)。2D 的对等内容见 `../Multiplayer/StateSyncKnowledge.md`(js 引擎)的「表现层与同步频率解耦」节,形态一一对应。挂在这里是历史落位,不是「只有 3D 才要做」。
|
|
340
|
-
|
|
341
|
-
要覆盖**三种收端形态**:
|
|
342
|
-
|
|
343
|
-
- **形态 A · 状态复制型**(收到远端 pose 直接 set):上行 20Hz、屏幕 60fps,硬 set 会一格一格跳。远端物体收端**几乎必做**位置 `lerp` + 朝向 `slerp` 逼近目标(代价是画面比真实晚约 50~100ms,可接受)。
|
|
344
|
-
- **形态 B · 确定性帧同步 / 锁步型**(收到一帧携带 N 步输入):**不能在一次调用里把 N 步跑完再渲染**(每同步周期瞬移一次)。N 步必须**入队**,由渲染循环按**固定步长**逐步消费(定步长累加器,与单机同一套);**队列空时保持当前状态、不外推**——确定性模拟下本地猜测会立刻与权威分叉。
|
|
345
|
-
|
|
346
|
-
```js
|
|
347
|
-
// ❌ 收到帧就把一批 step 跑完
|
|
348
|
-
onFrame(inputs) { for (let i = 0; i < 3; i++) step(state, inputs); render(); }
|
|
349
|
-
// ✅ 入队,渲染循环按固定步长消费
|
|
350
|
-
onFrame(inputs) { for (let i = 0; i < 3; i++) queue.push(inputs); }
|
|
351
|
-
update(delta) { acc += delta; while (acc >= STEP && queue.length) { step(state, queue.shift()); acc -= STEP; } }
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
> **隐蔽坑**:单机分支常已写对定步长累加器,联机分支却只「设输入、不推进」,全靠 20Hz 批量替换 → 每 50ms 瞬移。联机分支同样要定步长消费。
|
|
355
|
-
|
|
356
|
-
- **形态 C · 本地权威同款模拟 + 快照纠偏**(收端本地跑一套与 DS 相同的物理模拟,权威快照到达时向它收敛):适用于**本地能自己算出下一刻在哪**的连续运动——球类、弹道、载具惯性等。与形态 A 的本质区别是**渲染时刻**:A 渲染在过去(比真实晚 50~100ms 换平滑),C 渲染在**当下**(本地模拟一直往前跑,快照只用来纠偏),所以 C **必须处理「收到的权威态本身是旧的」**这件事——两个真实球类 3D 工程都栽在这里。四条铁律,缺一条就是越纠越飘:
|
|
357
|
-
|
|
358
|
-
1. **纠偏比较前,必须先把权威态外推到当前时刻**,再和本地当前值比。快照带的是「服务端 t 时刻的位置」,到你手里已经旧了 ≈70~110ms(一个 RTT 的一半 + patchRate 半窗口);直接拿快照原始位置减本地当前位置,会把「球本该前进的那段距离」当成偏差纠掉,累积成每秒往回瞬移十几二十次。**机检判据**:凡出现「`阈值判断(快照字段 − 本地当前字段)` 且这两者之间没有任何按时间推进的步骤」= 不合格。
|
|
359
|
-
2. **外推要用「标定过的时钟」,不能用到达时刻。** age = `getServerNow() − snap.t`(`snap.t` 是 DS 写快照时的服务端单调时钟,作为两端契约的一部分随快照下发;`getServerNow()` 见 `MultiplayerManager` 模板,客户端按最小 RTT 标定出本机与 DS 的时钟偏移——设施与用法见 `../Subsystems/Optional/MultiplayerManagerKnowledge.md`)。**用「到达时刻 − snap.t」当 age 是错的**:那把单向网络延迟当成了 0。⚠️ **这条与本文件「倒计时用 DS 时间戳」节是两码事,别混**:倒计时是**秒级**、直接拿 `deadline − now` 相减就够,几十毫秒的时钟差看不出来;纠偏是 **50~100ms 级**、时钟差直接顶破阈值,**必须先标定偏移**。同一个「DS 时间戳」,一个能裸用一个必须标定,尺度不同。
|
|
360
|
-
3. **外推公式 / 本地模拟 / DS 模拟三者同源。** 侧视网球栽在这条:DS 每 tick 大步长欧拉(dt=3)、客户端每帧一步(dt=1)、纠偏又用解析解 `0.5·g·t²`,三套积分各算各的 → 半隐式欧拉**对加速运动不是步长无关的**(dt=3 跑一步 ≠ dt=1 跑三步),每 50ms 系统性差约 3g,稳定漂移直接顶破阈值。**要么统一固定步长**(三处都用同一个 STEP 累加器),**要么统一改成闭式** `pos += v·dt + 0.5·a·dt²; v += a·dt`(**先算位置后更新速度**,这样 dt=3 一步严格等于 dt=1 三步)。做对之后,本地与权威的残差**只应来自反弹 / 限速这类离散事件**,且有界。
|
|
361
|
-
4. **阈值只在前三条都做对之后才有意义。** 阈值是**死区**,用来吸收离散事件带来的那点有界残差(第 3 条尾),**不是用来吸收系统误差**的。前三条没做对时,阈值调大只是「飘得慢一点」、调小只是「抖得勤一点」,都治不了根——先把外推、时钟、同源做对,阈值才是在做它该做的事。
|
|
362
|
-
|
|
363
|
-
**术语澄清(别把两件事混成一件)**:本节「## 3D 位姿与朝向同步」看不到,但 `OverviewKnowledge.md` 射击降级那行写的**「不做延迟补偿」,指的是「服务端回溯历史帧、还原『打中那一刻』」**——那条结论不变、依然正确(DS 确实不回溯历史帧)。它和形态 C 要做的**「客户端把权威态外推到当前时刻」是完全不同的两件事**:前者是服务端的历史重建(不做),后者是客户端的当下推算(连续运动玩法**必做**)。别因为「不做延迟补偿」就以为「权威态到了直接拿原始值比就行」——那正是第 1 条禁止的。
|
|
364
|
-
|
|
365
|
-
- 插值 / 预测 / 回滚(含形态 C 的本地模拟与纠偏)由**玩法层**做,**不进 `MultiplayerManager` 模板**(模板只收发 `unknown`;模板暴露的 `getServerNow()`/`getClockOffset()` 是**时钟测量设施**、不是纠偏本身,辨析见 `../Subsystems/Optional/MultiplayerManagerKnowledge.md`)。形态 A 的位置 `lerp` + 朝向 `slerp` 完整方法论见 `../3D/PoseInterpolationKnowledge.md`。
|
|
366
|
-
|
|
367
|
-
### 三、权威态与 2D 完全相同——DS 不感知维度
|
|
368
|
-
|
|
369
|
-
- 阶段 / 命中 / 得分 / 胜负 / 行动权仍走 **state 根字段 + DS 裁决**,判定逻辑和 2D 一字不差。
|
|
370
|
-
- **不要在 DS 里算三维碰撞 / 物理**:DS 只有标准库、无三方物理库。需要防作弊时对结果做**最小可验证约束**(位移距离上限、速度上限、目标可达性),把风险边界写进架构文档,而不是在 DS 复刻一套三维物理。
|
|
371
|
-
|
|
372
|
-
### 四、包体预算复核
|
|
373
|
-
|
|
374
|
-
- 位置 3 数 + 四元数 4 数,一个物体约 60~80 字节 JSON;4KB 单包可装几十个物体。
|
|
375
|
-
- 超限的正解仍是**砍精度 / 砍字段 / 降频 / 只发关键物体**,**不是拆包**(拆包不解决单个逻辑状态过大,还会被 code 1009 断连)。**注意此节讨论的是上行连续态的 4KB 预算;下行不受此限,不要为下行做这类取舍或拦截(见「频率与包体」节)。**
|
|
376
|
-
|
|
377
|
-
#### 逼近 4KB 的取舍顺序(多实体压包)
|
|
378
|
-
|
|
379
|
-
几十个动态实体同时上行时,单包会逼近 4KB 上限。**按下面顺序逐级降**,每一步都先保「权威裁决 + 对局可玩性」,最后才动实体数:
|
|
380
|
-
|
|
381
|
-
1. **先降上报频率**:20Hz → 10Hz。减一半包量,代价是收端插值更远、稍显迟钝,但最不伤对局。**首选。**
|
|
382
|
-
2. **再减字段**:静止/不动的物体**不发朝向**(四元数可省 20+ 字节/个);无移动/无速度的帧只发位置。**掉的都是次要维度,不伤权威。**
|
|
383
|
-
3. **再降精度**:位置两位小数 → 一位小数(省几字节/数);四元数三位 → 两位。**牺牲平滑度换空间。**
|
|
384
|
-
4. **最后只发关键实体**:玩家必发;次要装饰/非关键道具降到低频(如 2~5Hz)或只发事件不发连续态。**这是最后手段。**
|
|
385
|
-
|
|
386
|
-
**AOI**(只同步视野附近物体)是更大规模的正解,但**第一版红线外、不做**——见下一小节。第一版一律「全房全量同步」,靠上面 1→4 把实体数压到几十个以内。
|
|
387
|
-
|
|
388
|
-
#### 算例:十几个实体怎么压
|
|
389
|
-
|
|
390
|
-
单个实体的连续态字节估算(位置 + 四元数):
|
|
391
|
-
|
|
392
|
-
- 位置 `{x,y,z}` 各取 2 位小数:约 `6*4 + 6` ≈ 30 字节
|
|
393
|
-
- 四元数 `{qx,qy,qz,qw}` 取 3 位小数:约 `4*6 + 6` ≈ 34 字节
|
|
394
|
-
- 合计约 **64 字节/实体**(含 JSON 键名与逗号)
|
|
395
|
-
|
|
396
|
-
4KB = 4096 字节。纯连续态可装 **~64 个实体**。但**根字段 + 事件 + 状态开销都会挤占同一个 4KB 上行包**,实际可用的连续态实体数更少——**十几个角色 + 若干道具已逼近上沿**,这正是需求案场景四「压 4KB 顶端」的由来。
|
|
397
|
-
|
|
398
|
-
**触顶怎么砍(举例)**:若 10 个角色 + 15 个道具同时 20Hz 上行,算下来超 4096 字节,按上面顺序:
|
|
399
|
-
|
|
400
|
-
- ① 降到 10Hz → 包量减半,仍全实体(若仍超继续)→
|
|
401
|
-
- ② 静止道具不发朝向(省 ~24 字节/个 × 15)→(若仍超继续)→
|
|
402
|
-
- ③ 位置降 1 位小数、四元数降 2 位 →(若仍超继续)→
|
|
403
|
-
- ④ 把非关键装饰物降到 5Hz、只发位置,玩家保持 20Hz 全字段。
|
|
404
|
-
|
|
405
|
-
> 每一步都能还原单包大小;**不必等到超限才砍**,项目契约记录格式里就应写清「该玩法预计实体数 × 频率 × 每实体字节」的预算,上线前先在文档层面算一遍。
|
|
406
|
-
|
|
407
|
-
### 五、AOI(兴趣区域)——3D / 大世界新增判断点
|
|
408
|
-
|
|
409
|
-
- 3D 大场景里,远处物体没必要收全量 pose:可按距离**降频**或**不同步**。2D 小屏一般没有这个问题,属 3D 才需要额外判断的一层。
|
|
410
|
-
- **第一版红线外:不做 AOI**。第一版一律「全房全量同步、几十个实体封顶」,实体数靠上一节的取舍顺序压到上限以内;AOI 只作为超规模时的扩展方向记录在案,不在第一版实现。规模 / 形态明确后评估,不抢先做距离分区。
|
|
411
|
-
|
|
412
|
-
## 完成检查
|
|
413
|
-
|
|
414
|
-
- 全房唯一事实只有一个 DS owner,不依赖多客户端各自推演后“碰巧一致”。
|
|
415
|
-
- 必须恢复的数据不只存在于历史 `evt`。
|
|
416
|
-
- 客户端只提交意图或自身连续态,DS 不信任自报结果和身份。
|
|
417
|
-
- 抢唯一资源用 DS 侧 CAS(期望值匹配才写),迟到请求自然失败。
|
|
418
|
-
- 每个消息都能解释发送者、接收者、迟到、重复、断线和后加入行为。
|
|
419
|
-
- **上行**包体按字节受控(4KB 上限只卡上行),连续态频率不超过 20Hz;**下行不受 4KB 限制,未在任何下行发送路径上做体积拦截 / 裸 `return` 静默丢包**。
|
|
420
|
-
- 3D pose 带 z + 四元数;收端做 lerp/slerp;权威裁决未因 3D 而改动,DS 未算三维物理。
|
|
421
|
-
- **表现层与同步频率解耦**(有连续运动实体时必查):表现层每帧更新的数据,是否只在收到同步消息时才变化?**是则不合格**——收端必须按渲染帧插值 / 逐步消费。此条 2D3D 同判,不因维度豁免。
|
|
422
|
-
- **无「一次调用连跑多步再渲染」**:是否存在收到一帧就在同一次调用里连续执行多个模拟步、再整体替换 state 的路径?**有则不合格**——N 步入队、按固定步长逐步消费,队列空时保持当前状态不外推。
|
|
423
|
-
- **本地模拟 + 快照纠偏(形态 C)四问**:① 阈值比较前,是否先把权威态**按快照年龄外推到当前时刻**(凡「阈值判断(快照字段 − 本地当前字段)」中间无按时间推进的步骤 = 不合格)?② 外推所用的 age 是否来自**标定过的时钟**(`getServerNow() − snap.t`),而不是到达时刻?③ 外推公式 / 本地模拟 / DS 模拟**三处积分是否同源**(统一固定步长或统一闭式 `pos += v·dt + 0.5·a·dt²`)?④ 阈值是否只在前三条做对后才用来吸收离散事件残差(而非拿它掩盖系统漂移)?
|
|
424
|
-
- 私密态不进根字段、走 `client.send` 定向;DS 内存保有并在 `onJoin` 对后进房/重连补发。
|
|
425
|
-
- 重连保席位靠根字段席位表 + `onJoin` 用 `player_id` 认领旧 slot;与禁用 `allowReconnection` 分工明确。
|
|
426
|
-
- 阶段/行动者/回合序号在根字段、DS 单点迁移;倒计时从 DS 时间戳派生,客户端只读只发意图。
|
|
427
|
-
- **上行**连续态接近 4KB 时按「降频 → 减字段 → 降精度 → 只发关键实体」取舍,不拆包;AOI 属第一版红线外不做。(4KB 只约束上行,下行无此上限、不做此取舍。)
|
|
428
|
-
- 回放/历史不在状态同步里:根字段只保当前值;DS 日志局末落云存储、前端读日志重演,未用同步通道存历史。
|
|
429
|
-
- **可机检**:`ds/` 全文 grep 不到 `this.state.<字段>[` 形式的下标访问;所有 **MapSchema / ArraySchema** 容器走 `.set/.get/.has/.delete/.forEach`(JS 原生 `Map`、JSON 解析出的普通对象不受此限,只查 `state.` 开的容器字段)。每个 state 根字段都能说出它是**标量还是容器**,以及**客户端从哪个收口拿到它**。
|
|
430
|
-
- 客户端与 `ds/` 的字段和消息名逐项一致,但没有跨目录 import。
|
|
1
|
+
# 联网状态、同步与权威边界
|
|
2
|
+
|
|
3
|
+
> 仅在设计联网契约或排查“一端更新、另一端不一致”时读取。
|
|
4
|
+
> 本文提供跨玩法的判断方法,不提供任何具体游戏的字段、事件或服务端实现。
|
|
5
|
+
> 前半部分(owner / 通道 / 权威 / 恢复 / 频率)与维度无关,2D、3D 完全一致;3D 的唯一实质差异集中在末尾「3D 位姿与朝向同步」一节。
|
|
6
|
+
|
|
7
|
+
## 先确定 owner,再选通道
|
|
8
|
+
|
|
9
|
+
不要从“发什么消息”开始设计。先判断状态由谁拥有、丢失后是否必须恢复,再选择传输通道。
|
|
10
|
+
|
|
11
|
+
| 数据性质 | owner | 传输位置 | 客户端收口 | 典型特征 |
|
|
12
|
+
|---|---|---|---|---|
|
|
13
|
+
| 本机即时状态 | 玩法 System | 不需要绕 DS 回传 | System getter / 本机事件 | 本机已经知道,等待网络回声反而增加延迟 |
|
|
14
|
+
| 每名玩家各自的连续态 | 对应玩家上报,DS 存槽位 | `players[sessionId].data` | `mp-peer-pose` | 高频、每人一份、偶尔丢一帧仍可继续 |
|
|
15
|
+
| 房间唯一且必须恢复的权威状态 | DS | state 根字段 | `onStateField` / `mp-state-field` | 阶段、行动权、局面、比分、胜负等全房唯一事实 |
|
|
16
|
+
| 一次性表现通知 | DS 或玩家事件经 DS 转发 | `evt` | `onEvent` / `mp-event` | 错过不影响当前局面,可由现有状态重新渲染 |
|
|
17
|
+
|
|
18
|
+
关键事实:
|
|
19
|
+
|
|
20
|
+
- state 根字段在连接时携带当前值,适合后加入与重连恢复。
|
|
21
|
+
- `evt` 只投递发生时在线的连接。必须恢复的数据若使用 `evt`,DS 必须在 `onJoin` 定向补当前快照;能放根字段时优先放根字段。
|
|
22
|
+
- `players[sessionId].data` 不回推给发送者自己。本机状态由玩法 System 自己保存。
|
|
23
|
+
- `sessionId` 是一条 DS 连接内的实体 key;不要用 `player_id` 替代,同账号双开是两个实体。
|
|
24
|
+
- ⚠️ **根字段有两种形态,客户端收口不同**:上表把 root → `onStateField` 一概而论,**仅对标量根字段**(string/number/boolean)成立——`onStateField` 底层是 `$(room.state).listen(field)`,对 **MapSchema / ArraySchema 容器**只在整个引用被替换时触发,**收不到条目增删与嵌套字段变化**。容器型根字段要么在 `src/skill-modules/platform-services/MultiplayerManager.ts` 的 `_attachRoom()` 里补容器监听(写法见 `${CRAFT_CONTEXT_DIR}/knowledge/Subsystems/Optional/MultiplayerManagerKnowledge.md`「`onStateField` 订阅跨连接保留」),要么就别用容器(默认建议标量 JSON 字符串,见下「重连保席位」)。完整对照表 + 三问判据见 `${CRAFT_CONTEXT_DIR}/skills/platform-services/references/SERVER_GUIDE.md`「三条路怎么选」。
|
|
25
|
+
|
|
26
|
+
## 客户端提交意图,DS 产生结果
|
|
27
|
+
|
|
28
|
+
客户端输入不能直接成为权威结果。DS 收到 `pub` 后至少按实际玩法检查:
|
|
29
|
+
|
|
30
|
+
1. **发送者归属**:操作对象是否属于 `client.sessionId`,禁止相信 payload 自报的 player/session id。
|
|
31
|
+
2. **阶段与顺序**:当前阶段是否允许该操作,是否轮到该玩家。
|
|
32
|
+
3. **对象存在性**:目标、道具、格子或实体是否仍存在且可操作。
|
|
33
|
+
4. **空间与数值合法性**:位置、距离、速度、资源消耗和取值范围是否合理。
|
|
34
|
+
5. **幂等与竞态**:重复消息、同时争抢或迟到消息只能产生一次结果。
|
|
35
|
+
6. **频率与体积**:拒绝异常高频和超预算的**上行** payload(4KB 上限只卡上行,见「频率与包体」节)。拒绝时要打日志说明原因,不要静默丢弃;此检查仅针对客户端上行,**不要挪用到 DS 的下行发送路径**。
|
|
36
|
+
|
|
37
|
+
DS 校验后再修改根状态或广播事件。不得直接采信客户端提交的得分、奖励、胜负、死亡、命中、资源生成等结果。
|
|
38
|
+
|
|
39
|
+
不是所有实时玩法都要做完整服务端模拟,但应明确“客户端预测什么、DS 最终裁决什么”。无法权威模拟时,也要对结果做最小可验证约束,并在架构文档声明风险边界。
|
|
40
|
+
|
|
41
|
+
### 抢唯一资源用乐观并发(CAS)
|
|
42
|
+
|
|
43
|
+
多个客户端同时争抢**唯一资源**(首杀奖励、唯一道具、唯一座位、唯一击杀判定)时,用「期望值匹配才更新」的乐观并发,避免加锁:
|
|
44
|
+
|
|
45
|
+
- DS 是唯一写入者,天然是校验点。收到抢占意图时:读当前根状态字段 → 检查是否仍为期望值(尚未被占)→ 是才写入占有者并广播、否则拒绝并回一条失败事件。
|
|
46
|
+
- 客户端提交的是「我想抢,我看到的当前值是 X」,不是「我已经抢到了」;是否成功由 DS 依据它自己 state 的**当前**值裁定,迟到的第二个请求读到的已是被占值,自然失败。
|
|
47
|
+
- 这套判定只在 DS 里做,客户端不做本地占有假设(可做乐观 UI,但以 DS 结果为准回滚)。
|
|
48
|
+
|
|
49
|
+
## 私密态:按角色定向下发,禁进根字段
|
|
50
|
+
|
|
51
|
+
有些状态只该给**部分玩家**看。这类**私密态**的传输规则和公开态相反,单独一节。
|
|
52
|
+
|
|
53
|
+
**举例(帮助理解,非规则规定)**:狼人杀里各人的身份、军棋的暗子、你画我猜发给画者的题目、只发给本人的手牌——都是「每人看到的内容不同、且不能让别人看到」的私密态。这些例子**只用于说明「什么是私密态」**,不代表本引擎固化了某一款玩法的具体规则链;具体怎么分配、何时揭示、揭示给谁,由各项目的策划案和玩法 System 自己定,本节只给通用机制。
|
|
54
|
+
|
|
55
|
+
### 铁律:私密态禁放 state 根字段
|
|
56
|
+
|
|
57
|
+
根字段是**全房广播**的——任何客户端都能在本地读到完整 state,哪怕 UI 不渲染它。把私密内容(如身份)写进根字段,等于把答案发给了所有人,改 UI 藏不住,**必然泄漏**。私密态一律不进根字段。
|
|
58
|
+
|
|
59
|
+
判断口径:一份数据**是否对全房所有人是同一份**。是 → 根字段(棋盘、比分、阶段);否(每人内容不同、或只给本人)→ 私密态,走定向 `evt`。
|
|
60
|
+
|
|
61
|
+
### 通道:DS 侧按 sessionId 定向 send
|
|
62
|
+
|
|
63
|
+
私密态走**定向事件**——DS 只对目标那一条连接发,不广播:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// DS 侧:只发给某一个玩家(client 是该玩家的连接)
|
|
67
|
+
client.send("evt", { type: "secret_state", data: { /* 该玩家专属内容 */ } });
|
|
68
|
+
|
|
69
|
+
// 对照:room.broadcast 是全房,私密态绝不能用它
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- 发给谁由 DS 决定,接收方从 `onEvent`(`mp-event`)收,和公开事件同一个收口,靠 `type` 区分。
|
|
73
|
+
- 客户端**不自报私密内容**:发什么由 DS 裁定并只发给本人;客户端收到什么就是什么。
|
|
74
|
+
|
|
75
|
+
### 安全口径:目标身份以 DS 侧绑定为准,不信客户端自报
|
|
76
|
+
|
|
77
|
+
`player_id` 是**进房时由 DS 分配、并锁定到该条 sessionId** 的。私密下发要发给谁、重连认领谁的席位,**目标一律以 DS 侧的这份绑定为准**,不能每次从客户端 `options` 里读它自报的 id——否则 A 只要在自报里填 B 的 id,就能冒领 B 的暗子 / 席位。
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// DS 侧:进房时分配并锁定绑定,后续只认这份绑定
|
|
81
|
+
onJoin(client, options) {
|
|
82
|
+
// player_id 由 DS 分配 / 校验后锁定到 sessionId,不直接采信 options 里的自报值
|
|
83
|
+
const playerId = this._bindPlayer(client.sessionId, options);
|
|
84
|
+
// ...后续私密下发、席位认领都用 playerId(来自绑定表),不用 options.player_id
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
> 这条①②共用:凡「发给某人」「认领某人的东西」,目标都从 DS 绑定表取,不从客户端当次自报取。①违背它 → 冒领暗子;②违背它 → 冒领席位。
|
|
89
|
+
|
|
90
|
+
### 私密态在后进房 / 重连必须 onJoin 定向重发
|
|
91
|
+
|
|
92
|
+
`evt` 是一次性的、**只投递发送时在线的连接**。私密态若只在开局广播一次,**后进房或断线重连的玩家永远收不到自己的那份**——它不像根字段会在握手时自动携带当前值。
|
|
93
|
+
|
|
94
|
+
所以私密态由 DS **同时**维护在**服务端内存**(不是根字段,客户端读不到),并在 `onJoin` 里对刚进来的这条 client 按其绑定的 `playerId` 定向重发一次:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
// DS 侧 Room
|
|
98
|
+
onCreate() {
|
|
99
|
+
this._secrets = new Map(); // playerId -> 私密内容,仅存 DS 内存,不进 state
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 某时机把私密内容分配给某人(playerId 来自 DS 绑定,不来自客户端自报)
|
|
103
|
+
setSecret(playerId, client, content) {
|
|
104
|
+
this._secrets.set(playerId, content);
|
|
105
|
+
client.send("evt", { type: "secret_state", data: content });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 后进房 / 重连:按绑定表取 playerId,把这条 client 的私密态定向补一次
|
|
109
|
+
onJoin(client, options) {
|
|
110
|
+
const playerId = this._bindPlayer(client.sessionId, options);
|
|
111
|
+
const secret = this._secrets.get(playerId);
|
|
112
|
+
if (secret) client.send("evt", { type: "secret_state", data: secret });
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> 私密态存 DS 内存 + onJoin 定向重发,是「私密」和「可恢复」的唯一并存方式:放根字段可恢复但泄漏,只广播一次不泄漏但重连即丢。二者都不行。
|
|
117
|
+
|
|
118
|
+
### 私密 → 公开的单向转换(通用机制)
|
|
119
|
+
|
|
120
|
+
原本只发给某人的私密态,可能在**某个时机**变成「对某人 / 对所有人公开」。本节只给**通用机制**,不写任何具体玩法的转换规则:
|
|
121
|
+
|
|
122
|
+
- **由 DS 判定转换时机**:何时从私密转公开,由服务端按玩法裁决触发,客户端不自行揭示。
|
|
123
|
+
- **按目标定向「提升」下发**:转换是 DS 主动向**指定目标**(某个人、某几个人、或全房)重新下发这份内容。⚠️ 注意:即便揭示给多人,**这仍是「对特定目标定向提升」,不是把它写进根字段做全房广播**——目标集合由 DS 决定并逐一 `client.send`。
|
|
124
|
+
- **转换前存 DS 内存**:未转换时内容始终只在 DS 内存的私密表里,不进根字段;转换只改变 DS「发给谁」,不改变「私密态不落根字段」这条铁律。
|
|
125
|
+
- ⚠️ **转换那一刻下行包会明显变大,这是正常的、且不受上行 4KB 限制**:原本只发给 1 人的一小份私密态,转换后要向指定目标(某人 / 某几人 / 全房逐一)重新下发,内容可能是**一整个局面级**的大对象;这是 **DS→客户端的下行**,浏览器端不设 4KB 接收上限,不会触发 code 1009。**绝不要在这条下发路径上套上行的包体预算检查**(如 `if (overBudget(data)) return`)——那属于把「上行 4KB」误当成全局规则,会把这份本该送达的大包**静默吞掉**(下行不受限的完整说明见「频率与包体」节)。此处下发只管发全、发对目标,不做体积裁切。
|
|
126
|
+
|
|
127
|
+
可举一例帮助理解(**仅示意,非规则**):棋类玩法中「一方出局后,向其揭示全场剩余局面」即属此类——出局那一刻由 DS 判定,把原先各自私密的局面定向提升下发给该玩家。它仍是定向提升,不是全房广播;这份「全场剩余局面」下发时体积会陡增,属上面说的正常情形,不要在此处拦截。
|
|
128
|
+
|
|
129
|
+
### 本地标注不属于状态同步范畴
|
|
130
|
+
|
|
131
|
+
玩家给己方 / 对方棋子贴的本地便签、标记、备注,是**纯客户端本地**的辅助显示:不上报 DS、不进任何同步通道、对手不可见、断线重连也不需要恢复。它属于 UI 层,**不属于状态同步范畴**,本上下文不展开。
|
|
132
|
+
|
|
133
|
+
### 完成检查(私密态)
|
|
134
|
+
|
|
135
|
+
- 私密态**不在**任何 state 根字段里;grep 根字段 Schema 确认无身份 / 暗子 / 手牌等私密字段。
|
|
136
|
+
- 私密态走 `client.send`(定向),不走 `room.broadcast`(全房);私密→公开转换后**仍是定向提升**,未退化成根字段广播。
|
|
137
|
+
- 私密→公开转换的**下行发送路径上没有任何包体预算检查 / 裸 `return`**:转换时下行包变大是正常的、且不受 4KB 限制,不得在此静默拦截(4KB 只卡上行)。
|
|
138
|
+
- 私密下发 / 重连认领的目标**取自 DS 绑定表**,不取自客户端 `options` 自报的 id。
|
|
139
|
+
- DS 在内存保有私密态,`onJoin` 对新连接 / 重连按绑定 `playerId` 定向重发;后进房玩家能拿到自己的那份。
|
|
140
|
+
- 本地标注类数据未进任何同步通道。
|
|
141
|
+
|
|
142
|
+
## 后加入与重连
|
|
143
|
+
|
|
144
|
+
对每类数据回答:“错过此前全部消息,只看当前 state,能否继续?”
|
|
145
|
+
|
|
146
|
+
- 能:当前状态足以恢复,事件只用于表现。
|
|
147
|
+
- 不能:把必要事实移到根状态,或在 `onJoin` 定向发送一份完整快照。
|
|
148
|
+
- 玩家连续态:新连接通过当前 `players` Map 获得;不要依赖历史 pose。
|
|
149
|
+
- 断线重连会得到新的 `sessionId`。需要跨连接保留的业务身份只能由玩法明确映射,不能默认沿用旧 session。
|
|
150
|
+
|
|
151
|
+
三种结束路径必须分开:
|
|
152
|
+
|
|
153
|
+
- `mp-disconnect`:网络异常,用事件里的 `roomId` 或 `getLastRoomId()` 重走 `joinRoom()`。禁止在 detach 之后读 `getRoomId()`。
|
|
154
|
+
- `mp-room-closed`:本局已结束或进程回收,不重连。
|
|
155
|
+
- 主动 `leaveRoom()`:正常退出,不触发自动重连。
|
|
156
|
+
|
|
157
|
+
### 权威恒在 DS,不存在客户端切主
|
|
158
|
+
|
|
159
|
+
本子系统是**服务端权威**:权威逻辑跑在 DS,不跑在任何客户端。房主玩家掉线只是少一名玩家,DS 进程还在、裁决照常,**不存在“主逻辑无人计算”,因此不需要、也不实现“切主 / MasterClient 切换”**。遇到房主制、客户端权威、MasterClient 那套资料(房主端算逻辑、掉线抢切网络最好的玩家)不要套用——那是没有权威服务端的架构的补救,与本架构无关。我们对应的机制只是**某玩家断线后按原 `roomId` 重连**(重连得到新 `sessionId`,业务身份靠玩法自己映射),这与“切主”是两码事。
|
|
160
|
+
|
|
161
|
+
### 重连保席位:DS 用席位表认领旧 slot
|
|
162
|
+
|
|
163
|
+
上面说的「业务身份靠玩法自己映射」,落地范式是 **DS 在根字段维护一张席位表**,把「对局里的槽位」和「玩家身份」绑定,断线重连能认回原 slot。
|
|
164
|
+
|
|
165
|
+
- **根字段维护 `seats`**:`seats: { player_id -> { slot, hp, score, alive, ... } }`。这是全房可读的权威(谁占几号位、血量分、存活),不是私密态。
|
|
166
|
+
- **onJoin 用 DS 绑定后的 `playerId` 查表**:命中的 = 重连认领原席位,把**新 sessionId 绑回旧 slot**(旧 session 已失效,按新连接重建该 slot 的 `players[sessionId].data` 连续态);未命中 = 新玩家,占下一个新 slot。⚠️ `playerId` 取自 DS 侧绑定表(见上面「安全口径」),**不是每次从客户端 `options` 读自报值**。
|
|
167
|
+
|
|
168
|
+
> **⚠️ 席位表是容器,别用下标 / 别用 `{}`**:`seats` 是「按 player_id 索引的映射」。**绝不能写成 `this.state.seats = {}`**(普通对象不能当 Colyseus 根字段,`seats` 从未在 `defineTypes` 里声明的话,这行是往 Schema 实例挂未声明字段——不报错、能跑,但 `seats` **从头到尾不进编码**,客户端 `state` 里根本没这个字段,100% 不同步);也**不能对容器用下标读写**(`state.seats[k] = v` / `state.seats[k]` / `delete state.seats[k]` 在 `@colyseus/schema@4.0.30` 下**静默失效**:名下标只挂一个普通 JS 属性,**读得回来**所以按 key 取的路径全正常,但 `.size` 恒 0、`.forEach`/`for...of` 遍历不到、**完全不进编码,客户端永远收不到**——「一半路径能跑、一半静默空」正是本次双端不同步的最难定位形态)。详见 `${CRAFT_CONTEXT_DIR}/skills/platform-services/references/SERVER_GUIDE.md`「硬约束」节的 `MapSchema / ArraySchema 只能用方法访问`。
|
|
169
|
+
|
|
170
|
+
**席位表有两种合法形态,按下面判据选,不能只写一种**:
|
|
171
|
+
|
|
172
|
+
| 形态 | 声明 | 客户端收口 | 适用 |
|
|
173
|
+
|---|---|---|---|
|
|
174
|
+
| **JSON 字符串根字段**(默认推荐) | `seats: "string"` | 现成 `onStateField('seats')`,握手自带当前值,零客户端改动 | 整表 ≤ 约 1KB,且**低频**写(回合结算、偶发扣血)。席位表天然低频,默认走这个 |
|
|
175
|
+
| **MapSchema 根字段** | `seats: { map: SeatState }` | `onStateField` **收不到条目增删与嵌套字段变化**,须在 `MultiplayerManager.ts` 的 `_attachRoom()` 补容器监听(见 `${CRAFT_CONTEXT_DIR}/skills/platform-services/references/SERVER_GUIDE.md`「根字段有两种形态」) | 整表 ≥ 几 KB / 条目上百 / 需要「只有某个字段变化才更新」的字段级增量 |
|
|
176
|
+
|
|
177
|
+
> **判据优先级**(不能只看高频低频):① **owner**——DS 裁决的 → 根字段(高低频都一样);玩家自报的连续态 → `players[sid].data`(那是客户端上报通道、DS 只存不改,且**不回推给发起者自己**,把 DS 裁决的`hp` 塞进去会让本机另存一份、两份必分叉)。② **整表全量多大**——`patchRate` 已把下发频率锁在 20Hz,成本上限 = 全量 × 20Hz,与写入频率无关;≤ 约 1KB 字符串够用,≥ 几 KB 用 MapSchema。③ **客户端要什么粒度**——整表刷新即可 → 字符串;「只有 hp 变了才更新这一个血条」→ MapSchema。**默认走 JSON 字符串根字段**;确需字段级增量才扩到 MapSchema。
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
// ds/rooms/xxxSchema.mjs —— 席位表作为 JSON 字符串根字段(默认形态)
|
|
181
|
+
defineTypes(RoomState, {
|
|
182
|
+
players: { map: PlayerState }, // 连续态槽位,模板已有,勿改
|
|
183
|
+
phase: "string",
|
|
184
|
+
seats: "string", // player_id -> { slot, hp, score, alive } 的 JSON
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// ds/rooms/xxxRoom.mjs
|
|
188
|
+
onCreate() {
|
|
189
|
+
this._bindings = new Map(); // sessionId -> player_id(DS 分配的锁定绑定,JS 原生 Map)
|
|
190
|
+
this._nextSlot = 1;
|
|
191
|
+
}
|
|
192
|
+
_seats() { try { return JSON.parse(this.state.seats || "{}"); } catch { return {}; } }
|
|
193
|
+
_writeSeats(o) { this.state.seats = JSON.stringify(o); } // 必须整体赋值才触发同步
|
|
194
|
+
|
|
195
|
+
onJoin(client, options) {
|
|
196
|
+
// _bindPlayer 意图:首次进房由 DS 分配一个 player_id 并锁定到该 sessionId(存 _bindings),
|
|
197
|
+
// 之后"认领谁的席位 / 私密发给谁"都从 _bindings 取,不读客户端 options 里的自报 id ——
|
|
198
|
+
// 否则 A 在自报里填 B 的 id 就能冒领 B 的席位(见"安全口径"节)。
|
|
199
|
+
// ⚠️ player_id 是认领 key;sessionId 才是权限校验对象,两者别混用。
|
|
200
|
+
const playerId = this._bindPlayer(client, options);
|
|
201
|
+
const seats = this._seats();
|
|
202
|
+
if (seats[playerId]) {
|
|
203
|
+
// 重连:认回旧 slot,把新 sessionId 绑回旧席位
|
|
204
|
+
seats[playerId].sessionId = client.sessionId;
|
|
205
|
+
this._restoreContinuousState(seats[playerId]); // 重建该 slot 的 players[sid].data
|
|
206
|
+
} else {
|
|
207
|
+
// 新玩家:占新 slot
|
|
208
|
+
seats[playerId] = { slot: this._nextSlot++, hp: 100, score: 0, alive: true, sessionId: client.sessionId };
|
|
209
|
+
}
|
|
210
|
+
this._writeSeats(seats); // 改完必须整体写回,只改 seats 对象本身不会同步
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- **字符串形态唯一的坑**:`_seats()` 返回的是**快照副本**,直接改它不会同步,**必须 `_writeSeats()` 整体写回**。
|
|
215
|
+
- **`player_id` 的权威在 DS 侧绑定**:首次进房由 DS 分配并锁定到该 sessionId(`_bindings`),后续认领 / 下发一律从绑定表取。客户端若把 id 带回 `options`,只当**定位 key** 用(DS 查绑定表能否命中),不当授权凭证;「这条消息是不是本人发的」仍由 sessionId 判定(见「客户端提交意图」节)。要更硬可叠加平台下发可信身份,但「主管目标以 DS 绑定为准」这条不变。
|
|
216
|
+
- 和传输层**不矛盾**:传输层**禁用 `allowReconnection`**(见 `${CRAFT_CONTEXT_DIR}/skills/platform-services/references/SERVER_GUIDE.md`,DS 壳不保留旧连接),重连必然是**新 sessionId 的新连接**——所以「跨连接记住席位」只能靠上层的席位表,不能靠协议层的自动重连。这两件事一个管传输、一个管业务映射,方向不同、缺一不可。
|
|
217
|
+
|
|
218
|
+
### 最小骨架
|
|
219
|
+
|
|
220
|
+
**回合制桌牌**:`seats.pid` 存槽位 + 当前积分;玩家掉线,`mp-disconnect` 后业务按其 `player_id` 等待若干秒;重连 `joinRoom` 时 `onJoin` 命中即认回槽位、积分、当前手牌(手牌若私密则按上面私密态节补发)。超时未回则标记 `alive=false` 或让席位进入托管/弃权。
|
|
221
|
+
|
|
222
|
+
**实时对战**:`seats.pid` 存 `{ slot, hp, alive, score }`;掉线者尸体保留原地(位姿停更),重连认回后在宽限期内恢复原血量/比分。宽限期结束仍未回,服务端判定出局或由 AI 托管(取决于玩法策略),并广播事件。
|
|
223
|
+
|
|
224
|
+
### 完成检查(重连保席位)
|
|
225
|
+
|
|
226
|
+
- 席位表在**根字段**,全房可读、DS 单点写;不依赖客户端各自记忆。
|
|
227
|
+
- `onJoin` 用 **DS 绑定后的 `playerId`** 查表:命中 → 认回原 slot 并重建连续态;未命中 → 新玩家占新 slot;**不从 `options` 直接读自报 id 作主管目标**(防冒领席位,见「安全口径」)。
|
|
228
|
+
- 明确区分:`player_id` 是认领 key、`sessionId` 是权限校验对象;二者不被混用。
|
|
229
|
+
- 和「禁用 `allowReconnection`」不冲突:传输层新建连接,业务层靠席位表跨连接认回——写清二者分工。
|
|
230
|
+
- **可机检**:`ds/` 全文 grep 不到 `this.state.<字段>[` 形式的下标访问;所有 **MapSchema / ArraySchema** 容器走 `.set/.get/.has/.delete/.forEach`(JS 原生 `Map`、JSON 解析出的普通对象用下标/方法访问是正常的,不要误伤——只查 `state.` 开的容器字段)。每个 state 根字段都能说出它是**标量还是容器**,以及**客户端从哪个收口拿到它**(标量 → `onStateField`;容器 → `MultiplayerManager.ts` 的 `_attachRoom()` 里补的容器监听,见 `${CRAFT_CONTEXT_DIR}/skills/platform-services/references/SERVER_GUIDE.md`「根字段有两种形态」)。
|
|
231
|
+
|
|
232
|
+
## 阶段 / 回合状态机:根字段单点迁移,客户端只读
|
|
233
|
+
|
|
234
|
+
回合制与阶段驱动玩法(场景一的轮转、场景三的出题→作答→投票→揭晓)需要**阶段状态机**。它也是**全房唯一权威事实**,归 DS 单点迁移。
|
|
235
|
+
|
|
236
|
+
### 哪些放根字段
|
|
237
|
+
|
|
238
|
+
- **阶段**(`phase`: `prepare/playing/voting/reveal`…)、**当前行动者**(`turn_player` 或 `turn_sessionId`)、**回合序号**(`round`)——三者**都放根字段**。
|
|
239
|
+
- 客户端**只读根字段渲染**当前阶段,**只发意图**(落子、提交答案、投票),不自行推进阶段。
|
|
240
|
+
|
|
241
|
+
### DS 单点迁移
|
|
242
|
+
|
|
243
|
+
阶段迁移、行动权轮换**只在 DS 里算**,DS 改根字段后全房经 `onStateField` 自动同步。客户端无权改阶段、也无权广播「轮到我了」:
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
// DS 侧:轮转到下一个玩家(回合制)
|
|
247
|
+
nextTurn() {
|
|
248
|
+
const next = this._players[(this._turnIndex + 1) % this._players.length];
|
|
249
|
+
this.state.phase = "playing";
|
|
250
|
+
this.state.turn_sessionId = next.sessionId;
|
|
251
|
+
this.state.round += 1;
|
|
252
|
+
// 改根字段后,全房客户端经 onStateField 自动收到
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 多阶段机:出题 -> 作答 -> 投票 -> 揭晓
|
|
256
|
+
advancePhase() {
|
|
257
|
+
const order = ["pitch", "answer", "vote", "reveal"];
|
|
258
|
+
this.state.phase = order[(order.indexOf(this.state.phase) + 1) % order.length];
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 倒计时用 DS 时间戳,不用客户端各自计
|
|
263
|
+
|
|
264
|
+
- 倒计时起始/截止**时间戳放根字段**(如 `phase_deadline: <ds 时间戳 ms>`),客户端用它**算剩余**——不是每个客户端各自开 `setInterval` 计一段本地时长。
|
|
265
|
+
- 客户端本地计时的起点误差会累积、掉帧会漂移;极端情况各端看到的「还剩 3 秒、2 秒、1 秒」不一致,导致不同玩家同时看到不同阶段。
|
|
266
|
+
- DS 是唯一时钟源:到 `phase_deadline` 后由 DS 触发迁移(轮转或进下一阶段),不是靠某客户端喊「时间到了」。
|
|
267
|
+
|
|
268
|
+
### 最小骨架
|
|
269
|
+
|
|
270
|
+
**回合轮转(切下一个 sessionId)**:根字段 `turn_sessionId` + `round`;DS 在收到当前行动者有效落子 / 或用尽时限后 `advancePhase` 切下家;客户端只读 `turn_sessionId` 判断「现在轮到我发意图」,不发「我来切轮次」的消息。
|
|
271
|
+
|
|
272
|
+
**多阶段机(出题→作答→投票→揭晓)**:根字段 `phase` + `phase_deadline`;DS 依次迁移;每个阶段客户端只发对应阶段允许的意图(作答期才收答案、投票期才收投票),DS 校验「当前 phase 是否允许此操作」(见「客户端提交意图」节的阶段与顺序检查)。私密部分(如画者的题)按上面私密态节单独收发。
|
|
273
|
+
|
|
274
|
+
### 完成检查(状态机)
|
|
275
|
+
|
|
276
|
+
- 阶段 / 行动者 / 回合序号都在**根字段**,DS 单点迁移;客户端只读渲染、只发意图。
|
|
277
|
+
- 倒计时用 DS 时间戳派生剩余,不在客户端各自本地计时。
|
|
278
|
+
- DS 校验「当前阶段是否允许该操作」,防止客户端跨阶段发指令。
|
|
279
|
+
- 私密阶段的内容(身份/题)不走根字段,按私密态节定向下发。
|
|
280
|
+
|
|
281
|
+
## 频率与包体
|
|
282
|
+
|
|
283
|
+
- 上行连续态不超过 20Hz;更高频率不会提高服务端 patch 频率。
|
|
284
|
+
- **单包 4KB 上限只约束上行(客户端 → DS),下行(DS → 客户端)不受此限**:
|
|
285
|
+
- **上行**:客户端发给 DS 的单包 ≤ 4KB UTF-8 字节,发送前用 `TextEncoder` 计算。这个 4KB 来自传输层 `@colyseus/ws-transport` 的默认 `maxPayload`(`4 * 1024`),且默认**无压缩**(`perMessageDeflate = false`)。它是 **DS 作为接收方**能收下的最大消息字节——所以只卡「客户端往 DS 发」这一向。超限的代价是**连接以 code 1009 被断开、`onMessage` 根本不执行**(是断连,不是丢这一包),所以有效检查必须在**客户端发送前**做。
|
|
286
|
+
- **下行**:DS 发给客户端的包**没有对应的 4KB 大小上限**——浏览器端不设等价的接收字节限制,下行大包不会触发 1009、不会被断连。**因此绝不要把上行那套「超预算就裁 / 就 return」的逻辑套到下行发送路径上**:下行包该多大就多大(私密→公开转换、onJoin 定向补全整局面等场景下行本就会明显偏大),在下行处做体积拦截会**静默吞掉本应送达的消息**。
|
|
287
|
+
- ⚠️ **下行「没有大小上限」不等于「怎么发都行」——它仍受带宽与延迟约束**:下行大包**必须是低频、事件驱动的**(`onJoin` 补全、私密→公开转换、阶段切换等**一次性时机**)。**不要**因为「下行不受 4KB 限制」就在**每帧 / 定时器 / `setSimulationInterval` 路径**上 `broadcast` 全量局面——大包不会断连,但会在 WebSocket 上**队头阻塞**后续消息,DS 又是一局一进程、按容量调度,结果是延迟飙升、甚至心跳超时被强杀、整房掉线。持续态仍走 **state 增量**(`patchRate` 默认 50ms / 20Hz,框架自动 diff),不要用整包广播替代增量。**判据**:这条下发属于「一次性时机」还是「周期性」?后者不该发全量。
|
|
288
|
+
- 优先减少字段、降低精度、发送头部或关键采样点;不要用拆包规避单个逻辑状态过大。**(此条针对上行——下行不受包体大小预算约束,无需为下行拆包或裁字段;下行的约束是「低频事件驱动」,见上。)**
|
|
289
|
+
- **禁止静默丢弃消息**:任何方向的消息,凡因预算 / 校验被拒绝,**必须打日志**(方向 + 字节数 + 拒绝原因),**绝不裸 `return`**。静默丢弃会伪装成「消息发了但对方没收到」,是排查成本最高的一类故障;尤其下行本就不该做体积拦截,若真在下行处写了 `if (over) return` 之类,等于凭空丢包且无任何痕迹。
|
|
290
|
+
- 一次性事件只带裁决所需的最小意图,当前完整局面放 state。
|
|
291
|
+
- `max_players`、DS `maxClients`、玩法人数三者必须相同。
|
|
292
|
+
|
|
293
|
+
## 回放边界:局末一次性落盘,不进状态同步
|
|
294
|
+
|
|
295
|
+
状态同步**不承载回放 / 历史留存**:各通道只保「当前值」,不保「过去发生了什么」。回放不是状态同步的职责,是另一条独立路径。
|
|
296
|
+
|
|
297
|
+
- **根字段只保当前值**:`phase`、`score`、棋盘都是「此刻是什么」,没有历史数组、没有操作日志、没有上一帧的副本。
|
|
298
|
+
- **回放的独立路径**(只写方向,不写完整 DS-log 实现):DS 在对局过程中**累积全知动作日志**(谁在何时做了什么、DS 的裁决结果)→ **局末一次性写入已有的云存储**(局外数据,不走同步通道)→ **回放时前端读这条日志重演**,按日志逐条重建局面。
|
|
299
|
+
- **禁止用状态同步 / 根字段存历史**:不要把操作序列、撤销栈、每回合快照放进根字段或 `evt`。根字段体积按字节受控(见「频率与包体」),塞历史会直接挤压当前态的可用空间;且根字段是实时权威态,不是存档。
|
|
300
|
+
- **对局内的「上一动作」**(如「最后一步棋」「上一个喊话」)若玩法需要展示,属**当前值**而非历史:作为当前状态的一个字段随根字段同步,不进回放日志。
|
|
301
|
+
|
|
302
|
+
## 项目契约记录格式
|
|
303
|
+
|
|
304
|
+
每个联网玩法在架构文档的模块与耦合表中记录 owner 和依赖;精确线上字段在玩法 System / Room 的契约注释中维护,避免架构文档膨胀为 API 手册。
|
|
305
|
+
|
|
306
|
+
每类数据至少记录:
|
|
307
|
+
|
|
308
|
+
- 语义与 owner;
|
|
309
|
+
- 使用的通道及字段/事件名;
|
|
310
|
+
- 客户端上报内容与 DS 校验;
|
|
311
|
+
- 后加入/重连恢复方式;
|
|
312
|
+
- 更新频率与最大体积;
|
|
313
|
+
- 本机状态是否需要本地镜像。
|
|
314
|
+
|
|
315
|
+
字段和事件只属于当前项目,不得因某个实现成功或失败而写入全局 Knowledge。
|
|
316
|
+
|
|
317
|
+
## 3D 位姿与朝向同步(3D 相对 2D 的唯一实质差异)
|
|
318
|
+
|
|
319
|
+
同步层本身与维度无关:`players[sessionId].data` 通道只搬运一段 JSON,DS 不感知有没有 z 轴。3D 相对 2D 只在**连续态 pose 的内容**与**收端处理**两点不同,其余(owner 判定、权威裁决、恢复、频率、包体)一字不改。
|
|
320
|
+
|
|
321
|
+
### 一、pose 多带 z + 朝向用四元数
|
|
322
|
+
|
|
323
|
+
- 位置从 `{x, y}` 扩到 `{x, y, z}`。
|
|
324
|
+
- 朝向**用四元数,不用欧拉角**:欧拉角有万向锁、且不便平滑插值;四元数可直接 `slerp`。
|
|
325
|
+
- 连续态字段范式(走 `players[sid].data` 通道,`sendPose` 上报):
|
|
326
|
+
|
|
327
|
+
```js
|
|
328
|
+
// 3D 连续态:一个物体一份
|
|
329
|
+
{ x, y, z, // 位置,建议 toFixed(2)
|
|
330
|
+
qx, qy, qz, qw } // 朝向四元数,建议 toFixed(3)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
- 精度即带宽:位置两位小数、四元数三位小数通常足够;抖动明显时先降频、再考虑升精度,不要无脑全精度。
|
|
334
|
+
|
|
335
|
+
### 二、收端基本必须插值
|
|
336
|
+
|
|
337
|
+
**总命题**:表现层的更新节奏,不得由同步 / 帧到达的节奏决定。同步是 10~20Hz 的离散输入,渲染是 60fps 的连续输出,收端必须自己把离散摊成连续。这条对 **2D 与 3D 一样致命**——不是「3D 才明显」:2D 同样会每同步周期瞬移一次(曾有 2D io 工程正因此卡顿)。按**「是否有连续运动的实体」**判要不要做,不按维度、不按品类;有连续运动的(io / 射击 / 竞速 / 体育,2D3D 皆然)必做,纯回合 / 棋牌不涉及。
|
|
338
|
+
|
|
339
|
+
> **这三种收端形态与维度无关,2D 同样适用**——放在这条 3D 专属大节下,只因 3D 首次踩到(球类/弹道的本地模拟纠偏在 3D 项目里先炸)。2D 的对等内容见 `../Multiplayer/StateSyncKnowledge.md`(js 引擎)的「表现层与同步频率解耦」节,形态一一对应。挂在这里是历史落位,不是「只有 3D 才要做」。
|
|
340
|
+
|
|
341
|
+
要覆盖**三种收端形态**:
|
|
342
|
+
|
|
343
|
+
- **形态 A · 状态复制型**(收到远端 pose 直接 set):上行 20Hz、屏幕 60fps,硬 set 会一格一格跳。远端物体收端**几乎必做**位置 `lerp` + 朝向 `slerp` 逼近目标(代价是画面比真实晚约 50~100ms,可接受)。
|
|
344
|
+
- **形态 B · 确定性帧同步 / 锁步型**(收到一帧携带 N 步输入):**不能在一次调用里把 N 步跑完再渲染**(每同步周期瞬移一次)。N 步必须**入队**,由渲染循环按**固定步长**逐步消费(定步长累加器,与单机同一套);**队列空时保持当前状态、不外推**——确定性模拟下本地猜测会立刻与权威分叉。
|
|
345
|
+
|
|
346
|
+
```js
|
|
347
|
+
// ❌ 收到帧就把一批 step 跑完
|
|
348
|
+
onFrame(inputs) { for (let i = 0; i < 3; i++) step(state, inputs); render(); }
|
|
349
|
+
// ✅ 入队,渲染循环按固定步长消费
|
|
350
|
+
onFrame(inputs) { for (let i = 0; i < 3; i++) queue.push(inputs); }
|
|
351
|
+
update(delta) { acc += delta; while (acc >= STEP && queue.length) { step(state, queue.shift()); acc -= STEP; } }
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
> **隐蔽坑**:单机分支常已写对定步长累加器,联机分支却只「设输入、不推进」,全靠 20Hz 批量替换 → 每 50ms 瞬移。联机分支同样要定步长消费。
|
|
355
|
+
|
|
356
|
+
- **形态 C · 本地权威同款模拟 + 快照纠偏**(收端本地跑一套与 DS 相同的物理模拟,权威快照到达时向它收敛):适用于**本地能自己算出下一刻在哪**的连续运动——球类、弹道、载具惯性等。与形态 A 的本质区别是**渲染时刻**:A 渲染在过去(比真实晚 50~100ms 换平滑),C 渲染在**当下**(本地模拟一直往前跑,快照只用来纠偏),所以 C **必须处理「收到的权威态本身是旧的」**这件事——两个真实球类 3D 工程都栽在这里。四条铁律,缺一条就是越纠越飘:
|
|
357
|
+
|
|
358
|
+
1. **纠偏比较前,必须先把权威态外推到当前时刻**,再和本地当前值比。快照带的是「服务端 t 时刻的位置」,到你手里已经旧了 ≈70~110ms(一个 RTT 的一半 + patchRate 半窗口);直接拿快照原始位置减本地当前位置,会把「球本该前进的那段距离」当成偏差纠掉,累积成每秒往回瞬移十几二十次。**机检判据**:凡出现「`阈值判断(快照字段 − 本地当前字段)` 且这两者之间没有任何按时间推进的步骤」= 不合格。
|
|
359
|
+
2. **外推要用「标定过的时钟」,不能用到达时刻。** age = `getServerNow() − snap.t`(`snap.t` 是 DS 写快照时的服务端单调时钟,作为两端契约的一部分随快照下发;`getServerNow()` 见 `MultiplayerManager` 模板,客户端按最小 RTT 标定出本机与 DS 的时钟偏移——设施与用法见 `../Subsystems/Optional/MultiplayerManagerKnowledge.md`)。**用「到达时刻 − snap.t」当 age 是错的**:那把单向网络延迟当成了 0。⚠️ **这条与本文件「倒计时用 DS 时间戳」节是两码事,别混**:倒计时是**秒级**、直接拿 `deadline − now` 相减就够,几十毫秒的时钟差看不出来;纠偏是 **50~100ms 级**、时钟差直接顶破阈值,**必须先标定偏移**。同一个「DS 时间戳」,一个能裸用一个必须标定,尺度不同。
|
|
360
|
+
3. **外推公式 / 本地模拟 / DS 模拟三者同源。** 侧视网球栽在这条:DS 每 tick 大步长欧拉(dt=3)、客户端每帧一步(dt=1)、纠偏又用解析解 `0.5·g·t²`,三套积分各算各的 → 半隐式欧拉**对加速运动不是步长无关的**(dt=3 跑一步 ≠ dt=1 跑三步),每 50ms 系统性差约 3g,稳定漂移直接顶破阈值。**要么统一固定步长**(三处都用同一个 STEP 累加器),**要么统一改成闭式** `pos += v·dt + 0.5·a·dt²; v += a·dt`(**先算位置后更新速度**,这样 dt=3 一步严格等于 dt=1 三步)。做对之后,本地与权威的残差**只应来自反弹 / 限速这类离散事件**,且有界。
|
|
361
|
+
4. **阈值只在前三条都做对之后才有意义。** 阈值是**死区**,用来吸收离散事件带来的那点有界残差(第 3 条尾),**不是用来吸收系统误差**的。前三条没做对时,阈值调大只是「飘得慢一点」、调小只是「抖得勤一点」,都治不了根——先把外推、时钟、同源做对,阈值才是在做它该做的事。
|
|
362
|
+
|
|
363
|
+
**术语澄清(别把两件事混成一件)**:本节「## 3D 位姿与朝向同步」看不到,但 `OverviewKnowledge.md` 射击降级那行写的**「不做延迟补偿」,指的是「服务端回溯历史帧、还原『打中那一刻』」**——那条结论不变、依然正确(DS 确实不回溯历史帧)。它和形态 C 要做的**「客户端把权威态外推到当前时刻」是完全不同的两件事**:前者是服务端的历史重建(不做),后者是客户端的当下推算(连续运动玩法**必做**)。别因为「不做延迟补偿」就以为「权威态到了直接拿原始值比就行」——那正是第 1 条禁止的。
|
|
364
|
+
|
|
365
|
+
- 插值 / 预测 / 回滚(含形态 C 的本地模拟与纠偏)由**玩法层**做,**不进 `MultiplayerManager` 模板**(模板只收发 `unknown`;模板暴露的 `getServerNow()`/`getClockOffset()` 是**时钟测量设施**、不是纠偏本身,辨析见 `../Subsystems/Optional/MultiplayerManagerKnowledge.md`)。形态 A 的位置 `lerp` + 朝向 `slerp` 完整方法论见 `../3D/PoseInterpolationKnowledge.md`。
|
|
366
|
+
|
|
367
|
+
### 三、权威态与 2D 完全相同——DS 不感知维度
|
|
368
|
+
|
|
369
|
+
- 阶段 / 命中 / 得分 / 胜负 / 行动权仍走 **state 根字段 + DS 裁决**,判定逻辑和 2D 一字不差。
|
|
370
|
+
- **不要在 DS 里算三维碰撞 / 物理**:DS 只有标准库、无三方物理库。需要防作弊时对结果做**最小可验证约束**(位移距离上限、速度上限、目标可达性),把风险边界写进架构文档,而不是在 DS 复刻一套三维物理。
|
|
371
|
+
|
|
372
|
+
### 四、包体预算复核
|
|
373
|
+
|
|
374
|
+
- 位置 3 数 + 四元数 4 数,一个物体约 60~80 字节 JSON;4KB 单包可装几十个物体。
|
|
375
|
+
- 超限的正解仍是**砍精度 / 砍字段 / 降频 / 只发关键物体**,**不是拆包**(拆包不解决单个逻辑状态过大,还会被 code 1009 断连)。**注意此节讨论的是上行连续态的 4KB 预算;下行不受此限,不要为下行做这类取舍或拦截(见「频率与包体」节)。**
|
|
376
|
+
|
|
377
|
+
#### 逼近 4KB 的取舍顺序(多实体压包)
|
|
378
|
+
|
|
379
|
+
几十个动态实体同时上行时,单包会逼近 4KB 上限。**按下面顺序逐级降**,每一步都先保「权威裁决 + 对局可玩性」,最后才动实体数:
|
|
380
|
+
|
|
381
|
+
1. **先降上报频率**:20Hz → 10Hz。减一半包量,代价是收端插值更远、稍显迟钝,但最不伤对局。**首选。**
|
|
382
|
+
2. **再减字段**:静止/不动的物体**不发朝向**(四元数可省 20+ 字节/个);无移动/无速度的帧只发位置。**掉的都是次要维度,不伤权威。**
|
|
383
|
+
3. **再降精度**:位置两位小数 → 一位小数(省几字节/数);四元数三位 → 两位。**牺牲平滑度换空间。**
|
|
384
|
+
4. **最后只发关键实体**:玩家必发;次要装饰/非关键道具降到低频(如 2~5Hz)或只发事件不发连续态。**这是最后手段。**
|
|
385
|
+
|
|
386
|
+
**AOI**(只同步视野附近物体)是更大规模的正解,但**第一版红线外、不做**——见下一小节。第一版一律「全房全量同步」,靠上面 1→4 把实体数压到几十个以内。
|
|
387
|
+
|
|
388
|
+
#### 算例:十几个实体怎么压
|
|
389
|
+
|
|
390
|
+
单个实体的连续态字节估算(位置 + 四元数):
|
|
391
|
+
|
|
392
|
+
- 位置 `{x,y,z}` 各取 2 位小数:约 `6*4 + 6` ≈ 30 字节
|
|
393
|
+
- 四元数 `{qx,qy,qz,qw}` 取 3 位小数:约 `4*6 + 6` ≈ 34 字节
|
|
394
|
+
- 合计约 **64 字节/实体**(含 JSON 键名与逗号)
|
|
395
|
+
|
|
396
|
+
4KB = 4096 字节。纯连续态可装 **~64 个实体**。但**根字段 + 事件 + 状态开销都会挤占同一个 4KB 上行包**,实际可用的连续态实体数更少——**十几个角色 + 若干道具已逼近上沿**,这正是需求案场景四「压 4KB 顶端」的由来。
|
|
397
|
+
|
|
398
|
+
**触顶怎么砍(举例)**:若 10 个角色 + 15 个道具同时 20Hz 上行,算下来超 4096 字节,按上面顺序:
|
|
399
|
+
|
|
400
|
+
- ① 降到 10Hz → 包量减半,仍全实体(若仍超继续)→
|
|
401
|
+
- ② 静止道具不发朝向(省 ~24 字节/个 × 15)→(若仍超继续)→
|
|
402
|
+
- ③ 位置降 1 位小数、四元数降 2 位 →(若仍超继续)→
|
|
403
|
+
- ④ 把非关键装饰物降到 5Hz、只发位置,玩家保持 20Hz 全字段。
|
|
404
|
+
|
|
405
|
+
> 每一步都能还原单包大小;**不必等到超限才砍**,项目契约记录格式里就应写清「该玩法预计实体数 × 频率 × 每实体字节」的预算,上线前先在文档层面算一遍。
|
|
406
|
+
|
|
407
|
+
### 五、AOI(兴趣区域)——3D / 大世界新增判断点
|
|
408
|
+
|
|
409
|
+
- 3D 大场景里,远处物体没必要收全量 pose:可按距离**降频**或**不同步**。2D 小屏一般没有这个问题,属 3D 才需要额外判断的一层。
|
|
410
|
+
- **第一版红线外:不做 AOI**。第一版一律「全房全量同步、几十个实体封顶」,实体数靠上一节的取舍顺序压到上限以内;AOI 只作为超规模时的扩展方向记录在案,不在第一版实现。规模 / 形态明确后评估,不抢先做距离分区。
|
|
411
|
+
|
|
412
|
+
## 完成检查
|
|
413
|
+
|
|
414
|
+
- 全房唯一事实只有一个 DS owner,不依赖多客户端各自推演后“碰巧一致”。
|
|
415
|
+
- 必须恢复的数据不只存在于历史 `evt`。
|
|
416
|
+
- 客户端只提交意图或自身连续态,DS 不信任自报结果和身份。
|
|
417
|
+
- 抢唯一资源用 DS 侧 CAS(期望值匹配才写),迟到请求自然失败。
|
|
418
|
+
- 每个消息都能解释发送者、接收者、迟到、重复、断线和后加入行为。
|
|
419
|
+
- **上行**包体按字节受控(4KB 上限只卡上行),连续态频率不超过 20Hz;**下行不受 4KB 限制,未在任何下行发送路径上做体积拦截 / 裸 `return` 静默丢包**。
|
|
420
|
+
- 3D pose 带 z + 四元数;收端做 lerp/slerp;权威裁决未因 3D 而改动,DS 未算三维物理。
|
|
421
|
+
- **表现层与同步频率解耦**(有连续运动实体时必查):表现层每帧更新的数据,是否只在收到同步消息时才变化?**是则不合格**——收端必须按渲染帧插值 / 逐步消费。此条 2D3D 同判,不因维度豁免。
|
|
422
|
+
- **无「一次调用连跑多步再渲染」**:是否存在收到一帧就在同一次调用里连续执行多个模拟步、再整体替换 state 的路径?**有则不合格**——N 步入队、按固定步长逐步消费,队列空时保持当前状态不外推。
|
|
423
|
+
- **本地模拟 + 快照纠偏(形态 C)四问**:① 阈值比较前,是否先把权威态**按快照年龄外推到当前时刻**(凡「阈值判断(快照字段 − 本地当前字段)」中间无按时间推进的步骤 = 不合格)?② 外推所用的 age 是否来自**标定过的时钟**(`getServerNow() − snap.t`),而不是到达时刻?③ 外推公式 / 本地模拟 / DS 模拟**三处积分是否同源**(统一固定步长或统一闭式 `pos += v·dt + 0.5·a·dt²`)?④ 阈值是否只在前三条做对后才用来吸收离散事件残差(而非拿它掩盖系统漂移)?
|
|
424
|
+
- 私密态不进根字段、走 `client.send` 定向;DS 内存保有并在 `onJoin` 对后进房/重连补发。
|
|
425
|
+
- 重连保席位靠根字段席位表 + `onJoin` 用 `player_id` 认领旧 slot;与禁用 `allowReconnection` 分工明确。
|
|
426
|
+
- 阶段/行动者/回合序号在根字段、DS 单点迁移;倒计时从 DS 时间戳派生,客户端只读只发意图。
|
|
427
|
+
- **上行**连续态接近 4KB 时按「降频 → 减字段 → 降精度 → 只发关键实体」取舍,不拆包;AOI 属第一版红线外不做。(4KB 只约束上行,下行无此上限、不做此取舍。)
|
|
428
|
+
- 回放/历史不在状态同步里:根字段只保当前值;DS 日志局末落云存储、前端读日志重演,未用同步通道存历史。
|
|
429
|
+
- **可机检**:`ds/` 全文 grep 不到 `this.state.<字段>[` 形式的下标访问;所有 **MapSchema / ArraySchema** 容器走 `.set/.get/.has/.delete/.forEach`(JS 原生 `Map`、JSON 解析出的普通对象不受此限,只查 `state.` 开的容器字段)。每个 state 根字段都能说出它是**标量还是容器**,以及**客户端从哪个收口拿到它**。
|
|
430
|
+
- 客户端与 `ds/` 的字段和消息名逐项一致,但没有跨目录 import。
|