summaryrefslogtreecommitdiffstats
path: root/src/skel/glfw
diff options
context:
space:
mode:
Diffstat (limited to 'src/skel/glfw')
-rw-r--r--src/skel/glfw/glfw.cpp103
1 files changed, 92 insertions, 11 deletions
diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp
index 8d3fc7d7..92a5a93f 100644
--- a/src/skel/glfw/glfw.cpp
+++ b/src/skel/glfw/glfw.cpp
@@ -12,12 +12,14 @@ DWORD _dwOperatingSystemVersion;
#include "resource.h"
#else
long _dwOperatingSystemVersion;
+#ifndef __SWITCH__
#ifndef __APPLE__
#include <sys/sysinfo.h>
#else
#include <mach/mach_host.h>
#include <sys/sysctl.h>
#endif
+#endif
#include <errno.h>
#include <locale.h>
#include <signal.h>
@@ -50,11 +52,7 @@ long _dwOperatingSystemVersion;
#include "Font.h"
#include "MemoryMgr.h"
-// We found out that GLFW's keyboard input handling is still pretty delayed/not stable, so now we fetch input from X11 directly on Linux.
-#if !defined _WIN32 && !defined __APPLE__ && !defined __SWITCH__ // && !defined WAYLAND
-#define GET_KEYBOARD_INPUT_FROM_X11
-#endif
-
+// This is defined on project-level, via premake5 or cmake
#ifdef GET_KEYBOARD_INPUT_FROM_X11
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
@@ -327,6 +325,78 @@ psNativeTextureSupport(void)
/*
*****************************************************************************
*/
+
+#ifdef __SWITCH__
+
+static HidVibrationValue SwitchVibrationValues[2];
+static HidVibrationDeviceHandle SwitchVibrationDeviceHandles[2][2];
+static HidVibrationDeviceHandle SwitchVibrationDeviceGC;
+
+static PadState SwitchPad;
+
+static Result HidInitializationResult[2];
+static Result HidInitializationGCResult;
+
+static void _psInitializeVibration()
+{
+ HidInitializationResult[0] = hidInitializeVibrationDevices(SwitchVibrationDeviceHandles[0], 2, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
+ if(R_FAILED(HidInitializationResult[0])) {
+ printf("Failed to initialize VibrationDevice for Handheld Mode\n");
+ }
+ HidInitializationResult[1] = hidInitializeVibrationDevices(SwitchVibrationDeviceHandles[1], 2, HidNpadIdType_No1, HidNpadStyleSet_NpadFullCtrl);
+ if(R_FAILED(HidInitializationResult[1])) {
+ printf("Failed to initialize VibrationDevice for Detached Mode\n");
+ }
+ HidInitializationGCResult = hidInitializeVibrationDevices(&SwitchVibrationDeviceGC, 1, HidNpadIdType_No1, HidNpadStyleTag_NpadGc);
+ if(R_FAILED(HidInitializationResult[1])) {
+ printf("Failed to initialize VibrationDevice for GC Mode\n");
+ }
+
+ SwitchVibrationValues[0].freq_low = 160.0f;
+ SwitchVibrationValues[0].freq_high = 320.0f;
+
+ padConfigureInput(1, HidNpadStyleSet_NpadFullCtrl);
+ padInitializeDefault(&SwitchPad);
+}
+
+static void _psHandleVibration()
+{
+ padUpdate(&SwitchPad);
+
+ uint8 target_device = padIsHandheld(&SwitchPad) ? 0 : 1;
+
+ if(R_SUCCEEDED(HidInitializationResult[target_device])) {
+ CPad* pad = CPad::GetPad(0);
+
+ // value conversion based on SDL2 switch port
+ SwitchVibrationValues[0].amp_high = SwitchVibrationValues[0].amp_low = pad->ShakeFreq == 0 ? 0.0f : 320.0f;
+ SwitchVibrationValues[0].freq_low = pad->ShakeFreq == 0.0 ? 160.0f : (float)pad->ShakeFreq * 1.26f;
+ SwitchVibrationValues[0].freq_high = pad->ShakeFreq == 0.0 ? 320.0f : (float)pad->ShakeFreq * 1.26f;
+
+ if (pad->ShakeDur < CTimer::GetTimeStepInMilliseconds())
+ pad->ShakeDur = 0;
+ else
+ pad->ShakeDur -= CTimer::GetTimeStepInMilliseconds();
+ if (pad->ShakeDur == 0) pad->ShakeFreq = 0;
+
+
+ if(target_device == 1 && R_SUCCEEDED(HidInitializationGCResult)) {
+ // gamecube rumble
+ hidSendVibrationGcErmCommand(SwitchVibrationDeviceGC, pad->ShakeFreq > 0 ? HidVibrationGcErmCommand_Start : HidVibrationGcErmCommand_Stop);
+ }
+
+ memcpy(&SwitchVibrationValues[1], &SwitchVibrationValues[0], sizeof(HidVibrationValue));
+ hidSendVibrationValues(SwitchVibrationDeviceHandles[target_device], SwitchVibrationValues, 2);
+ }
+}
+#else
+static void _psInitializeVibration() {}
+static void _psHandleVibration() {}
+#endif
+
+/*
+ *****************************************************************************
+ */
RwBool
psInitialize(void)
{
@@ -407,6 +477,8 @@ psInitialize(void)
#endif
#endif
+
+ _psInitializeVibration();
gGameState = GS_START_UP;
TRACE("gGameState = GS_START_UP");
@@ -484,6 +556,9 @@ psInitialize(void)
_dwMemAvailPhys = (uint64_t)(vm_stat.free_count * page_size);
debug("Physical memory size %llu\n", _dwMemAvailPhys);
debug("Available physical memory %llu\n", size);
+#elif defined (__SWITCH__)
+ svcGetInfo(&_dwMemAvailPhys, InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0);
+ debug("Physical memory size %llu\n", _dwMemAvailPhys);
#else
struct sysinfo systemInfo;
sysinfo(&systemInfo);
@@ -949,13 +1024,15 @@ void psPostRWinit(void)
RwVideoMode vm;
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
+ glfwSetFramebufferSizeCallback(PSGLOBAL(window), resizeCB);
+#ifndef IGNORE_MOUSE_KEYBOARD
#ifndef GET_KEYBOARD_INPUT_FROM_X11
glfwSetKeyCallback(PSGLOBAL(window), keypressCB);
#endif
- glfwSetFramebufferSizeCallback(PSGLOBAL(window), resizeCB);
glfwSetScrollCallback(PSGLOBAL(window), scrollCB);
glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB);
glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB);
+#endif
glfwSetWindowIconifyCallback(PSGLOBAL(window), windowIconifyCB);
glfwSetWindowFocusCallback(PSGLOBAL(window), windowFocusCB);
glfwSetJoystickCallback(joysChangeCB);
@@ -1791,7 +1868,7 @@ main(int argc, char *argv[])
InitMemoryMgr();
#endif
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__SWITCH__)
struct sigaction act;
act.sa_sigaction = terminateHandler;
act.sa_flags = SA_SIGINFO;
@@ -1935,10 +2012,12 @@ main(int argc, char *argv[])
#ifdef LOAD_INI_SETTINGS
LoadINIControllerSettings();
- if (connectedPadButtons != 0) {
- ControlsManager.InitDefaultControlConfigJoyPad(connectedPadButtons);
- SaveINIControllerSettings();
- }
+ if (connectedPadButtons != 0)
+ ControlsManager.InitDefaultControlConfigJoyPad(connectedPadButtons); // add (connected-saved) amount of new button assignments on top of ours
+
+ // these have 2 purposes: creating .ini at the start, and adding newly introduced settings to old .ini at the start
+ SaveINISettings();
+ SaveINIControllerSettings();
#endif
}
@@ -2453,6 +2532,8 @@ void CapturePad(RwInt32 padID)
if ( Abs(rightStickPos.y) > 0.3f )
pad->PCTempJoyState.RightStickY = (int32)(rightStickPos.y * 128.0f);
}
+
+ _psHandleVibration();
return;
}