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