MCPcopy
hub / github.com/liabru/matter-js / runExample

Function runExample

test/ExampleWorker.js:10–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8const DateOriginal = global.Date;
9
10const runExample = options => {
11 const {
12 Matter,
13 logs,
14 frameCallbacks
15 } = prepareEnvironment(options);
16
17 let memoryDeltaAverage = 0;
18 let timeDeltaAverage = 0;
19 let overlapTotal = 0;
20 let overlapCount = 0;
21 let i;
22 let j;
23
24 try {
25 let runner;
26 let engine;
27 let render;
28 let extrinsicCapture;
29
30 const pairOverlap = (pair) => {
31 const collision = Matter.Collision.collides(pair.bodyA, pair.bodyB);
32 return collision ? Math.max(collision.depth - pair.slop, 0) : -1;
33 };
34
35 for (i = 0; i < options.repeats; i += 1) {
36 if (global.gc) {
37 global.gc();
38 }
39
40 const Examples = requireUncached('../examples/index');
41 const example = Examples[options.name]();
42
43 runner = example.runner;
44 engine = example.engine;
45 render = example.render;
46
47 for (j = 0; j < options.updates; j += 1) {
48 const time = j * runner.delta;
49 const callbackCount = frameCallbacks.length;
50
51 global.timeNow = time;
52
53 for (let p = 0; p < callbackCount; p += 1) {
54 const frameCallback = frameCallbacks.shift();
55 const memoryBefore = process.memoryUsage().heapUsed;
56 const timeBefore = process.hrtime();
57
58 frameCallback(time);
59
60 const timeDuration = process.hrtime(timeBefore);
61 const timeDelta = timeDuration[0] * 1e9 + timeDuration[1];
62 const memoryAfter = process.memoryUsage().heapUsed;
63 const memoryDelta = Math.max(memoryAfter - memoryBefore, 0);
64
65 memoryDeltaAverage = smoothExp(memoryDeltaAverage, memoryDelta);
66 timeDeltaAverage = smoothExp(timeDeltaAverage, timeDelta);
67 }

Callers

nothing calls this directly

Calls 8

prepareEnvironmentFunction · 0.85
requireUncachedFunction · 0.85
smoothExpFunction · 0.85
pairOverlapFunction · 0.85
captureExtrinsicsFunction · 0.85
resetEnvironmentFunction · 0.85
captureIntrinsicsFunction · 0.85
captureStateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…