vibes-plug 2.5.0 → 2.14.1

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 (187) hide show
  1. package/.claude/rules/vibes-plug-core.md +32 -0
  2. package/.cursor/rules/vibes-plug-core.mdc +51 -0
  3. package/.cursorrules +42 -0
  4. package/AGENTS.md +37 -7
  5. package/BLUEPRINT.md +319 -217
  6. package/CHANGELOG.md +170 -1
  7. package/CLAUDE.md +70 -0
  8. package/LICENSE +1 -1
  9. package/README.md +611 -415
  10. package/index.js +19 -0
  11. package/package.json +44 -8
  12. package/plugin.json +24 -7
  13. package/scripts/check-anti-slop.js +53 -0
  14. package/scripts/generate_swarm_gif.py +295 -0
  15. package/scripts/install.js +201 -0
  16. package/skills/accessibility-testing-expert/SKILL.md +116 -0
  17. package/skills/ai-llm-integration-expert/SKILL.md +192 -178
  18. package/skills/ai-media-generation-expert/SKILL.md +172 -0
  19. package/skills/ai-prompt-engineering-expert/SKILL.md +134 -0
  20. package/skills/angular-expert/SKILL.md +148 -0
  21. package/skills/anti-slop/SKILL.md +133 -0
  22. package/skills/api-design-expert/SKILL.md +6 -3
  23. package/skills/api-gateway-proxy-expert/SKILL.md +81 -0
  24. package/skills/app-analyzer-optimizer/SKILL.md +6 -3
  25. package/skills/apple-ecosystem-expert/SKILL.md +144 -141
  26. package/skills/astro-framework-expert/SKILL.md +200 -0
  27. package/skills/async-queue-temporal-expert/SKILL.md +189 -26
  28. package/skills/authentication-identity-expert/SKILL.md +78 -181
  29. package/skills/autonomous-red-teamer/SKILL.md +172 -28
  30. package/skills/autonomous-tdd-debugger/SKILL.md +70 -64
  31. package/skills/biome-linter-formatter-expert/SKILL.md +89 -0
  32. package/skills/blockchain-web3-expert/SKILL.md +115 -0
  33. package/skills/bootstrap-to-modern/SKILL.md +9 -6
  34. package/skills/brainstorming/SKILL.md +60 -52
  35. package/skills/browser-automation-expert/SKILL.md +197 -21
  36. package/skills/bun-runtime-expert/SKILL.md +7 -1
  37. package/skills/chatbot-messaging-expert/SKILL.md +114 -0
  38. package/skills/ci-cd-devops-architect/SKILL.md +45 -36
  39. package/skills/cloud-hosting-expert/SKILL.md +7 -1
  40. package/skills/coderabbit/SKILL.md +7 -1
  41. package/skills/compliance-gdpr-privacy-expert/SKILL.md +85 -0
  42. package/skills/cron-scheduler-expert/SKILL.md +303 -297
  43. package/skills/data-pipeline-etl-expert/SKILL.md +84 -0
  44. package/skills/data-telemetry-expert/SKILL.md +7 -1
  45. package/skills/data-visualization-expert/SKILL.md +154 -0
  46. package/skills/database-orm-expert/SKILL.md +165 -294
  47. package/skills/deep-research-analyst/SKILL.md +136 -0
  48. package/skills/dependency-upgrade-migrator/SKILL.md +300 -294
  49. package/skills/design-system-architect/SKILL.md +309 -260
  50. package/skills/desktop-electron-expert/SKILL.md +128 -0
  51. package/skills/documentation-site-expert/SKILL.md +59 -0
  52. package/skills/doku-mcp-server/SKILL.md +7 -1
  53. package/skills/doku-payment-gateway/SKILL.md +7 -1
  54. package/skills/domain-driven-design-expert/SKILL.md +82 -0
  55. package/skills/e2e-testing-expert/SKILL.md +7 -1
  56. package/skills/ecommerce-expert/SKILL.md +87 -0
  57. package/skills/email-notification-expert/SKILL.md +393 -360
  58. package/skills/error-resilience-expert/SKILL.md +506 -479
  59. package/skills/event-driven-architect/SKILL.md +7 -1
  60. package/skills/feature-flag-analytics-expert/SKILL.md +65 -45
  61. package/skills/file-upload-media-expert/SKILL.md +436 -430
  62. package/skills/firebase-security-expert/SKILL.md +7 -1
  63. package/skills/form-validation-expert/SKILL.md +406 -400
  64. package/skills/fullstack-expert/SKILL.md +184 -202
  65. package/skills/gemini-agent-booster/SKILL.md +173 -135
  66. package/skills/geospatial-maps-expert/SKILL.md +80 -0
  67. package/skills/global-a11y-i18n-expert/SKILL.md +7 -1
  68. package/skills/glsl-shader-expert/SKILL.md +158 -69
  69. package/skills/go-programming-expert/SKILL.md +21 -15
  70. package/skills/graph-rag-knowledge-expert/SKILL.md +200 -0
  71. package/skills/graphql-apollo-expert/SKILL.md +113 -107
  72. package/skills/headless-cms-expert/SKILL.md +181 -0
  73. package/skills/hig/SKILL.md +7 -1
  74. package/skills/js-backend-expert/SKILL.md +218 -216
  75. package/skills/legacy-code-translator/SKILL.md +70 -64
  76. package/skills/local-slm-edge-ai-expert/SKILL.md +167 -0
  77. package/skills/logging-error-tracking-expert/SKILL.md +343 -337
  78. package/skills/mcp-server-architect/SKILL.md +308 -194
  79. package/skills/micro-frontend-architect/SKILL.md +111 -105
  80. package/skills/mobile-expo-expert/SKILL.md +8 -2
  81. package/skills/modern-css-native-expert/SKILL.md +189 -0
  82. package/skills/monorepo-architect/SKILL.md +7 -1
  83. package/skills/mpa-orchestrator/SKILL.md +20 -1
  84. package/skills/multi-agent-orchestration/SKILL.md +254 -234
  85. package/skills/multiple-entry-points/SKILL.md +37 -1
  86. package/skills/mvc-expert/SKILL.md +7 -1
  87. package/skills/n8n-automation-expert/SKILL.md +89 -0
  88. package/skills/nextjs-app-router-expert/SKILL.md +148 -0
  89. package/skills/openapi-swagger-codegen-expert/SKILL.md +67 -0
  90. package/skills/payment-gateway-expert/SKILL.md +85 -1
  91. package/skills/pdf-document-generation-expert/SKILL.md +91 -0
  92. package/skills/performance-web-vitals/SKILL.md +7 -1
  93. package/skills/post-quantum-crypto-migrator/SKILL.md +57 -57
  94. package/skills/prd-architect/SKILL.md +182 -201
  95. package/skills/proactive-background-watcher/SKILL.md +67 -61
  96. package/skills/production-ready-hardener/SKILL.md +459 -456
  97. package/skills/pwa-offline-first-expert/SKILL.md +226 -0
  98. package/skills/pydantic-ai-expert/SKILL.md +161 -0
  99. package/skills/python-programming-expert/SKILL.md +407 -401
  100. package/skills/rate-limit-abuse-prevention/SKILL.md +376 -370
  101. package/skills/realtime-collaboration-expert/SKILL.md +55 -1
  102. package/skills/rich-text-editor-expert/SKILL.md +177 -0
  103. package/skills/rust-programming-expert/SKILL.md +7 -1
  104. package/skills/saas-architect/SKILL.md +154 -0
  105. package/skills/saas-billing/SKILL.md +7 -1
  106. package/skills/saas-multi-tenant/SKILL.md +7 -1
  107. package/skills/scalability-clean-code/SKILL.md +7 -1
  108. package/skills/search-engine-expert/SKILL.md +89 -0
  109. package/skills/secure-fuzz-testing/SKILL.md +7 -1
  110. package/skills/self-healing-cloud-orchestrator/SKILL.md +57 -57
  111. package/skills/senior-frontend/SKILL.md +139 -161
  112. package/skills/senior-frontend/scripts/frontend_scaffolder.py +1 -1
  113. package/skills/seo/SKILL.md +41 -17
  114. package/skills/session-memory-manager/SKILL.md +128 -0
  115. package/skills/solidjs-expert/SKILL.md +80 -0
  116. package/skills/spa-orchestrator/SKILL.md +20 -1
  117. package/skills/sse-websocket-streaming-expert/SKILL.md +93 -0
  118. package/skills/state-management-expert/SKILL.md +7 -1
  119. package/skills/supabase-security-expert/SKILL.md +7 -1
  120. package/skills/svelte-sveltekit-expert/SKILL.md +91 -0
  121. package/skills/svg-animation-motion-expert/SKILL.md +115 -0
  122. package/skills/synthetic-data-finetuning-expert/SKILL.md +155 -0
  123. package/skills/tailwind-expert/SKILL.md +88 -136
  124. package/skills/tanstack-query-expert/SKILL.md +7 -1
  125. package/skills/tauri-expert/SKILL.md +7 -1
  126. package/skills/typescript-expert/SKILL.md +12 -6
  127. package/skills/ui-ux-pro-max/SKILL.md +25 -3
  128. package/skills/vector-db-rag-expert/SKILL.md +175 -19
  129. package/skills/vercel-ai-sdk-expert/SKILL.md +181 -0
  130. package/skills/visual-qa-vision-agent/SKILL.md +70 -64
  131. package/skills/voice-ai-realtime-agent/SKILL.md +242 -0
  132. package/skills/vue-frontend-expert/SKILL.md +131 -125
  133. package/skills/wasm-edge-computing-expert/SKILL.md +97 -0
  134. package/skills/web-3d-graphics-expert/SKILL.md +262 -80
  135. package/skills/web-game-engine-expert/SKILL.md +281 -48
  136. package/skills/web-scraper/SKILL.md +157 -207
  137. package/skills/website-design-cloner/SKILL.md +179 -173
  138. package/skills/webxr-ar-vr-expert/SKILL.md +108 -63
  139. package/skills/wordpress-headless-expert/SKILL.md +144 -0
  140. package/skills/zero-to-prod-orchestrator/SKILL.md +65 -38
  141. package/skills/zero-trust-secret-vault/SKILL.md +87 -39
  142. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  143. package/.github/workflows/publish.yml +0 -20
  144. package/CONTRIBUTING.md +0 -199
  145. package/SECURITY.md +0 -21
  146. package/banner.png +0 -0
  147. package/skills/ai-cost-token-optimizer/SKILL.md +0 -52
  148. package/skills/asisten_ramah/SKILL.md +0 -41
  149. package/skills/auto-doc-updater/SKILL.md +0 -214
  150. package/skills/autonomous-chaos-monkey/SKILL.md +0 -63
  151. package/skills/autonomous-swarm-director/SKILL.md +0 -69
  152. package/skills/edge-serverless-db-expert/SKILL.md +0 -43
  153. package/skills/hyper-context-synthesizer/SKILL.md +0 -55
  154. package/skills/llm-cost-arbitrage-router/SKILL.md +0 -59
  155. package/skills/mcp-client-orchestrator/SKILL.md +0 -70
  156. package/skills/mobile-push-notification-expert/SKILL.md +0 -51
  157. package/skills/monday-design-aesthetic/SKILL.md +0 -67
  158. package/skills/project-context-mapper/SKILL.md +0 -79
  159. package/skills/saas-mvp-launcher/SKILL.md +0 -241
  160. package/skills/saas-transformer/SKILL.md +0 -489
  161. package/skills/saas-transformer/references/billing_integration_guide.md +0 -401
  162. package/skills/self-evolving-memory-graph/SKILL.md +0 -75
  163. package/skills/senior-fullstack/SKILL.md +0 -167
  164. package/skills/senior-fullstack/references/architecture_patterns.md +0 -160
  165. package/skills/senior-fullstack/references/development_workflows.md +0 -222
  166. package/skills/senior-fullstack/references/tech_stack_guide.md +0 -190
  167. package/skills/senior-fullstack/scripts/code_quality_analyzer.py +0 -114
  168. package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +0 -114
  169. package/skills/senior-fullstack/scripts/project_scaffolder.py +0 -114
  170. package/skills/seo-aeo-landing-page-writer/SKILL.md +0 -97
  171. package/skills/seo-geo/SKILL.md +0 -188
  172. package/skills/session-context-loader/SKILL.md +0 -77
  173. package/skills/session-handoff-resume/SKILL.md +0 -158
  174. package/skills/skill_baru/SKILL.md +0 -172
  175. package/skills/supabase-migration/SKILL.md +0 -45
  176. package/skills/token-saver/SKILL.md +0 -119
  177. package/skills/ui-components-expert/SKILL.md +0 -280
  178. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
  179. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  180. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
  181. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
  182. package/skills/ui_ux_expert/SKILL.md +0 -125
  183. package/skills/vibe-code-gardener/SKILL.md +0 -181
  184. package/vibes-swarm-demo.gif +0 -0
  185. /package/skills/{saas-transformer → saas-architect}/references/feature_gating_patterns.md +0 -0
  186. /package/skills/{saas-transformer → saas-architect}/references/saas_transformation_checklist.md +0 -0
  187. /package/skills/{saas-transformer → saas-architect}/scripts/saas_transformation_scanner.py +0 -0
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  name: web-game-engine-expert
3
- description: "Expert guide for web-based game development. Covers Entity Component System (ECS) architectures, physics engines (Rapier, Havok, Cannon-es), collision detection, and game loop optimization."
4
- author: "Roedy Rustam"
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
5
  ---
