Spaces:
Running
Running
π Moved timing to GameLoop, passed state.
Browse files- index.js +6 -6
- wgpu-state.js +1 -1
index.js
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
|
2 |
|
3 |
import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './wgpu-constants.js';
|
@@ -22,10 +24,8 @@ import { generateGlyphVerticesForText } from './wgpu-text.js';
|
|
22 |
await initializeDevice(state);
|
23 |
await InitializeShaders(state);
|
24 |
await InitializePipeline(state);
|
25 |
-
|
26 |
-
state.timing.lastTime = performance.now();
|
27 |
-
|
28 |
await InitializeResources(state);
|
|
|
29 |
GameLoop(state);
|
30 |
}
|
31 |
|
@@ -78,7 +78,7 @@ import { generateGlyphVerticesForText } from './wgpu-text.js';
|
|
78 |
}
|
79 |
|
80 |
function GameLoop(state) {
|
81 |
-
function Tick() {
|
82 |
state.timing.currentTime = performance.now();
|
83 |
state.timing.frameTime = (state.timing.currentTime - state.timing.lastTime) / 1000;
|
84 |
state.timing.lastTime = state.timing.currentTime;
|
@@ -91,10 +91,10 @@ import { generateGlyphVerticesForText } from './wgpu-text.js';
|
|
91 |
}
|
92 |
|
93 |
Render(state);
|
94 |
-
setTimeout(Tick, state.timing.frameDuration);
|
95 |
}
|
96 |
|
97 |
-
Tick();
|
98 |
}
|
99 |
|
100 |
await Main();
|
|
|
1 |
+
// index.js
|
2 |
+
|
3 |
import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
|
4 |
|
5 |
import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './wgpu-constants.js';
|
|
|
24 |
await initializeDevice(state);
|
25 |
await InitializeShaders(state);
|
26 |
await InitializePipeline(state);
|
|
|
|
|
|
|
27 |
await InitializeResources(state);
|
28 |
+
|
29 |
GameLoop(state);
|
30 |
}
|
31 |
|
|
|
78 |
}
|
79 |
|
80 |
function GameLoop(state) {
|
81 |
+
function Tick(state) {
|
82 |
state.timing.currentTime = performance.now();
|
83 |
state.timing.frameTime = (state.timing.currentTime - state.timing.lastTime) / 1000;
|
84 |
state.timing.lastTime = state.timing.currentTime;
|
|
|
91 |
}
|
92 |
|
93 |
Render(state);
|
94 |
+
setTimeout(() => Tick(state), state.timing.frameDuration);
|
95 |
}
|
96 |
|
97 |
+
Tick(state);
|
98 |
}
|
99 |
|
100 |
await Main();
|
wgpu-state.js
CHANGED
@@ -36,7 +36,7 @@ export function createState(config) {
|
|
36 |
deltaTime: 0,
|
37 |
currentTime: 0,
|
38 |
frameTime: 0,
|
39 |
-
lastTime:
|
40 |
}
|
41 |
};
|
42 |
}
|
|
|
36 |
deltaTime: 0,
|
37 |
currentTime: 0,
|
38 |
frameTime: 0,
|
39 |
+
lastTime: performance.now(),
|
40 |
}
|
41 |
};
|
42 |
}
|