2016-10-12 00:48:38 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-09 02:36:26 +00:00
|
|
|
#include <cmath>
|
2016-12-09 21:57:01 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
|
|
|
|
|
|
|
// ControlReference
|
|
|
|
//
|
|
|
|
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
|
|
|
//
|
|
|
|
// After being bound to devices and controls with UpdateReference,
|
|
|
|
// each one can link to multiple devices and controls
|
|
|
|
// when you change a ControlReference's expression,
|
|
|
|
// you must use UpdateReference on it to rebind controls
|
|
|
|
//
|
|
|
|
|
|
|
|
class ControlReference
|
|
|
|
{
|
|
|
|
public:
|
2019-11-06 21:59:36 +00:00
|
|
|
// Note: this is per thread.
|
|
|
|
static void SetInputGate(bool enable);
|
|
|
|
static bool GetInputGate();
|
2016-10-12 00:48:38 +00:00
|
|
|
|
2017-02-10 18:58:42 +00:00
|
|
|
virtual ~ControlReference();
|
2016-10-12 00:48:38 +00:00
|
|
|
virtual ControlState State(const ControlState state = 0) = 0;
|
2016-12-09 21:13:11 +00:00
|
|
|
virtual bool IsInput() const = 0;
|
2016-10-12 00:48:38 +00:00
|
|
|
|
2019-10-18 19:54:02 +00:00
|
|
|
template <typename T>
|
|
|
|
T GetState();
|
|
|
|
|
2016-12-09 21:07:49 +00:00
|
|
|
int BoundCount() const;
|
2017-02-28 09:58:03 +00:00
|
|
|
ciface::ExpressionParser::ParseStatus GetParseStatus() const;
|
2018-12-30 22:06:29 +00:00
|
|
|
void UpdateReference(ciface::ExpressionParser::ControlEnvironment& env);
|
2017-06-08 02:02:16 +00:00
|
|
|
std::string GetExpression() const;
|
2020-11-08 00:04:33 +00:00
|
|
|
|
|
|
|
// Returns a human-readable error description when the given expression is invalid.
|
|
|
|
std::optional<std::string> SetExpression(std::string expr);
|
2016-10-12 00:48:38 +00:00
|
|
|
|
|
|
|
ControlState range;
|
|
|
|
|
|
|
|
protected:
|
2016-12-09 21:13:11 +00:00
|
|
|
ControlReference();
|
2017-06-08 02:02:16 +00:00
|
|
|
std::string m_expression;
|
2016-12-09 21:57:01 +00:00
|
|
|
std::unique_ptr<ciface::ExpressionParser::Expression> m_parsed_expression;
|
2017-02-28 09:58:03 +00:00
|
|
|
ciface::ExpressionParser::ParseStatus m_parse_status;
|
2016-10-12 00:48:38 +00:00
|
|
|
};
|
|
|
|
|
2019-10-18 19:54:02 +00:00
|
|
|
template <>
|
|
|
|
inline bool ControlReference::GetState<bool>()
|
|
|
|
{
|
2020-02-09 02:36:26 +00:00
|
|
|
// Round to nearest of 0 or 1.
|
|
|
|
return std::lround(State()) > 0;
|
2019-10-18 19:54:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-09 02:36:26 +00:00
|
|
|
template <>
|
|
|
|
inline int ControlReference::GetState<int>()
|
|
|
|
{
|
|
|
|
return std::lround(State());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline ControlState ControlReference::GetState<ControlState>()
|
2019-10-18 19:54:02 +00:00
|
|
|
{
|
|
|
|
return State();
|
|
|
|
}
|
|
|
|
|
2016-10-12 00:48:38 +00:00
|
|
|
//
|
|
|
|
// InputReference
|
|
|
|
//
|
|
|
|
// Control reference for inputs
|
|
|
|
//
|
|
|
|
class InputReference : public ControlReference
|
|
|
|
{
|
|
|
|
public:
|
2016-12-09 21:07:49 +00:00
|
|
|
InputReference();
|
2016-12-09 21:13:11 +00:00
|
|
|
bool IsInput() const override;
|
2016-10-12 00:48:38 +00:00
|
|
|
ControlState State(const ControlState state) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// OutputReference
|
|
|
|
//
|
|
|
|
// Control reference for outputs
|
|
|
|
//
|
|
|
|
class OutputReference : public ControlReference
|
|
|
|
{
|
|
|
|
public:
|
2016-12-09 21:07:49 +00:00
|
|
|
OutputReference();
|
2016-12-09 21:13:11 +00:00
|
|
|
bool IsInput() const override;
|
2016-10-12 00:48:38 +00:00
|
|
|
ControlState State(const ControlState state) override;
|
|
|
|
};
|