mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Compare commits
4 Commits
69ece6e6af
...
80ab51801d
Author | SHA1 | Date | |
---|---|---|---|
|
80ab51801d | ||
|
2c92e5b5b3 | ||
|
fe96bf4108 | ||
|
5048cf9a15 |
@ -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"]
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
app-id: org.DolphinEmu.dolphin-emu
|
app-id: org.DolphinEmu.dolphin-emu
|
||||||
runtime: org.kde.Platform
|
runtime: org.kde.Platform
|
||||||
runtime-version: '6.7'
|
runtime-version: '6.8'
|
||||||
sdk: org.kde.Sdk
|
sdk: org.kde.Sdk
|
||||||
command: dolphin-emu-wrapper
|
command: dolphin-emu-wrapper
|
||||||
rename-desktop-file: dolphin-emu.desktop
|
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
|
url: https://github.com/Unrud/xdg-screensaver-shim/archive/0.0.2.tar.gz
|
||||||
sha256: 0ed2a69fe6ee6cbffd2fe16f85116db737f17fb1e79bfb812d893cf15c728399
|
sha256: 0ed2a69fe6ee6cbffd2fe16f85116db737f17fb1e79bfb812d893cf15c728399
|
||||||
|
|
||||||
# build the vendored SDL2 from Externals until the runtime gets 2.30.6
|
|
||||||
- SDL2/SDL2.json
|
|
||||||
|
|
||||||
- name: dolphin-emu
|
- name: dolphin-emu
|
||||||
buildsystem: cmake-ninja
|
buildsystem: cmake-ninja
|
||||||
config-opts:
|
config-opts:
|
||||||
|
@ -5,40 +5,88 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdlib>
|
#include <filesystem>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <locale>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <string_view>
|
||||||
#include <unistd.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
|
||||||
namespace ciface::Pipes
|
namespace ciface::Pipes
|
||||||
{
|
{
|
||||||
static const std::array<std::string, 12> s_button_tokens{
|
static constexpr std::array s_button_tokens = {"A", "B", "X", "Y", "Z", "START",
|
||||||
{"A", "B", "X", "Y", "Z", "START", "L", "R", "D_UP", "D_DOWN", "D_LEFT", "D_RIGHT"}};
|
"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);
|
double result = 0;
|
||||||
// ignore current locale
|
TryParse(text, &result);
|
||||||
is.imbue(std::locale::classic());
|
|
||||||
double result;
|
|
||||||
is >> result;
|
|
||||||
return 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
|
class InputBackend final : public ciface::InputBackend
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -53,43 +101,42 @@ std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* co
|
|||||||
|
|
||||||
void InputBackend::PopulateDevices()
|
void InputBackend::PopulateDevices()
|
||||||
{
|
{
|
||||||
// Search the Pipes directory for files that we can open in read-only,
|
// Search the "Pipes" directory for fifo files that we can open in read-only,
|
||||||
// non-blocking mode. The device name is the virtual name of the file.
|
// non-blocking mode. The filename becomes the Device name.
|
||||||
File::FSTEntry fst;
|
const std::string& dir_path = File::GetUserPath(D_PIPES_IDX);
|
||||||
std::string dir_path = File::GetUserPath(D_PIPES_IDX);
|
std::error_code error;
|
||||||
if (!File::Exists(dir_path))
|
for (const auto& dir_entry : std::filesystem::directory_iterator{dir_path, error})
|
||||||
return;
|
|
||||||
fst = File::ScanDirectoryTree(dir_path, false);
|
|
||||||
if (!fst.isDirectory)
|
|
||||||
return;
|
|
||||||
for (unsigned int i = 0; i < fst.size; ++i)
|
|
||||||
{
|
{
|
||||||
const File::FSTEntry& child = fst.children[i];
|
if (!dir_entry.is_fifo())
|
||||||
if (child.isDirectory)
|
|
||||||
continue;
|
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)
|
if (fd < 0)
|
||||||
continue;
|
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)
|
for (const auto& tok : s_button_tokens)
|
||||||
{
|
{
|
||||||
PipeInput* btn = new PipeInput("Button " + tok);
|
auto [iter, inserted] = m_buttons.emplace(tok, false);
|
||||||
AddInput(btn);
|
AddInput(new ButtonInput(tok, &iter->second));
|
||||||
m_buttons[tok] = btn;
|
|
||||||
}
|
}
|
||||||
for (const auto& tok : s_shoulder_tokens)
|
for (const auto& tok : s_shoulder_tokens)
|
||||||
{
|
{
|
||||||
AddAxis(tok, 0.0);
|
AddAxis(tok);
|
||||||
}
|
}
|
||||||
for (const auto& tok : s_axis_tokens)
|
for (const auto& tok : s_axis_tokens)
|
||||||
{
|
{
|
||||||
AddAxis(tok + " X", 0.5);
|
AddAxis(tok + std::string{" X"});
|
||||||
AddAxis(tok + " Y", 0.5);
|
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,
|
// 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.
|
// then dequeue a command off the front of m_buf and parse it.
|
||||||
char buf[32];
|
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)
|
while (bytes_read > 0)
|
||||||
{
|
{
|
||||||
m_buf.append(buf, bytes_read);
|
m_buf.append(buf, bytes_read);
|
||||||
@ -120,29 +167,18 @@ Core::DeviceRemoval PipeDevice::UpdateInput()
|
|||||||
return Core::DeviceRemoval::Keep;
|
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.
|
auto [iter, inserted] = m_axes.emplace(name, 0.0);
|
||||||
PipeInput* ax_hi = new PipeInput("Axis " + name + " +");
|
AddInput(new AnalogInput<-1>(name, &iter->second));
|
||||||
ax_hi->SetState(value);
|
AddInput(new AnalogInput<+1>(std::move(name), &iter->second));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipeDevice::SetAxis(const std::string& entry, double value)
|
void PipeDevice::SetAxis(const std::string& entry, double value)
|
||||||
{
|
{
|
||||||
value = std::clamp(value, 0.0, 1.0);
|
auto search = m_axes.find(entry);
|
||||||
double hi = std::max(0.0, value - 0.5) * 2.0;
|
if (search != m_axes.end())
|
||||||
double lo = (0.5 - std::min(0.5, value)) * 2.0;
|
search->second = std::clamp(value, 0.0, 1.0) * 2.0 - 1.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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipeDevice::ParseCommand(const std::string& command)
|
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]);
|
auto search = m_buttons.find(tokens[1]);
|
||||||
if (search != m_buttons.end())
|
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")
|
else if (tokens[0] == "SET")
|
||||||
{
|
{
|
||||||
if (tokens.size() == 3)
|
if (tokens.size() == 3)
|
||||||
{
|
{
|
||||||
double value = StringToDouble(tokens[2]);
|
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)
|
else if (tokens.size() == 4)
|
||||||
{
|
{
|
||||||
|
@ -3,10 +3,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
|
||||||
namespace ciface::Pipes
|
namespace ciface::Pipes
|
||||||
@ -23,38 +19,4 @@ namespace ciface::Pipes
|
|||||||
|
|
||||||
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
|
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
|
} // namespace ciface::Pipes
|
||||||
|
Loading…
Reference in New Issue
Block a user