diff --git a/src/Input.c b/src/Input.c index 1da4710bc..04ad10cb2 100644 --- a/src/Input.c +++ b/src/Input.c @@ -448,6 +448,8 @@ void Gamepad_SetAxis(int axis, float x, float y, double delta) { void Gamepad_Tick(double delta) { int btn; + Input.JoystickMovement = false; + Window_ProcessGamepads(delta); for (btn = GAMEPAD_BEG_BTN; btn < INPUT_COUNT; btn++) { diff --git a/src/Launcher.c b/src/Launcher.c index 5bb7a4d27..6c4822bdf 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -273,6 +273,7 @@ void Launcher_Run(void) { for (;;) { Window_ProcessEvents(10 / 1000.0); + Window_ProcessGamepads(10 / 1000.0); if (!Window_Main.Exists || Launcher_ShouldExit) break; Launcher_Active->Tick(Launcher_Active); diff --git a/src/Window.h b/src/Window.h index d82ed37ad..b79d406bf 100644 --- a/src/Window.h +++ b/src/Window.h @@ -136,6 +136,8 @@ void Window_SetSize(int width, int height); void Window_RequestClose(void); /* Processes all pending window messages/events. */ void Window_ProcessEvents(double delta); +/* Processes all pending gamepad/joystick input. */ +void Window_ProcessGamepads(double delta); /* Sets the position of the cursor. */ /* NOTE: This should be avoided because it is unsupported on some platforms. */ diff --git a/src/Window_3DS.c b/src/Window_3DS.c index 4b665d857..ad2c9b6aa 100644 --- a/src/Window_3DS.c +++ b/src/Window_3DS.c @@ -89,6 +89,43 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +static void ProcessTouchInput(int mods) { + touchPosition touch; + hidTouchRead(&touch); + + if (mods & KEY_TOUCH) { + Input_AddTouch(0, touch.px, touch.py); + } else if (hidKeysUp() & KEY_TOUCH) { + Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); + } +} + +void Window_ProcessEvents(double delta) { + hidScanInput(); + + if (!aptMainLoop()) { + Window_Main.Exists = false; + Window_RequestClose(); + return; + } + + u32 mods = hidKeysDown() | hidKeysHeld(); + ProcessTouchInput(mods); +} + +void Window_ProcessGamepads(double delta) { } + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for 3DS + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(u32 mods) { Gamepad_SetButton(CCPAD_L, mods & KEY_L); Gamepad_SetButton(CCPAD_R, mods & KEY_R); @@ -119,31 +156,9 @@ static void ProcessCircleInput(int axis, circlePosition* pos, double delta) { Gamepad_SetAxis(axis, pos->dx / AXIS_SCALE, -pos->dy / AXIS_SCALE, delta); } -static void ProcessTouchInput(int mods) { - touchPosition touch; - hidTouchRead(&touch); - - if (mods & KEY_TOUCH) { - Input_AddTouch(0, touch.px, touch.py); - } else if (hidKeysUp() & KEY_TOUCH) { - Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); - } -} - -void Window_ProcessEvents(double delta) { - hidScanInput(); - Input.JoystickMovement = false; - - if (!aptMainLoop()) { - Window_Main.Exists = false; - Window_RequestClose(); - return; - } - +void Window_ProcessGamepads(double delta) { u32 mods = hidKeysDown() | hidKeysHeld(); HandleButtons(mods); - - ProcessTouchInput(mods); circlePosition hid_pos; hidCircleRead(&hid_pos); @@ -160,12 +175,6 @@ void Window_ProcessEvents(double delta) { } } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for 3DS - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - -void Window_UpdateRawMouse(void) { } /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_Android.c b/src/Window_Android.c index 3357c6ac5..b51e495d8 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -373,6 +373,8 @@ void Window_ProcessEvents(double delta) { JavaICall_Void(env, JAVA_processEvents, NULL); } +void Window_ProcessGamepads(double delta) { } + /* No actual mouse cursor */ static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; } void Cursor_SetPosition(int x, int y) { } diff --git a/src/Window_Dreamcast.c b/src/Window_Dreamcast.c index e415dbe48..5377d0014 100644 --- a/src/Window_Dreamcast.c +++ b/src/Window_Dreamcast.c @@ -173,6 +173,41 @@ static void ProcessKeyboardInput(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +static void ProcessMouseInput(double delta) { + maple_device_t* mouse; + mouse_state_t* state; + + mouse = maple_enum_type(0, MAPLE_FUNC_MOUSE); + if (!mouse) return; + state = (mouse_state_t*)maple_dev_status(mouse); + if (!state) return; + + int mods = state->buttons; + Input_SetNonRepeatable(CCMOUSE_L, mods & MOUSE_LEFTBUTTON); + Input_SetNonRepeatable(CCMOUSE_R, mods & MOUSE_RIGHTBUTTON); + Input_SetNonRepeatable(CCMOUSE_M, mods & MOUSE_SIDEBUTTON); + + if (!Input.RawMode) return; + float scale = (delta * 60.0) / 2.0f; + Event_RaiseRawMove(&PointerEvents.RawMoved, + state->dx * scale, state->dy * scale); +} + +void Window_ProcessEvents(double delta) { + ProcessKeyboardInput(); + ProcessMouseInput(delta); +} + +void Cursor_SetPosition(int x, int y) { } /* TODO: Dreamcast mouse support */ + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(int mods) { // TODO CONT_Z @@ -206,7 +241,7 @@ static void HandleController(cont_state_t* state, double delta) { HandleJoystick(PAD_AXIS_RIGHT, state->joyx, state->joyy, delta); } -static void ProcessControllerInput(double delta) { +void Window_ProcessGamepads(double delta) { maple_device_t* cont; cont_state_t* state; @@ -219,38 +254,6 @@ static void ProcessControllerInput(double delta) { HandleController(state, delta); } -static void ProcessMouseInput(double delta) { - maple_device_t* mouse; - mouse_state_t* state; - - mouse = maple_enum_type(0, MAPLE_FUNC_MOUSE); - if (!mouse) return; - state = (mouse_state_t*)maple_dev_status(mouse); - if (!state) return; - - int mods = state->buttons; - Input_SetNonRepeatable(CCMOUSE_L, mods & MOUSE_LEFTBUTTON); - Input_SetNonRepeatable(CCMOUSE_R, mods & MOUSE_RIGHTBUTTON); - Input_SetNonRepeatable(CCMOUSE_M, mods & MOUSE_SIDEBUTTON); - - if (!Input.RawMode) return; - float scale = (delta * 60.0) / 2.0f; - Event_RaiseRawMove(&PointerEvents.RawMoved, - state->dx * scale, state->dy * scale); -} - -void Window_ProcessEvents(double delta) { - ProcessControllerInput(delta); - ProcessKeyboardInput(); - ProcessMouseInput(delta); -} - -void Cursor_SetPosition(int x, int y) { } /* TODO: Dreamcast mouse support */ - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index 832cc79b9..cf25ef232 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -225,6 +225,84 @@ static int dragCurX, dragCurY; static int dragStartX, dragStartY; static cc_bool dragActive; +void Window_ProcessEvents(double delta) { + ProcessKeyboardInput(); +} + +static void GetIRPos(int res, int* x, int* y) { + if (res == WPAD_ERR_NONE) { + WPADData* wd = WPAD_Data(0); + + *x = wd->ir.x; + *y = wd->ir.y; + } else { + *x = 0; + *y = 0; + } +} + +static void ScanAndGetIRPos(int* x, int* y) { + u32 type; + WPAD_ScanPads(); + + int res = WPAD_Probe(0, &type); + GetIRPos(res, x, y); +} + + +static void ProcessWPADDrag(u32 mods) { + int x, y; + GetIRPos(res, &x, &y); + + if (mods & WPAD_BUTTON_B) { + if (!dragActive) { + dragStartX = dragCurX = x; + dragStartY = dragCurY = y; + } + dragActive = true; + } else { + dragActive = false; + } + Pointer_SetPosition(0, x, y); +} + +#define FACTOR 2 +void Window_UpdateRawMouse(void) { + if (!dragActive) return; + int x, y; + ScanAndGetIRPos(&x, &y); + + // TODO: Refactor the logic. is it 100% right too? + dragCurX = dragStartX + (dragCurX - dragStartX) / FACTOR; + dragCurY = dragStartY + (dragCurY - dragStartY) / FACTOR; + + int dx = x - dragCurX; Math_Clamp(dx, -40, 40); + int dy = y - dragCurY; Math_Clamp(dy, -40, 40); + Event_RaiseRawMove(&PointerEvents.RawMoved, dx, dy); + + dragCurX = x; dragCurY = y; +} +#else +void Window_ProcessEvents(double delta) { +} + +void Window_UpdateRawMouse(void) { } +#endif + +void Cursor_SetPosition(int x, int y) { } // No point in GameCube/Wii +// TODO: Display cursor on Wii when not raw mode +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ +#if defined HW_RVL +static int dragCurX, dragCurY; +static int dragStartX, dragStartY; +static cc_bool dragActive; + static void ProcessWPAD_Buttons(int mods) { Gamepad_SetButton(CCPAD_L, mods & WPAD_BUTTON_1); Gamepad_SetButton(CCPAD_R, mods & WPAD_BUTTON_2); @@ -320,20 +398,7 @@ static void ProcessClassicInput(double delta) { ProcessClassic_Joystick(PAD_AXIS_RIGHT, &ctrls.rjs, delta); } - -static void GetIRPos(int res, int* x, int* y) { - if (res == WPAD_ERR_NONE) { - WPADData* wd = WPAD_Data(0); - - *x = wd->ir.x; - *y = wd->ir.y; - } else { - *x = 0; - *y = 0; - } -} - -static void ProcessWPADInput(double delta) { +static void ProcessWPADInput(double delta) { WPAD_ScanPads(); u32 mods = WPAD_ButtonsDown(0) | WPAD_ButtonsHeld(0); u32 type; @@ -350,68 +415,19 @@ static void ProcessWPADInput(double delta) { ProcessWPAD_Buttons(mods); } - int x, y; - GetIRPos(res, &x, &y); - - if (mods & WPAD_BUTTON_B) { - if (!dragActive) { - dragStartX = dragCurX = x; - dragStartY = dragCurY = y; - } - dragActive = true; - } else { - dragActive = false; - } - Pointer_SetPosition(0, x, y); + ProcessWPADDrag(mods); } -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - Input.Sources = INPUT_SOURCE_GAMEPAD; - +void Window_ProcessGamepads(double delta) { ProcessWPADInput(delta); ProcessPADInput(delta); - ProcessKeyboardInput(); -} - -static void ScanAndGetIRPos(int* x, int* y) { - u32 type; - WPAD_ScanPads(); - - int res = WPAD_Probe(0, &type); - GetIRPos(res, x, y); -} -#define FACTOR 2 -void Window_UpdateRawMouse(void) { - if (!dragActive) return; - int x, y; - ScanAndGetIRPos(&x, &y); - - // TODO: Refactor the logic. is it 100% right too? - dragCurX = dragStartX + (dragCurX - dragStartX) / FACTOR; - dragCurY = dragStartY + (dragCurY - dragStartY) / FACTOR; - - int dx = x - dragCurX; Math_Clamp(dx, -40, 40); - int dy = y - dragCurY; Math_Clamp(dy, -40, 40); - Event_RaiseRawMove(&PointerEvents.RawMoved, dx, dy); - - dragCurX = x; dragCurY = y; } #else -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - +void Window_ProcessGamepads(double delta) { ProcessPADInput(delta); } - -void Window_UpdateRawMouse(void) { } #endif -void Cursor_SetPosition(int x, int y) { } // No point in GameCube/Wii -// TODO: Display cursor on Wii when not raw mode -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_N64.c b/src/Window_N64.c index e21b414d9..761c23e60 100644 --- a/src/Window_N64.c +++ b/src/Window_N64.c @@ -74,6 +74,19 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + joypad_poll(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(joypad_buttons_t btns) { Gamepad_SetButton(CCPAD_L, btns.l); Gamepad_SetButton(CCPAD_R, btns.r); @@ -106,19 +119,12 @@ static void ProcessAnalogInput(joypad_inputs_t* inputs, double delta) { Gamepad_SetAxis(PAD_AXIS_RIGHT, x / AXIS_SCALE, -y / AXIS_SCALE, delta); } -void Window_ProcessEvents(double delta) { - joypad_poll(); - +void Window_ProcessGamepads(double delta) { joypad_inputs_t inputs = joypad_get_inputs(JOYPAD_PORT_1); HandleButtons(inputs.btn); ProcessAnalogInput(&inputs, delta); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_NDS.c b/src/Window_NDS.c index d8f1b42c3..884dc83c6 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -97,7 +97,41 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ -static void HandleButtons(int mods) { +static void ProcessTouchInput(int mods) { + touchPosition touch; + touchRead(&touch); + Camera.Sensitivity = 100; // TODO not hardcode this + + if (mods & KEY_TOUCH) { + Input_AddTouch(0, touch.px, touch.py); + } else if (keysUp() & KEY_TOUCH) { + Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); + } +} + +void Window_ProcessEvents(double delta) { + scanKeys(); + + if (keyboardOpen) { + keyboardUpdate(); + } else { + ProcessTouchInput(keys); + } +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ +void Window_ProcessGamepads(double delta) { + int mods = keysDown() | keysHeld(); + Gamepad_SetButton(CCPAD_L, mods & KEY_L); Gamepad_SetButton(CCPAD_R, mods & KEY_R); @@ -115,36 +149,6 @@ static void HandleButtons(int mods) { Gamepad_SetButton(CCPAD_DOWN, mods & KEY_DOWN); } -static void ProcessTouchInput(int mods) { - touchPosition touch; - touchRead(&touch); - Camera.Sensitivity = 100; // TODO not hardcode this - - if (mods & KEY_TOUCH) { - Input_AddTouch(0, touch.px, touch.py); - } else if (keysUp() & KEY_TOUCH) { - Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); - } -} - -void Window_ProcessEvents(double delta) { - scanKeys(); - int keys = keysDown() | keysHeld(); - HandleButtons(keys); - - if (keyboardOpen) { - keyboardUpdate(); - } else { - ProcessTouchInput(keys); - } -} - -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_PS1.c b/src/Window_PS1.c index 0e6e1ec8a..db9c3661f 100644 --- a/src/Window_PS1.c +++ b/src/Window_PS1.c @@ -78,6 +78,19 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_UpdateRawMouse(void) { } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(int buttons) { // Confusingly, it seems that when a bit is on, it means the button is NOT pressed // So just flip the bits to make more sense @@ -119,17 +132,11 @@ static void ProcessPadInput(PADTYPE* pad, double delta) { } } -void Window_ProcessEvents(double delta) { +void Window_ProcessGamepads(double delta) { PADTYPE* pad = (PADTYPE*)&pad_buff[0][0]; if (pad->stat == 0) ProcessPadInput(pad, delta); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_UpdateRawMouse(void) { } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_PS2.c b/src/Window_PS2.c index 2f7444040..ea5e5c371 100644 --- a/src/Window_PS2.c +++ b/src/Window_PS2.c @@ -84,6 +84,19 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_UpdateRawMouse(void) { } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(int buttons) { // Confusingly, it seems that when a bit is on, it means the button is NOT pressed // So just flip the bits to make more sense @@ -124,9 +137,8 @@ static void ProcessPadInput(double delta, struct padButtonStatus* pad) { } static cc_bool setMode; -void Window_ProcessEvents(double delta) { +void Window_ProcessGamepads(double delta) { struct padButtonStatus pad; - Input.JoystickMovement = false; int state = padGetState(0, 0); if (state != PAD_STATE_STABLE) return; @@ -141,12 +153,6 @@ void Window_ProcessEvents(double delta) { if (ret != 0) ProcessPadInput(delta, &pad); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_UpdateRawMouse(void) { } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_PS3.c b/src/Window_PS3.c index 4ada25a88..255ffea6c 100644 --- a/src/Window_PS3.c +++ b/src/Window_PS3.c @@ -252,6 +252,21 @@ static void ProcessKBInput(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + ioKbGetInfo(&kb_info); + if (kb_info.status[0]) ProcessKBInput(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_UpdateRawMouse(void) { } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(padData* data) { //Platform_Log2("BUTTONS: %h (%h)", &data->button[2], &data->button[0]); Gamepad_SetButton(CCPAD_A, data->BTN_TRIANGLE); @@ -287,25 +302,14 @@ static void ProcessPadInput(double delta, padData* pad) { HandleJoystick(PAD_AXIS_RIGHT, pad->ANA_R_H - 0x80, pad->ANA_R_V - 0x80, delta); } -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - +void Window_ProcessGamepads(double delta) { ioPadGetInfo(&pad_info); if (pad_info.status[0]) { ioPadGetData(0, &pad_data); ProcessPadInput(delta, &pad_data); } - - ioKbGetInfo(&kb_info); - if (kb_info.status[0]) ProcessKBInput(); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_UpdateRawMouse(void) { } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_PSP.c b/src/Window_PSP.c index 87b37568a..571f17b3a 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -67,6 +67,18 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(int mods) { Gamepad_SetButton(CCPAD_L, mods & PSP_CTRL_LTRIGGER); Gamepad_SetButton(CCPAD_R, mods & PSP_CTRL_RTRIGGER); @@ -96,7 +108,7 @@ static void ProcessCircleInput(SceCtrlData* pad, double delta) { Gamepad_SetAxis(PAD_AXIS_RIGHT, x / AXIS_SCALE, y / AXIS_SCALE, delta); } -void Window_ProcessEvents(double delta) { +void Window_ProcessGamepads(double delta) { SceCtrlData pad; /* TODO implement */ int ret = sceCtrlPeekBufferPositive(&pad, 1); @@ -107,11 +119,6 @@ void Window_ProcessEvents(double delta) { ProcessCircleInput(&pad, delta); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_PSVita.c b/src/Window_PSVita.c index 5565c29f5..75ada09a7 100644 --- a/src/Window_PSVita.c +++ b/src/Window_PSVita.c @@ -86,33 +86,6 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ -static void HandleButtons(int mods) { - Gamepad_SetButton(CCPAD_A, mods & SCE_CTRL_TRIANGLE); - Gamepad_SetButton(CCPAD_B, mods & SCE_CTRL_SQUARE); - Gamepad_SetButton(CCPAD_X, mods & SCE_CTRL_CROSS); - Gamepad_SetButton(CCPAD_Y, mods & SCE_CTRL_CIRCLE); - - Gamepad_SetButton(CCPAD_START, mods & SCE_CTRL_START); - Gamepad_SetButton(CCPAD_SELECT, mods & SCE_CTRL_SELECT); - - Gamepad_SetButton(CCPAD_LEFT, mods & SCE_CTRL_LEFT); - Gamepad_SetButton(CCPAD_RIGHT, mods & SCE_CTRL_RIGHT); - Gamepad_SetButton(CCPAD_UP, mods & SCE_CTRL_UP); - Gamepad_SetButton(CCPAD_DOWN, mods & SCE_CTRL_DOWN); - - Gamepad_SetButton(CCPAD_L, mods & SCE_CTRL_LTRIGGER); - Gamepad_SetButton(CCPAD_R, mods & SCE_CTRL_RTRIGGER); -} - -#define AXIS_SCALE 16.0f -static void ProcessCircleInput(int axis, int x, int y, double delta) { - // May not be exactly 0 on actual hardware - if (Math_AbsI(x) <= 8) x = 0; - if (Math_AbsI(y) <= 8) y = 0; - - Gamepad_SetAxis(axis, x / AXIS_SCALE, y / AXIS_SCALE, delta); -} - static void AdjustTouchPress(int* x, int* y) { if (!frontPanel.maxDispX || !frontPanel.maxDispY) return; // TODO: Shouldn't ever happen? need to check @@ -146,6 +119,47 @@ static void ProcessTouchInput(void) { } } +void Window_ProcessEvents(double delta) { + ProcessTouchInput(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_UpdateRawMouse(void) { } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ +static void HandleButtons(int mods) { + Gamepad_SetButton(CCPAD_A, mods & SCE_CTRL_TRIANGLE); + Gamepad_SetButton(CCPAD_B, mods & SCE_CTRL_SQUARE); + Gamepad_SetButton(CCPAD_X, mods & SCE_CTRL_CROSS); + Gamepad_SetButton(CCPAD_Y, mods & SCE_CTRL_CIRCLE); + + Gamepad_SetButton(CCPAD_START, mods & SCE_CTRL_START); + Gamepad_SetButton(CCPAD_SELECT, mods & SCE_CTRL_SELECT); + + Gamepad_SetButton(CCPAD_LEFT, mods & SCE_CTRL_LEFT); + Gamepad_SetButton(CCPAD_RIGHT, mods & SCE_CTRL_RIGHT); + Gamepad_SetButton(CCPAD_UP, mods & SCE_CTRL_UP); + Gamepad_SetButton(CCPAD_DOWN, mods & SCE_CTRL_DOWN); + + Gamepad_SetButton(CCPAD_L, mods & SCE_CTRL_LTRIGGER); + Gamepad_SetButton(CCPAD_R, mods & SCE_CTRL_RTRIGGER); +} + +#define AXIS_SCALE 16.0f +static void ProcessCircleInput(int axis, int x, int y, double delta) { + // May not be exactly 0 on actual hardware + if (Math_AbsI(x) <= 8) x = 0; + if (Math_AbsI(y) <= 8) y = 0; + + Gamepad_SetAxis(axis, x / AXIS_SCALE, y / AXIS_SCALE, delta); +} + static void ProcessPadInput(double delta) { SceCtrlData pad; @@ -160,19 +174,10 @@ static void ProcessPadInput(double delta) { ProcessCircleInput(PAD_AXIS_RIGHT, pad.rx - 127, pad.ry - 127, delta); } -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - +void Window_ProcessGamepads(double delta) { ProcessPadInput(delta); - ProcessTouchInput(); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_UpdateRawMouse(void) { } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_SDL.c b/src/Window_SDL.c index 86848a4c8..bafe1c955 100644 --- a/src/Window_SDL.c +++ b/src/Window_SDL.c @@ -295,6 +295,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + static void Cursor_GetRawPos(int* x, int* y) { SDL_GetMouseState(x, y); } diff --git a/src/Window_SDL3.c b/src/Window_SDL3.c index bf60dfe7c..16de14269 100644 --- a/src/Window_SDL3.c +++ b/src/Window_SDL3.c @@ -281,6 +281,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + static void Cursor_GetRawPos(int* x, int* y) { float xPos, yPos; SDL_GetMouseState(&xPos, &yPos); diff --git a/src/Window_Saturn.c b/src/Window_Saturn.c index e4df97b7c..9817baebe 100644 --- a/src/Window_Saturn.c +++ b/src/Window_Saturn.c @@ -78,6 +78,20 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + smpc_peripheral_process(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_UpdateRawMouse(void) { } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void ProcessButtons(int mods) { Gamepad_SetButton(CCPAD_A, mods & PERIPHERAL_DIGITAL_A); Gamepad_SetButton(CCPAD_B, mods & PERIPHERAL_DIGITAL_B); @@ -95,19 +109,11 @@ static void ProcessButtons(int mods) { Gamepad_SetButton(CCPAD_DOWN, mods & PERIPHERAL_DIGITAL_DOWN); } -void Window_ProcessEvents(double delta) { - smpc_peripheral_process(); +void Window_ProcessGamepads(double delta) { smpc_peripheral_digital_port(1, &state); - ProcessButtons(state.pressed.raw | state.held.raw); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_UpdateRawMouse(void) { } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_Switch.c b/src/Window_Switch.c index 529c7fab5..586dde33a 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -108,6 +108,41 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +static void ProcessTouchInput(void) { + static int prev_touchcount = 0; + HidTouchScreenState state = {0}; + hidGetTouchScreenStates(&state, 1); + + if (state.count) { + Input_AddTouch(0, state.touches[0].x, state.touches[0].y); + } else if (prev_touchcount) { + Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); + } + prev_touchcount = state.count; +} + +void Window_ProcessEvents(double delta) { + // Scan the gamepad. This should be done once for each frame + padUpdate(&pad); + + if (!appletMainLoop()) { + Window_Main.Exists = false; + Window_RequestClose(); + return; + } + ProcessTouchInput(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void HandleButtons(u64 mods) { Gamepad_SetButton(CCPAD_L, mods & HidNpadButton_L); Gamepad_SetButton(CCPAD_R, mods & HidNpadButton_R); @@ -135,30 +170,7 @@ static void ProcessJoystickInput(int axis, HidAnalogStickState* pos, double delt Gamepad_SetAxis(axis, pos->x / AXIS_SCALE, -pos->y / AXIS_SCALE, delta); } -static void ProcessTouchInput(void) { - static int prev_touchcount = 0; - HidTouchScreenState state = {0}; - hidGetTouchScreenStates(&state, 1); - - if (state.count) { - Input_AddTouch(0, state.touches[0].x, state.touches[0].y); - } else if (prev_touchcount) { - Input_RemoveTouch(0, Pointers[0].x, Pointers[0].y); - } - prev_touchcount = state.count; -} - -void Window_ProcessEvents(double delta) { - // Scan the gamepad. This should be done once for each frame - padUpdate(&pad); - Input.JoystickMovement = false; - - if (!appletMainLoop()) { - Window_Main.Exists = false; - Window_RequestClose(); - return; - } - +void Window_ProcessGamepads(double delta) { u64 keys = padGetButtons(&pad); HandleButtons(keys); @@ -167,16 +179,8 @@ void Window_ProcessEvents(double delta) { HidAnalogStickState analog_stick_r = padGetStickPos(&pad, 1); ProcessJoystickInput(PAD_AXIS_LEFT, &analog_stick_l, delta); ProcessJoystickInput(PAD_AXIS_RIGHT, &analog_stick_r, delta); - - ProcessTouchInput(); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_Web.c b/src/Window_Web.c index 4147b5eee..eed822d42 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -529,6 +529,26 @@ static void ProcessPendingResize(void) { UpdateWindowBounds(); } +void Window_ProcessEvents(double delta) { + if (!needResize) return; + needResize = false; + ProcessPendingResize(); +} + +/* Not needed because browser provides relative mouse and touch events */ +static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; } +/* Not allowed to move cursor from javascript */ +void Cursor_SetPosition(int x, int y) { } + +extern void interop_SetCursorVisible(int visible); +static void Cursor_DoSetVisible(cc_bool visible) { + interop_SetCursorVisible(visible); +} + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ /* https://www.w3.org/TR/gamepad/#dfn-standard-gamepad */ #define GetGamepadButton(i) i < numButtons ? ev->digitalButton[i] : 0 static void ProcessGamepadButtons(EmscriptenGamepadEvent* ev) { @@ -566,7 +586,6 @@ static void ProcessGamepadAxis(int axis, float x, float y, double delta) { static void ProcessGamepadInput(EmscriptenGamepadEvent* ev, double delta) { Input.Sources |= INPUT_SOURCE_GAMEPAD; - Input.JoystickMovement = false; ProcessGamepadButtons(ev); if (ev->numAxes >= 4) { @@ -577,7 +596,7 @@ static void ProcessGamepadInput(EmscriptenGamepadEvent* ev, double delta) { } } -void Window_ProcessEvents(double delta) { +void Window_ProcessGamepads(double delta) { int i, res, count; Input.Sources = INPUT_SOURCE_NORMAL; @@ -591,22 +610,12 @@ void Window_ProcessEvents(double delta) { if (res == 0) ProcessGamepadInput(&ev, delta); } } - - if (!needResize) return; - needResize = false; - ProcessPendingResize(); } -/* Not needed because browser provides relative mouse and touch events */ -static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; } -/* Not allowed to move cursor from javascript */ -void Cursor_SetPosition(int x, int y) { } - -extern void interop_SetCursorVisible(int visible); -static void Cursor_DoSetVisible(cc_bool visible) { - interop_SetCursorVisible(visible); -} +/*########################################################################################################################* +*-------------------------------------------------------Misc/Other--------------------------------------------------------* +*#########################################################################################################################*/ extern void interop_ShowDialog(const char* title, const char* msg); static void ShowDialogCore(const char* title, const char* msg) { interop_ShowDialog(title, msg); diff --git a/src/Window_WiiU.c b/src/Window_WiiU.c index 56d2afc21..dfc7cd38d 100644 --- a/src/Window_WiiU.c +++ b/src/Window_WiiU.c @@ -119,6 +119,26 @@ void Window_RequestClose(void) { } +/*########################################################################################################################* +*----------------------------------------------------Input processing-----------------------------------------------------* +*#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + if (!WHBProcIsRunning()) { + Window_Main.Exists = false; + Window_RequestClose(); + } +} + +void Window_UpdateRawMouse(void) { } + +void Cursor_SetPosition(int x, int y) { } +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ static void ProcessKPAD(double delta) { KPADStatus kpad = { 0 }; int res = KPADRead(0, &kpad, 1); @@ -195,25 +215,11 @@ static void ProcessVPAD(double delta) { } -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - - if (!WHBProcIsRunning()) { - Window_Main.Exists = false; - Window_RequestClose(); - return; - } - +void Window_ProcessGamepads(double delta) { ProcessVPAD(delta); ProcessKPAD(delta); } -void Window_UpdateRawMouse(void) { } - -void Cursor_SetPosition(int x, int y) { } -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_Win.c b/src/Window_Win.c index bf2a123b9..79392a317 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -533,6 +533,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + static void Cursor_GetRawPos(int* x, int* y) { POINT point; GetCursorPos(&point); diff --git a/src/Window_X11.c b/src/Window_X11.c index 4d82b95e0..4b97e8173 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -699,6 +699,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + static void Cursor_GetRawPos(int* x, int* y) { Window rootW, childW; int childX, childY; diff --git a/src/Window_Xbox.c b/src/Window_Xbox.c index e416e39b0..7086e9328 100644 --- a/src/Window_Xbox.c +++ b/src/Window_Xbox.c @@ -107,6 +107,20 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + usbh_pooling_hubs(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for Xbox + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ // https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad // NOTE: Analog buttons use dedicated field rather than being part of dButtons #define XINPUT_GAMEPAD_DPAD_UP 0x0001 @@ -149,9 +163,7 @@ static void HandleJoystick(int axis, int x, int y, double delta) { Gamepad_SetAxis(axis, x / AXIS_SCALE, -y / AXIS_SCALE, delta); } -void Window_ProcessEvents(double delta) { - Input.JoystickMovement = false; - usbh_pooling_hubs(); +void Window_ProcessGamepads(double delta) { if (!xid_ctrl) return; HandleButtons(&gp_state); @@ -159,12 +171,6 @@ void Window_ProcessEvents(double delta) { HandleJoystick(PAD_AXIS_RIGHT, gp_state.rightStickX, gp_state.rightStickY, delta); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for Xbox - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/Window_Xbox360.c b/src/Window_Xbox360.c index aa9a47550..6316645e7 100644 --- a/src/Window_Xbox360.c +++ b/src/Window_Xbox360.c @@ -71,6 +71,20 @@ void Window_RequestClose(void) { /*########################################################################################################################* *----------------------------------------------------Input processing-----------------------------------------------------* *#########################################################################################################################*/ +void Window_ProcessEvents(double delta) { + usb_do_poll(); +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for Xbox + +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ /* struct controller_data_s { @@ -99,22 +113,14 @@ static void HandleButtons(struct controller_data_s* pad) { Gamepad_SetButton(CCPAD_DOWN, pad->down); } -void Window_ProcessEvents(double delta) { - usb_do_poll(); - +void Window_ProcessGamepads(double delta) { struct controller_data_s pad; - int res = get_controller_data(&pad, 0); - if (res == 0) return; - - HandleButtons(&pad); + int res = get_controller_data(&pad, 0); + if (res == 0) return; + + HandleButtons(&pad); } -void Cursor_SetPosition(int x, int y) { } // Makes no sense for Xbox - -void Window_EnableRawMouse(void) { Input.RawMode = true; } -void Window_DisableRawMouse(void) { Input.RawMode = false; } -void Window_UpdateRawMouse(void) { } - /*########################################################################################################################* *------------------------------------------------------Framebuffer--------------------------------------------------------* diff --git a/src/interop_BeOS.cpp b/src/interop_BeOS.cpp index 3cdaaf307..9307c4276 100644 --- a/src/interop_BeOS.cpp +++ b/src/interop_BeOS.cpp @@ -628,6 +628,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + static void Cursor_GetRawPos(int* x, int* y) { BPoint where; uint32 buttons; diff --git a/src/interop_cocoa.m b/src/interop_cocoa.m index c42bd135d..8abc9a424 100644 --- a/src/interop_cocoa.m +++ b/src/interop_cocoa.m @@ -568,6 +568,8 @@ void Window_ProcessEvents(double delta) { } } +void Window_ProcessGamepads(double delta) { } + /*########################################################################################################################* *-----------------------------------------------------------Dialogs-------------------------------------------------------* diff --git a/src/interop_ios.m b/src/interop_ios.m index 50899269b..5947cacf8 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -493,6 +493,8 @@ void Window_ProcessEvents(double delta) { } while (res == kCFRunLoopRunHandledSource); } +void Window_ProcessGamepads(double delta) { } + void ShowDialogCore(const char* title, const char* msg) { // UIAlertController - iOS 8.0 // UIAlertAction - iOS 8.0