Merge pull request #7663 from jordan-woyak/expression-parser-improve

Expression parser improvements
This commit is contained in:
JMC47
2019-10-17 17:35:30 -04:00
committed by GitHub
14 changed files with 1566 additions and 424 deletions
+240 -32
View File
@@ -4,6 +4,7 @@
#include "DolphinQt/Config/Mapping/IOWindow.h"
#include <optional>
#include <thread>
#include <QComboBox>
@@ -11,7 +12,9 @@
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QSlider>
@@ -25,22 +28,174 @@
#include "DolphinQt/QtUtils/BlockUserInputFilter.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
constexpr int SLIDER_TICK_COUNT = 100;
namespace
{
// TODO: Make sure these functions return colors that will be visible in the current theme.
QTextCharFormat GetSpecialCharFormat()
{
QTextCharFormat format;
format.setFontWeight(QFont::Weight::Bold);
return format;
}
QTextCharFormat GetLiteralCharFormat()
{
QTextCharFormat format;
format.setForeground(QBrush{Qt::darkMagenta});
return format;
}
QTextCharFormat GetInvalidCharFormat()
{
QTextCharFormat format;
format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
format.setUnderlineColor(Qt::darkRed);
return format;
}
QTextCharFormat GetControlCharFormat()
{
QTextCharFormat format;
format.setForeground(QBrush{Qt::darkGreen});
return format;
}
QTextCharFormat GetVariableCharFormat()
{
QTextCharFormat format;
format.setForeground(QBrush{Qt::darkYellow});
return format;
}
QTextCharFormat GetBarewordCharFormat()
{
QTextCharFormat format;
format.setForeground(QBrush{Qt::darkBlue});
return format;
}
QTextCharFormat GetCommentCharFormat()
{
QTextCharFormat format;
format.setForeground(QBrush{Qt::darkGray});
return format;
}
} // namespace
ControlExpressionSyntaxHighlighter::ControlExpressionSyntaxHighlighter(QTextDocument* parent,
QLineEdit* result)
: QSyntaxHighlighter(parent), m_result_text(result)
{
}
void ControlExpressionSyntaxHighlighter::highlightBlock(const QString&)
{
// TODO: This is going to result in improper highlighting with non-ascii characters:
ciface::ExpressionParser::Lexer lexer(document()->toPlainText().toStdString());
std::vector<ciface::ExpressionParser::Token> tokens;
const auto tokenize_status = lexer.Tokenize(tokens);
using ciface::ExpressionParser::TokenType;
const auto set_block_format = [this](int start, int count, const QTextCharFormat& format) {
if (start + count <= currentBlock().position() ||
start >= currentBlock().position() + currentBlock().length())
{
// This range is not within the current block.
return;
}
int block_start = start - currentBlock().position();
if (block_start < 0)
{
count += block_start;
block_start = 0;
}
setFormat(block_start, count, format);
};
for (auto& token : tokens)
{
std::optional<QTextCharFormat> char_format;
switch (token.type)
{
case TokenType::TOK_INVALID:
char_format = GetInvalidCharFormat();
break;
case TokenType::TOK_LPAREN:
case TokenType::TOK_RPAREN:
case TokenType::TOK_COMMA:
char_format = GetSpecialCharFormat();
break;
case TokenType::TOK_LITERAL:
char_format = GetLiteralCharFormat();
break;
case TokenType::TOK_CONTROL:
char_format = GetControlCharFormat();
break;
case TokenType::TOK_BAREWORD:
char_format = GetBarewordCharFormat();
break;
case TokenType::TOK_VARIABLE:
char_format = GetVariableCharFormat();
break;
case TokenType::TOK_COMMENT:
char_format = GetCommentCharFormat();
break;
default:
if (token.IsBinaryOperator())
char_format = GetSpecialCharFormat();
break;
}
if (char_format.has_value())
set_block_format(int(token.string_position), int(token.string_length), *char_format);
}
// This doesn't need to be run for every "block", but it works.
if (ciface::ExpressionParser::ParseStatus::Successful != tokenize_status)
{
m_result_text->setText(tr("Invalid Token."));
}
else
{
ciface::ExpressionParser::RemoveInertTokens(&tokens);
const auto parse_status = ciface::ExpressionParser::ParseTokens(tokens);
m_result_text->setText(
QString::fromStdString(parse_status.description.value_or(_trans("Success."))));
if (ciface::ExpressionParser::ParseStatus::Successful != parse_status.status)
{
const auto token = *parse_status.token;
set_block_format(int(token.string_position), int(token.string_length),
GetInvalidCharFormat());
}
}
}
IOWindow::IOWindow(QWidget* parent, ControllerEmu::EmulatedController* controller,
ControlReference* ref, IOWindow::Type type)
: QDialog(parent), m_reference(ref), m_controller(controller), m_type(type)
{
CreateMainLayout();
ConnectWidgets();
setWindowTitle(type == IOWindow::Type::Input ? tr("Configure Input") : tr("Configure Output"));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
ConfigChanged();
ConnectWidgets();
}
void IOWindow::CreateMainLayout()
@@ -51,18 +206,54 @@ void IOWindow::CreateMainLayout()
m_option_list = new QListWidget();
m_select_button = new QPushButton(tr("Select"));
m_detect_button = new QPushButton(tr("Detect"));
m_or_button = new QPushButton(tr("| OR"));
m_and_button = new QPushButton(tr("&& AND"));
m_add_button = new QPushButton(tr("+ ADD"));
m_not_button = new QPushButton(tr("! NOT"));
m_test_button = new QPushButton(tr("Test"));
m_expression_text = new QPlainTextEdit();
m_button_box = new QDialogButtonBox();
m_clear_button = new QPushButton(tr("Clear"));
m_apply_button = new QPushButton(tr("Apply"));
m_range_slider = new QSlider(Qt::Horizontal);
m_range_spinbox = new QSpinBox();
m_parse_text = new QLineEdit();
m_parse_text->setReadOnly(true);
m_expression_text = new QPlainTextEdit();
m_expression_text->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
new ControlExpressionSyntaxHighlighter(m_expression_text->document(), m_parse_text);
m_operators_combo = new QComboBox();
m_operators_combo->addItem(tr("Operators"));
m_operators_combo->insertSeparator(1);
if (m_type == Type::Input)
{
m_operators_combo->addItem(tr("! Not"));
m_operators_combo->addItem(tr("* Multiply"));
m_operators_combo->addItem(tr("/ Divide"));
m_operators_combo->addItem(tr("% Modulo"));
m_operators_combo->addItem(tr("+ Add"));
m_operators_combo->addItem(tr("- Subtract"));
m_operators_combo->addItem(tr("> Greater-than"));
m_operators_combo->addItem(tr("< Less-than"));
m_operators_combo->addItem(tr("& And"));
}
m_operators_combo->addItem(tr("| Or"));
if (m_type == Type::Input)
{
m_operators_combo->addItem(tr(", Comma"));
}
m_functions_combo = new QComboBox();
m_functions_combo->addItem(tr("Functions"));
m_functions_combo->insertSeparator(1);
m_functions_combo->addItem(QStringLiteral("if"));
m_functions_combo->addItem(QStringLiteral("timer"));
m_functions_combo->addItem(QStringLiteral("toggle"));
m_functions_combo->addItem(QStringLiteral("deadzone"));
m_functions_combo->addItem(QStringLiteral("smooth"));
m_functions_combo->addItem(QStringLiteral("hold"));
m_functions_combo->addItem(QStringLiteral("tap"));
m_functions_combo->addItem(QStringLiteral("relative"));
m_functions_combo->addItem(QStringLiteral("pulse"));
// Devices
m_main_layout->addWidget(m_devices_combo);
@@ -77,16 +268,6 @@ void IOWindow::CreateMainLayout()
m_range_spinbox->setMaximum(500);
m_main_layout->addLayout(range_hbox);
// Options (Buttons, Outputs) and action buttons
// macOS style doesn't support expanding buttons
#ifndef __APPLE__
for (QPushButton* button : {m_select_button, m_detect_button, m_or_button, m_and_button,
m_add_button, m_not_button, m_test_button})
{
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
#endif
auto* hbox = new QHBoxLayout();
auto* button_vbox = new QVBoxLayout();
hbox->addWidget(m_option_list, 8);
@@ -94,17 +275,15 @@ void IOWindow::CreateMainLayout()
button_vbox->addWidget(m_select_button);
button_vbox->addWidget(m_type == Type::Input ? m_detect_button : m_test_button);
button_vbox->addWidget(m_or_button);
button_vbox->addWidget(m_operators_combo);
if (m_type == Type::Input)
{
button_vbox->addWidget(m_and_button);
button_vbox->addWidget(m_add_button);
button_vbox->addWidget(m_not_button);
button_vbox->addWidget(m_functions_combo);
}
m_main_layout->addLayout(hbox, 2);
m_main_layout->addWidget(m_expression_text, 1);
m_main_layout->addWidget(m_parse_text);
// Button Box
m_main_layout->addWidget(m_button_box);
@@ -132,11 +311,7 @@ void IOWindow::ConfigChanged()
void IOWindow::ConnectWidgets()
{
connect(m_select_button, &QPushButton::clicked, [this] { AppendSelectedOption(""); });
connect(m_add_button, &QPushButton::clicked, [this] { AppendSelectedOption(" + "); });
connect(m_and_button, &QPushButton::clicked, [this] { AppendSelectedOption(" & "); });
connect(m_or_button, &QPushButton::clicked, [this] { AppendSelectedOption(" | "); });
connect(m_not_button, &QPushButton::clicked, [this] { AppendSelectedOption("!"); });
connect(m_select_button, &QPushButton::clicked, [this] { AppendSelectedOption(); });
connect(m_detect_button, &QPushButton::clicked, this, &IOWindow::OnDetectButtonPressed);
connect(m_test_button, &QPushButton::clicked, this, &IOWindow::OnTestButtonPressed);
@@ -147,17 +322,38 @@ void IOWindow::ConnectWidgets()
this, &IOWindow::OnRangeChanged);
connect(m_range_slider, static_cast<void (QSlider::*)(int value)>(&QSlider::valueChanged), this,
&IOWindow::OnRangeChanged);
connect(m_expression_text, &QPlainTextEdit::textChanged, [this] {
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
m_apply_button->setText(m_apply_button->text() + QStringLiteral("*"));
});
connect(m_operators_combo, QOverload<int>::of(&QComboBox::activated), [this](int index) {
if (0 == index)
return;
m_expression_text->insertPlainText(m_operators_combo->currentText().left(1));
m_operators_combo->setCurrentIndex(0);
});
connect(m_functions_combo, QOverload<int>::of(&QComboBox::activated), [this](int index) {
if (0 == index)
return;
m_expression_text->insertPlainText(m_functions_combo->currentText() + QStringLiteral("()"));
m_functions_combo->setCurrentIndex(0);
});
}
void IOWindow::AppendSelectedOption(const std::string& prefix)
void IOWindow::AppendSelectedOption()
{
if (m_option_list->currentItem() == nullptr)
return;
m_expression_text->insertPlainText(
QString::fromStdString(prefix) +
MappingCommon::GetExpressionForControl(m_option_list->currentItem()->text(), m_devq,
m_controller->GetDefaultDevice()));
m_expression_text->insertPlainText(MappingCommon::GetExpressionForControl(
m_option_list->currentItem()->text(), m_devq, m_controller->GetDefaultDevice()));
}
void IOWindow::OnDeviceChanged(const QString& device)
@@ -175,7 +371,19 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button)
}
m_reference->SetExpression(m_expression_text->toPlainText().toStdString());
m_controller->UpdateReferences(g_controller_interface);
m_controller->UpdateSingleControlReference(g_controller_interface, m_reference);
m_apply_button->setText(m_apply_button->text().remove(QStringLiteral("*")));
if (ciface::ExpressionParser::ParseStatus::SyntaxError == m_reference->GetParseStatus())
{
QMessageBox error(this);
error.setIcon(QMessageBox::Critical);
error.setWindowTitle(tr("Error"));
error.setText(tr("The expression contains a syntax error."));
error.setWindowModality(Qt::WindowModal);
error.exec();
}
if (button != m_apply_button)
accept();
@@ -6,6 +6,7 @@
#include <QDialog>
#include <QString>
#include <QSyntaxHighlighter>
#include "Common/Flag.h"
#include "InputCommon/ControllerInterface/Device.h"
@@ -14,6 +15,7 @@ class ControlReference;
class QAbstractButton;
class QComboBox;
class QDialogButtonBox;
class QLineEdit;
class QListWidget;
class QVBoxLayout;
class QWidget;
@@ -27,6 +29,19 @@ namespace ControllerEmu
class EmulatedController;
}
class ControlExpressionSyntaxHighlighter final : public QSyntaxHighlighter
{
Q_OBJECT
public:
ControlExpressionSyntaxHighlighter(QTextDocument* parent, QLineEdit* result);
protected:
void highlightBlock(const QString& text) final override;
private:
QLineEdit* const m_result_text;
};
class IOWindow final : public QDialog
{
Q_OBJECT
@@ -51,7 +66,7 @@ private:
void OnTestButtonPressed();
void OnRangeChanged(int range);
void AppendSelectedOption(const std::string& prefix);
void AppendSelectedOption();
void UpdateOptionList();
void UpdateDeviceList();
@@ -70,19 +85,18 @@ private:
// Shared actions
QPushButton* m_select_button;
QPushButton* m_or_button;
QComboBox* m_operators_combo;
// Input actions
QPushButton* m_detect_button;
QPushButton* m_and_button;
QPushButton* m_not_button;
QPushButton* m_add_button;
QComboBox* m_functions_combo;
// Output actions
QPushButton* m_test_button;
// Textarea
QPlainTextEdit* m_expression_text;
QLineEdit* m_parse_text;
// Buttonbox
QDialogButtonBox* m_button_box;
@@ -100,7 +100,7 @@ void MappingButton::Detect()
return;
m_reference->SetExpression(expression.toStdString());
m_parent->GetController()->UpdateReferences(g_controller_interface);
m_parent->GetController()->UpdateSingleControlReference(g_controller_interface, m_reference);
ConfigChanged();
m_parent->SaveSettings();
@@ -111,7 +111,7 @@ void MappingButton::Clear()
m_reference->range = 100.0 / SLIDER_TICK_COUNT;
m_reference->SetExpression("");
m_parent->GetController()->UpdateReferences(g_controller_interface);
m_parent->GetController()->UpdateSingleControlReference(g_controller_interface, m_reference);
m_parent->SaveSettings();
ConfigChanged();
+2
View File
@@ -45,6 +45,8 @@ add_library(inputcommon
ControlReference/ControlReference.h
ControlReference/ExpressionParser.cpp
ControlReference/ExpressionParser.h
ControlReference/FunctionExpression.cpp
ControlReference/FunctionExpression.h
)
target_link_libraries(inputcommon PUBLIC
@@ -25,12 +25,12 @@ bool ControlReference::InputGateOn()
// Updates a controlreference's binded devices/controls
// need to call this to re-bind a control reference after changing its expression
//
void ControlReference::UpdateReference(const ciface::Core::DeviceContainer& devices,
const ciface::Core::DeviceQualifier& default_device)
void ControlReference::UpdateReference(ciface::ExpressionParser::ControlEnvironment& env)
{
ControlFinder finder(devices, default_device, IsInput());
if (m_parsed_expression)
m_parsed_expression->UpdateReferences(finder);
{
m_parsed_expression->UpdateReferences(env);
}
}
int ControlReference::BoundCount() const
@@ -54,7 +54,9 @@ std::string ControlReference::GetExpression() const
void ControlReference::SetExpression(std::string expr)
{
m_expression = std::move(expr);
std::tie(m_parse_status, m_parsed_expression) = ParseExpression(m_expression);
auto parse_result = ParseExpression(m_expression);
m_parse_status = parse_result.status;
m_parsed_expression = std::move(parse_result.expr);
}
ControlReference::ControlReference() : range(1), m_parsed_expression(nullptr)
@@ -30,8 +30,7 @@ public:
int BoundCount() const;
ciface::ExpressionParser::ParseStatus GetParseStatus() const;
void UpdateReference(const ciface::Core::DeviceContainer& devices,
const ciface::Core::DeviceQualifier& default_device);
void UpdateReference(ciface::ExpressionParser::ControlEnvironment& env);
std::string GetExpression() const;
void SetExpression(std::string expr);
File diff suppressed because it is too large Load Diff
@@ -4,56 +4,58 @@
#pragma once
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "InputCommon/ControllerInterface/Device.h"
namespace ciface::ExpressionParser
{
class ControlQualifier
enum TokenType
{
public:
bool has_device;
Core::DeviceQualifier device_qualifier;
std::string control_name;
ControlQualifier() : has_device(false) {}
operator std::string() const
{
if (has_device)
return device_qualifier.ToString() + ":" + control_name;
else
return control_name;
}
TOK_WHITESPACE,
TOK_INVALID,
TOK_EOF,
TOK_LPAREN,
TOK_RPAREN,
TOK_NOT,
TOK_CONTROL,
TOK_LITERAL,
TOK_VARIABLE,
TOK_BAREWORD,
TOK_COMMENT,
// Binary Ops:
TOK_BINARY_OPS_BEGIN,
TOK_AND = TOK_BINARY_OPS_BEGIN,
TOK_OR,
TOK_ADD,
TOK_SUB,
TOK_MUL,
TOK_DIV,
TOK_MOD,
TOK_ASSIGN,
TOK_LTHAN,
TOK_GTHAN,
TOK_COMMA,
TOK_BINARY_OPS_END,
};
class ControlFinder
class Token
{
public:
ControlFinder(const Core::DeviceContainer& container_, const Core::DeviceQualifier& default_,
const bool is_input_)
: container(container_), default_device(default_), is_input(is_input_)
{
}
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
Core::Device::Control* FindControl(ControlQualifier qualifier) const;
TokenType type;
std::string data;
private:
const Core::DeviceContainer& container;
const Core::DeviceQualifier& default_device;
bool is_input;
};
// Position in the input string:
std::size_t string_position = 0;
std::size_t string_length = 0;
class Expression
{
public:
virtual ~Expression() = default;
virtual ControlState GetValue() const = 0;
virtual void SetValue(ControlState state) = 0;
virtual int CountNumControls() const = 0;
virtual void UpdateReferences(ControlFinder& finder) = 0;
virtual operator std::string() const = 0;
explicit Token(TokenType type_);
Token(TokenType type_, std::string data_);
bool IsBinaryOperator() const;
};
enum class ParseStatus
@@ -63,5 +65,129 @@ enum class ParseStatus
EmptyExpression,
};
std::pair<ParseStatus, std::unique_ptr<Expression>> ParseExpression(const std::string& expr);
class Lexer
{
public:
std::string expr;
std::string::iterator it;
explicit Lexer(std::string expr_);
ParseStatus Tokenize(std::vector<Token>& tokens);
private:
template <typename F>
std::string FetchCharsWhile(F&& func)
{
std::string value;
while (it != expr.end() && func(*it))
{
value += *it;
++it;
}
return value;
}
std::string FetchDelimString(char delim);
std::string FetchWordChars();
Token GetDelimitedLiteral();
Token GetVariable();
Token GetFullyQualifiedControl();
Token GetBareword(char c);
Token GetRealLiteral(char c);
Token PeekToken();
Token NextToken();
};
class ControlQualifier
{
public:
bool has_device;
Core::DeviceQualifier device_qualifier;
std::string control_name;
ControlQualifier() : has_device(false) {}
operator std::string() const
{
if (has_device)
return device_qualifier.ToString() + ":" + control_name;
else
return control_name;
}
void FromString(const std::string& str)
{
const auto col_pos = str.find_last_of(':');
has_device = (str.npos != col_pos);
if (has_device)
{
device_qualifier.FromString(str.substr(0, col_pos));
control_name = str.substr(col_pos + 1);
}
else
{
device_qualifier.FromString("");
control_name = str;
}
}
};
class ControlEnvironment
{
public:
using VariableContainer = std::map<std::string, ControlState>;
ControlEnvironment(const Core::DeviceContainer& container_, const Core::DeviceQualifier& default_,
VariableContainer& vars)
: m_variables(vars), container(container_), default_device(default_)
{
}
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const;
Core::Device::Input* FindInput(ControlQualifier qualifier) const;
Core::Device::Output* FindOutput(ControlQualifier qualifier) const;
ControlState* GetVariablePtr(const std::string& name);
private:
VariableContainer& m_variables;
const Core::DeviceContainer& container;
const Core::DeviceQualifier& default_device;
};
class Expression
{
public:
virtual ~Expression() = default;
virtual ControlState GetValue() const = 0;
virtual void SetValue(ControlState state) = 0;
virtual int CountNumControls() const = 0;
virtual void UpdateReferences(ControlEnvironment& finder) = 0;
};
class ParseResult
{
public:
static ParseResult MakeEmptyResult();
static ParseResult MakeSuccessfulResult(std::unique_ptr<Expression>&& expr);
static ParseResult MakeErrorResult(Token token, std::string description);
ParseStatus status;
std::unique_ptr<Expression> expr;
// Used for parse errors:
// TODO: This should probably be moved elsewhere:
std::optional<Token> token;
std::optional<std::string> description;
private:
ParseResult() = default;
};
ParseResult ParseExpression(const std::string& expr);
ParseResult ParseTokens(const std::vector<Token>& tokens);
void RemoveInertTokens(std::vector<Token>* tokens);
} // namespace ciface::ExpressionParser
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,55 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
#include <variant>
#include <vector>
#include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControlReference/FunctionExpression.h"
namespace ciface
{
namespace ExpressionParser
{
class FunctionExpression : public Expression
{
public:
struct ArgumentsAreValid
{
};
struct ExpectedArguments
{
std::string text;
};
using ArgumentValidation = std::variant<ArgumentsAreValid, ExpectedArguments>;
int CountNumControls() const override;
void UpdateReferences(ControlEnvironment& env) override;
ArgumentValidation SetArguments(std::vector<std::unique_ptr<Expression>>&& args);
void SetValue(ControlState value) override;
protected:
virtual ArgumentValidation
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) = 0;
Expression& GetArg(u32 number);
const Expression& GetArg(u32 number) const;
u32 GetArgCount() const;
private:
std::vector<std::unique_ptr<Expression>> m_args;
};
std::unique_ptr<FunctionExpression> MakeFunctionExpression(std::string name);
} // namespace ExpressionParser
} // namespace ciface
@@ -38,23 +38,38 @@ std::unique_lock<std::recursive_mutex> EmulatedController::GetStateLock()
void EmulatedController::UpdateReferences(const ControllerInterface& devi)
{
const auto lock = GetStateLock();
m_default_device_is_connected = devi.HasConnectedDevice(m_default_device);
ciface::ExpressionParser::ControlEnvironment env(devi, GetDefaultDevice(), m_expression_vars);
UpdateReferences(env);
}
void EmulatedController::UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env)
{
const auto lock = GetStateLock();
for (auto& ctrlGroup : groups)
{
for (auto& control : ctrlGroup->controls)
control->control_ref.get()->UpdateReference(devi, GetDefaultDevice());
control->control_ref->UpdateReference(env);
// Attachments:
if (ctrlGroup->type == GroupType::Attachments)
{
for (auto& attachment : static_cast<Attachments*>(ctrlGroup.get())->GetAttachmentList())
attachment->UpdateReferences(devi);
attachment->UpdateReferences(env);
}
}
}
void EmulatedController::UpdateSingleControlReference(const ControllerInterface& devi,
ControlReference* ref)
{
ciface::ExpressionParser::ControlEnvironment env(devi, GetDefaultDevice(), m_expression_vars);
ref->UpdateReference(env);
}
bool EmulatedController::IsDefaultDeviceConnected() const
{
return m_default_device_is_connected;
@@ -13,6 +13,7 @@
#include "Common/Common.h"
#include "Common/IniFile.h"
#include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerInterface/Device.h"
class ControllerInterface;
@@ -20,6 +21,8 @@ class ControllerInterface;
const char* const named_directions[] = {_trans("Up"), _trans("Down"), _trans("Left"),
_trans("Right")};
class ControlReference;
namespace ControllerEmu
{
class ControlGroup;
@@ -43,6 +46,7 @@ public:
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
void UpdateReferences(const ControllerInterface& devi);
void UpdateSingleControlReference(const ControllerInterface& devi, ControlReference* ref);
// This returns a lock that should be held before calling State() on any control
// references and GetState(), by extension. This prevents a race condition
@@ -75,6 +79,12 @@ public:
return T(std::lround((zero_value - neg_1_value) * input_value + zero_value));
}
protected:
// TODO: Wiimote attachment has its own member that isn't being used..
ciface::ExpressionParser::ControlEnvironment::VariableContainer m_expression_vars;
void UpdateReferences(ciface::ExpressionParser::ControlEnvironment& env);
private:
ciface::Core::DeviceQualifier m_default_device;
bool m_default_device_is_connected{false};
@@ -64,6 +64,7 @@
<ClCompile Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.cpp" />
<ClCompile Include="ControllerInterface\Win32\Win32.cpp" />
<ClCompile Include="ControllerInterface\XInput\XInput.cpp" />
<ClCompile Include="ControlReference\FunctionExpression.cpp" />
<ClCompile Include="GCAdapter.cpp">
<!--
Disable "nonstandard extension used : zero-sized array in struct/union" warning,
@@ -100,6 +101,7 @@
<ClInclude Include="ControllerInterface\DInput\DInputKeyboardMouse.h" />
<ClInclude Include="ControllerInterface\DInput\XInputFilter.h" />
<ClInclude Include="ControlReference\ControlReference.h" />
<ClInclude Include="ControlReference\FunctionExpression.h" />
<ClInclude Include="ControlReference\ExpressionParser.h" />
<ClInclude Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.h" />
<ClInclude Include="ControllerInterface\Win32\Win32.h" />
@@ -113,6 +113,9 @@
<ClCompile Include="ControlReference\ControlReference.cpp">
<Filter>ControllerInterface</Filter>
</ClCompile>
<ClCompile Include="ControlReference\FunctionExpression.cpp">
<Filter>ControllerInterface</Filter>
</ClCompile>
<ClCompile Include="InputProfile.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Attachments.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
@@ -206,6 +209,9 @@
<ClInclude Include="ControlReference\ControlReference.h">
<Filter>ControllerInterface</Filter>
</ClInclude>
<ClCompile Include="ControlReference\FunctionExpression.h">
<Filter>ControllerInterface</Filter>
</ClCompile>
<ClInclude Include="InputProfile.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Attachments.h">
<Filter>ControllerEmu\ControlGroup</Filter>