6
6
 
7
- # Web Game Engine Expert (Physics & ECS)
7
+ # Web Game Engine Expert (Physics, Architecture & Game Loops)
8
8
 
9
9
  [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
10
10
 
@@ -13,84 +13,317 @@ author: "Roedy Rustam"
13
13
  <a name="english"></a>
14
14
  ## English
15
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
+
16
25
  ### Description
17
- Production-grade guidance for building highly interactive 3D simulations and web games. Focuses on integrating modern WebAssembly-based **Physics Engines** (Havok, Rapier, Cannon-es) and structuring application state using the **Entity Component System (ECS)** pattern (e.g., bitECS, Miniplex).
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**.
18
27
 
19
28
  ### Trigger Conditions
20
29
  Activate this skill when the user is:
21
- - Adding physics (gravity, collisions, rigid bodies) to a 3D scene (Three.js/Babylon.js).
22
- - Dealing with performance issues in web games with thousands of objects.
23
- - Structuring a complex game or simulation architecture.
24
- - Using `@dimforge/rapier3d`, `havok`, or `cannon-es`.
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
25
55
 
26
- ### Core Concepts
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.
27
58
 
28
- #### 1. Physics Engine Integration
29
- Avoid calculating collisions manually in JavaScript. Use a dedicated physics engine.
30
- - **Babylon.js + Havok:** Babylon.js natively supports Havok Physics (the same engine used in AAA titles like Zelda BotW).
31
- - **Three.js / React Three Fiber + Rapier:** Use `@react-three/rapier` for seamless integration in R3F. It is written in Rust and compiled to WebAssembly.
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
32
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`):
33
108
  ```tsx
34
- // React Three Fiber + Rapier Example
35
- import { Physics, RigidBody } from '@react-three/rapier';
109
+ import { Physics, RigidBody, CuboidCollider } from '@react-three/rapier';
36
110
 
37
- function GameScene() {
111
+ export function GamePhysicsWorld({ children }: { children: React.ReactNode }) {
38
112
  return (
39
- <Physics gravity={[0, -9.81, 0]}>
40
- {/* Falling Object */}
41
- <RigidBody colliders="box" position={[0, 10, 0]}>
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">
42
116
  <mesh>
43
- <boxGeometry />
44
- <meshStandardMaterial color="hotpink" />
117
+ <sphereGeometry args={[0.5]} />
118
+ <meshStandardMaterial color="dodgerblue" />
45
119
  </mesh>
46
120
  </RigidBody>
47
121
 
48
122
  {/* Static Floor */}
49
- <RigidBody type="fixed" colliders="cuboid">
50
- <mesh position={[0, -1, 0]}>
51
- <boxGeometry args={[10, 1, 10]} />
52
- <meshStandardMaterial color="gray" />
53
- </mesh>
123
+ <RigidBody type="fixed">
124
+ <CuboidCollider args={[20, 0.5, 20]} position={[0, -0.5, 0]} />
54
125
  </RigidBody>
126
+
127
+ {children}
55
128
  </Physics>
56
129
  );
57
130
  }
58
131
  ```
59
132
 
60
- #### 2. Entity Component System (ECS)
61
- Traditional Object-Oriented Programming (OOP) can cause performance bottlenecks in games due to poor cache locality. ECS stores data in contiguous memory arrays (Components) and processes them in tight loops (Systems).
62
- - Use **bitECS** for extreme performance (uses TypedArrays).
63
- - Use **Miniplex** for an easier, developer-friendly React integration.
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);
64
204
 
65
- ### Best Practices
66
- - **Decouple Logic from Rendering:** The physics engine should update at a fixed timestep (e.g., 60Hz), while rendering should happen at the screen's refresh rate (e.g., 144Hz) using interpolation to prevent stuttering.
67
- - **Use Simple Colliders:** Never use complex mesh colliders (Convex/Trimesh) for moving objects unless absolutely necessary. Use primitives (Spheres, Boxes, Capsules).
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
+ ```
68
215
 
69
216
  ---
70
217
 
71
- ### Integration with Other Skills (MANDATORY)
72
- This skill works best when combined with:
73
- - `web-3d-graphics-expert` — For the visual rendering of the physics world.
74
- - `webxr-ar-vr-expert` — For adding grabbable physics objects in VR space.
75
- - `realtime-collaboration-expert` — For synchronizing physics state across multiple players using WebRTC.
218
+ ### 5. 3D Spatial Positional Audio (Web Audio API)
76
219
 
77
- ### Referenced By Orchestrators (MANDATORY)
78
- - `brainstorming` — Add to "3D & Graphics" or "Game Development".
79
- - `zero-to-prod-orchestrator` — Phase 5 (Frontend / Simulation).
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.
80
273
 
81
274
  ---
82
275
 
83
276
  <a name="bahasa-indonesia"></a>
84
277
  ## Bahasa Indonesia
85
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
+
86
288
  ### Deskripsi
87
- Panduan pengembangan *game* dan simulasi 3D di web. Mencakup integrasi *Physics Engine* berbasis WebAssembly (Rapier, Havok, Cannon) dan arsitektur *Entity Component System* (ECS).
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**.
88
290
 
89
291
  ### Kondisi Pemicu
90
- - Saat menambahkan gravitasi, tabrakan (collision), atau benda padat (rigid body) ke dalam aplikasi 3D.
91
- - Saat membuat game web yang membutuhkan performa tinggi dengan ribuan entitas.
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.
92
326
 
93
- ### Panduan Singkat
94
- - **Pilih Mesin Fisika:** Gunakan **Havok** jika menggunakan Babylon.js. Gunakan **Rapier** (`@react-three/rapier`) jika menggunakan Three.js/R3F.
95
- - **Gunakan Collider Sederhana:** Untuk objek bergerak, selalu gunakan *primitive colliders* (Kotak, Bola, Kapsul) alih-alih *mesh collider* agar perhitungan CPU/WASM tetap ringan.
96
- - **Pola ECS (Entity Component System):** Untuk game kompleks, pisahkan logika dan data menggunakan arsitektur ECS (seperti `miniplex` atau `bitECS`) untuk memaksimalkan performa *cache* memori.
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*.