Skip to content

Commit

Permalink
Limit the gamepad publish rate to 20Hz (#162)
Browse files Browse the repository at this point in the history
* Throttle gamepad refresh rate

* Change refresh rate to 20hz

* Clean up
  • Loading branch information
GLDuval authored Feb 27, 2023
1 parent 1e0eaa4 commit 570b885
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/renderer/inputSystem/InputSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
GamepadButtonBinding,
} from '@/renderer/inputSystem/@types';

// 1000ms / refresh rate in Hz
const GAMEPAD_REFRESH_RATE = 1000 / 20;

/* TODO
* - button axis (RT, LT)
* - support key combinations?
Expand Down Expand Up @@ -93,8 +96,10 @@ export class InputSystem {

private update = () => {
if (this.isRunning) {
this.updateGamepad();
requestAnimationFrame(this.update);
setTimeout(() => {
this.updateGamepad();
requestAnimationFrame(this.update);
}, GAMEPAD_REFRESH_RATE);
}
};

Expand Down

0 comments on commit 570b885

Please sign in to comment.