8
8
9
9
<script setup lang="ts">
10
10
import { range } from ' lodash-es'
11
- import { onMounted , ref } from ' vue'
12
- import { snaproll , SnaprollActionType , type SnaprollSubscription } from ' ./index'
13
- import { Pane } from ' tweakpane'
14
11
import { mean } from ' simple-statistics'
12
+ import { Pane } from ' tweakpane'
13
+ import { onMounted , ref } from ' vue'
14
+ import { Snaproll , SnaprollActionType , type SnaprollSubscription } from ' ./index'
15
15
16
16
// class Estimation {
17
17
// private currentCount = 0
@@ -88,7 +88,7 @@ class Estimation {
88
88
}
89
89
}
90
90
91
- const loop = snaproll ({ fps: 30 })
91
+ const loop = new Snaproll ({ fps: 30 })
92
92
const boxRefs = ref <HTMLElement []>([])
93
93
94
94
function lerp(v0 : number , v1 : number , t : number ) {
@@ -110,10 +110,17 @@ const boxes = range(50).map((_, index) => {
110
110
velocity ,
111
111
}
112
112
113
+ // 4 seconds
114
+ const updateStepsMax = Math .round (4000 / loop .timestep )
115
+ let updateSteps = 0
116
+
113
117
const subscription: SnaprollSubscription = (action ) => {
114
118
const element = boxRefs .value [box .index ]
115
119
116
120
switch (action .type ) {
121
+ case SnaprollActionType .Begin :
122
+ updateSteps = 0
123
+ break
117
124
case SnaprollActionType .Update :
118
125
box .lastPosition = box .position
119
126
box .position += box .velocity * action .timestep
@@ -125,10 +132,9 @@ const boxes = range(50).map((_, index) => {
125
132
box .lastPosition ,
126
133
box .position ,
127
134
action .delta / action .timestep ,
128
- // 1 - Math.exp(-lambda * action.delta),
129
135
)}vw `
130
136
131
- if (action . panic ) {
137
+ if (++ updateSteps >= updateStepsMax ) {
132
138
loop .resetFrameDelta ()
133
139
}
134
140
@@ -169,7 +175,6 @@ const observer = new PerformanceObserver((list) => {
169
175
if (entry .entryType === ' measure' ) {
170
176
durations .push (entry .duration )
171
177
172
-
173
178
if (durations .length > 60 ) {
174
179
durations .shift ()
175
180
}
@@ -192,7 +197,7 @@ const read = {
192
197
get draw() {
193
198
return estimationDraw .getFrequency ()
194
199
},
195
- get mean () {
200
+ get perf () {
196
201
try {
197
202
return mean (durations ) * 100
198
203
} catch {
@@ -246,7 +251,7 @@ Object.keys(read).forEach((key) => {
246
251
readonly: true ,
247
252
view: ' graph' ,
248
253
min: 0 ,
249
- max: 200 ,
254
+ max: 100 ,
250
255
bufferSize: 100 ,
251
256
})
252
257
})
0 commit comments