Skip to content

Commit

Permalink
ExpressionParser: Remove !while and add optional 2nd argument to !smo…
Browse files Browse the repository at this point in the history
…oth.
  • Loading branch information
jordan-woyak committed Oct 11, 2019
1 parent ca7ce67 commit 7912dc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
1 change: 0 additions & 1 deletion Source/Core/DolphinQt/Config/Mapping/IOWindow.cpp
Expand Up @@ -224,7 +224,6 @@ void IOWindow::CreateMainLayout()
m_functions_combo->addItem(QStringLiteral("!sin"));
m_functions_combo->addItem(QStringLiteral("!timer"));
m_functions_combo->addItem(QStringLiteral("!toggle"));
m_functions_combo->addItem(QStringLiteral("!while"));
m_functions_combo->addItem(QStringLiteral("!deadzone"));
m_functions_combo->addItem(QStringLiteral("!smooth"));
m_functions_combo->addItem(QStringLiteral("!hold"));
Expand Down
42 changes: 6 additions & 36 deletions Source/Core/InputCommon/ControlReference/FunctionExpression.cpp
Expand Up @@ -163,37 +163,6 @@ class UnaryMinusExpression : public FunctionExpression
std::string GetFuncName() const override { return "minus"; }
};

// usage: !while(condition, expression)
class WhileExpression : public FunctionExpression
{
virtual bool ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
return 2 == args.size();
}

ControlState GetValue() const override
{
// Returns 1.0 on successful loop, 0.0 on reps exceeded. Sensible?

for (int i = 0; i != LOOP_MAX_REPS; ++i)
{
// Check condition of 1st argument:
const ControlState val = GetArg(0).GetValue();
if (val < CONDITION_THRESHOLD)
return 1.0;

// Evaluate 2nd argument:
GetArg(1).GetValue();
}

// Exceeded max reps:
return 0.0;
}

void SetValue(ControlState value) override {}
std::string GetFuncName() const override { return "while"; }
};

// usage: !deadzone(input, amount)
class DeadzoneExpression : public FunctionExpression
{
Expand All @@ -213,13 +182,13 @@ class DeadzoneExpression : public FunctionExpression
std::string GetFuncName() const override { return "deadzone"; }
};

// usage: !smooth(input, seconds)
// usage: !smooth(input, seconds_up, seconds_down = seconds_up)
// seconds is seconds to change from 0.0 to 1.0
class SmoothExpression : public FunctionExpression
{
virtual bool ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
{
return 2 == args.size();
return 2 == args.size() || 3 == args.size();
}

ControlState GetValue() const override
Expand All @@ -229,8 +198,11 @@ class SmoothExpression : public FunctionExpression
m_last_update = now;

const ControlState desired_value = GetArg(0).GetValue();
const ControlState smooth = GetArg(1).GetValue();

const ControlState smooth_up = GetArg(1).GetValue();
const ControlState smooth_down = (3 == GetArgCount() ? GetArg(2).GetValue() : smooth_up);

const ControlState smooth = (desired_value < m_value) ? smooth_down : smooth_up;
const ControlState max_move = std::chrono::duration_cast<FSec>(elapsed).count() / smooth;

if (std::isinf(max_move))
Expand Down Expand Up @@ -473,8 +445,6 @@ std::unique_ptr<FunctionExpression> MakeFunctionExpression(std::string name)
return std::make_unique<TimerExpression>();
else if ("toggle" == name)
return std::make_unique<ToggleExpression>();
else if ("while" == name)
return std::make_unique<WhileExpression>();
else if ("minus" == name)
return std::make_unique<UnaryMinusExpression>();
else if ("deadzone" == name)
Expand Down

0 comments on commit 7912dc5

Please sign in to comment.