2016-10-12 00:48:38 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-10-12 00:48:38 +00:00
|
|
|
|
2019-02-27 01:46:21 +00:00
|
|
|
#include "InputCommon/ControlReference/ControlReference.h"
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
using namespace ciface::ExpressionParser;
|
|
|
|
|
2019-11-06 21:59:36 +00:00
|
|
|
static thread_local bool tls_input_gate = true;
|
|
|
|
|
|
|
|
void ControlReference::SetInputGate(bool enable)
|
|
|
|
{
|
|
|
|
tls_input_gate = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ControlReference::GetInputGate()
|
2016-10-12 00:48:38 +00:00
|
|
|
{
|
2019-11-06 21:59:36 +00:00
|
|
|
return tls_input_gate;
|
2016-10-12 00:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// UpdateReference
|
|
|
|
//
|
|
|
|
// Updates a controlreference's binded devices/controls
|
2017-06-08 02:02:16 +00:00
|
|
|
// need to call this to re-bind a control reference after changing its expression
|
2016-10-12 00:48:38 +00:00
|
|
|
//
|
2018-12-30 22:06:29 +00:00
|
|
|
void ControlReference::UpdateReference(ciface::ExpressionParser::ControlEnvironment& env)
|
2016-10-12 00:48:38 +00:00
|
|
|
{
|
2017-06-08 01:48:17 +00:00
|
|
|
if (m_parsed_expression)
|
2018-12-30 22:06:29 +00:00
|
|
|
{
|
|
|
|
m_parsed_expression->UpdateReferences(env);
|
|
|
|
}
|
2016-12-09 21:07:49 +00:00
|
|
|
}
|
2016-12-09 21:19:23 +00:00
|
|
|
|
2016-12-09 21:07:49 +00:00
|
|
|
int ControlReference::BoundCount() const
|
|
|
|
{
|
2016-12-09 21:57:01 +00:00
|
|
|
if (m_parsed_expression)
|
2017-06-08 00:30:07 +00:00
|
|
|
return m_parsed_expression->CountNumControls();
|
2016-12-09 21:07:49 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-28 09:58:03 +00:00
|
|
|
ParseStatus ControlReference::GetParseStatus() const
|
2016-12-09 21:19:23 +00:00
|
|
|
{
|
|
|
|
return m_parse_status;
|
|
|
|
}
|
|
|
|
|
2017-06-08 02:02:16 +00:00
|
|
|
std::string ControlReference::GetExpression() const
|
|
|
|
{
|
|
|
|
return m_expression;
|
|
|
|
}
|
|
|
|
|
2020-11-08 00:04:33 +00:00
|
|
|
std::optional<std::string> ControlReference::SetExpression(std::string expr)
|
2017-06-08 02:02:16 +00:00
|
|
|
{
|
|
|
|
m_expression = std::move(expr);
|
2019-03-02 20:47:26 +00:00
|
|
|
auto parse_result = ParseExpression(m_expression);
|
|
|
|
m_parse_status = parse_result.status;
|
|
|
|
m_parsed_expression = std::move(parse_result.expr);
|
2020-11-08 00:04:33 +00:00
|
|
|
return parse_result.description;
|
2017-06-08 02:02:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 04:43:19 +00:00
|
|
|
ControlReference::ControlReference() = default;
|
2016-12-09 21:07:49 +00:00
|
|
|
|
2017-02-10 18:58:42 +00:00
|
|
|
ControlReference::~ControlReference() = default;
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
InputReference::InputReference() : ControlReference()
|
2016-12-09 21:07:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
OutputReference::OutputReference() : ControlReference()
|
2016-12-09 21:07:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:13:11 +00:00
|
|
|
bool InputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OutputReference::IsInput() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
//
|
|
|
|
// InputReference :: State
|
|
|
|
//
|
|
|
|
// Gets the state of an input reference
|
|
|
|
// override function for ControlReference::State ...
|
|
|
|
//
|
|
|
|
ControlState InputReference::State(const ControlState ignore)
|
|
|
|
{
|
2019-11-06 21:59:36 +00:00
|
|
|
if (m_parsed_expression && GetInputGate())
|
2016-12-09 21:57:01 +00:00
|
|
|
return m_parsed_expression->GetValue() * range;
|
2016-10-12 00:48:38 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// OutputReference :: State
|
|
|
|
//
|
|
|
|
// Set the state of all binded outputs
|
|
|
|
// overrides ControlReference::State .. combined them so I could make the GUI simple / inputs ==
|
|
|
|
// same as outputs one list
|
|
|
|
// I was lazy and it works so watever
|
|
|
|
//
|
|
|
|
ControlState OutputReference::State(const ControlState state)
|
|
|
|
{
|
2018-04-19 21:47:11 +00:00
|
|
|
if (m_parsed_expression)
|
|
|
|
m_parsed_expression->SetValue(state * range);
|
2016-10-12 00:48:38 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|