mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 18:46:11 +00:00
* Allow HTTP access to Raspberry Pi over local network Lower audio buffer maximum theoretical size to get the worker code to compile on Raspberry Pi * Add https port flag to run https worker and coordinator on the same machine Add https chain and key flags to allow to use an existing certificate and bypass letsencrypt Note the ping address resolution is still broken with this configuration * Add option to define a ping server in the coordinator This is useful when it is not predicatable what address and port the worker will be runnning at This only works when there is a single worker * Free temporarily allocated CStrings Store constant CString * Only load core once and unload it when done * Add Nintendo 64 support! Disclaimer: only tested with Mupen64plus and Mupen64plusNext on Raspberry Pi. It probably needs more work to run on every system and with other OpenGL libretro libraries. Input controls are hacked together, it really needs analog stick and remapping support to play in a nicer way. I am worried there might be a memory leak when unloading Mupen64plus but this needs further investigation. * Add analog sticks + R2,L2,R3,L3 support * Add client logic to control left analog stick via keyboard and touch Add client logic to toggle between dpad mode and analog mode (even for joystick) Might need to revisit if and when remapping is implemented Tocuh sensitivity of analog stick is pretty high, might need tweaking * Add cores for Raspberry Pi Add N64 core for linux x86_64 * Reset use OpenGL flag on nanoarch shutdown (line lost in refactoring)
94 lines
2.6 KiB
JavaScript
Vendored
94 lines
2.6 KiB
JavaScript
Vendored
const input = (() => {
|
|
let pollIntervalMs = 10;
|
|
let pollIntervalId = 0;
|
|
let controllerChangedIndex = -1;
|
|
|
|
let controllerState = {
|
|
// control
|
|
[KEY.A]: false,
|
|
[KEY.B]: false,
|
|
[KEY.X]: false,
|
|
[KEY.Y]: false,
|
|
[KEY.L]: false,
|
|
[KEY.R]: false,
|
|
[KEY.SELECT]: false,
|
|
[KEY.START]: false,
|
|
// dpad
|
|
[KEY.UP]: false,
|
|
[KEY.DOWN]: false,
|
|
[KEY.LEFT]: false,
|
|
[KEY.RIGHT]: false,
|
|
// extra
|
|
[KEY.R2]: false,
|
|
[KEY.L2]: false,
|
|
[KEY.R3]: false,
|
|
[KEY.L3]: false
|
|
};
|
|
|
|
const controllerEncoded = new Array(5).fill(0);
|
|
|
|
const keys = Object.keys(controllerState);
|
|
|
|
const poll = () => {
|
|
return {
|
|
setPollInterval: (ms) => pollIntervalMs = ms,
|
|
enable: () => {
|
|
if (pollIntervalId > 0) return;
|
|
|
|
log.info(`[input] poll set to ${pollIntervalMs}ms`);
|
|
pollIntervalId = setInterval(sendControllerState, pollIntervalMs)
|
|
},
|
|
disable: () => {
|
|
if (pollIntervalId < 1) return;
|
|
|
|
log.info('[input] poll has been disabled');
|
|
clearInterval(pollIntervalId);
|
|
pollIntervalId = 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
const sendControllerState = () => {
|
|
if (controllerChangedIndex >= 0) {
|
|
event.pub(CONTROLLER_UPDATED, _encodeState());
|
|
controllerChangedIndex = -1;
|
|
}
|
|
};
|
|
|
|
const setKeyState = (name, state) => {
|
|
if (controllerState[name] !== undefined) {
|
|
controllerState[name] = state;
|
|
controllerChangedIndex = Math.max(controllerChangedIndex, 0);
|
|
}
|
|
};
|
|
|
|
const setAxisChanged = (index, value) => {
|
|
if (controllerEncoded[index+1] !== undefined) {
|
|
controllerEncoded[index+1] = Math.floor(32767 * value);
|
|
controllerChangedIndex = Math.max(controllerChangedIndex, index+1);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Converts key state into a bitmap and prepends it to the axes state.
|
|
*
|
|
* @returns {Uint16Array} The controller state.
|
|
* First uint16 is the controller state bitmap.
|
|
* The other uint16 are the axes values.
|
|
* Truncated to the last value changed.
|
|
*
|
|
* @private
|
|
*/
|
|
const _encodeState = () => {
|
|
controllerEncoded[0] = 0;
|
|
for (let i = 0, len = keys.length; i < len; i++) controllerEncoded[0] += controllerState[keys[i]] ? 1 << i : 0;
|
|
|
|
return new Uint16Array(controllerEncoded.slice(0, controllerChangedIndex+1));
|
|
}
|
|
|
|
return {
|
|
poll,
|
|
setKeyState,
|
|
setAxisChanged,
|
|
}
|
|
})(event, KEY);
|