Compare commits

...

4 Commits

Author SHA1 Message Date
Jordan Woyak
a6310ab450
Merge 83ed817ad2 into 2c92e5b5b3 2024-11-12 11:15:41 +01:00
OatmealDome
2c92e5b5b3
Merge pull request #13160 from cpba/flatpak-6.8-runtime
Flatpak: Upgrade kde runtime to 6.8
2024-11-12 00:30:46 -05:00
Carles Pastor
fe96bf4108 Flatpak: Upgrade kde runtime to 6.8
this version bundles SDL2-2.30.6, the temporary measure of building the
vendored version from exports is no longer necessary.
2024-11-10 12:06:06 +01:00
Jordan Woyak
83ed817ad2 ControllerInterface/SDL: Add Battery Input. 2024-11-04 22:24:42 -06:00
3 changed files with 62 additions and 26 deletions

View File

@ -1,22 +0,0 @@
{
"name": "SDL2",
"buildsystem": "autotools",
"config-opts": ["--disable-static"],
"sources": [
{
"type": "dir",
"path": "../../Externals/SDL/SDL"
}
],
"cleanup": [ "/bin/sdl2-config",
"/include",
"/lib/libSDL2.la",
"/lib/libSDL2main.a",
"/lib/libSDL2main.la",
"/lib/libSDL2_test.a",
"/lib/libSDL2_test.la",
"/lib/cmake",
"/share/aclocal",
"/lib/pkgconfig"]
}

View File

@ -1,6 +1,6 @@
app-id: org.DolphinEmu.dolphin-emu
runtime: org.kde.Platform
runtime-version: '6.7'
runtime-version: '6.8'
sdk: org.kde.Sdk
command: dolphin-emu-wrapper
rename-desktop-file: dolphin-emu.desktop
@ -47,9 +47,6 @@ modules:
url: https://github.com/Unrud/xdg-screensaver-shim/archive/0.0.2.tar.gz
sha256: 0ed2a69fe6ee6cbffd2fe16f85116db737f17fb1e79bfb812d893cf15c728399
# build the vendored SDL2 from Externals until the runtime gets 2.30.6
- SDL2/SDL2.json
- name: dolphin-emu
buildsystem: cmake-ninja
config-opts:

View File

@ -56,6 +56,38 @@ bool IsTriggerAxis(int index)
return index >= 4;
}
ControlState GetBatteryValueFromSDLPowerLevel(SDL_JoystickPowerLevel sdl_power_level)
{
// Values come from comments in SDL_joystick.h
// A proper percentage will be exposed in SDL3.
ControlState result;
switch (sdl_power_level)
{
case SDL_JOYSTICK_POWER_EMPTY:
result = 0.025;
break;
case SDL_JOYSTICK_POWER_LOW:
result = 0.125;
break;
case SDL_JOYSTICK_POWER_MEDIUM:
result = 0.45;
break;
case SDL_JOYSTICK_POWER_FULL:
result = 0.85;
break;
case SDL_JOYSTICK_POWER_WIRED:
case SDL_JOYSTICK_POWER_MAX:
result = 1.0;
break;
case SDL_JOYSTICK_POWER_UNKNOWN:
default:
result = 0.0;
break;
}
return result * ciface::BATTERY_INPUT_MAX_VALUE;
}
} // namespace
namespace ciface::SDL
@ -142,6 +174,18 @@ private:
const u8 m_direction;
};
class BatteryInput final : public Input
{
public:
explicit BatteryInput(const ControlState* battery_value) : m_battery_value(*battery_value) {}
std::string GetName() const override { return "Battery"; }
ControlState GetState() const override { return m_battery_value; }
bool IsDetectable() const override { return false; }
private:
const ControlState& m_battery_value;
};
// Rumble
template <int LowEnable, int HighEnable, int SuffixIndex>
class GenericMotor : public Output
@ -269,12 +313,18 @@ public:
std::string GetName() const override;
std::string GetSource() const override;
int GetSDLInstanceID() const;
Core::DeviceRemoval UpdateInput() override
{
m_battery_value = GetBatteryValueFromSDLPowerLevel(SDL_JoystickCurrentPowerLevel(m_joystick));
return Core::DeviceRemoval::Keep;
}
private:
SDL_GameController* const m_gamecontroller;
std::string m_name;
SDL_Joystick* const m_joystick;
SDL_Haptic* m_haptic = nullptr;
ControlState m_battery_value;
};
class InputBackend final : public ciface::InputBackend
@ -767,6 +817,17 @@ GameController::GameController(SDL_GameController* const gamecontroller,
}
}
}
// Needed to make the below power level not "UNKNOWN".
SDL_JoystickUpdate();
// Battery
if (SDL_JoystickPowerLevel const power_level = SDL_JoystickCurrentPowerLevel(m_joystick);
power_level != SDL_JOYSTICK_POWER_UNKNOWN)
{
m_battery_value = GetBatteryValueFromSDLPowerLevel(power_level);
AddInput(new BatteryInput{&m_battery_value});
}
}
GameController::~GameController()