@@ -55,10 +55,10 @@ export class Testbed {
55
55
preTimestepAction ?: ( gfx : Graphics ) => void ;
56
56
stepId : number ;
57
57
prevDemo : string ;
58
- lastMessageTime : number ;
59
58
snap : Uint8Array ;
60
59
snapStepId : number ;
61
60
time : number ;
61
+ physicsTime : number ;
62
62
accumulator : number ;
63
63
64
64
constructor ( RAPIER : RAPIER_API , builders : Builders ) {
@@ -73,6 +73,7 @@ export class Testbed {
73
73
this . mouse = { x : 0 , y : 0 } ;
74
74
this . events = new RAPIER . EventQueue ( true ) ;
75
75
this . time = 0 ;
76
+ this . physicsTime = 0 ;
76
77
this . accumulator = 0 ;
77
78
78
79
this . switchToDemo ( builders . keys ( ) . next ( ) . value ) ;
@@ -91,16 +92,13 @@ export class Testbed {
91
92
this . preTimestepAction = null ;
92
93
this . world = world ;
93
94
this . world . maxVelocityIterations = this . parameters . numVelocityIter ;
94
- this . world . timestep = 1 / 60 ;
95
95
this . demoToken += 1 ;
96
96
this . stepId = 0 ;
97
97
this . gui . resetTiming ( ) ;
98
98
99
99
world . forEachCollider ( ( coll ) => {
100
100
this . graphics . addCollider ( this . RAPIER , world , coll ) ;
101
101
} ) ;
102
-
103
- this . lastMessageTime = new Date ( ) . getTime ( ) ;
104
102
}
105
103
106
104
lookAt ( pos : Parameters < Graphics [ "lookAt" ] > [ 0 ] ) {
@@ -141,15 +139,15 @@ export class Testbed {
141
139
}
142
140
143
141
run ( ) {
144
- const time = performance . now ( ) ;
145
- const fixedStep = this . world . timestep ;
146
- const frameTime = Math . min ( 0.01 , ( time - this . time ) / 1000 ) ;
142
+ let time = performance . now ( ) ;
143
+ let fixedStep = this . world . timestep ;
144
+ let deltaTime = ( time - this . time ) / 1000 ;
145
+ let physicsDeltaTime = ( time - this . physicsTime ) / 1000 ;
147
146
148
147
this . time = time ;
149
- this . accumulator += frameTime ;
148
+ this . accumulator += deltaTime ;
150
149
151
- // Run physics at a fixed update interval
152
- while ( this . accumulator >= fixedStep ) {
150
+ if ( physicsDeltaTime >= fixedStep ) {
153
151
if ( this . parameters . running || this . parameters . stepping ) {
154
152
this . world . maxVelocityIterations =
155
153
this . parameters . numVelocityIter ;
@@ -158,8 +156,9 @@ export class Testbed {
158
156
this . preTimestepAction ( this . graphics ) ;
159
157
}
160
158
159
+ let t = performance . now ( ) ;
161
160
this . world . step ( this . events ) ;
162
- this . gui . setTiming ( performance . now ( ) - time ) ;
161
+ this . gui . setTiming ( performance . now ( ) - t ) ;
163
162
this . stepId += 1 ;
164
163
165
164
if ( ! ! this . parameters . debugInfos ) {
@@ -187,10 +186,14 @@ export class Testbed {
187
186
}
188
187
}
189
188
189
+ this . physicsTime = time ;
190
190
this . accumulator -= fixedStep ;
191
191
}
192
192
193
- const alpha = this . accumulator / fixedStep ;
193
+ // let alpha = this.accumulator / fixedStep;
194
+ let alpha = 1 ;
195
+
196
+ console . log ( alpha ) ;
194
197
195
198
if ( this . parameters . stepping ) {
196
199
this . parameters . running = false ;
0 commit comments