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",
|
"renderer.h": "c",
|
||||||
"switch.h": "c",
|
"switch.h": "c",
|
||||||
"xmemory0": "c",
|
"xmemory0": "c",
|
||||||
"socket.h": "c"
|
"socket.h": "c",
|
||||||
|
"unistd.h": "c"
|
||||||
},
|
},
|
||||||
"Lua.diagnostics.disable": [
|
"Lua.diagnostics.disable": [
|
||||||
"lowercase-global",
|
"lowercase-global",
|
||||||
|
|
|
@ -29,7 +29,6 @@ const GyroServer = function (opt) {
|
||||||
|
|
||||||
var connectedClient = null;
|
var connectedClient = null;
|
||||||
var lastRequestAt = 0;
|
var lastRequestAt = 0;
|
||||||
var phoneIsConnected = false;
|
|
||||||
var packetCounter = 0;
|
var packetCounter = 0;
|
||||||
const clientTimeoutLimit = 5000;
|
const clientTimeoutLimit = 5000;
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
|
|
||||||
ipcRenderer.on('close', function (event, data) {
|
ipcRenderer.on('close', function (event, data) {
|
||||||
$("#startBtn").addClass('btn-dark').removeClass('btn-danger');
|
|
||||||
$("#startBtn").html("Start Streamer");
|
|
||||||
running = false;
|
|
||||||
});
|
});
|
||||||
var running = false;
|
var running = false;
|
||||||
function connect() {
|
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 });
|
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() {
|
function disconnect() {
|
||||||
|
$("#startBtn").addClass('btn-dark').removeClass('btn-danger');
|
||||||
|
$("#startBtn").html("Start Streamer");
|
||||||
ipcRenderer.send('kill');
|
ipcRenderer.send('kill');
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
function restart() {
|
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 () {
|
$('#startBtn').click(function () {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
|
@ -20,9 +25,6 @@ $('#startBtn').click(function () {
|
||||||
} else {
|
} else {
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
$('#startBtn').addClass('btn-danger').removeClass('btn-dark');
|
|
||||||
$("#startBtn").html("End Streamer");
|
|
||||||
running = true;
|
|
||||||
});
|
});
|
||||||
$('#donateBtn').click(function () {
|
$('#donateBtn').click(function () {
|
||||||
ipcRenderer.send('donate');
|
ipcRenderer.send('donate');
|
||||||
|
|
|
@ -20,7 +20,7 @@ var minimizeToTray = false;
|
||||||
var autoChangeResolution = false;
|
var autoChangeResolution = false;
|
||||||
var ip = "0.0.0.0"
|
var ip = "0.0.0.0"
|
||||||
var quality = 5;
|
var quality = 5;
|
||||||
var hidStreamClient = new net.Socket();
|
var hidStreamClient = null;
|
||||||
var usingVideo = true;
|
var usingVideo = true;
|
||||||
var usingAudio = true;
|
var usingAudio = true;
|
||||||
var abxySwap = false;
|
var abxySwap = false;
|
||||||
|
@ -33,6 +33,7 @@ var mouseControl = "ANALOG";
|
||||||
var ffmpegProcess;
|
var ffmpegProcess;
|
||||||
var ffmpegAudioProcess;
|
var ffmpegAudioProcess;
|
||||||
var clientSender;
|
var clientSender;
|
||||||
|
var isRunning = true;
|
||||||
var restartingStream = false;
|
var restartingStream = false;
|
||||||
var autoLauncher = new AutoLaunch({
|
var autoLauncher = new AutoLaunch({
|
||||||
name: 'SkyNX',
|
name: 'SkyNX',
|
||||||
|
@ -89,6 +90,7 @@ app.on('ready', function () {
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', function () {
|
||||||
|
isRunning = false;
|
||||||
killStream();
|
killStream();
|
||||||
if (process.platform !== 'darwin') app.quit()
|
if (process.platform !== 'darwin') app.quit()
|
||||||
})
|
})
|
||||||
|
@ -118,6 +120,7 @@ function log(str) {
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
ipcMain.on('close', function () {
|
ipcMain.on('close', function () {
|
||||||
|
isRunning = false;
|
||||||
killStream();
|
killStream();
|
||||||
mainWindow.destroy();
|
mainWindow.destroy();
|
||||||
});
|
});
|
||||||
|
@ -181,11 +184,12 @@ ipcMain.on("restartComputer", (event, fullMessage) => {
|
||||||
//***************************************************************/
|
//***************************************************************/
|
||||||
|
|
||||||
function killStream() {
|
function killStream() {
|
||||||
if (autoChangeResolution) {
|
if (autoChangeResolution && !restartingStream) {
|
||||||
changeScreenRes(originalW, originalH);
|
changeScreenRes(originalW, originalH);
|
||||||
}
|
}
|
||||||
if (hidStreamClient) {
|
if (hidStreamClient && !restartingStream) {
|
||||||
hidStreamClient.end();
|
hidStreamClient.end();
|
||||||
|
hidStreamClient.destroy();
|
||||||
}
|
}
|
||||||
if (ffmpegProcess) {
|
if (ffmpegProcess) {
|
||||||
ffmpegProcess.kill();
|
ffmpegProcess.kill();
|
||||||
|
@ -193,28 +197,10 @@ function killStream() {
|
||||||
if (ffmpegAudioProcess) {
|
if (ffmpegAudioProcess) {
|
||||||
ffmpegAudioProcess.kill();
|
ffmpegAudioProcess.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSender.send("close");
|
|
||||||
}
|
}
|
||||||
function startStreamer(arg) {
|
function startStreamer() {
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (usingVideo) {
|
if (usingVideo) {
|
||||||
if (autoChangeResolution && !restartingStream) {
|
if (autoChangeResolution) {
|
||||||
changeScreenRes("1280", "720");
|
changeScreenRes("1280", "720");
|
||||||
}
|
}
|
||||||
var fps = 60;
|
var fps = 60;
|
||||||
|
@ -222,17 +208,20 @@ function startStreamer(arg) {
|
||||||
fps = 30;
|
fps = 30;
|
||||||
}
|
}
|
||||||
var ffmpegVideoArgs = [];
|
var ffmpegVideoArgs = [];
|
||||||
if (encoding == "NVENC") { //Nvidia Encoding
|
var bitrate = quality * 1024;
|
||||||
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"];
|
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");
|
log("Using Nvidia Encoding");
|
||||||
} else if (encoding == "AMDVCE") { //AMD Video Coding Engine
|
} 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");
|
log("Using AMD Video Coding Engine");
|
||||||
} else if (encoding == "QSV") {
|
} 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");
|
log("Using Intel QSV Encoding");
|
||||||
} else { //CPU Software 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");
|
log("Using CPU Encoding");
|
||||||
}
|
}
|
||||||
ffmpegProcess = spawn(
|
ffmpegProcess = spawn(
|
||||||
|
@ -253,11 +242,12 @@ function startStreamer(arg) {
|
||||||
if (autoChangeResolution && !restartingStream) {
|
if (autoChangeResolution && !restartingStream) {
|
||||||
changeScreenRes(originalW, originalH);
|
changeScreenRes(originalW, originalH);
|
||||||
}
|
}
|
||||||
|
ffmpegProcess = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (usingAudio) {
|
if (usingAudio) {
|
||||||
ffmpegAudioProcess = spawn(
|
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"],
|
["-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 }
|
{ detached: false }
|
||||||
);
|
);
|
||||||
|
@ -269,28 +259,47 @@ function startStreamer(arg) {
|
||||||
});
|
});
|
||||||
ffmpegAudioProcess.on('close', (code) => {
|
ffmpegAudioProcess.on('close', (code) => {
|
||||||
log(`AudioProcess process exited with code ${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) => {
|
ipcMain.on('connect', (event, arg) => {
|
||||||
clientSender = event.sender;
|
clientSender = event.sender;
|
||||||
killStream()
|
setArgs(arg);
|
||||||
startStreamer(arg);
|
// killStream()
|
||||||
|
isRunning = true;
|
||||||
|
setTimeout(connectHID, 0);
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('restart', (event, arg) => {
|
ipcMain.on('restart', (event, arg) => {
|
||||||
restartingStream = true;
|
restartingStream = true;
|
||||||
|
setArgs(arg);
|
||||||
killStream()
|
killStream()
|
||||||
setTimeout(function () {
|
setTimeout(() => {
|
||||||
|
startStreamer();
|
||||||
restartingStream = false;
|
restartingStream = false;
|
||||||
startStreamer(arg);
|
}, 2000)
|
||||||
}, 1000)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ipcMain.on('kill', (event, arg) => {
|
ipcMain.on('kill', (event, arg) => {
|
||||||
|
isRunning = false;
|
||||||
|
restartingStream = false;
|
||||||
killStream()
|
killStream()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -349,6 +358,7 @@ function parseInputStruct(buff) {
|
||||||
.floatle('gyroX')
|
.floatle('gyroX')
|
||||||
.floatle('gyroY')
|
.floatle('gyroY')
|
||||||
.floatle('gyroZ')
|
.floatle('gyroZ')
|
||||||
|
.word32Ule('frameRate')
|
||||||
.word32Ule('controllerCount')
|
.word32Ule('controllerCount')
|
||||||
input._setBuff(buff);
|
input._setBuff(buff);
|
||||||
return input;
|
return input;
|
||||||
|
@ -655,10 +665,9 @@ function handleTouchInput(hid) {
|
||||||
function handleGyroAndAccel(hid) {
|
function handleGyroAndAccel(hid) {
|
||||||
var gyro = { x: hid.get("gyroX"), y: hid.get("gyroY"), z: hid.get("gyroZ") }
|
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") }
|
var accel = { x: hid.get("accelX"), y: hid.get("accelY"), z: hid.get("accelZ") }
|
||||||
for (axis in gyro) {
|
// for (axis in gyro) {
|
||||||
gyro[axis] *= 250;
|
// gyro[axis] *= 250;
|
||||||
}
|
// }
|
||||||
gyro.y *= -1;
|
|
||||||
GyroServ.sendMotionData(gyro, accel);
|
GyroServ.sendMotionData(gyro, accel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,16 +676,18 @@ var hidDataBuffer = "";
|
||||||
function connectHID() {
|
function connectHID() {
|
||||||
log("Connecting to switch...");
|
log("Connecting to switch...");
|
||||||
log(ip)
|
log(ip)
|
||||||
|
hidStreamClient = new net.Socket();
|
||||||
hidStreamClient.connect(2223, ip, function () {
|
hidStreamClient.connect(2223, ip, function () {
|
||||||
hidStreamClient.setNoDelay(true);
|
hidStreamClient.setNoDelay(true);
|
||||||
log('Connected to Switch!');
|
log('Connected to Switch!');
|
||||||
|
startStreamer();
|
||||||
});
|
});
|
||||||
hidStreamClient.on('error', function (ex) {
|
hidStreamClient.on('error', function (err) {
|
||||||
if (ex) {
|
log('Error: ' + err);
|
||||||
log("Could not connect to Switch. Connection timed out...");
|
// if (err.code == "ECONNREFUSED") {
|
||||||
// setTimeout(connectHID, 1000);
|
// setTimeout(connectHID, 1000);
|
||||||
}
|
// }
|
||||||
});
|
})
|
||||||
hidStreamClient.on('data', function (chunk) {
|
hidStreamClient.on('data', function (chunk) {
|
||||||
hidDataBuffer += chunk.toString("hex");
|
hidDataBuffer += chunk.toString("hex");
|
||||||
var completeData = "";
|
var completeData = "";
|
||||||
|
@ -697,16 +708,17 @@ function connectHID() {
|
||||||
if (controllerCount > controllerIds.length) {
|
if (controllerCount > controllerIds.length) {
|
||||||
plugControllerIn();
|
plugControllerIn();
|
||||||
}
|
}
|
||||||
// fpsPrintTimer++;
|
fpsPrintTimer++;
|
||||||
// if (fpsPrintTimer == 10) {
|
if (fpsPrintTimer == 10) {
|
||||||
// log("switchFps=" + hid.get("frameRate"))
|
log("switchFps=" + hid.get("frameRate"))
|
||||||
// fpsPrintTimer = 0;
|
fpsPrintTimer = 0;
|
||||||
// }
|
}
|
||||||
var playerNumber;
|
var playerNumber;
|
||||||
for (i in controllerIds) {
|
for (i in controllerIds) {
|
||||||
playerNumber = parseInt(i) + 1;
|
playerNumber = parseInt(i) + 1;
|
||||||
handleControllerInput(hid, controllerIds[i], playerNumber);
|
handleControllerInput(hid, controllerIds[i], playerNumber);
|
||||||
}
|
}
|
||||||
|
handleGyroAndAccel(hid);
|
||||||
handleMouseInputToggling(hid, 1);
|
handleMouseInputToggling(hid, 1);
|
||||||
if (mouseControl == "ANALOG" && mouseInput) {
|
if (mouseControl == "ANALOG" && mouseInput) {
|
||||||
handleAnalogMouse(hid, 1);
|
handleAnalogMouse(hid, 1);
|
||||||
|
@ -714,7 +726,6 @@ function connectHID() {
|
||||||
handleGyroMouse(hid, 1);
|
handleGyroMouse(hid, 1);
|
||||||
}
|
}
|
||||||
handleTouchInput(hid);
|
handleTouchInput(hid);
|
||||||
handleGyroAndAccel(hid);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hidStreamClient.on('close', function () {
|
hidStreamClient.on('close', function () {
|
||||||
|
@ -726,7 +737,10 @@ function connectHID() {
|
||||||
controllerIds = [];
|
controllerIds = [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
// killStream();
|
killStream();
|
||||||
|
if (isRunning) {
|
||||||
|
setTimeout(connectHID, 1000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,74 +6,112 @@
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
PadState pad;
|
PadState pad;
|
||||||
|
PadState pad2;
|
||||||
|
PadState pad3;
|
||||||
|
PadState pad4;
|
||||||
HiddbgAbstractedPadHandle pads[4] = {0};
|
HiddbgAbstractedPadHandle pads[4] = {0};
|
||||||
HiddbgAbstractedPadState states[4] = {0};
|
HiddbgAbstractedPadState states[4] = {0};
|
||||||
HidSixAxisSensorHandle handles[4];
|
HidSixAxisSensorHandle handles[4];
|
||||||
s32 tmpout = 0;
|
|
||||||
Result rc = 0;
|
Result rc = 0;
|
||||||
void gamePadSend(JoyConSocket *connection)
|
void gamePadSend(JoyConSocket *connection)
|
||||||
{
|
{
|
||||||
JoyPkg pkg;
|
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.streamStart = (uint64_t)UINT64_MAX; // easy identifiers for the start and stop of tcp stream
|
||||||
pkg.streamEnd = (uint64_t)UINT64_MAX / 2;
|
pkg.streamEnd = (uint64_t)UINT64_MAX / 2;
|
||||||
pkg.controllerCount = (uint32_t)1;
|
uint32_t controllerCount = 0;
|
||||||
|
|
||||||
padUpdate(&pad);
|
padUpdate(&pad);
|
||||||
|
padUpdate(&pad2);
|
||||||
|
padUpdate(&pad3);
|
||||||
|
padUpdate(&pad4);
|
||||||
|
|
||||||
u64 kDown = padGetButtonsDown(&pad);
|
if (padIsConnected(&pad))
|
||||||
u64 kHeld = padGetButtons(&pad);
|
{
|
||||||
u64 kUp = padGetButtonsUp(&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;
|
if (padIsConnected(&pad2))
|
||||||
rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads) / sizeof(u64), &tmpout);
|
{
|
||||||
|
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) {
|
if (padIsConnected(&pad3))
|
||||||
// s8 AbstractedVirtualPadId=0;
|
{
|
||||||
|
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.
|
pkg.controllerCount = (uint32_t)controllerCount;
|
||||||
// states[0].type = BIT(1);
|
// printf("controllerCount: %d\n", controllerCount);
|
||||||
// // Use state-merge for the above controller, the state will be merged with an existing controller.
|
// printf("%d %d %d %d %d\n", pkg.heldKeys1, pkg.lJoyX1, pkg.lJoyY1, pkg.rJoyX1, pkg.rJoyY1);
|
||||||
// // For a plain virtual controller, use NpadInterfaceType_Bluetooth, and update the above type value.
|
// printf("%d %d %d %d %d\n", pkg.heldKeys2, pkg.lJoyX2, pkg.lJoyY2, pkg.rJoyX2, pkg.rJoyY2);
|
||||||
// states[0].npadInterfaceType = HidNpadInterfaceType_Rail;
|
// 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);
|
||||||
// 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);
|
|
||||||
|
|
||||||
HidTouchScreenState touchState = {0};
|
HidTouchScreenState touchState = {0};
|
||||||
if (hidGetTouchScreenStates(&touchState, 1))
|
if (hidGetTouchScreenStates(&touchState, 1))
|
||||||
|
@ -84,28 +122,32 @@ void gamePadSend(JoyConSocket *connection)
|
||||||
pkg.touchY2 = (uint32_t)touchState.touches[1].y;
|
pkg.touchY2 = (uint32_t)touchState.touches[1].y;
|
||||||
}
|
}
|
||||||
// printf("%d %d %d %d\n", pkg.touchX1, pkg.touchY1, pkg.touchX2, pkg.touchY2);
|
// printf("%d %d %d %d\n", pkg.touchX1, pkg.touchY1, pkg.touchX2, pkg.touchY2);
|
||||||
// HidSixAxisSensorState sixaxis = {0};
|
HidSixAxisSensorState sixaxis = {0};
|
||||||
// u64 style_set = padGetStyleSet(&pad);
|
u64 style_set = padGetStyleSet(&pad);
|
||||||
// if (style_set & HidNpadStyleTag_NpadHandheld)
|
if (style_set & HidNpadStyleTag_NpadHandheld)
|
||||||
// hidGetSixAxisSensorStates(handles[0], &sixaxis, 1);
|
hidGetSixAxisSensorStates(handles[0], &sixaxis, 1);
|
||||||
// else if (style_set & HidNpadStyleTag_NpadFullKey)
|
else if (style_set & HidNpadStyleTag_NpadFullKey)
|
||||||
// hidGetSixAxisSensorStates(handles[1], &sixaxis, 1);
|
hidGetSixAxisSensorStates(handles[1], &sixaxis, 1);
|
||||||
// else if (style_set & HidNpadStyleTag_NpadJoyDual)
|
else if (style_set & HidNpadStyleTag_NpadJoyDual)
|
||||||
// {
|
{
|
||||||
// // For JoyDual, read from either the Left or Right Joy-Con depending on which is/are connected
|
// For JoyDual, read from either the Left or Right Joy-Con depending on which is/are connected
|
||||||
// u64 attrib = padGetAttributes(&pad);
|
u64 attrib = padGetAttributes(&pad);
|
||||||
// if (attrib & HidNpadAttribute_IsLeftConnected)
|
if (attrib & HidNpadAttribute_IsLeftConnected)
|
||||||
// hidGetSixAxisSensorStates(handles[2], &sixaxis, 1);
|
hidGetSixAxisSensorStates(handles[2], &sixaxis, 1);
|
||||||
// else if (attrib & HidNpadAttribute_IsRightConnected)
|
else if (attrib & HidNpadAttribute_IsRightConnected)
|
||||||
// hidGetSixAxisSensorStates(handles[3], &sixaxis, 1);
|
hidGetSixAxisSensorStates(handles[3], &sixaxis, 1);
|
||||||
// }
|
}
|
||||||
// pkg.accelX = (float_t)sixaxis.acceleration.x;
|
pkg.accelX = (float_t)sixaxis.acceleration.x;
|
||||||
// pkg.accelY = (float_t)sixaxis.acceleration.y;
|
pkg.accelY = (float_t)sixaxis.acceleration.y;
|
||||||
// pkg.accelZ = (float_t)sixaxis.acceleration.z;
|
pkg.accelZ = (float_t)sixaxis.acceleration.z;
|
||||||
// pkg.gyroX = (float_t)sixaxis.angle.x;
|
pkg.gyroX = (float_t)sixaxis.angle.x;
|
||||||
// pkg.gyroY = (float_t)sixaxis.angle.y;
|
pkg.gyroY = (float_t)sixaxis.angle.y;
|
||||||
// pkg.gyroZ = (float_t)sixaxis.angle.z;
|
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);
|
// 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);
|
sendJoyConInput(connection, &pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,11 +160,12 @@ void handleInput(JoyConSocket *connection)
|
||||||
void input_init()
|
void input_init()
|
||||||
{
|
{
|
||||||
padConfigureInput(4, HidNpadStyleSet_NpadStandard);
|
padConfigureInput(4, HidNpadStyleSet_NpadStandard);
|
||||||
padInitializeAny(&pad);
|
padInitialize(&pad, HidNpadIdType_No1, HidNpadIdType_Handheld);
|
||||||
rc = hiddbgInitialize();
|
padInitialize(&pad2, HidNpadIdType_No2, HidNpadStyleTag_NpadJoyDual);
|
||||||
|
padInitialize(&pad3, HidNpadIdType_No3, HidNpadStyleTag_NpadJoyDual);
|
||||||
|
padInitialize(&pad4, HidNpadIdType_No4, HidNpadStyleTag_NpadJoyDual);
|
||||||
|
|
||||||
hidInitializeTouchScreen();
|
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[0], 1, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
|
||||||
hidGetSixAxisSensorHandles(&handles[1], 1, HidNpadIdType_No1, HidNpadStyleTag_NpadFullKey);
|
hidGetSixAxisSensorHandles(&handles[1], 1, HidNpadIdType_No1, HidNpadStyleTag_NpadFullKey);
|
||||||
hidGetSixAxisSensorHandles(&handles[2], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
|
hidGetSixAxisSensorHandles(&handles[2], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
|
||||||
|
@ -133,8 +176,7 @@ void input_init()
|
||||||
}
|
}
|
||||||
void input_unInit()
|
void input_unInit()
|
||||||
{
|
{
|
||||||
hiddbgUnsetAllAutoPilotVirtualPadState();
|
|
||||||
hiddbgExit();
|
|
||||||
hidStopSixAxisSensor(handles[0]);
|
hidStopSixAxisSensor(handles[0]);
|
||||||
hidStopSixAxisSensor(handles[1]);
|
hidStopSixAxisSensor(handles[1]);
|
||||||
hidStopSixAxisSensor(handles[2]);
|
hidStopSixAxisSensor(handles[2]);
|
||||||
|
|
|
@ -52,12 +52,16 @@ ClkrstSession cpuSession;
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
// consoleInit(NULL);
|
// consoleInit(NULL);
|
||||||
/* Init all switch required systems */
|
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_None);
|
||||||
|
appletSetWirelessPriorityMode(AppletWirelessPriorityMode_OptimizedForWlan);
|
||||||
|
appletSetAutoSleepDisabled(true);
|
||||||
|
|
||||||
printf("networkInit\n");
|
printf("networkInit\n");
|
||||||
network_init(&socketInitConf);
|
network_init(&socketInitConf);
|
||||||
|
|
||||||
printf("romfsInit\n");
|
printf("romfsInit\n");
|
||||||
romfsInit();
|
romfsInit();
|
||||||
|
// chdir("romfs:/");
|
||||||
|
|
||||||
printf("audoutInitialize\n");
|
printf("audoutInitialize\n");
|
||||||
audoutInitialize();
|
audoutInitialize();
|
||||||
|
@ -83,8 +87,6 @@ void init()
|
||||||
videoContext->renderContext = renderContext;
|
videoContext->renderContext = renderContext;
|
||||||
printf("startRender\n");
|
printf("startRender\n");
|
||||||
startRender(videoContext);
|
startRender(videoContext);
|
||||||
printf("appletSetIdleTimeDetectionExtension\n");
|
|
||||||
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_None);
|
|
||||||
printf("Complete INIT!\n");
|
printf("Complete INIT!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ typedef struct
|
||||||
float_t gyroX;
|
float_t gyroX;
|
||||||
float_t gyroY;
|
float_t gyroY;
|
||||||
float_t gyroZ;
|
float_t gyroZ;
|
||||||
|
uint32_t renderFPS;
|
||||||
uint32_t controllerCount;
|
uint32_t controllerCount;
|
||||||
uint64_t streamEnd;
|
uint64_t streamEnd;
|
||||||
} JoyPkg;
|
} JoyPkg;
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
float timeThen = 0;
|
float timeThen = 0;
|
||||||
float timeNow = 1;
|
float timeNow = 1;
|
||||||
float delta = 1;
|
float delta = 1;
|
||||||
|
uint32_t renderFPS = 0;
|
||||||
|
uint32_t getFPS()
|
||||||
|
{
|
||||||
|
return renderFPS;
|
||||||
|
}
|
||||||
void initDelta()
|
void initDelta()
|
||||||
{
|
{
|
||||||
timeThen = svcGetSystemTick();
|
timeThen = svcGetSystemTick();
|
||||||
|
@ -196,16 +201,15 @@ void initBubbles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_Texture *logoTexture = NULL;
|
SDL_Texture *logoTexture = NULL;
|
||||||
|
bool logoLoaded = false;
|
||||||
RenderContext *makeRenderer()
|
RenderContext *makeRenderer()
|
||||||
{
|
{
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
|
||||||
SDL_Log("TTF_Init");
|
IMG_Init(IMG_INIT_PNG);
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
SDL_Log("plInitialize");
|
chdir("romfs:/");
|
||||||
plInitialize(PlServiceType_User);
|
plInitialize(PlServiceType_User);
|
||||||
SDL_Log("malloc RenderContext\n");
|
|
||||||
RenderContext *context = malloc(sizeof(RenderContext));
|
RenderContext *context = malloc(sizeof(RenderContext));
|
||||||
SDL_Log("SDL_CreateWindow\n");
|
|
||||||
context->window = SDL_CreateWindow("sdl2_gles2", 0, 0, RESX, RESY, SDL_WINDOW_FULLSCREEN);
|
context->window = SDL_CreateWindow("sdl2_gles2", 0, 0, RESX, RESY, SDL_WINDOW_FULLSCREEN);
|
||||||
if (context->window == NULL)
|
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);
|
context->renderer = SDL_CreateRenderer(context->window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
if (context->renderer == NULL)
|
if (context->renderer == NULL)
|
||||||
{
|
{
|
||||||
|
@ -224,20 +227,24 @@ RenderContext *makeRenderer()
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
SDL_Log("SDL_SetRenderDrawBlendMode");
|
|
||||||
SDL_SetRenderDrawBlendMode(context->renderer, SDL_BLENDMODE_BLEND); // enable transparency
|
SDL_SetRenderDrawBlendMode(context->renderer, SDL_BLENDMODE_BLEND); // enable transparency
|
||||||
|
|
||||||
SDL_Log("IMG_LoadTexture ICON");
|
SDL_Log("IMG_LoadTexture iconTransparent");
|
||||||
IMG_Init(IMG_INIT_PNG);
|
// logoTexture = IMG_LoadTexture(context->renderer, "iconTransparent.png");
|
||||||
logoTexture = IMG_LoadTexture(context->renderer, "iconTransparent.png");
|
SDL_Surface *sdllogo = IMG_Load("iconTransparent.png");
|
||||||
// SDL_Surface *logo = IMG_Load("iconTransparent.png");
|
if (sdllogo == NULL)
|
||||||
// if (logo)
|
{
|
||||||
// {
|
SDL_Log("IMG_Load: %s\n", SDL_GetError());
|
||||||
// logoTexture = SDL_CreateTextureFromSurface(context->renderer, logo);
|
}
|
||||||
// SDL_FreeSurface(logo);
|
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
|
// Create font cache
|
||||||
SDL_Log("SDL_CreateTexture");
|
|
||||||
context->yuv_text = SDL_CreateTexture(context->renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
|
context->yuv_text = SDL_CreateTexture(context->renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
|
||||||
|
|
||||||
context->rect.x = 0;
|
context->rect.x = 0;
|
||||||
|
@ -245,27 +252,19 @@ RenderContext *makeRenderer()
|
||||||
context->rect.w = RESX;
|
context->rect.w = RESX;
|
||||||
context->rect.h = RESY;
|
context->rect.h = RESY;
|
||||||
|
|
||||||
SDL_Log("mutexInit texture_mut");
|
|
||||||
mutexInit(&context->texture_mut);
|
mutexInit(&context->texture_mut);
|
||||||
SDL_Log("mutexInit frame_avail_mut");
|
|
||||||
mutexInit(&context->frame_avail_mut);
|
mutexInit(&context->frame_avail_mut);
|
||||||
SDL_Log("mutexInit video_active_mut");
|
|
||||||
mutexInit(&context->video_active_mut);
|
mutexInit(&context->video_active_mut);
|
||||||
context->frame_avail = false;
|
context->frame_avail = false;
|
||||||
context->video_active = false;
|
context->video_active = false;
|
||||||
|
|
||||||
PlFontData fontData, fontExtData;
|
PlFontData fontData, fontExtData;
|
||||||
SDL_Log("plGetSharedFontByType");
|
|
||||||
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
|
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
|
||||||
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
|
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
|
||||||
SDL_Log((char *)fontData.address);
|
SDL_Log((char *)fontData.address);
|
||||||
SDL_Log("FC_CreateFont");
|
|
||||||
context->font = 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);
|
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();
|
initDelta();
|
||||||
SDL_Log("initBubbles");
|
|
||||||
initBubbles();
|
initBubbles();
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
|
@ -460,6 +459,7 @@ void renderBubbles(RenderContext *context)
|
||||||
fillCircle(context, bubbles[i].x, bubbles[i].y, bubbles[i].r, bubbles[i].color);
|
fillCircle(context, bubbles[i].x, bubbles[i].y, bubbles[i].r, bubbles[i].color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawSplash(RenderContext *context)
|
void drawSplash(RenderContext *context)
|
||||||
{
|
{
|
||||||
loopStart();
|
loopStart();
|
||||||
|
@ -481,13 +481,18 @@ void drawSplash(RenderContext *context)
|
||||||
int imgH = 256;
|
int imgH = 256;
|
||||||
// printf("SDL_QueryTexture\n");
|
// printf("SDL_QueryTexture\n");
|
||||||
// SDL_QueryTexture(logoTexture, NULL, NULL, &imgW, &imgH);
|
// SDL_QueryTexture(logoTexture, NULL, NULL, &imgW, &imgH);
|
||||||
|
// imgDest.x = (1280 / 2) - (imgW / 2);
|
||||||
|
// imgDest.y = (720 / 2) - (imgH / 2);
|
||||||
SDL_Rect imgDest;
|
SDL_Rect imgDest;
|
||||||
imgDest.x = (1280 / 2) - (imgW / 2);
|
imgDest.x = (1280 / 2) - (imgW / 2);
|
||||||
imgDest.y = (720 / 2) - (imgH / 2);
|
imgDest.y = (720 / 2) - (imgH / 2);
|
||||||
imgDest.w = imgW;
|
imgDest.w = imgW;
|
||||||
imgDest.h = imgH;
|
imgDest.h = imgH;
|
||||||
// printf("SDL_RenderCopy\n");
|
if (logoTexture != NULL)
|
||||||
// SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
|
{
|
||||||
|
// printf("SDL_RenderCopy\n");
|
||||||
|
// SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Color white = {230, 230, 230, 255};
|
SDL_Color white = {230, 230, 230, 255};
|
||||||
u32 ip = gethostid();
|
u32 ip = gethostid();
|
||||||
|
@ -511,6 +516,13 @@ void handleFrame(RenderContext *renderContext, VideoContext *videoContext)
|
||||||
memcpy(renderContext->VPlane, frame->data[2], sizeof(renderContext->VPlane));
|
memcpy(renderContext->VPlane, frame->data[2], sizeof(renderContext->VPlane));
|
||||||
mutexUnlock(&renderContext->texture_mut);
|
mutexUnlock(&renderContext->texture_mut);
|
||||||
setFrameAvail(renderContext);
|
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)
|
void displayFrame(RenderContext *renderContext)
|
||||||
|
|
|
@ -17,6 +17,8 @@ void handleFrame(RenderContext *context, VideoContext *videoContext);
|
||||||
/* Draws a frame */
|
/* Draws a frame */
|
||||||
void displayFrame(RenderContext *renderContext);
|
void displayFrame(RenderContext *renderContext);
|
||||||
|
|
||||||
|
uint32_t getFPS(void);
|
||||||
|
|
||||||
/* Deallocates the render context */
|
/* Deallocates the render context */
|
||||||
void freeRenderer(RenderContext *context);
|
void freeRenderer(RenderContext *context);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue