[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,98 +2,232 @@
|
||||
id: wiki-2026-0508-시뮬레이션-simulation
|
||||
title: 시뮬레이션(Simulation)
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Frontend Simulation, Browser Physics Simulation, WebGL Simulation, Particle System]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.84
|
||||
verification_status: applied
|
||||
tags: [frontend, simulation, webgl, webgpu, physics, particle, canvas]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: TypeScript / GLSL / WGSL
|
||||
framework: Three.js, WebGPU, matter.js, rapier.js, p5.js
|
||||
---
|
||||
|
||||
# [[시뮬레이션(Simulation)|시뮬레이션(Simulation)]]
|
||||
# 시뮬레이션(Simulation)
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
시뮬레이션(Simulation)은 게임의 정식 출시 이전, 또는 라이브 운영 과정에서 복잡한 게임 경제 시스템의 균형을 테스트하고 플레이어의 행동을 예측하기 위해 활용되는 핵심 프로세스이다[1, 2]. 기존의 플레이 테스트나 정적인 스프레드시트 방식의 한계를 극복하고 코딩 없이도 복잡한 시스템을 모델링할 수 있게 해준다[3, 4]. 주로 몬테카를로 시뮬레이션(Monte Carlo Simulation)을 통해 수많은 무작위 가상 여정을 실행함으로써, 인플레이션 위험을 사전에 식별하고 게임 내 재화의 적절한 균형을 보장하는 역할을 한다[2, 5].
|
||||
## 매 한 줄
|
||||
> **"매 frontend 의 simulation — 매 real-time interactive computation: physics, particle, fluid, agent-based, financial — 매 main thread 의 X, 매 GPU compute / Worker 의 offload"**. 매 2026 의 modern stack: WebGPU compute shader (10-100× WebGL), Rust→WASM physics (rapier), Three.js + WebGPU renderer.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **전통적 테스트 방법의 한계와 시뮬레이션의 필요성**
|
||||
프리미엄(Freemium) 모바일 게임 등의 경제 구조는 다수의 통화와 자원, 인앱 결제가 복잡하게 얽혀 있어 전통적인 플레이 테스트만으로는 막대한 시간과 비용이 소모되며 검증이 어렵다[6, 7]. 또한, 엑셀과 같은 스프레드시트를 활용한 전통적 분석은 평균값에 의존한 정적(Static)인 형태이기 때문에 실제 게임 플레이 과정에서 발생하는 무작위성(Randomness)이나 창발성(Emergence), 그리고 플레이어의 다양한 편향을 예측하는 데 근본적인 한계가 존재한다[2, 5]. 반면, 컴퓨터를 통한 시뮬레이션은 핵심 게임 개발이 완료되기 전에도 메커니즘을 테스트할 수 있어 수 주 단위의 테스트를 수 시간 내지 수 일로 단축시킨다[8].
|
||||
## 매 핵심
|
||||
|
||||
* **몬테카를로 시뮬레이션과 대수의 법칙**
|
||||
실제 플레이어는 설계자가 의도한 수학적으로 최적화된 패턴으로만 게임을 즐기지 않으며, 다양한 편향성을 가지고 행동한다[5]. 이를 예측하기 위해 불확실한 요소에 무작위 샘플링을 반복하는 몬테카를로 시뮬레이션과 '대수의 법칙(Law of Large Numbers)'이 활용된다[9, 10]. 이 방식을 사용하면 수만 번의 가상 플레이어 여정을 실행하여 특정 구간에서 재화가 결핍되거나 인플레이션이 일어나는 시점을 정확히 포착하고, 게임 내 통화의 '수도꼭지(Tap)'와 '배수구(Sink)'의 밸런스를 정교하게 조정할 수 있다[2, 11].
|
||||
### 매 Simulation 의 categories
|
||||
- **Physics simulation** — rigid body, soft body, cloth (rapier, matter.js, cannon.js).
|
||||
- **Particle system** — fire, smoke, snow (GPU instancing).
|
||||
- **Fluid simulation** — Navier-Stokes (compute shader, SPH).
|
||||
- **Agent-based** — boids, crowd, traffic.
|
||||
- **Financial / Monte Carlo** — option pricing, risk simulation.
|
||||
- **Cellular automata** — Game of Life, Reaction-Diffusion.
|
||||
|
||||
* **데이터 연동 및 디지털 트윈(Digital Twin)으로의 진화**
|
||||
개발 초기 단계의 시뮬레이션 모델은 출시 이후 라이브 옵스(LiveOps)를 통해 얻어지는 실제 텔레메트리 데이터(JSON 형태 등)를 지속해서 주입(Ingestion)받으면서 더욱 고도화된다[2, 12]. 현실의 데이터를 통해 교정된 모델은 단순한 가정에서 벗어나 게임의 복제본인 '디지털 트윈'으로 기능하며, 미래의 플레이어 행동과 경제 시스템의 변화를 정확하게 예측할 수 있게 돕는다[2, 12].
|
||||
### 매 Performance Architecture
|
||||
- **Main thread** — DOM, input handling 만.
|
||||
- **Worker** — physics step, integration (Rust→WASM).
|
||||
- **GPU compute (WebGPU)** — particle update, fluid, large array.
|
||||
- **OffscreenCanvas** — 매 worker 의 직접 render.
|
||||
- **SharedArrayBuffer** — main↔worker 의 zero-copy state.
|
||||
|
||||
* **AI 밸런서(AI Balancer)를 통한 자동화**
|
||||
최근 시뮬레이션 기술은 AI와 결합하여 수동적인 파라미터 조작 방식을 넘어 자동화된 밸런싱 도구로 발전하고 있다[13]. 예를 들어, 경제 설계자가 "초반 10분 동안 플레이어가 3번만 죽도록 설정"한다는 목표를 시스템에 입력하면, AI가 해당 목표(참여도, LTV 극대화 등)를 충족할 수 있도록 게임 내 각종 파라미터를 자동으로 최적화하고 미세 조정해 준다[2, 13, 14].
|
||||
### 매 2026 의 key tech
|
||||
- **WebGPU** — Chrome 113+, Safari 18+, Firefox 130+.
|
||||
- **Compute shader (WGSL)** — 매 general-purpose GPU 계산.
|
||||
- **Rapier 0.x** — Rust physics, 10× cannon.js.
|
||||
- **Three.js r170+** — WebGPURenderer 의 stable.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[게임 경제 설계(Game Economy Design)|게임 경제 설계(Game Economy Design)]], [[인플레이션(Inflation)|인플레이션(Inflation)]], [[몬테카를로 시뮬레이션(Monte Carlo Simulation)|몬테카를로 시뮬레이션(Monte Carlo Simulation)]], [[디지털 트윈(Digital Twin)|디지털 트윈(Digital Twin)]], 플레이어 여정(Player Journey)
|
||||
- **Projects/Contexts:** [[마키네이션(Machinations)|마키네이션(Machinations)]] 플랫폼을 통한 경제 모델 검증 사례, Web3 경제 토크노믹스(Tokenomics) 구축 전 사전 검증 과정
|
||||
- **Contradictions/Notes:** 엑셀 기반의 정적 스프레드시트 분석은 설계자가 완벽하고 통제 가능한 평균치 모델을 세우도록 유도하지만, 실제 라이브 게임 환경과 플레이어 행동에는 이러한 이상적 수치가 적용되지 않으므로 무작위성이 부여된 다중 시뮬레이션과 상충되는 결과를 나타낼 수 있다[2, 4, 5].
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-29*
|
||||
### Pattern 1: WebGPU Compute (particle update)
|
||||
```ts
|
||||
// 매 100k particle 의 GPU 의 update
|
||||
const adapter = await navigator.gpu.requestAdapter();
|
||||
const device = await adapter!.requestDevice();
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
const computeShader = device.createShaderModule({
|
||||
code: `
|
||||
struct Particle { pos: vec2f, vel: vec2f };
|
||||
@group(0) @binding(0) var<storage, read_write> particles: array<Particle>;
|
||||
@group(0) @binding(1) var<uniform> dt: f32;
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
@compute @workgroup_size(64)
|
||||
fn main(@builtin(global_invocation_id) id: vec3u) {
|
||||
let i = id.x;
|
||||
if (i >= arrayLength(&particles)) { return; }
|
||||
var p = particles[i];
|
||||
p.vel += vec2f(0, -9.81) * dt;
|
||||
p.pos += p.vel * dt;
|
||||
if (p.pos.y < 0) { p.vel.y *= -0.8; p.pos.y = 0; }
|
||||
particles[i] = p;
|
||||
}
|
||||
`
|
||||
});
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Pattern 2: Rapier (Rust→WASM physics)
|
||||
```ts
|
||||
import RAPIER from '@dimforge/rapier3d-compat';
|
||||
await RAPIER.init();
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
const world = new RAPIER.World({ x: 0, y: -9.81, z: 0 });
|
||||
const groundDesc = RAPIER.RigidBodyDesc.fixed();
|
||||
const ground = world.createRigidBody(groundDesc);
|
||||
world.createCollider(RAPIER.ColliderDesc.cuboid(10, 0.1, 10), ground);
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
const ballDesc = RAPIER.RigidBodyDesc.dynamic().setTranslation(0, 5, 0);
|
||||
const ball = world.createRigidBody(ballDesc);
|
||||
world.createCollider(RAPIER.ColliderDesc.ball(0.5).setRestitution(0.7), ball);
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
function step() {
|
||||
world.step();
|
||||
const t = ball.translation();
|
||||
mesh.position.set(t.x, t.y, t.z);
|
||||
requestAnimationFrame(step);
|
||||
}
|
||||
```
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
### Pattern 3: Three.js Particle System (instancing)
|
||||
```ts
|
||||
import * as THREE from 'three';
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
const count = 100_000;
|
||||
const geometry = new THREE.BufferGeometry();
|
||||
const positions = new Float32Array(count * 3);
|
||||
for (let i = 0; i < count; i++) {
|
||||
positions[i*3] = (Math.random() - 0.5) * 100;
|
||||
positions[i*3+1] = Math.random() * 50;
|
||||
positions[i*3+2] = (Math.random() - 0.5) * 100;
|
||||
}
|
||||
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
|
||||
const material = new THREE.PointsMaterial({ size: 0.1, color: 0xffaa00 });
|
||||
const points = new THREE.Points(geometry, material);
|
||||
scene.add(points);
|
||||
```
|
||||
|
||||
### Pattern 4: Boids (agent-based)
|
||||
```ts
|
||||
function update(boids: Boid[], dt: number) {
|
||||
for (const b of boids) {
|
||||
let coh = vec(0,0), sep = vec(0,0), alg = vec(0,0);
|
||||
let n = 0;
|
||||
for (const o of boids) {
|
||||
const d = dist(b.pos, o.pos);
|
||||
if (d > 0 && d < 50) {
|
||||
coh = add(coh, o.pos);
|
||||
alg = add(alg, o.vel);
|
||||
if (d < 20) sep = sub(sep, sub(o.pos, b.pos));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
if (n > 0) {
|
||||
coh = scale(sub(scale(coh, 1/n), b.pos), 0.01);
|
||||
alg = scale(scale(alg, 1/n), 0.05);
|
||||
}
|
||||
b.vel = add(b.vel, add(coh, add(sep, alg)));
|
||||
b.vel = limit(b.vel, 200);
|
||||
b.pos = add(b.pos, scale(b.vel, dt));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 5: Worker offload + OffscreenCanvas
|
||||
```ts
|
||||
// main.ts
|
||||
const canvas = document.querySelector('canvas')!;
|
||||
const off = canvas.transferControlToOffscreen();
|
||||
const worker = new Worker('./sim.worker.ts', { type: 'module' });
|
||||
worker.postMessage({ canvas: off }, [off]);
|
||||
|
||||
// sim.worker.ts
|
||||
self.onmessage = ({ data }) => {
|
||||
const ctx = data.canvas.getContext('webgpu') as GPUCanvasContext;
|
||||
// ... initialize WebGPU + run sim loop entirely off main thread
|
||||
};
|
||||
```
|
||||
|
||||
### Pattern 6: Reaction-Diffusion (cellular)
|
||||
```ts
|
||||
// Gray-Scott equation 의 step (compute shader pseudo)
|
||||
@compute @workgroup_size(8, 8)
|
||||
fn step(@builtin(global_invocation_id) id: vec3u) {
|
||||
let p = vec2i(id.xy);
|
||||
let A = textureLoad(input, p, 0).r;
|
||||
let B = textureLoad(input, p, 0).g;
|
||||
let lapA = laplacian_r(input, p);
|
||||
let lapB = laplacian_g(input, p);
|
||||
let dA = Da*lapA - A*B*B + f*(1.0 - A);
|
||||
let dB = Db*lapB + A*B*B - (k + f)*B;
|
||||
textureStore(output, p, vec4f(A + dA, B + dB, 0, 1));
|
||||
}
|
||||
```
|
||||
|
||||
### Pattern 7: Fixed Timestep with Interpolation
|
||||
```ts
|
||||
const FIXED_DT = 1/60;
|
||||
let acc = 0, prevState: State, state: State;
|
||||
|
||||
function frame(now: number) {
|
||||
const dt = (now - lastT) / 1000;
|
||||
lastT = now;
|
||||
acc += Math.min(dt, 0.25);
|
||||
while (acc >= FIXED_DT) {
|
||||
prevState = clone(state);
|
||||
state = step(state, FIXED_DT);
|
||||
acc -= FIXED_DT;
|
||||
}
|
||||
const alpha = acc / FIXED_DT;
|
||||
render(lerp(prevState, state, alpha));
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 시뮬레이션 | Tech |
|
||||
|---|---|
|
||||
| Rigid body 3D | Rapier (Rust→WASM) |
|
||||
| 2D physics game | matter.js |
|
||||
| Particle 100k+ | WebGPU compute |
|
||||
| Particle <10k | Three.js Points |
|
||||
| Fluid | WebGPU compute (SPH) |
|
||||
| Crowd / boids | Worker + Float32Array |
|
||||
| Cellular automata | WebGPU compute texture |
|
||||
|
||||
**기본값**: Worker 의 simulation step + WebGPU compute (대규모) + OffscreenCanvas 의 render + fixed timestep.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Frontend]] · [[WebGL]]
|
||||
- 변형: [[WebGPU]] · [[Three.js]] · [[Game Loop]]
|
||||
- 응용: [[Particle System]] · [[Physics Engine]]
|
||||
- Adjacent: [[Web Workers]] · [[OffscreenCanvas]] · [[Monte Carlo Simulation]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: simulation algorithm 의 selection (Verlet vs Euler), WebGPU compute shader 의 boilerplate 생성, fixed timestep 의 패턴 권고.
|
||||
**언제 X**: 매 GPU driver-specific 의 issue — 매 actual hardware 의 test 의 필요.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **변동 dt 의 sim step**: 매 deterministic 의 X, 매 instability.
|
||||
- **Main thread 의 100k particle**: 매 jank 의 보장.
|
||||
- **DOM element 의 particle 의 render**: 매 reflow 폭발.
|
||||
- **Per-frame allocation**: 매 GC pause, 매 stutter.
|
||||
- **Naive O(n²) collision**: 매 spatial hash / quadtree 의 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (WebGPU spec, Rapier docs, Three.js r170 docs, Glenn Fiedler "Fix Your Timestep" 2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — simulation categories, WebGPU compute, Rapier, fixed timestep |
|
||||
|
||||
Reference in New Issue
Block a user