Compare commits

...

4 Commits

Author SHA1 Message Date
Jordan Woyak
80ab51801d
Merge 5048cf9a15 into 2c92e5b5b3 2024-11-12 13:29:00 -06: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
5048cf9a15 ControllerInterface/Pipes: Cleanup and minor fixes. 2024-11-05 00:28:22 -06:00
4 changed files with 96 additions and 123 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

@ -5,40 +5,88 @@
#include <algorithm>
#include <array>
#include <cstdlib>
#include <fcntl.h>
#include <iostream>
#include <locale>
#include <filesystem>
#include <map>
#include <sstream>
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <string_view>
#include <vector>
#include <fcntl.h>
#include <unistd.h>
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ciface::Pipes
{
static const std::array<std::string, 12> s_button_tokens{
{"A", "B", "X", "Y", "Z", "START", "L", "R", "D_UP", "D_DOWN", "D_LEFT", "D_RIGHT"}};
static constexpr std::array s_button_tokens = {"A", "B", "X", "Y", "Z", "START",
"L", "R", "D_UP", "D_DOWN", "D_LEFT", "D_RIGHT"};
static const std::array<std::string, 2> s_shoulder_tokens{{"L", "R"}};
static constexpr std::array s_shoulder_tokens{"L", "R"};
static const std::array<std::string, 2> s_axis_tokens{{"MAIN", "C"}};
static constexpr std::array s_axis_tokens{"MAIN", "C"};
static double StringToDouble(const std::string& text)
static double StringToDouble(std::string text)
{
std::istringstream is(text);
// ignore current locale
is.imbue(std::locale::classic());
double result;
is >> result;
double result = 0;
TryParse(text, &result);
return result;
}
class PipeDevice : public Core::Device
{
public:
PipeDevice(int fd, std::string name);
~PipeDevice();
Core::DeviceRemoval UpdateInput() override;
std::string GetName() const override { return m_name; }
std::string GetSource() const override { return "Pipe"; }
private:
class ButtonInput : public Input
{
public:
ButtonInput(std::string_view name, const bool* value) : m_name(std::move(name)), m_state(*value)
{
}
std::string GetName() const override { return "Button " + std::string{m_name}; }
ControlState GetState() const override { return m_state; }
private:
const std::string_view m_name;
const bool& m_state;
};
template <int Range>
class AnalogInput : public Input
{
public:
AnalogInput(std::string name, const ControlState* value)
: m_name(std::move(name)), m_state(*value)
{
}
std::string GetName() const override { return "Axis " + m_name + (Range < 0 ? " -" : " +"); }
ControlState GetState() const override { return m_state / Range; }
private:
const std::string m_name;
const ControlState& m_state;
};
void AddAxis(std::string name);
void ParseCommand(const std::string& command);
void SetAxis(const std::string& entry, double value);
const int m_fd;
const std::string m_name;
std::string m_buf;
std::map<std::string, bool> m_buttons;
std::map<std::string, ControlState> m_axes;
};
class InputBackend final : public ciface::InputBackend
{
public:
@ -53,43 +101,42 @@ std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* co
void InputBackend::PopulateDevices()
{
// Search the Pipes directory for files that we can open in read-only,
// non-blocking mode. The device name is the virtual name of the file.
File::FSTEntry fst;
std::string dir_path = File::GetUserPath(D_PIPES_IDX);
if (!File::Exists(dir_path))
return;
fst = File::ScanDirectoryTree(dir_path, false);
if (!fst.isDirectory)
return;
for (unsigned int i = 0; i < fst.size; ++i)
// Search the "Pipes" directory for fifo files that we can open in read-only,
// non-blocking mode. The filename becomes the Device name.
const std::string& dir_path = File::GetUserPath(D_PIPES_IDX);
std::error_code error;
for (const auto& dir_entry : std::filesystem::directory_iterator{dir_path, error})
{
const File::FSTEntry& child = fst.children[i];
if (child.isDirectory)
if (!dir_entry.is_fifo())
continue;
int fd = open(child.physicalName.c_str(), O_RDONLY | O_NONBLOCK);
const int fd = open(dir_entry.path().c_str(), O_RDONLY | O_NONBLOCK);
if (fd < 0)
continue;
g_controller_interface.AddDevice(std::make_shared<PipeDevice>(fd, child.virtualName));
GetControllerInterface().AddDevice(
std::make_shared<PipeDevice>(fd, dir_entry.path().filename()));
}
if (error)
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Pipes/PopulateDevices: {}", error.message());
}
PipeDevice::PipeDevice(int fd, const std::string& name) : m_fd(fd), m_name(name)
PipeDevice::PipeDevice(int fd, std::string name) : m_fd(fd), m_name(std::move(name))
{
for (const auto& tok : s_button_tokens)
{
PipeInput* btn = new PipeInput("Button " + tok);
AddInput(btn);
m_buttons[tok] = btn;
auto [iter, inserted] = m_buttons.emplace(tok, false);
AddInput(new ButtonInput(tok, &iter->second));
}
for (const auto& tok : s_shoulder_tokens)
{
AddAxis(tok, 0.0);
AddAxis(tok);
}
for (const auto& tok : s_axis_tokens)
{
AddAxis(tok + " X", 0.5);
AddAxis(tok + " Y", 0.5);
AddAxis(tok + std::string{" X"});
AddAxis(tok + std::string{" Y"});
}
}
@ -103,7 +150,7 @@ Core::DeviceRemoval PipeDevice::UpdateInput()
// Read any pending characters off the pipe. If we hit a newline,
// then dequeue a command off the front of m_buf and parse it.
char buf[32];
ssize_t bytes_read = read(m_fd, buf, sizeof buf);
ssize_t bytes_read = read(m_fd, buf, sizeof(buf));
while (bytes_read > 0)
{
m_buf.append(buf, bytes_read);
@ -120,29 +167,18 @@ Core::DeviceRemoval PipeDevice::UpdateInput()
return Core::DeviceRemoval::Keep;
}
void PipeDevice::AddAxis(const std::string& name, double value)
void PipeDevice::AddAxis(std::string name)
{
// Dolphin uses separate axes for left/right, which complicates things.
PipeInput* ax_hi = new PipeInput("Axis " + name + " +");
ax_hi->SetState(value);
PipeInput* ax_lo = new PipeInput("Axis " + name + " -");
ax_lo->SetState(value);
m_axes[name + " +"] = ax_hi;
m_axes[name + " -"] = ax_lo;
AddFullAnalogSurfaceInputs(ax_lo, ax_hi);
auto [iter, inserted] = m_axes.emplace(name, 0.0);
AddInput(new AnalogInput<-1>(name, &iter->second));
AddInput(new AnalogInput<+1>(std::move(name), &iter->second));
}
void PipeDevice::SetAxis(const std::string& entry, double value)
{
value = std::clamp(value, 0.0, 1.0);
double hi = std::max(0.0, value - 0.5) * 2.0;
double lo = (0.5 - std::min(0.5, value)) * 2.0;
auto search_hi = m_axes.find(entry + " +");
if (search_hi != m_axes.end())
search_hi->second->SetState(hi);
auto search_lo = m_axes.find(entry + " -");
if (search_lo != m_axes.end())
search_lo->second->SetState(lo);
auto search = m_axes.find(entry);
if (search != m_axes.end())
search->second = std::clamp(value, 0.0, 1.0) * 2.0 - 1.0;
}
void PipeDevice::ParseCommand(const std::string& command)
@ -154,14 +190,14 @@ void PipeDevice::ParseCommand(const std::string& command)
{
auto search = m_buttons.find(tokens[1]);
if (search != m_buttons.end())
search->second->SetState(tokens[0] == "PRESS" ? 1.0 : 0.0);
search->second = tokens[0] == "PRESS";
}
else if (tokens[0] == "SET")
{
if (tokens.size() == 3)
{
double value = StringToDouble(tokens[2]);
SetAxis(tokens[1], (value / 2.0) + 0.5);
SetAxis(tokens[1], (value + 1.0) / 2.0);
}
else if (tokens.size() == 4)
{

View File

@ -3,10 +3,6 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include "InputCommon/ControllerInterface/ControllerInterface.h"
namespace ciface::Pipes
@ -23,38 +19,4 @@ namespace ciface::Pipes
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
class PipeDevice : public Core::Device
{
public:
PipeDevice(int fd, const std::string& name);
~PipeDevice();
Core::DeviceRemoval UpdateInput() override;
std::string GetName() const override { return m_name; }
std::string GetSource() const override { return "Pipe"; }
private:
class PipeInput : public Input
{
public:
PipeInput(const std::string& name) : m_name(name), m_state(0.0) {}
std::string GetName() const override { return m_name; }
ControlState GetState() const override { return m_state; }
void SetState(ControlState state) { m_state = state; }
private:
const std::string m_name;
ControlState m_state;
};
void AddAxis(const std::string& name, double value);
void ParseCommand(const std::string& command);
void SetAxis(const std::string& entry, double value);
const int m_fd;
const std::string m_name;
std::string m_buf;
std::map<std::string, PipeInput*> m_buttons;
std::map<std::string, PipeInput*> m_axes;
};
} // namespace ciface::Pipes