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