Skip to content

Commit 04a85e9

Browse files
committed
minimap: don't do more 20 updates per seconds
1 parent 3cd7785 commit 04a85e9

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/controls.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ contro.on('trigger', ({ command }) => {
499499
case 'general.rotateCameraRight':
500500
case 'general.rotateCameraUp':
501501
case 'general.rotateCameraDown':
502+
case 'general.playersList':
502503
// no-op
503504
break
504505
case 'general.swapHands': {

src/react/Minimap.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ export default (
2222
const canvasTick = useRef(0)
2323
const canvasRef = useRef<HTMLCanvasElement>(null)
2424
const [position, setPosition] = useState({ x: 0, y: 0, z: 0 })
25+
const lastUpdate = useRef(0)
26+
const THROTTLE_MS = 50 // 20fps
2527

2628
const updateMap = () => {
29+
const now = Date.now()
30+
if (now - lastUpdate.current < THROTTLE_MS) return
31+
lastUpdate.current = now
32+
2733
setPosition({ x: adapter.playerPosition.x, y: adapter.playerPosition.y, z: adapter.playerPosition.z })
2834
if (adapter.mapDrawer) {
2935
if (!full.current) {

0 commit comments

Comments
 (0)