Added configurable input sampling frequency
This commit is contained in:
parent
639227ea1d
commit
2c72b58fc2
2 changed files with 49 additions and 17 deletions
|
|
@ -463,6 +463,22 @@ function changeInput(evt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeFrequency(evt) {
|
||||||
|
let newFrequency = evt.target.value;
|
||||||
|
|
||||||
|
if (newFrequency === "RAF") {
|
||||||
|
useRAF = true;
|
||||||
|
} else {
|
||||||
|
newFrequency = Number(newFrequency);
|
||||||
|
if (!isNaN(newFrequency)) {
|
||||||
|
useRAF = false;
|
||||||
|
frequency = (1/newFrequency) * 1000;
|
||||||
|
} else {
|
||||||
|
console.log("New frequency is not a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const LOADER_ANIMATION_FRAMES = [0,1,2,3,3,2,1,0];
|
const LOADER_ANIMATION_FRAMES = [0,1,2,3,3,2,1,0];
|
||||||
let loaderFrame = 1;
|
let loaderFrame = 1;
|
||||||
let highlightedBlock = false;
|
let highlightedBlock = false;
|
||||||
|
|
@ -547,7 +563,8 @@ function updateGamepadDisplay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let timeOld = false;
|
let timeOld = false;
|
||||||
let frequency = (1/120) * 1000;
|
let frequency = (1/240) * 1000;
|
||||||
|
let useRAF = false;
|
||||||
function eventLoop() {
|
function eventLoop() {
|
||||||
// Update x/y ratio for the sticks based on
|
// Update x/y ratio for the sticks based on
|
||||||
// pressed buttons if we're using a keyboard
|
// pressed buttons if we're using a keyboard
|
||||||
|
|
@ -601,21 +618,23 @@ function eventLoop() {
|
||||||
|
|
||||||
updateGamepadDisplay()
|
updateGamepadDisplay()
|
||||||
|
|
||||||
// if (!timeOld) {
|
if (useRAF) {
|
||||||
// timeOld = performance.now();
|
requestAnimationFrame(eventLoop);
|
||||||
// }
|
} else {
|
||||||
// timeNew = performance.now();
|
if (!timeOld) {
|
||||||
// delta = timeNew - timeOld;
|
timeOld = performance.now();
|
||||||
// diff = delta - frequency;
|
}
|
||||||
|
timeNew = performance.now();
|
||||||
// if (diff > 0) {
|
delta = timeNew - timeOld;
|
||||||
// setTimeout(eventLoop, frequency - diff);
|
diff = delta - frequency;
|
||||||
// } else {
|
|
||||||
// setTimeout(eventLoop, frequency);
|
if (diff > 0) {
|
||||||
// }
|
setTimeout(eventLoop, frequency - diff);
|
||||||
// timeOld = timeNew;
|
} else {
|
||||||
|
setTimeout(eventLoop, frequency);
|
||||||
requestAnimationFrame(eventLoop);
|
}
|
||||||
|
timeOld = timeNew;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMacro() {
|
function sendMacro() {
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="controller-config" class="hidden surface">
|
<section id="controller-config" class="surface hidden">
|
||||||
<div id="controller-underlay-container">
|
<div id="controller-underlay-container">
|
||||||
<div class="controller-display hidden">
|
<div class="controller-display hidden">
|
||||||
<div class="control-indicator" id="jl_"></div>
|
<div class="control-indicator" id="jl_"></div>
|
||||||
|
|
@ -120,6 +120,19 @@
|
||||||
a button on the gamepad before it shows up on the
|
a button on the gamepad before it shows up on the
|
||||||
input device list.
|
input device list.
|
||||||
</p>
|
</p>
|
||||||
|
<h2 class="surface-lighter">Input Sampling Frequency</h2>
|
||||||
|
<select id="input-frequency" name="Select an Input Sampling Frequency" onchange="changeFrequency(event)">
|
||||||
|
<option value="240">240Hz</option>
|
||||||
|
<option value="120">120Hz</option>
|
||||||
|
<option value="60">60Hz</option>
|
||||||
|
<option value="RAF">Monitor Refresh Rate</option>
|
||||||
|
</select>
|
||||||
|
<p>
|
||||||
|
Note: "Monitor Refresh Rate" is a more stable but
|
||||||
|
(potentially) slower frequency. This loop uses the
|
||||||
|
"requestAnimationFrame()" function, rather than
|
||||||
|
"setTimeout()".
|
||||||
|
</p>
|
||||||
<h2 class="surface-lighter">Control Mapping</h2>
|
<h2 class="surface-lighter">Control Mapping</h2>
|
||||||
<div id="keyboard-map" class="surface-lighter">
|
<div id="keyboard-map" class="surface-lighter">
|
||||||
<table>
|
<table>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue