vibes-plug 2.11.0 → 3.9.0
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/.claude/rules/vibes-plug-core.md +5 -0
- package/.cursor/rules/vibes-plug-core.mdc +8 -3
- package/.cursorrules +9 -3
- package/AGENTS.md +25 -4
- package/CHANGELOG.md +151 -0
- package/CLAUDE.md +15 -8
- package/README.md +216 -641
- package/bin/vibes.mjs +1104 -0
- package/index.js +1 -1
- package/package.json +11 -3
- package/plugin.json +4 -3
- package/scripts/check-anti-slop.js +53 -0
- package/scripts/check-anti-slop.mjs +53 -0
- package/scripts/generate_swarm_gif.py +2 -2
- package/scripts/install.js +3 -1
- package/scripts/update_skills.js +1 -1
- package/scripts/update_skills.mjs +86 -0
- package/scripts/validate-skills.mjs +111 -0
- package/skills/accessibility-testing-expert/SKILL.md +117 -116
- package/skills/affective-computing-emotion-ai/SKILL.md +83 -0
- package/skills/agentic-coding-workflow-expert/SKILL.md +297 -0
- package/skills/agentic-memory-architect/SKILL.md +52 -0
- package/skills/agentic-micro-economy-architect/SKILL.md +92 -0
- package/skills/ai-llm-integration-expert/SKILL.md +330 -187
- package/skills/ai-media-generation-expert/SKILL.md +173 -172
- package/skills/ai-prompt-engineering-expert/SKILL.md +170 -50
- package/skills/ai-safety-governance-expert/SKILL.md +223 -0
- package/skills/angular-expert/SKILL.md +149 -148
- package/skills/anti-slop/SKILL.md +134 -0
- package/skills/api-design-expert/SKILL.md +4 -3
- package/skills/api-gateway-proxy-expert/SKILL.md +3 -2
- package/skills/app-analyzer-optimizer/SKILL.md +4 -3
- package/skills/apple-ecosystem-expert/SKILL.md +6 -5
- package/skills/astro-framework-expert/SKILL.md +201 -200
- package/skills/async-queue-temporal-expert/SKILL.md +218 -240
- package/skills/authentication-identity-expert/SKILL.md +79 -184
- package/skills/autonomous-red-teamer/SKILL.md +338 -203
- package/skills/autonomous-tdd-debugger/SKILL.md +6 -5
- package/skills/biome-linter-formatter-expert/SKILL.md +90 -89
- package/skills/blockchain-web3-expert/SKILL.md +116 -115
- package/skills/brainstorming/SKILL.md +392 -377
- package/skills/browser-automation-expert/SKILL.md +260 -222
- package/skills/bun-runtime-expert/SKILL.md +5 -4
- package/skills/chatbot-messaging-expert/SKILL.md +115 -114
- package/skills/ci-cd-devops-architect/SKILL.md +3 -2
- package/skills/cloud-hosting-expert/SKILL.md +5 -4
- package/skills/coderabbit/SKILL.md +5 -4
- package/skills/compliance-gdpr-privacy-expert/SKILL.md +3 -2
- package/skills/composable-mach-architect/SKILL.md +338 -0
- package/skills/cron-scheduler-expert/SKILL.md +5 -4
- package/skills/data-pipeline-etl-expert/SKILL.md +3 -2
- package/skills/data-telemetry-expert/SKILL.md +5 -4
- package/skills/data-visualization-expert/SKILL.md +155 -154
- package/skills/database-orm-expert/SKILL.md +102 -240
- package/skills/deep-research-analyst/SKILL.md +182 -0
- package/skills/dependency-upgrade-migrator/SKILL.md +11 -10
- package/skills/design-system-architect/SKILL.md +34 -3
- package/skills/desktop-electron-expert/SKILL.md +129 -128
- package/skills/documentation-site-expert/SKILL.md +60 -59
- package/skills/doku-mcp-server/SKILL.md +5 -4
- package/skills/doku-payment-gateway/SKILL.md +250 -232
- package/skills/domain-driven-design-expert/SKILL.md +3 -2
- package/skills/e2e-testing-expert/SKILL.md +5 -4
- package/skills/ecommerce-expert/SKILL.md +88 -87
- package/skills/email-notification-expert/SKILL.md +35 -7
- package/skills/ephemeral-generative-ui-architect/SKILL.md +88 -0
- package/skills/error-resilience-expert/SKILL.md +26 -4
- package/skills/event-driven-architect/SKILL.md +5 -4
- package/skills/feature-flag-analytics-expert/SKILL.md +3 -2
- package/skills/file-upload-media-expert/SKILL.md +5 -4
- package/skills/firebase-security-expert/SKILL.md +5 -4
- package/skills/form-validation-expert/SKILL.md +7 -6
- package/skills/frontier-ai-models-expert/SKILL.md +116 -0
- package/skills/fullstack-expert/SKILL.md +68 -144
- package/skills/gemini-agent-booster/SKILL.md +248 -172
- package/skills/geospatial-maps-expert/SKILL.md +81 -80
- package/skills/global-a11y-i18n-expert/SKILL.md +5 -4
- package/skills/glsl-shader-expert/SKILL.md +155 -71
- package/skills/go-programming-expert/SKILL.md +5 -4
- package/skills/graph-rag-knowledge-expert/SKILL.md +201 -159
- package/skills/graphql-apollo-expert/SKILL.md +5 -4
- package/skills/headless-cms-expert/SKILL.md +182 -181
- package/skills/hig/SKILL.md +5 -4
- package/skills/js-backend-expert/SKILL.md +219 -218
- package/skills/legacy-code-translator/SKILL.md +6 -5
- package/skills/llm-finops-router/SKILL.md +52 -0
- package/skills/local-slm-edge-ai-expert/SKILL.md +168 -167
- package/skills/logging-error-tracking-expert/SKILL.md +5 -4
- package/skills/mcp-server-architect/SKILL.md +316 -294
- package/skills/micro-frontend-architect/SKILL.md +5 -4
- package/skills/mobile-expo-expert/SKILL.md +5 -4
- package/skills/modern-css-native-expert/SKILL.md +190 -189
- package/skills/monorepo-architect/SKILL.md +5 -4
- package/skills/mpa-orchestrator/SKILL.md +41 -4
- package/skills/multi-agent-orchestration/SKILL.md +388 -254
- package/skills/mvc-expert/SKILL.md +5 -4
- package/skills/n8n-automation-expert/SKILL.md +90 -89
- package/skills/nextjs-app-router-expert/SKILL.md +3 -2
- package/skills/openapi-swagger-codegen-expert/SKILL.md +4 -3
- package/skills/payment-gateway-expert/SKILL.md +131 -128
- package/skills/pdf-document-generation-expert/SKILL.md +92 -91
- package/skills/performance-web-vitals/SKILL.md +5 -4
- package/skills/post-quantum-crypto-migrator/SKILL.md +3 -2
- package/skills/prd-architect/SKILL.md +85 -109
- package/skills/proactive-background-watcher/SKILL.md +5 -4
- package/skills/production-ready-hardener/SKILL.md +25 -27
- package/skills/pwa-offline-first-expert/SKILL.md +227 -185
- package/skills/pydantic-ai-expert/SKILL.md +162 -0
- package/skills/python-programming-expert/SKILL.md +5 -4
- package/skills/rate-limit-abuse-prevention/SKILL.md +5 -4
- package/skills/realtime-collaboration-expert/SKILL.md +3 -2
- package/skills/rich-text-editor-expert/SKILL.md +178 -177
- package/skills/rust-programming-expert/SKILL.md +5 -4
- package/skills/saas-architect/SKILL.md +155 -0
- package/skills/saas-billing/SKILL.md +394 -382
- package/skills/saas-multi-tenant/SKILL.md +7 -6
- package/skills/scalability-clean-code/SKILL.md +5 -4
- package/skills/search-engine-expert/SKILL.md +90 -89
- package/skills/self-healing-cloud-orchestrator/SKILL.md +3 -2
- package/skills/senior-frontend/SKILL.md +21 -18
- package/skills/senior-frontend/scripts/frontend_scaffolder.py +1 -1
- package/skills/seo/SKILL.md +4 -4
- package/skills/session-memory-manager/SKILL.md +129 -0
- package/skills/solidjs-expert/SKILL.md +81 -80
- package/skills/spa-orchestrator/SKILL.md +5 -4
- package/skills/sse-websocket-streaming-expert/SKILL.md +3 -2
- package/skills/state-management-expert/SKILL.md +5 -4
- package/skills/supabase-security-expert/SKILL.md +5 -4
- package/skills/svelte-sveltekit-expert/SKILL.md +92 -91
- package/skills/svg-animation-motion-expert/SKILL.md +3 -2
- package/skills/synthetic-data-finetuning-expert/SKILL.md +156 -0
- package/skills/tailwind-expert/SKILL.md +62 -5
- package/skills/tanstack-query-expert/SKILL.md +5 -4
- package/skills/tauri-expert/SKILL.md +5 -4
- package/skills/typescript-expert/SKILL.md +5 -4
- package/skills/ui-ux-pro-max/SKILL.md +7 -4
- package/skills/vector-db-rag-expert/SKILL.md +209 -208
- package/skills/vercel-ai-sdk-expert/SKILL.md +226 -0
- package/skills/voice-ai-realtime-agent/SKILL.md +243 -202
- package/skills/vue-frontend-expert/SKILL.md +5 -4
- package/skills/wasm-edge-computing-expert/SKILL.md +3 -2
- package/skills/web-3d-graphics-expert/SKILL.md +259 -82
- package/skills/web-game-engine-expert/SKILL.md +278 -50
- package/skills/web-scraper/SKILL.md +158 -157
- package/skills/website-design-cloner/SKILL.md +5 -4
- package/skills/webxr-ar-vr-expert/SKILL.md +105 -65
- package/skills/wordpress-headless-expert/SKILL.md +145 -144
- package/skills/zero-tech-debt-auditor/SKILL.md +115 -0
- package/skills/zero-to-prod-orchestrator/SKILL.md +281 -227
- package/skills/zero-trust-secret-vault/SKILL.md +3 -2
- package/BLUEPRINT.md +0 -309
- package/skills/ai-cost-token-optimizer/SKILL.md +0 -82
- package/skills/ai-evals-benchmark-expert/SKILL.md +0 -188
- package/skills/asisten-ramah/SKILL.md +0 -47
- package/skills/auto-doc-updater/SKILL.md +0 -220
- package/skills/autonomous-chaos-monkey/SKILL.md +0 -63
- package/skills/background-jobs-queue-expert/SKILL.md +0 -235
- package/skills/bootstrap-to-modern/SKILL.md +0 -94
- package/skills/database-migration-versioning-expert/SKILL.md +0 -90
- package/skills/edge-serverless-db-expert/SKILL.md +0 -99
- package/skills/mcp-client-orchestrator/SKILL.md +0 -76
- package/skills/mobile-push-notification-expert/SKILL.md +0 -71
- package/skills/monday-design-aesthetic/SKILL.md +0 -73
- package/skills/multiple-entry-points/SKILL.md +0 -91
- package/skills/project-context-mapper/SKILL.md +0 -85
- package/skills/saas-mvp-launcher/SKILL.md +0 -260
- package/skills/saas-transformer/SKILL.md +0 -500
- package/skills/saas-transformer/references/billing_integration_guide.md +0 -401
- package/skills/secure-fuzz-testing/SKILL.md +0 -207
- package/skills/self-evolving-memory-graph/SKILL.md +0 -91
- package/skills/session-context-loader/SKILL.md +0 -83
- package/skills/session-handoff-resume/SKILL.md +0 -164
- package/skills/skill-baru/SKILL.md +0 -178
- package/skills/supabase-migration/SKILL.md +0 -91
- package/skills/token-saver/SKILL.md +0 -119
- package/skills/ui-components-expert/SKILL.md +0 -166
- package/skills/vibe-code-gardener/SKILL.md +0 -181
- package/skills/visual-qa-vision-agent/SKILL.md +0 -71
- /package/skills/{saas-transformer → saas-architect}/references/feature_gating_patterns.md +0 -0
- /package/skills/{saas-transformer → saas-architect}/references/saas_transformation_checklist.md +0 -0
- /package/skills/{saas-transformer → saas-architect}/scripts/saas_transformation_scanner.py +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: web-game-engine-expert
|
|
3
|
-
description: "Expert guide for web-based game development. Covers
|
|
4
|
-
author: "
|
|
3
|
+
description: "Expert guide for modern web-based game development. Covers PlayCanvas, Babylon.js Havok, Three.js/R3F Rapier & Jolt Physics, Fixed-Timestep Accumulators, Zero-GC Pooling, ECS (bitECS/Miniplex), Spatial Audio (HRTF), and WebTransport networking / Panduan ahli pengembangan game web modern dan efisien."
|
|
4
|
+
author: "vibes-plug-swarm"
|
|
5
|
+
version: "3.0.0"
|
|
5
6
|
---
|
|
6
7
|
|
|
7
|
-
# Web Game Engine Expert (Physics &
|
|
8
|
+
# Web Game Engine Expert (Physics, Architecture & Game Loops)
|
|
8
9
|
|
|
9
10
|
[English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
|
|
10
11
|
|
|
@@ -14,72 +15,262 @@ author: "Roedy Rustam"
|
|
|
14
15
|
## English
|
|
15
16
|
|
|
16
17
|
### Orchestration & Integration
|
|
17
|
-
Connects and orchestrates with relevant domain skills
|
|
18
|
+
Connects and orchestrates with relevant domain skills:
|
|
19
|
+
- `web-3d-graphics-expert` — Visual rendering layer (WebGPU, Three.js, Babylon.js, PlayCanvas).
|
|
20
|
+
- `glsl-shader-expert` — Custom gameplay shaders, damage flashes, VFX materials.
|
|
21
|
+
- `webxr-ar-vr-expert` — Spatial controls and VR/AR controller tracking.
|
|
22
|
+
- `realtime-collaboration-expert` — Low-latency multiplayer state synchronization (WebRTC / WebTransport).
|
|
23
|
+
- `performance-web-vitals` — Frame budgeting (16.6ms for 60fps, 8.3ms for 120fps) and eliminating Garbage Collection stalls.
|
|
24
|
+
- `wasm-edge-computing-expert` — Compiling custom Rust/C++ simulation modules to WASM.
|
|
18
25
|
|
|
19
26
|
### Description
|
|
20
|
-
Production-grade guidance for
|
|
27
|
+
Production-grade guidance for engineering commercial-quality 2D and 3D web games running at steady 60 to 144+ FPS. Enforces strict game architectural patterns: **Fixed-Timestep Accumulators with render interpolation**, **WebAssembly Physics Engines** (Rapier 3D, Jolt Physics, Havok), **Zero-GC Object Pooling** to eliminate JavaScript garbage collection stutters, **Entity Component System (ECS)** architectures, **Web Audio API 3D Spatial Sound (HRTF)**, and **WebTransport / WebRTC low-latency netcode**.
|
|
21
28
|
|
|
22
29
|
### Trigger Conditions
|
|
23
30
|
Activate this skill when the user is:
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
31
|
+
- Developing a web-based game or physics simulation (2D or 3D).
|
|
32
|
+
- Integrating physics with `@dimforge/rapier3d`, `jolt-physics`, `@babylonjs/havok`, or `@react-three/rapier`.
|
|
33
|
+
- Building or refactoring a game loop to fix frame pacing or physics stuttering on 120Hz/144Hz monitors.
|
|
34
|
+
- Implementing an Entity Component System (ECS) with `bitECS` or `miniplex`.
|
|
35
|
+
- Designing zero-allocation object pools for projectiles, particles, or temporary math vectors.
|
|
36
|
+
- Adding Gamepad API, Pointer Lock mouse look, or mobile virtual touch controls.
|
|
37
|
+
- Integrating 3D positional audio via the Web Audio API.
|
|
38
|
+
- Architecting multiplayer game networking with WebTransport (QUIC datagrams) or WebRTC DataChannels.
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
### Modern Web Game Engine Landscape (2026)
|
|
43
|
+
|
|
44
|
+
| Engine / Stack | Dimension | Physics Backend | Key Strengths |
|
|
45
|
+
| :--- | :--- | :--- | :--- |
|
|
46
|
+
| **PlayCanvas Engine** | 3D | Ammo.js / Rapier WASM | Complete production game engine, tiny runtime (~200KB), mobile-first 60fps, built-in sound & input. |
|
|
47
|
+
| **Babylon.js + Havok** | 3D | Havok Physics WASM | AAA physics simulation, native sub-stepping, character controllers, convex decomposition. |
|
|
48
|
+
| **Three.js / R3F + Rapier / Jolt** | 3D | Rapier 3D (Rust) / Jolt (C++) | Modular, massive ecosystem, best for React/Vue indie games and procedural worlds. |
|
|
49
|
+
| **LittleJS** | 2D | Built-in lightweight physics | Micro-size (<50KB), hyper-fast hybrid WebGL/2D canvas, ideal for 2D platformers & game jams. |
|
|
50
|
+
| **PixiJS v8** | 2D | Matter.js / Rapier 2D | Next-gen WebGPU 2D rendering pipeline, thousands of animated sprites at 144 FPS. |
|
|
51
|
+
| **Needle Engine** | 3D | PhysX / Rapier | Export directly from Unity/Blender into Three.js with full component lifecycles. |
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### 1. The Deterministic Game Loop: Fixed-Timestep Accumulator
|
|
56
|
+
|
|
57
|
+
> **CRITICAL RULE**: Never tie physics updates directly to `requestAnimationFrame` delta time. A variable delta causes non-deterministic physics, tunneling, and jitter on 120Hz/144Hz monitors.
|
|
58
|
+
- **Solution:** Accumulate frame time and step physics at a fixed tick rate (e.g., 60Hz). Calculate `alpha` to interpolate render transforms smoothly between the previous and current physics state.
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
export class GameLoop {
|
|
62
|
+
private accumulator = 0;
|
|
63
|
+
private lastTime = performance.now();
|
|
64
|
+
private readonly FIXED_TIMESTEP = 1 / 60; // 60Hz fixed physics step
|
|
65
|
+
private readonly MAX_FRAME_TIME = 0.25; // Clamp to prevent "spiral of death" during lag
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
private updatePhysics: (dt: number) => void,
|
|
69
|
+
private render: (alpha: number) => void
|
|
70
|
+
) {}
|
|
71
|
+
|
|
72
|
+
public start() {
|
|
73
|
+
this.lastTime = performance.now();
|
|
74
|
+
requestAnimationFrame(this.tick);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private tick = (currentTime: number) => {
|
|
78
|
+
let frameTime = (currentTime - this.lastTime) / 1000;
|
|
79
|
+
this.lastTime = currentTime;
|
|
80
|
+
|
|
81
|
+
// Clamp huge lags (e.g., user changed browser tab)
|
|
82
|
+
if (frameTime > this.MAX_FRAME_TIME) {
|
|
83
|
+
frameTime = this.MAX_FRAME_TIME;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.accumulator += frameTime;
|
|
87
|
+
|
|
88
|
+
// Execute fixed updates
|
|
89
|
+
while (this.accumulator >= this.FIXED_TIMESTEP) {
|
|
90
|
+
this.updatePhysics(this.FIXED_TIMESTEP);
|
|
91
|
+
this.accumulator -= this.FIXED_TIMESTEP;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Alpha is the leftover fractional progress towards the next physics step [0.0, 1.0)
|
|
95
|
+
const alpha = this.accumulator / this.FIXED_TIMESTEP;
|
|
96
|
+
this.render(alpha);
|
|
30
97
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
98
|
+
requestAnimationFrame(this.tick);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
35
104
|
|
|
105
|
+
### 2. High-Performance WASM Physics: Rapier & Jolt
|
|
106
|
+
|
|
107
|
+
#### Option A: Rapier 3D (Rust + WASM + SIMD)
|
|
108
|
+
Lightweight, determinism-friendly, native support in React Three Fiber (`@react-three/rapier`):
|
|
36
109
|
```tsx
|
|
37
|
-
|
|
38
|
-
import { Physics, RigidBody } from '@react-three/rapier';
|
|
110
|
+
import { Physics, RigidBody, CuboidCollider } from '@react-three/rapier';
|
|
39
111
|
|
|
40
|
-
function
|
|
112
|
+
export function GamePhysicsWorld({ children }: { children: React.ReactNode }) {
|
|
41
113
|
return (
|
|
42
|
-
<Physics gravity={[0, -9.81, 0]}>
|
|
43
|
-
{/*
|
|
44
|
-
<RigidBody
|
|
114
|
+
<Physics gravity={[0, -9.81, 0]} timeStep="vary">
|
|
115
|
+
{/* Player Dynamic Capsule */}
|
|
116
|
+
<RigidBody position={[0, 2, 0]} enabledRotations={[false, false, false]} colliders="ball">
|
|
45
117
|
<mesh>
|
|
46
|
-
<
|
|
47
|
-
<meshStandardMaterial color="
|
|
118
|
+
<sphereGeometry args={[0.5]} />
|
|
119
|
+
<meshStandardMaterial color="dodgerblue" />
|
|
48
120
|
</mesh>
|
|
49
121
|
</RigidBody>
|
|
50
122
|
|
|
51
123
|
{/* Static Floor */}
|
|
52
|
-
<RigidBody type="fixed"
|
|
53
|
-
<
|
|
54
|
-
<boxGeometry args={[10, 1, 10]} />
|
|
55
|
-
<meshStandardMaterial color="gray" />
|
|
56
|
-
</mesh>
|
|
124
|
+
<RigidBody type="fixed">
|
|
125
|
+
<CuboidCollider args={[20, 0.5, 20]} position={[0, -0.5, 0]} />
|
|
57
126
|
</RigidBody>
|
|
127
|
+
|
|
128
|
+
{children}
|
|
58
129
|
</Physics>
|
|
59
130
|
);
|
|
60
131
|
}
|
|
61
132
|
```
|
|
62
133
|
|
|
63
|
-
####
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
134
|
+
#### Option B: Jolt Physics WASM (`jolt-physics`)
|
|
135
|
+
The AAA open-source physics engine used in titles like *Horizon Forbidden West*. Best for massive simulations (>2,000 rigid bodies) and advanced ragdolls in vanilla Three.js or Babylon.js.
|
|
136
|
+
|
|
137
|
+
> **Physics Best Practice**: ALWAYS use primitive colliders (`Sphere`, `Box`, `Capsule`) for moving dynamic bodies. NEVER use `Trimesh` (triangle mesh) for dynamic objects; `Trimesh` should only be used for static world terrain.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### 3. Zero-GC Memory Management & Object Pooling
|
|
142
|
+
|
|
143
|
+
> **CRITICAL RULE**: In games, memory allocation (`new Vector3()`, `new Bullet()`) inside the tick loop triggers V8 Garbage Collection (GC) pauses every few seconds, dropping frames from 60 to 45 FPS.
|
|
144
|
+
- **Scratch Object Reuse:** Create scratch variables once at module level.
|
|
145
|
+
```typescript
|
|
146
|
+
// BAD: Allocates a new vector every frame
|
|
147
|
+
const dir = new THREE.Vector3().subVectors(target, source).normalize();
|
|
148
|
+
|
|
149
|
+
// GOOD: Reuses module-level scratch vector
|
|
150
|
+
const _scratchVec = new THREE.Vector3();
|
|
151
|
+
_scratchVec.subVectors(target, source).normalize();
|
|
152
|
+
```
|
|
153
|
+
- **Generic Object Pool:**
|
|
154
|
+
```typescript
|
|
155
|
+
export class ObjectPool<T> {
|
|
156
|
+
private pool: T[] = [];
|
|
157
|
+
constructor(
|
|
158
|
+
private factory: () => T,
|
|
159
|
+
private reset: (item: T) => void,
|
|
160
|
+
initialSize = 50
|
|
161
|
+
) {
|
|
162
|
+
for (let i = 0; i < initialSize; i++) {
|
|
163
|
+
this.pool.push(this.factory());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public acquire(): T {
|
|
168
|
+
return this.pool.length > 0 ? this.pool.pop()! : this.factory();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public release(item: T): void {
|
|
172
|
+
this.reset(item);
|
|
173
|
+
this.pool.push(item);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 4. Input Management: Pointer Lock & Gamepad API
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// 1. First-Person / Third-Person Mouse Look
|
|
184
|
+
export function setupPointerLock(canvas: HTMLCanvasElement, onLook: (dx: number, dy: number) => void) {
|
|
185
|
+
canvas.addEventListener('click', () => {
|
|
186
|
+
if (document.pointerLockElement !== canvas) {
|
|
187
|
+
canvas.requestPointerLock();
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
window.addEventListener('mousemove', (e) => {
|
|
192
|
+
if (document.pointerLockElement === canvas) {
|
|
193
|
+
onLook(e.movementX, e.movementY);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 2. Gamepad API with Deadzone Normalization
|
|
199
|
+
export function pollGamepad(deadzone = 0.15) {
|
|
200
|
+
const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];
|
|
201
|
+
const gp = gamepads[0];
|
|
202
|
+
if (!gp) return null;
|
|
203
|
+
|
|
204
|
+
const filterAxis = (val: number) => (Math.abs(val) > deadzone ? val : 0);
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
moveX: filterAxis(gp.axes[0]),
|
|
208
|
+
moveY: filterAxis(gp.axes[1]),
|
|
209
|
+
lookX: filterAxis(gp.axes[2]),
|
|
210
|
+
lookY: filterAxis(gp.axes[3]),
|
|
211
|
+
buttonJump: gp.buttons[0]?.pressed ?? false,
|
|
212
|
+
buttonAction: gp.buttons[1]?.pressed ?? false
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### 5. 3D Spatial Positional Audio (Web Audio API)
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
export class SpatialAudioManager {
|
|
223
|
+
private ctx = new AudioContext();
|
|
224
|
+
private listener = this.ctx.listener;
|
|
225
|
+
|
|
226
|
+
public updateListenerPosition(pos: { x: number; y: number; z: number }, forward: { x: number; y: number; z: number }, up = { x: 0, y: 1, z: 0 }) {
|
|
227
|
+
if (this.listener.positionX) {
|
|
228
|
+
this.listener.positionX.value = pos.x;
|
|
229
|
+
this.listener.positionY.value = pos.y;
|
|
230
|
+
this.listener.positionZ.value = pos.z;
|
|
231
|
+
this.listener.forwardX.value = forward.x;
|
|
232
|
+
this.listener.forwardY.value = forward.y;
|
|
233
|
+
this.listener.forwardZ.value = forward.z;
|
|
234
|
+
this.listener.upX.value = up.x;
|
|
235
|
+
this.listener.upY.value = up.y;
|
|
236
|
+
this.listener.upZ.value = up.z;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public createSpatialSound(audioBuffer: AudioBuffer, pos: { x: number; y: number; z: number }) {
|
|
241
|
+
const source = this.ctx.createBufferSource();
|
|
242
|
+
source.buffer = audioBuffer;
|
|
67
243
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
244
|
+
const panner = this.ctx.createPanner();
|
|
245
|
+
panner.panningModel = 'HRTF'; // High-fidelity Head-Related Transfer Function
|
|
246
|
+
panner.distanceModel = 'inverse';
|
|
247
|
+
panner.refDistance = 1;
|
|
248
|
+
panner.maxDistance = 1000;
|
|
249
|
+
panner.rolloffFactor = 1;
|
|
250
|
+
panner.positionX.value = pos.x;
|
|
251
|
+
panner.positionY.value = pos.y;
|
|
252
|
+
panner.positionZ.value = pos.z;
|
|
253
|
+
|
|
254
|
+
source.connect(panner);
|
|
255
|
+
panner.connect(this.ctx.destination);
|
|
256
|
+
source.start();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
71
260
|
|
|
72
261
|
---
|
|
73
262
|
|
|
74
|
-
###
|
|
75
|
-
This skill works best when combined with:
|
|
76
|
-
- `web-3d-graphics-expert` — For the visual rendering of the physics world.
|
|
77
|
-
- `webxr-ar-vr-expert` — For adding grabbable physics objects in VR space.
|
|
78
|
-
- `realtime-collaboration-expert` — For synchronizing physics state across multiple players using WebRTC.
|
|
263
|
+
### 6. Modern Multiplayer Networking: WebTransport vs WebRTC
|
|
79
264
|
|
|
80
|
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
265
|
+
For fast-paced real-time action games:
|
|
266
|
+
- **Avoid WebSockets for player movement:** WebSockets use TCP. When a packet is lost, TCP pauses delivery of all subsequent packets (Head-of-Line blocking), causing massive lag spikes.
|
|
267
|
+
- **Use WebTransport (QUIC) or WebRTC DataChannels:**
|
|
268
|
+
- Unreliable, unordered datagrams for continuous movement updates (`x, y, z, vx, vy, vz`).
|
|
269
|
+
- Reliable streams for critical state transitions (damage, weapon fire, chat, player joined).
|
|
270
|
+
- **Client-Side Prediction & Reconciliation:**
|
|
271
|
+
1. Client immediately simulates movement locally upon keypress and stores input history with tick numbers.
|
|
272
|
+
2. Server processes input at fixed 20Hz-60Hz and replies with authoritative position.
|
|
273
|
+
3. Client reconciles authoritative state and replays unacknowledged inputs to avoid input lag.
|
|
83
274
|
|
|
84
275
|
---
|
|
85
276
|
|
|
@@ -87,16 +278,53 @@ This skill works best when combined with:
|
|
|
87
278
|
## Bahasa Indonesia
|
|
88
279
|
|
|
89
280
|
### Integrasi Orkestrasi
|
|
90
|
-
Terhubung dan mengorkestrasi skill domain yang relevan
|
|
281
|
+
Terhubung dan mengorkestrasi skill domain yang relevan:
|
|
282
|
+
- `web-3d-graphics-expert` — Lapisan visual rendering (WebGPU, Three.js, Babylon.js, PlayCanvas).
|
|
283
|
+
- `glsl-shader-expert` — Shader kustom untuk efek visual, kilatan luka, dan partikel game.
|
|
284
|
+
- `webxr-ar-vr-expert` — Kontrol spasial dan pelacakan kontroler VR/AR.
|
|
285
|
+
- `realtime-collaboration-expert` — Sinkronisasi state multiplayer real-time (WebRTC / WebTransport).
|
|
286
|
+
- `performance-web-vitals` — Manajemen frame budget (16.6ms untuk 60fps) dan pencegahan Garbage Collection stall.
|
|
287
|
+
- `wasm-edge-computing-expert` — Kompilasi modul simulasi C++/Rust kustom ke WebAssembly.
|
|
91
288
|
|
|
92
289
|
### Deskripsi
|
|
93
|
-
Panduan
|
|
290
|
+
Panduan produksi untuk merekayasa game web komersial 2D dan 3D dengan target stabil di 60 hingga 144+ FPS. Menerapkan arsitektur game modern: **Fixed-Timestep Accumulator dengan interpolasi render**, **Physics Engine berbasis WebAssembly** (Rapier 3D, Jolt Physics, Havok), **Zero-GC Object Pooling** untuk mencegah lonjakan Garbage Collector JavaScript, arsitektur **ECS (Entity Component System)**, **Audio Spasial 3D Web Audio API (HRTF)**, dan **Netcode WebTransport / WebRTC berlatensi rendah**.
|
|
94
291
|
|
|
95
292
|
### Kondisi Pemicu
|
|
96
|
-
|
|
97
|
-
-
|
|
293
|
+
Aktifkan skill ini ketika pengguna:
|
|
294
|
+
- Membangun game web atau simulasi fisika (2D maupun 3D).
|
|
295
|
+
- Mengintegrasikan mesin fisika `@dimforge/rapier3d`, `jolt-physics`, `@babylonjs/havok`, atau `@react-three/rapier`.
|
|
296
|
+
- Memperbaiki ketidakteraturan fisika atau *stuttering* pada monitor 120Hz/144Hz.
|
|
297
|
+
- Mengimplementasikan ECS (*Entity Component System*) dengan `bitECS` atau `miniplex`.
|
|
298
|
+
- Mendesain *Object Pool* tanpa alokasi memori berulang untuk proyektil, peluru, atau partikel.
|
|
299
|
+
- Mengintegrasikan kontrol Gamepad API, Pointer Lock (mouse look), atau kontrol sentuh virtual mobile.
|
|
300
|
+
- Menambahkan audio spasial 3D menggunakan Web Audio API.
|
|
301
|
+
- Merancang arsitektur multiplayer real-time menggunakan WebTransport atau WebRTC.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
### Prinsip Inti Rekayasa Game Web
|
|
306
|
+
|
|
307
|
+
1. **Fixed-Timestep Accumulator Loop (Wajib)**:
|
|
308
|
+
- Jangan pernah menjalankan komputasi fisika langsung pada delta waktu `requestAnimationFrame`. Perubahan refresh rate monitor (60Hz, 120Hz, 144Hz) akan merusak konsistensi fisika.
|
|
309
|
+
- Akumulasikan waktu frame dan jalankan langkah fisika pada tick tetap (misal 60Hz), lalu hitung `alpha` untuk menginterpolasikan posisi render grafis secara mulus.
|
|
310
|
+
|
|
311
|
+
2. **Mesin Fisika WASM (Rapier / Jolt / Havok)**:
|
|
312
|
+
- Gunakan **Rapier 3D** (Rust WASM + SIMD) untuk Three.js/R3F.
|
|
313
|
+
- Gunakan **Jolt Physics** untuk simulasi skala besar ribuan objek dinamis.
|
|
314
|
+
- Gunakan **Havok** jika membangun di atas Babylon.js.
|
|
315
|
+
- Hindari penggunaan *mesh collider* (Trimesh) pada objek bergerak; selalu gunakan primitif (Bola, Kotak, Kapsul).
|
|
316
|
+
|
|
317
|
+
3. **Manajemen Memori Zero-GC**:
|
|
318
|
+
- Pembuatan objek baru (`new Vector3()`, objek peluru) setiap frame memicu *Garbage Collection* di browser yang menyebabkan frame drop berkala.
|
|
319
|
+
- Daur ulang objek menggunakan pola *Object Pooling* dan gunakan kembali variabel scratch statis.
|
|
320
|
+
|
|
321
|
+
4. **Kontrol Responsif**:
|
|
322
|
+
- Manfaatkan *Pointer Lock API* untuk kontrol kamera first-person / third-person dengan `movementX` dan `movementY`.
|
|
323
|
+
- Gunakan *Gamepad API* dengan deadzone filter untuk mendukung controller konsol (PlayStation, Xbox).
|
|
324
|
+
|
|
325
|
+
5. **Audio Spasial 3D (HRTF)**:
|
|
326
|
+
- Hubungkan *AudioListener* ke transformasi kamera, dan hubungkan suara ke *PannerNode* dengan model panning `'HRTF'` untuk audio 3 dimensi realistis berdasarkan jarak dan arah.
|
|
98
327
|
|
|
99
|
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
- **Pola ECS (Entity Component System):** Untuk game kompleks, pisahkan logika dan data menggunakan arsitektur ECS (seperti `miniplex` atau `bitECS`) untuk memaksimalkan performa *cache* memori.
|
|
328
|
+
6. **Netcode Modern (WebTransport)**:
|
|
329
|
+
- Jangan gunakan WebSocket (TCP) untuk posisi pergerakan pemain karena rentan terhadap *Head-of-Line blocking*.
|
|
330
|
+
- Gunakan **WebTransport** (datagram UDP over QUIC) atau WebRTC DataChannels disertai *Client-Side Prediction* dan *Server Reconciliation*.
|