mirror of
https://github.com/DevL0rd/SkyNX
synced 2024-11-21 18:43:03 +00:00
everything works now except mouse input methods
This commit is contained in:
parent
25f4cfd3bc
commit
37b57fe9f1
10 changed files with 245 additions and 170 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -20,7 +20,8 @@
|
|||
"renderer.h": "c",
|
||||
"switch.h": "c",
|
||||
"xmemory0": "c",
|
||||
"socket.h": "c"
|
||||
"socket.h": "c",
|
||||
"unistd.h": "c"
|
||||
},
|
||||
"Lua.diagnostics.disable": [
|
||||
"lowercase-global",
|
||||
|
|
|
@ -29,7 +29,6 @@ const GyroServer = function (opt) {
|
|||
|
||||
var connectedClient = null;
|
||||
var lastRequestAt = 0;
|
||||
var phoneIsConnected = false;
|
||||
var packetCounter = 0;
|
||||
const clientTimeoutLimit = 5000;
|
||||
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
|
||||
ipcRenderer.on('close', function (event, data) {
|
||||
$("#startBtn").addClass('btn-dark').removeClass('btn-danger');
|
||||
$("#startBtn").html("Start Streamer");
|
||||
running = false;
|
||||
});
|
||||
var running = false;
|
||||
function connect() {
|
||||
$('#startBtn').addClass('btn-danger').removeClass('btn-dark');
|
||||
$("#startBtn").html("End Streamer");
|
||||
running = true;
|
||||
ipcRenderer.send('connect', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding, limitFPS: clientSettings.limitFPS, mouseControl: clientSettings.mouseControl });
|
||||
}
|
||||
function disconnect() {
|
||||
$("#startBtn").addClass('btn-dark').removeClass('btn-danger');
|
||||
$("#startBtn").html("Start Streamer");
|
||||
ipcRenderer.send('kill');
|
||||
running = false;
|
||||
}
|
||||
function restart() {
|
||||
ipcRenderer.send('restart', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding, limitFPS: clientSettings.limitFPS, mouseControl: clientSettings.mouseControl });
|
||||
if (running) {
|
||||
ipcRenderer.send('restart', { ip: clientSettings.ip, q: clientSettings.quality, disableVideo: clientSettings.disableVideo, disableAudio: clientSettings.disableAudio, abxySwap: clientSettings.abxySwap, encoding: clientSettings.encoding, limitFPS: clientSettings.limitFPS, mouseControl: clientSettings.mouseControl });
|
||||
}
|
||||
}
|
||||
$('#startBtn').click(function () {
|
||||
if (!running) {
|
||||
|
@ -20,9 +25,6 @@ $('#startBtn').click(function () {
|
|||
} else {
|
||||
disconnect();
|
||||
}
|
||||
$('#startBtn').addClass('btn-danger').removeClass('btn-dark');
|
||||
$("#startBtn").html("End Streamer");
|
||||
running = true;
|
||||
});
|
||||
$('#donateBtn').click(function () {
|
||||
ipcRenderer.send('donate');
|
||||
|
|
|
@ -20,7 +20,7 @@ var minimizeToTray = false;
|
|||
var autoChangeResolution = false;
|
||||
var ip = "0.0.0.0"
|
||||
var quality = 5;
|
||||
var hidStreamClient = new net.Socket();
|
||||
var hidStreamClient = null;
|
||||
var usingVideo = true;
|
||||
var usingAudio = true;
|
||||
var abxySwap = false;
|
||||
|
@ -33,6 +33,7 @@ var mouseControl = "ANALOG";
|
|||
var ffmpegProcess;
|
||||
var ffmpegAudioProcess;
|
||||
var clientSender;
|
||||
var isRunning = true;
|
||||
var restartingStream = false;
|
||||
var autoLauncher = new AutoLaunch({
|
||||
name: 'SkyNX',
|
||||
|
@ -89,6 +90,7 @@ app.on('ready', function () {
|
|||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
isRunning = false;
|
||||
killStream();
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
@ -118,6 +120,7 @@ function log(str) {
|
|||
|
||||
// Emitted when the window is closed.
|
||||
ipcMain.on('close', function () {
|
||||
isRunning = false;
|
||||
killStream();
|
||||
mainWindow.destroy();
|
||||
});
|
||||
|
@ -181,11 +184,12 @@ ipcMain.on("restartComputer", (event, fullMessage) => {
|
|||
//***************************************************************/
|
||||
|
||||
function killStream() {
|
||||
if (autoChangeResolution) {
|
||||
if (autoChangeResolution && !restartingStream) {
|
||||
changeScreenRes(originalW, originalH);
|
||||
}
|
||||
if (hidStreamClient) {
|
||||
if (hidStreamClient && !restartingStream) {
|
||||
hidStreamClient.end();
|
||||
hidStreamClient.destroy();
|
||||
}
|
||||
if (ffmpegProcess) {
|
||||
ffmpegProcess.kill();
|
||||
|
@ -193,28 +197,10 @@ function killStream() {
|
|||
if (ffmpegAudioProcess) {
|
||||
ffmpegAudioProcess.kill();
|
||||
}
|
||||
|
||||
clientSender.send("close");
|
||||
}
|
||||
function startStreamer(arg) {
|
||||
|
||||
screenWidth = mainScreen.bounds.width * screen.getPrimaryDisplay().scaleFactor;
|
||||
screenHeight = mainScreen.bounds.height * screen.getPrimaryDisplay().scaleFactor;
|
||||
ip = arg.ip
|
||||
quality = arg.q;
|
||||
hidStreamClient = new net.Socket();
|
||||
usingVideo = !arg.disableVideo;
|
||||
usingAudio = !arg.disableAudio;
|
||||
abxySwap = arg.abxySwap;
|
||||
limitFPS = arg.limitFPS;
|
||||
screenScale = screen.getPrimaryDisplay().scaleFactor;
|
||||
mouseControl = arg.mouseControl;
|
||||
encoding = arg.encoding
|
||||
|
||||
setTimeout(connectHID, 0);
|
||||
|
||||
function startStreamer() {
|
||||
if (usingVideo) {
|
||||
if (autoChangeResolution && !restartingStream) {
|
||||
if (autoChangeResolution) {
|
||||
changeScreenRes("1280", "720");
|
||||
}
|
||||
var fps = 60;
|
||||
|
@ -222,17 +208,20 @@ function startStreamer(arg) {
|
|||
fps = 30;
|
||||
}
|
||||
var ffmpegVideoArgs = [];
|
||||
if (encoding == "NVENC") { //Nvidia Encoding
|
||||
ffmpegVideoArgs = ["-probesize", "50M", "-hwaccel", "auto", "-f", "gdigrab", "-framerate", fps, "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-c:v", "h264_nvenc", "-gpu", "0", "-rc", "constqp/cbr/vbr", "-zerolatency", "1", "-f", "h264", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-cq:v", "19", "-g", "999999", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / (fps / 4)) + "M", "tcp://" + ip + ":2222"];
|
||||
var bitrate = quality * 1024;
|
||||
bitrate = bitrate + "k";
|
||||
console.log(bitrate)
|
||||
if (encoding == "NVENC") {
|
||||
ffmpegVideoArgs = ["-probesize", "32", "-hwaccel", "auto", "-y", "-f", "gdigrab", "-framerate", fps, "-vsync", "vfr", "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-c:v", "h264_nvenc", "-gpu", "0", "-rc", "vbr", "-zerolatency", "1", "-f", "h264", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-cq:v", "19", "-g", "999999", "-b:v", bitrate, "-minrate", bitrate, "-maxrate", bitrate, "-bufsize", bitrate, "tcp://" + ip + ":2222"];
|
||||
log("Using Nvidia Encoding");
|
||||
} else if (encoding == "AMDVCE") { //AMD Video Coding Engine
|
||||
ffmpegVideoArgs = ["-probesize", "50M", "-hwaccel", "auto", "-f", "gdigrab", "-framerate", fps, "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-c:v", "h264_amf", "-usage", "1", "-rc", "cbr", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / (fps / 4)) + "M", "tcp://" + ip + ":2222"];
|
||||
ffmpegVideoArgs = ["-probesize", "32", "-hwaccel", "auto", "-y", "-f", "gdigrab", "-framerate", fps, "-vsync", "vfr", "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-c:v", "h264_amf", "-usage", "1", "-rc", "vbr", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-b:v", bitrate, "-minrate", bitrate, "-maxrate", bitrate, "-bufsize", bitrate, "tcp://" + ip + ":2222"];
|
||||
log("Using AMD Video Coding Engine");
|
||||
} else if (encoding == "QSV") {
|
||||
ffmpegVideoArgs = ["-probesize", "50M", "-hwaccel", "auto", "-f", "gdigrab", "-framerate", fps, "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-c:v", "h264_qsv", "-preset", "faster", "-profile", "baseline", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / (fps / 4)) + "M", "tcp://" + ip + ":2222"];
|
||||
ffmpegVideoArgs = ["-probesize", "32", "-hwaccel", "auto", "-y", "-f", "gdigrab", "-framerate", fps, "-vsync", "vfr", "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-c:v", "h264_qsv", "-preset", "faster", "-profile", "baseline", "-vf", "scale=1280x720", "-pix_fmt", "yuv420p", "-b:v", bitrate, "-minrate", bitrate, "-maxrate", bitrate, "-bufsize", bitrate, "tcp://" + ip + ":2222"];
|
||||
log("Using Intel QSV Encoding");
|
||||
} else { //CPU Software Encoding
|
||||
ffmpegVideoArgs = ["-probesize", "50M", "-hwaccel", "auto", "-f", "gdigrab", "-framerate", fps, "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", "nal-hrd=cbr", "-b:v", quality + "M", "-minrate", quality - 3 + "M", "-maxrate", quality + "M", "-bufsize", (quality / 2) + "M", "tcp://" + ip + ":2222"];
|
||||
ffmpegVideoArgs = ["-probesize", "32", "-hwaccel", "auto", "-y", "-f", "gdigrab", "-framerate", fps, "-vsync", "vfr", "-video_size", screenWidth + "x" + screenHeight, "-offset_x", "0", "-offset_y", "0", "-draw_mouse", "1", "-i", "desktop", "-f", "h264", "-vf", "scale=1280x720", "-preset", "ultrafast", "-crf", "18", "-tune", "zerolatency", "-pix_fmt", "yuv420p", "-profile:v", "baseline", "-x264-params", "nal-hrd=vbr:opencl=true", "-b:v", bitrate, "-minrate", bitrate, "-maxrate", bitrate, "-bufsize", bitrate, "tcp://" + ip + ":2222"];
|
||||
log("Using CPU Encoding");
|
||||
}
|
||||
ffmpegProcess = spawn(
|
||||
|
@ -253,11 +242,12 @@ function startStreamer(arg) {
|
|||
if (autoChangeResolution && !restartingStream) {
|
||||
changeScreenRes(originalW, originalH);
|
||||
}
|
||||
ffmpegProcess = null;
|
||||
});
|
||||
}
|
||||
if (usingAudio) {
|
||||
ffmpegAudioProcess = spawn(
|
||||
"./lib/ffmpeg.exe",
|
||||
"./lib/ffmpeg_old.exe",
|
||||
["-y", "-f", "dshow", "-i", 'audio=virtual-audio-capturer', "-f", "s16le", "-ar", "16000", "-ac", "2", "-c:a", "pcm_s16le", "udp://" + ip + ":2224?pkt_size=640"],
|
||||
{ detached: false }
|
||||
);
|
||||
|
@ -269,28 +259,47 @@ function startStreamer(arg) {
|
|||
});
|
||||
ffmpegAudioProcess.on('close', (code) => {
|
||||
log(`AudioProcess process exited with code ${code}`);
|
||||
ffmpegAudioProcess = null;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setArgs(arg) {
|
||||
screenWidth = mainScreen.bounds.width * screen.getPrimaryDisplay().scaleFactor;
|
||||
screenHeight = mainScreen.bounds.height * screen.getPrimaryDisplay().scaleFactor;
|
||||
ip = arg.ip
|
||||
quality = arg.q;
|
||||
hidStreamClient = new net.Socket();
|
||||
usingVideo = !arg.disableVideo;
|
||||
usingAudio = !arg.disableAudio;
|
||||
abxySwap = arg.abxySwap;
|
||||
limitFPS = arg.limitFPS;
|
||||
screenScale = screen.getPrimaryDisplay().scaleFactor;
|
||||
mouseControl = arg.mouseControl;
|
||||
encoding = arg.encoding
|
||||
}
|
||||
ipcMain.on('connect', (event, arg) => {
|
||||
clientSender = event.sender;
|
||||
killStream()
|
||||
startStreamer(arg);
|
||||
setArgs(arg);
|
||||
// killStream()
|
||||
isRunning = true;
|
||||
setTimeout(connectHID, 0);
|
||||
})
|
||||
|
||||
ipcMain.on('restart', (event, arg) => {
|
||||
restartingStream = true;
|
||||
setArgs(arg);
|
||||
killStream()
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
startStreamer();
|
||||
restartingStream = false;
|
||||
startStreamer(arg);
|
||||
}, 1000)
|
||||
}, 2000)
|
||||
});
|
||||
|
||||
|
||||
ipcMain.on('kill', (event, arg) => {
|
||||
isRunning = false;
|
||||
restartingStream = false;
|
||||
killStream()
|
||||
});
|
||||
|
||||
|
@ -349,6 +358,7 @@ function parseInputStruct(buff) {
|
|||
.floatle('gyroX')
|
||||
.floatle('gyroY')
|
||||
.floatle('gyroZ')
|
||||
.word32Ule('frameRate')
|
||||
.word32Ule('controllerCount')
|
||||
input._setBuff(buff);
|
||||
return input;
|
||||
|
@ -655,10 +665,9 @@ function handleTouchInput(hid) {
|
|||
function handleGyroAndAccel(hid) {
|
||||
var gyro = { x: hid.get("gyroX"), y: hid.get("gyroY"), z: hid.get("gyroZ") }
|
||||
var accel = { x: hid.get("accelX"), y: hid.get("accelY"), z: hid.get("accelZ") }
|
||||
for (axis in gyro) {
|
||||
gyro[axis] *= 250;
|
||||
}
|
||||
gyro.y *= -1;
|
||||
// for (axis in gyro) {
|
||||
// gyro[axis] *= 250;
|
||||
// }
|
||||
GyroServ.sendMotionData(gyro, accel);
|
||||
}
|
||||
|
||||
|
@ -667,16 +676,18 @@ var hidDataBuffer = "";
|
|||
function connectHID() {
|
||||
log("Connecting to switch...");
|
||||
log(ip)
|
||||
hidStreamClient = new net.Socket();
|
||||
hidStreamClient.connect(2223, ip, function () {
|
||||
hidStreamClient.setNoDelay(true);
|
||||
log('Connected to Switch!');
|
||||
startStreamer();
|
||||
});
|
||||
hidStreamClient.on('error', function (ex) {
|
||||
if (ex) {
|
||||
log("Could not connect to Switch. Connection timed out...");
|
||||
// setTimeout(connectHID, 1000);
|
||||
}
|
||||
});
|
||||
hidStreamClient.on('error', function (err) {
|
||||
log('Error: ' + err);
|
||||
// if (err.code == "ECONNREFUSED") {
|
||||
// setTimeout(connectHID, 1000);
|
||||
// }
|
||||
})
|
||||
hidStreamClient.on('data', function (chunk) {
|
||||
hidDataBuffer += chunk.toString("hex");
|
||||
var completeData = "";
|
||||
|
@ -697,16 +708,17 @@ function connectHID() {
|
|||
if (controllerCount > controllerIds.length) {
|
||||
plugControllerIn();
|
||||
}
|
||||
// fpsPrintTimer++;
|
||||
// if (fpsPrintTimer == 10) {
|
||||
// log("switchFps=" + hid.get("frameRate"))
|
||||
// fpsPrintTimer = 0;
|
||||
// }
|
||||
fpsPrintTimer++;
|
||||
if (fpsPrintTimer == 10) {
|
||||
log("switchFps=" + hid.get("frameRate"))
|
||||
fpsPrintTimer = 0;
|
||||
}
|
||||
var playerNumber;
|
||||
for (i in controllerIds) {
|
||||
playerNumber = parseInt(i) + 1;
|
||||
handleControllerInput(hid, controllerIds[i], playerNumber);
|
||||
}
|
||||
handleGyroAndAccel(hid);
|
||||
handleMouseInputToggling(hid, 1);
|
||||
if (mouseControl == "ANALOG" && mouseInput) {
|
||||
handleAnalogMouse(hid, 1);
|
||||
|
@ -714,7 +726,6 @@ function connectHID() {
|
|||
handleGyroMouse(hid, 1);
|
||||
}
|
||||
handleTouchInput(hid);
|
||||
handleGyroAndAccel(hid);
|
||||
});
|
||||
|
||||
hidStreamClient.on('close', function () {
|
||||
|
@ -726,7 +737,10 @@ function connectHID() {
|
|||
controllerIds = [];
|
||||
} catch (error) {
|
||||
}
|
||||
// killStream();
|
||||
killStream();
|
||||
if (isRunning) {
|
||||
setTimeout(connectHID, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,74 +6,112 @@
|
|||
#include "renderer.h"
|
||||
|
||||
PadState pad;
|
||||
PadState pad2;
|
||||
PadState pad3;
|
||||
PadState pad4;
|
||||
HiddbgAbstractedPadHandle pads[4] = {0};
|
||||
HiddbgAbstractedPadState states[4] = {0};
|
||||
HidSixAxisSensorHandle handles[4];
|
||||
s32 tmpout = 0;
|
||||
Result rc = 0;
|
||||
void gamePadSend(JoyConSocket *connection)
|
||||
{
|
||||
JoyPkg pkg;
|
||||
HidAnalogStickState analog_stick_l;
|
||||
HidAnalogStickState analog_stick_r;
|
||||
pkg.streamStart = (uint64_t)UINT64_MAX; // easy identifiers for the start and stop of tcp stream
|
||||
pkg.streamEnd = (uint64_t)UINT64_MAX / 2;
|
||||
pkg.controllerCount = (uint32_t)1;
|
||||
|
||||
uint32_t controllerCount = 0;
|
||||
padUpdate(&pad);
|
||||
padUpdate(&pad2);
|
||||
padUpdate(&pad3);
|
||||
padUpdate(&pad4);
|
||||
|
||||
u64 kDown = padGetButtonsDown(&pad);
|
||||
u64 kHeld = padGetButtons(&pad);
|
||||
u64 kUp = padGetButtonsUp(&pad);
|
||||
if (padIsConnected(&pad))
|
||||
{
|
||||
controllerCount++;
|
||||
analog_stick_l = padGetStickPos(&pad, 0);
|
||||
analog_stick_r = padGetStickPos(&pad, 1);
|
||||
pkg.heldKeys1 = (uint32_t)padGetButtons(&pad);
|
||||
pkg.lJoyX1 = (int32_t)analog_stick_l.x;
|
||||
pkg.lJoyY1 = (int32_t)analog_stick_l.y;
|
||||
pkg.rJoyX1 = (int32_t)analog_stick_r.x;
|
||||
pkg.rJoyY1 = (int32_t)analog_stick_r.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg.heldKeys1 = 0;
|
||||
pkg.lJoyX1 = 0;
|
||||
pkg.lJoyY1 = 0;
|
||||
pkg.rJoyX1 = 0;
|
||||
pkg.rJoyY1 = 0;
|
||||
}
|
||||
|
||||
tmpout = 0;
|
||||
rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads) / sizeof(u64), &tmpout);
|
||||
if (padIsConnected(&pad2))
|
||||
{
|
||||
controllerCount++;
|
||||
analog_stick_l = padGetStickPos(&pad2, 0);
|
||||
analog_stick_r = padGetStickPos(&pad2, 1);
|
||||
pkg.heldKeys2 = (uint32_t)padGetButtons(&pad2);
|
||||
pkg.lJoyX2 = (int32_t)analog_stick_l.x;
|
||||
pkg.lJoyY2 = (int32_t)analog_stick_l.y;
|
||||
pkg.rJoyX2 = (int32_t)analog_stick_r.x;
|
||||
pkg.rJoyY2 = (int32_t)analog_stick_r.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg.heldKeys2 = 0;
|
||||
pkg.lJoyX2 = 0;
|
||||
pkg.lJoyY2 = 0;
|
||||
pkg.rJoyX2 = 0;
|
||||
pkg.rJoyY2 = 0;
|
||||
}
|
||||
|
||||
// if (tmpout>=1) {
|
||||
// s8 AbstractedVirtualPadId=0;
|
||||
if (padIsConnected(&pad3))
|
||||
{
|
||||
controllerCount++;
|
||||
analog_stick_l = padGetStickPos(&pad3, 0);
|
||||
analog_stick_r = padGetStickPos(&pad3, 1);
|
||||
pkg.heldKeys3 = (uint32_t)padGetButtons(&pad3);
|
||||
pkg.lJoyX3 = (int32_t)analog_stick_l.x;
|
||||
pkg.lJoyY3 = (int32_t)analog_stick_l.y;
|
||||
pkg.rJoyX3 = (int32_t)analog_stick_r.x;
|
||||
pkg.rJoyY3 = (int32_t)analog_stick_r.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg.heldKeys3 = 0;
|
||||
pkg.lJoyX3 = 0;
|
||||
pkg.lJoyY3 = 0;
|
||||
pkg.rJoyX3 = 0;
|
||||
pkg.rJoyY3 = 0;
|
||||
}
|
||||
|
||||
// // Setup state. You could also construct it without using hiddbgGetAbstractedPadsState, if preferred.
|
||||
if (padIsConnected(&pad4))
|
||||
{
|
||||
controllerCount++;
|
||||
analog_stick_l = padGetStickPos(&pad4, 0);
|
||||
analog_stick_r = padGetStickPos(&pad4, 1);
|
||||
pkg.heldKeys4 = (uint32_t)padGetButtons(&pad4);
|
||||
pkg.lJoyX4 = (int32_t)analog_stick_l.x;
|
||||
pkg.lJoyY4 = (int32_t)analog_stick_l.y;
|
||||
pkg.rJoyX4 = (int32_t)analog_stick_r.x;
|
||||
pkg.rJoyY4 = (int32_t)analog_stick_r.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
pkg.heldKeys4 = 0;
|
||||
pkg.lJoyX4 = 0;
|
||||
pkg.lJoyY4 = 0;
|
||||
pkg.rJoyX4 = 0;
|
||||
pkg.rJoyY4 = 0;
|
||||
}
|
||||
|
||||
// // Set type to one that's usable with state-merge. Note that this is also available with Hdls.
|
||||
// states[0].type = BIT(1);
|
||||
// // Use state-merge for the above controller, the state will be merged with an existing controller.
|
||||
// // For a plain virtual controller, use NpadInterfaceType_Bluetooth, and update the above type value.
|
||||
// states[0].npadInterfaceType = HidNpadInterfaceType_Rail;
|
||||
|
||||
// states[0].state.buttons |= HidNpadButton_ZL;
|
||||
|
||||
// rc = hiddbgSetAutoPilotVirtualPadState(AbstractedVirtualPadId, &states[0]);
|
||||
// printf("hiddbgSetAutoPilotVirtualPadState(): 0x%x\n", rc);
|
||||
// }
|
||||
|
||||
HidAnalogStickState analog_stick_l = padGetStickPos(&pad, 0);
|
||||
HidAnalogStickState analog_stick_r = padGetStickPos(&pad, 1);
|
||||
pkg.heldKeys1 = (uint32_t)kHeld;
|
||||
pkg.lJoyX1 = (int32_t)analog_stick_l.x;
|
||||
pkg.lJoyY1 = (int32_t)analog_stick_l.y;
|
||||
pkg.rJoyX1 = (int32_t)analog_stick_r.x;
|
||||
pkg.rJoyY1 = (int32_t)analog_stick_r.y;
|
||||
|
||||
pkg.heldKeys2 = (uint32_t)states[1].state.buttons;
|
||||
pkg.lJoyX2 = (int32_t)states[1].state.analog_stick_l.x;
|
||||
pkg.lJoyY2 = (int32_t)states[1].state.analog_stick_l.y;
|
||||
pkg.rJoyX2 = (int32_t)states[1].state.analog_stick_r.x;
|
||||
pkg.rJoyY2 = (int32_t)states[1].state.analog_stick_r.y;
|
||||
|
||||
pkg.heldKeys3 = (uint32_t)states[2].state.buttons;
|
||||
pkg.lJoyX3 = (int32_t)states[2].state.analog_stick_l.x;
|
||||
pkg.lJoyY3 = (int32_t)states[2].state.analog_stick_l.y;
|
||||
pkg.rJoyX3 = (int32_t)states[2].state.analog_stick_r.x;
|
||||
pkg.rJoyY3 = (int32_t)states[2].state.analog_stick_r.y;
|
||||
|
||||
pkg.heldKeys4 = (uint32_t)states[3].state.buttons;
|
||||
pkg.lJoyX4 = (int32_t)states[3].state.analog_stick_l.x;
|
||||
pkg.lJoyY4 = (int32_t)states[3].state.analog_stick_l.y;
|
||||
pkg.rJoyX4 = (int32_t)states[3].state.analog_stick_r.x;
|
||||
pkg.rJoyY4 = (int32_t)states[3].state.analog_stick_r.y;
|
||||
|
||||
// printf("%d %d %d %d\n", pkg.lJoyX1, pkg.lJoyY1, pkg.rJoyX1, pkg.rJoyY1);
|
||||
// printf("%d %d %d %d\n", pkg.lJoyX2, pkg.lJoyY2, pkg.rJoyX2, pkg.rJoyY2);
|
||||
// printf("%d %d %d %d\n", pkg.lJoyX3, pkg.lJoyY3, pkg.rJoyX3, pkg.rJoyY3);
|
||||
// printf("%d %d %d %d\n", pkg.lJoyX4, pkg.lJoyY4, pkg.rJoyX4, pkg.rJoyY4);
|
||||
pkg.controllerCount = (uint32_t)controllerCount;
|
||||
// printf("controllerCount: %d\n", controllerCount);
|
||||
// printf("%d %d %d %d %d\n", pkg.heldKeys1, pkg.lJoyX1, pkg.lJoyY1, pkg.rJoyX1, pkg.rJoyY1);
|
||||
// printf("%d %d %d %d %d\n", pkg.heldKeys2, pkg.lJoyX2, pkg.lJoyY2, pkg.rJoyX2, pkg.rJoyY2);
|
||||
// printf("%d %d %d %d %d\n", pkg.heldKeys3, pkg.lJoyX3, pkg.lJoyY3, pkg.rJoyX3, pkg.rJoyY3);
|
||||
// printf("%d %d %d %d %d\n", pkg.heldKeys4, pkg.lJoyX4, pkg.lJoyY4, pkg.rJoyX4, pkg.rJoyY4);
|
||||
|
||||
HidTouchScreenState touchState = {0};
|
||||
if (hidGetTouchScreenStates(&touchState, 1))
|
||||
|
@ -84,28 +122,32 @@ void gamePadSend(JoyConSocket *connection)
|
|||
pkg.touchY2 = (uint32_t)touchState.touches[1].y;
|
||||
}
|
||||
// printf("%d %d %d %d\n", pkg.touchX1, pkg.touchY1, pkg.touchX2, pkg.touchY2);
|
||||
// HidSixAxisSensorState sixaxis = {0};
|
||||
// u64 style_set = padGetStyleSet(&pad);
|
||||
// if (style_set & HidNpadStyleTag_NpadHandheld)
|
||||
// hidGetSixAxisSensorStates(handles[0], &sixaxis, 1);
|
||||
// else if (style_set & HidNpadStyleTag_NpadFullKey)
|
||||
// hidGetSixAxisSensorStates(handles[1], &sixaxis, 1);
|
||||
// else if (style_set & HidNpadStyleTag_NpadJoyDual)
|
||||
// {
|
||||
// // For JoyDual, read from either the Left or Right Joy-Con depending on which is/are connected
|
||||
// u64 attrib = padGetAttributes(&pad);
|
||||
// if (attrib & HidNpadAttribute_IsLeftConnected)
|
||||
// hidGetSixAxisSensorStates(handles[2], &sixaxis, 1);
|
||||
// else if (attrib & HidNpadAttribute_IsRightConnected)
|
||||
// hidGetSixAxisSensorStates(handles[3], &sixaxis, 1);
|
||||
// }
|
||||
// pkg.accelX = (float_t)sixaxis.acceleration.x;
|
||||
// pkg.accelY = (float_t)sixaxis.acceleration.y;
|
||||
// pkg.accelZ = (float_t)sixaxis.acceleration.z;
|
||||
// pkg.gyroX = (float_t)sixaxis.angle.x;
|
||||
// pkg.gyroY = (float_t)sixaxis.angle.y;
|
||||
// pkg.gyroZ = (float_t)sixaxis.angle.z;
|
||||
HidSixAxisSensorState sixaxis = {0};
|
||||
u64 style_set = padGetStyleSet(&pad);
|
||||
if (style_set & HidNpadStyleTag_NpadHandheld)
|
||||
hidGetSixAxisSensorStates(handles[0], &sixaxis, 1);
|
||||
else if (style_set & HidNpadStyleTag_NpadFullKey)
|
||||
hidGetSixAxisSensorStates(handles[1], &sixaxis, 1);
|
||||
else if (style_set & HidNpadStyleTag_NpadJoyDual)
|
||||
{
|
||||
// For JoyDual, read from either the Left or Right Joy-Con depending on which is/are connected
|
||||
u64 attrib = padGetAttributes(&pad);
|
||||
if (attrib & HidNpadAttribute_IsLeftConnected)
|
||||
hidGetSixAxisSensorStates(handles[2], &sixaxis, 1);
|
||||
else if (attrib & HidNpadAttribute_IsRightConnected)
|
||||
hidGetSixAxisSensorStates(handles[3], &sixaxis, 1);
|
||||
}
|
||||
pkg.accelX = (float_t)sixaxis.acceleration.x;
|
||||
pkg.accelY = (float_t)sixaxis.acceleration.y;
|
||||
pkg.accelZ = (float_t)sixaxis.acceleration.z;
|
||||
pkg.gyroX = (float_t)sixaxis.angle.x;
|
||||
pkg.gyroY = (float_t)sixaxis.angle.y;
|
||||
pkg.gyroZ = (float_t)sixaxis.angle.z;
|
||||
// acceleration
|
||||
// angle
|
||||
// angular_velocity
|
||||
// printf("%f %f %f %f %f %f\n", pkg.accelX, pkg.accelY, pkg.accelZ, pkg.gyroX, pkg.gyroY, pkg.gyroZ);
|
||||
pkg.renderFPS = (uint32_t)getFPS();
|
||||
sendJoyConInput(connection, &pkg);
|
||||
}
|
||||
|
||||
|
@ -118,11 +160,12 @@ void handleInput(JoyConSocket *connection)
|
|||
void input_init()
|
||||
{
|
||||
padConfigureInput(4, HidNpadStyleSet_NpadStandard);
|
||||
padInitializeAny(&pad);
|
||||
rc = hiddbgInitialize();
|
||||
padInitialize(&pad, HidNpadIdType_No1, HidNpadIdType_Handheld);
|
||||
padInitialize(&pad2, HidNpadIdType_No2, HidNpadStyleTag_NpadJoyDual);
|
||||
padInitialize(&pad3, HidNpadIdType_No3, HidNpadStyleTag_NpadJoyDual);
|
||||
padInitialize(&pad4, HidNpadIdType_No4, HidNpadStyleTag_NpadJoyDual);
|
||||
|
||||
hidInitializeTouchScreen();
|
||||
// It's necessary to initialize these separately as they all have different handle values
|
||||
HidSixAxisSensorHandle handles[4];
|
||||
hidGetSixAxisSensorHandles(&handles[0], 1, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
|
||||
hidGetSixAxisSensorHandles(&handles[1], 1, HidNpadIdType_No1, HidNpadStyleTag_NpadFullKey);
|
||||
hidGetSixAxisSensorHandles(&handles[2], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
|
||||
|
@ -133,8 +176,7 @@ void input_init()
|
|||
}
|
||||
void input_unInit()
|
||||
{
|
||||
hiddbgUnsetAllAutoPilotVirtualPadState();
|
||||
hiddbgExit();
|
||||
|
||||
hidStopSixAxisSensor(handles[0]);
|
||||
hidStopSixAxisSensor(handles[1]);
|
||||
hidStopSixAxisSensor(handles[2]);
|
||||
|
|
|
@ -52,12 +52,16 @@ ClkrstSession cpuSession;
|
|||
void init()
|
||||
{
|
||||
// consoleInit(NULL);
|
||||
/* Init all switch required systems */
|
||||
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_None);
|
||||
appletSetWirelessPriorityMode(AppletWirelessPriorityMode_OptimizedForWlan);
|
||||
appletSetAutoSleepDisabled(true);
|
||||
|
||||
printf("networkInit\n");
|
||||
network_init(&socketInitConf);
|
||||
|
||||
printf("romfsInit\n");
|
||||
romfsInit();
|
||||
// chdir("romfs:/");
|
||||
|
||||
printf("audoutInitialize\n");
|
||||
audoutInitialize();
|
||||
|
@ -83,8 +87,6 @@ void init()
|
|||
videoContext->renderContext = renderContext;
|
||||
printf("startRender\n");
|
||||
startRender(videoContext);
|
||||
printf("appletSetIdleTimeDetectionExtension\n");
|
||||
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_None);
|
||||
printf("Complete INIT!\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef struct
|
|||
float_t gyroX;
|
||||
float_t gyroY;
|
||||
float_t gyroZ;
|
||||
uint32_t renderFPS;
|
||||
uint32_t controllerCount;
|
||||
uint64_t streamEnd;
|
||||
} JoyPkg;
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
float timeThen = 0;
|
||||
float timeNow = 1;
|
||||
float delta = 1;
|
||||
uint32_t renderFPS = 0;
|
||||
uint32_t getFPS()
|
||||
{
|
||||
return renderFPS;
|
||||
}
|
||||
void initDelta()
|
||||
{
|
||||
timeThen = svcGetSystemTick();
|
||||
|
@ -196,16 +201,15 @@ void initBubbles()
|
|||
}
|
||||
}
|
||||
SDL_Texture *logoTexture = NULL;
|
||||
bool logoLoaded = false;
|
||||
RenderContext *makeRenderer()
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
||||
SDL_Log("TTF_Init");
|
||||
IMG_Init(IMG_INIT_PNG);
|
||||
TTF_Init();
|
||||
SDL_Log("plInitialize");
|
||||
chdir("romfs:/");
|
||||
plInitialize(PlServiceType_User);
|
||||
SDL_Log("malloc RenderContext\n");
|
||||
RenderContext *context = malloc(sizeof(RenderContext));
|
||||
SDL_Log("SDL_CreateWindow\n");
|
||||
context->window = SDL_CreateWindow("sdl2_gles2", 0, 0, RESX, RESY, SDL_WINDOW_FULLSCREEN);
|
||||
if (context->window == NULL)
|
||||
{
|
||||
|
@ -215,7 +219,6 @@ RenderContext *makeRenderer()
|
|||
;
|
||||
}
|
||||
|
||||
SDL_Log("SDL_CreateRenderer\n");
|
||||
context->renderer = SDL_CreateRenderer(context->window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (context->renderer == NULL)
|
||||
{
|
||||
|
@ -224,20 +227,24 @@ RenderContext *makeRenderer()
|
|||
while (1)
|
||||
;
|
||||
}
|
||||
SDL_Log("SDL_SetRenderDrawBlendMode");
|
||||
SDL_SetRenderDrawBlendMode(context->renderer, SDL_BLENDMODE_BLEND); // enable transparency
|
||||
|
||||
SDL_Log("IMG_LoadTexture ICON");
|
||||
IMG_Init(IMG_INIT_PNG);
|
||||
logoTexture = IMG_LoadTexture(context->renderer, "iconTransparent.png");
|
||||
// SDL_Surface *logo = IMG_Load("iconTransparent.png");
|
||||
// if (logo)
|
||||
// {
|
||||
// logoTexture = SDL_CreateTextureFromSurface(context->renderer, logo);
|
||||
// SDL_FreeSurface(logo);
|
||||
// }
|
||||
SDL_Log("IMG_LoadTexture iconTransparent");
|
||||
// logoTexture = IMG_LoadTexture(context->renderer, "iconTransparent.png");
|
||||
SDL_Surface *sdllogo = IMG_Load("iconTransparent.png");
|
||||
if (sdllogo == NULL)
|
||||
{
|
||||
SDL_Log("IMG_Load: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Log("WIDTH: %d\n", sdllogo->w);
|
||||
SDL_Log("HEIGHT: %d\n", sdllogo->h);
|
||||
logoTexture = SDL_CreateTextureFromSurface(context->renderer, sdllogo);
|
||||
SDL_FreeSurface(sdllogo);
|
||||
}
|
||||
|
||||
// Create font cache
|
||||
SDL_Log("SDL_CreateTexture");
|
||||
context->yuv_text = SDL_CreateTexture(context->renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
|
||||
|
||||
context->rect.x = 0;
|
||||
|
@ -245,27 +252,19 @@ RenderContext *makeRenderer()
|
|||
context->rect.w = RESX;
|
||||
context->rect.h = RESY;
|
||||
|
||||
SDL_Log("mutexInit texture_mut");
|
||||
mutexInit(&context->texture_mut);
|
||||
SDL_Log("mutexInit frame_avail_mut");
|
||||
mutexInit(&context->frame_avail_mut);
|
||||
SDL_Log("mutexInit video_active_mut");
|
||||
mutexInit(&context->video_active_mut);
|
||||
context->frame_avail = false;
|
||||
context->video_active = false;
|
||||
|
||||
PlFontData fontData, fontExtData;
|
||||
SDL_Log("plGetSharedFontByType");
|
||||
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
|
||||
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
|
||||
SDL_Log((char *)fontData.address);
|
||||
SDL_Log("FC_CreateFont");
|
||||
context->font = FC_CreateFont();
|
||||
SDL_Log("FC_LoadFont_RW");
|
||||
FC_LoadFont_RW(context->font, context->renderer, SDL_RWFromMem((void *)fontData.address, fontData.size), SDL_RWFromMem((void *)fontExtData.address, fontExtData.size), 1, 40, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
|
||||
SDL_Log("initDelta");
|
||||
initDelta();
|
||||
SDL_Log("initBubbles");
|
||||
initBubbles();
|
||||
|
||||
return context;
|
||||
|
@ -460,6 +459,7 @@ void renderBubbles(RenderContext *context)
|
|||
fillCircle(context, bubbles[i].x, bubbles[i].y, bubbles[i].r, bubbles[i].color);
|
||||
}
|
||||
}
|
||||
|
||||
void drawSplash(RenderContext *context)
|
||||
{
|
||||
loopStart();
|
||||
|
@ -481,13 +481,18 @@ void drawSplash(RenderContext *context)
|
|||
int imgH = 256;
|
||||
// printf("SDL_QueryTexture\n");
|
||||
// SDL_QueryTexture(logoTexture, NULL, NULL, &imgW, &imgH);
|
||||
// imgDest.x = (1280 / 2) - (imgW / 2);
|
||||
// imgDest.y = (720 / 2) - (imgH / 2);
|
||||
SDL_Rect imgDest;
|
||||
imgDest.x = (1280 / 2) - (imgW / 2);
|
||||
imgDest.y = (720 / 2) - (imgH / 2);
|
||||
imgDest.w = imgW;
|
||||
imgDest.h = imgH;
|
||||
// printf("SDL_RenderCopy\n");
|
||||
// SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
|
||||
if (logoTexture != NULL)
|
||||
{
|
||||
// printf("SDL_RenderCopy\n");
|
||||
// SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
|
||||
}
|
||||
|
||||
SDL_Color white = {230, 230, 230, 255};
|
||||
u32 ip = gethostid();
|
||||
|
@ -511,6 +516,13 @@ void handleFrame(RenderContext *renderContext, VideoContext *videoContext)
|
|||
memcpy(renderContext->VPlane, frame->data[2], sizeof(renderContext->VPlane));
|
||||
mutexUnlock(&renderContext->texture_mut);
|
||||
setFrameAvail(renderContext);
|
||||
|
||||
if (++videoContext->video_frame_count % 60 == 0)
|
||||
{
|
||||
new_time = svcGetSystemTick();
|
||||
renderFPS = (uint32_t)(60.0 / ((new_time - old_time) / 19200000.0));
|
||||
old_time = new_time;
|
||||
}
|
||||
}
|
||||
|
||||
void displayFrame(RenderContext *renderContext)
|
||||
|
|
|
@ -17,6 +17,8 @@ void handleFrame(RenderContext *context, VideoContext *videoContext);
|
|||
/* Draws a frame */
|
||||
void displayFrame(RenderContext *renderContext);
|
||||
|
||||
uint32_t getFPS(void);
|
||||
|
||||
/* Deallocates the render context */
|
||||
void freeRenderer(RenderContext *context);
|
||||
|
||||
|
|
Loading…
Reference in a new issue