fix input drops
This commit is contained in:
parent
c4978fa9a2
commit
475ad8955d
19
app.js
19
app.js
|
@ -4,6 +4,8 @@ const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
let lastFrame = "";
|
let lastFrame = "";
|
||||||
let emulator;
|
let emulator;
|
||||||
|
let currentKey = "";
|
||||||
|
let keyCooldown = 0;
|
||||||
const mainHTML = fs.readFileSync(path.join(__dirname, "html", "gb.html"), "utf8");
|
const mainHTML = fs.readFileSync(path.join(__dirname, "html", "gb.html"), "utf8");
|
||||||
const KEYMAP = {
|
const KEYMAP = {
|
||||||
RIGHT: 0,
|
RIGHT: 0,
|
||||||
|
@ -25,10 +27,15 @@ async function run() {
|
||||||
path: "./rom.gb",
|
path: "./rom.gb",
|
||||||
interval: 16.6666667,
|
interval: 16.6666667,
|
||||||
onFrame: function(frame) {
|
onFrame: function(frame) {
|
||||||
if (lastFrame !== frame) {
|
if (currentKey !== "") {
|
||||||
lastFrame = frame;
|
emulator.gameboy.pressKey(currentKey);
|
||||||
|
keyCooldown--;
|
||||||
|
if (keyCooldown <= 0) {
|
||||||
|
currentKey = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastFrame = frame;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.get("/", async(request, reply) => {
|
fastify.get("/", async(request, reply) => {
|
||||||
|
@ -43,8 +50,12 @@ async function run() {
|
||||||
fastify.get("/control", async(request, reply) => {
|
fastify.get("/control", async(request, reply) => {
|
||||||
const button = request.query.button;
|
const button = request.query.button;
|
||||||
if (button) {
|
if (button) {
|
||||||
const mappedButton = KEYMAP[button.toUpperCase()];
|
if (keyCooldown > 0)
|
||||||
if (mappedButton) emulator.pressKeys(emulator.gameboy, [mappedButton]);
|
return;
|
||||||
|
if (KEYMAP[button]) {
|
||||||
|
currentKey = button;
|
||||||
|
keyCooldown = 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user