mirror of
https://github.com/libretro/ppsspp.git
synced 2024-11-23 16:19:44 +00:00
Simple tilt controls (horizontal axis only, good for racing games)
This commit is contained in:
parent
83ba2d04ec
commit
34c0c204bc
@ -96,6 +96,7 @@ void CConfig::Load(const char *iniFileName)
|
||||
#endif
|
||||
control->Get("LargeControls", &bLargeControls, false);
|
||||
control->Get("KeyMapping",iMappingMap);
|
||||
control->Get("AccelerometerToAnalogHoriz", &bAccelerometerToAnalogHoriz, false);
|
||||
|
||||
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
|
||||
pspConfig->Get("Language", &ilanguage, PSP_SYSTEMPARAM_LANGUAGE_ENGLISH);
|
||||
@ -154,6 +155,7 @@ void CConfig::Save()
|
||||
control->Set("ShowTouchControls", bShowTouchControls);
|
||||
control->Set("LargeControls", bLargeControls);
|
||||
control->Set("KeyMapping",iMappingMap);
|
||||
control->Set("AccelerometerToAnalogHoriz", bAccelerometerToAnalogHoriz);
|
||||
|
||||
IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam");
|
||||
pspConfig->Set("Language", ilanguage);
|
||||
|
@ -79,6 +79,7 @@ public:
|
||||
bool bShowFPSCounter;
|
||||
bool bShowDebugStats;
|
||||
bool bLargeControls;
|
||||
bool bAccelerometerToAnalogHoriz;
|
||||
|
||||
// Control
|
||||
std::map<int,int> iMappingMap; // Can be used differently depending on systems
|
||||
|
@ -97,6 +97,24 @@ void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) {
|
||||
}
|
||||
}
|
||||
|
||||
inline float curve1(float x) {
|
||||
const float deadzone = 0.15f;
|
||||
const float factor = 1.0f / (1.0f - deadzone);
|
||||
if (x > deadzone) {
|
||||
return (x - deadzone) * (x - deadzone) * factor;
|
||||
} else if (x < -0.1f) {
|
||||
return -(x + deadzone) * (x + deadzone) * factor;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
inline float clamp1(float x) {
|
||||
if (x > 1.0f) return 1.0f;
|
||||
if (x < -1.0f) return -1.0f;
|
||||
return x;
|
||||
}
|
||||
|
||||
void EmuScreen::update(InputState &input)
|
||||
{
|
||||
if (errorMessage_.size()) {
|
||||
@ -110,12 +128,11 @@ void EmuScreen::update(InputState &input)
|
||||
if (invalid_)
|
||||
return;
|
||||
|
||||
// First translate touches into pad input.
|
||||
// First translate touches into native pad input.
|
||||
UpdateGamepad(input);
|
||||
UpdateInputState(&input);
|
||||
|
||||
// Then translate pad input into PSP pad input.
|
||||
|
||||
// Then translate pad input into PSP pad input. Also, add in tilt.
|
||||
static const int mapping[12][2] = {
|
||||
{PAD_BUTTON_A, CTRL_CROSS},
|
||||
{PAD_BUTTON_B, CTRL_CIRCLE},
|
||||
@ -139,7 +156,17 @@ void EmuScreen::update(InputState &input)
|
||||
__CtrlButtonUp(mapping[i][1]);
|
||||
}
|
||||
}
|
||||
__CtrlSetAnalog(input.pad_lstick_x, input.pad_lstick_y);
|
||||
|
||||
float stick_x = input.pad_lstick_x;
|
||||
float stick_y = input.pad_lstick_y;
|
||||
// Apply tilt
|
||||
if (g_Config.bAccelerometerToAnalogHoriz) {
|
||||
// TODO: Deadzone, etc.
|
||||
stick_x += clamp1(curve1(input.acc.y) * 2.0f);
|
||||
stick_x = clamp1(stick_x);
|
||||
}
|
||||
|
||||
__CtrlSetAnalog(stick_x, stick_y);
|
||||
|
||||
if (input.pad_buttons_down & (PAD_BUTTON_MENU | PAD_BUTTON_BACK)) {
|
||||
if (g_Config.bBufferedRendering)
|
||||
|
@ -340,6 +340,7 @@ void SettingsScreen::render() {
|
||||
UICheckBox(GEN_ID, x + 450, y, "Large Controls", ALIGN_TOPLEFT, &g_Config.bLargeControls);
|
||||
UICheckBox(GEN_ID, x + 50, y += stride, "Show Analog Stick", ALIGN_TOPLEFT, &g_Config.bShowAnalogStick);
|
||||
}
|
||||
UICheckBox(GEN_ID, x, y += 50, "Tilt to Analog (horizontal)", ALIGN_TOPLEFT, &g_Config.bAccelerometerToAnalogHoriz);
|
||||
// UICheckBox(GEN_ID, x, y += stride, "Draw raw framebuffer (for some homebrew)", ALIGN_TOPLEFT, &g_Config.bDisplayFramebuffer);
|
||||
|
||||
if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres-10), LARGE_BUTTON_WIDTH, "Back", ALIGN_RIGHT | ALIGN_BOTTOM)) {
|
||||
|
Loading…
Reference in New Issue
Block a user