chore: add prettier and format
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<script lang="ts" setup>
|
||||
const props = defineProps({
|
||||
x: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
y: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
x: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
y: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const SAMPLES = 60;
|
||||
@@ -15,54 +15,53 @@ let average = { deltaTime: 0, realDeltaTime: 0 };
|
||||
const lastFrames: (typeof average)[] = [];
|
||||
|
||||
useUpdate((deltaTime, realDeltaTime) => {
|
||||
lastFrames.push({ deltaTime, realDeltaTime });
|
||||
lastFrames.push({ deltaTime, realDeltaTime });
|
||||
|
||||
if (lastFrames.length > SAMPLES) {
|
||||
lastFrames.shift();
|
||||
}
|
||||
if (lastFrames.length > SAMPLES) {
|
||||
lastFrames.shift();
|
||||
}
|
||||
|
||||
if (lastFrames.length > 0) {
|
||||
average = {
|
||||
deltaTime:
|
||||
lastFrames.reduce((acc, v) => acc + v.deltaTime, 0) /
|
||||
lastFrames.length,
|
||||
realDeltaTime:
|
||||
lastFrames.reduce((acc, v) => acc + v.realDeltaTime, 0) /
|
||||
lastFrames.length,
|
||||
};
|
||||
}
|
||||
if (lastFrames.length > 0) {
|
||||
average = {
|
||||
deltaTime:
|
||||
lastFrames.reduce((acc, v) => acc + v.deltaTime, 0) / lastFrames.length,
|
||||
realDeltaTime:
|
||||
lastFrames.reduce((acc, v) => acc + v.realDeltaTime, 0) /
|
||||
lastFrames.length,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
useRender((ctx) => {
|
||||
const LINE_COUNT = 5;
|
||||
const LINE_HEIGHT = 12;
|
||||
const LINE_COUNT = 5;
|
||||
const LINE_HEIGHT = 12;
|
||||
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(props.x - 2, props.y, 140, LINE_COUNT * LINE_HEIGHT + 3);
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(props.x - 2, props.y, 140, LINE_COUNT * LINE_HEIGHT + 3);
|
||||
|
||||
let textY = props.y;
|
||||
let textY = props.y;
|
||||
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillText("[avg on 60 frames]", props.x, (textY += LINE_HEIGHT));
|
||||
ctx.fillText(
|
||||
`fps=${(1000 / average.deltaTime).toFixed()}`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`frame_time=${average.deltaTime.toFixed(2)}ms`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`real_fps=${(1000 / average.realDeltaTime).toFixed()}`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`real_frame_time=${average.realDeltaTime.toFixed(2)}ms`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillStyle = "black";
|
||||
ctx.fillText("[avg on 60 frames]", props.x, (textY += LINE_HEIGHT));
|
||||
ctx.fillText(
|
||||
`fps=${(1000 / average.deltaTime).toFixed()}`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`frame_time=${average.deltaTime.toFixed(2)}ms`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`real_fps=${(1000 / average.realDeltaTime).toFixed()}`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
ctx.fillText(
|
||||
`real_frame_time=${average.realDeltaTime.toFixed(2)}ms`,
|
||||
props.x,
|
||||
(textY += LINE_HEIGHT),
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user