Skip to content

Commit d2d30b2

Browse files
fix: pr feedback
1 parent 24be85f commit d2d30b2

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

testbed3d/src/Testbed.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export class Testbed {
5555
preTimestepAction?: (gfx: Graphics) => void;
5656
stepId: number;
5757
prevDemo: string;
58-
lastMessageTime: number;
5958
snap: Uint8Array;
6059
snapStepId: number;
6160
time: number;
61+
physicsTime: number;
6262
accumulator: number;
6363

6464
constructor(RAPIER: RAPIER_API, builders: Builders) {
@@ -73,6 +73,7 @@ export class Testbed {
7373
this.mouse = {x: 0, y: 0};
7474
this.events = new RAPIER.EventQueue(true);
7575
this.time = 0;
76+
this.physicsTime = 0;
7677
this.accumulator = 0;
7778

7879
this.switchToDemo(builders.keys().next().value);
@@ -94,16 +95,13 @@ export class Testbed {
9495
this.preTimestepAction = null;
9596
this.world = world;
9697
this.world.maxVelocityIterations = this.parameters.numVelocityIter;
97-
this.world.timestep = 1 / 60;
9898
this.demoToken += 1;
9999
this.stepId = 0;
100100
this.gui.resetTiming();
101101

102102
world.forEachCollider((coll) => {
103103
this.graphics.addCollider(this.RAPIER, world, coll);
104104
});
105-
106-
this.lastMessageTime = new Date().getTime();
107105
}
108106

109107
lookAt(pos: Parameters<Graphics["lookAt"]>[0]) {
@@ -144,15 +142,15 @@ export class Testbed {
144142
}
145143

146144
run() {
147-
const time = performance.now();
148-
const fixedStep = this.world.timestep;
149-
const frameTime = Math.min(0.01, (time - this.time) / 1000);
145+
let time = performance.now();
146+
let fixedStep = this.world.timestep;
147+
let deltaTime = (time - this.time) / 1000;
148+
let physicsDeltaTime = (time - this.physicsTime) / 1000;
150149

151150
this.time = time;
152-
this.accumulator += frameTime;
151+
this.accumulator += deltaTime;
153152

154-
// Run physics at a fixed update interval
155-
while (this.accumulator >= fixedStep) {
153+
if (physicsDeltaTime >= fixedStep) {
156154
if (this.parameters.running || this.parameters.stepping) {
157155
this.world.maxVelocityIterations =
158156
this.parameters.numVelocityIter;
@@ -161,8 +159,9 @@ export class Testbed {
161159
this.preTimestepAction(this.graphics);
162160
}
163161

162+
let t = performance.now();
164163
this.world.step(this.events);
165-
this.gui.setTiming(performance.now() - time);
164+
this.gui.setTiming(performance.now() - t);
166165
this.stepId += 1;
167166

168167
if (!!this.parameters.debugInfos) {
@@ -190,10 +189,14 @@ export class Testbed {
190189
}
191190
}
192191

192+
this.physicsTime = time;
193193
this.accumulator -= fixedStep;
194194
}
195195

196-
const alpha = this.accumulator / fixedStep;
196+
// let alpha = this.accumulator / fixedStep;
197+
let alpha = 1;
198+
199+
console.log(alpha);
197200

198201
if (this.parameters.stepping) {
199202
this.parameters.running = false;

0 commit comments

Comments
 (0)