| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <cmath> |
| 7 |
#include <memory> |
| 8 |
|
| 9 |
#include "InputCommon/ControlReference/ExpressionParser.h" |
| 10 |
#include "InputCommon/ControllerInterface/CoreDevice.h" |
| 11 |
|
| 12 |
namespace ControllerEmu |
| 13 |
{ |
| 14 |
template <typename T> |
| 15 |
T ControlStateCast(ControlState value); |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class ControlReference |
| 29 |
{ |
| 30 |
public: |
| 31 |
|
| 32 |
static void SetInputGate(bool enable); |
| 33 |
static bool GetInputGate(); |
| 34 |
|
| 35 |
virtual ~ControlReference(); |
| 36 |
virtual ControlState State(const ControlState state = 0) = 0; |
| 37 |
virtual bool IsInput() const = 0; |
| 38 |
|
| 39 |
template <typename T> |
| 40 |
T GetState() |
| 41 |
{ |
| 42 |
return ControllerEmu::ControlStateCast<T>(State()); |
| 43 |
} |
| 44 |
|
| 45 |
int BoundCount() const; |
| 46 |
ciface::ExpressionParser::ParseStatus GetParseStatus() const; |
| 47 |
void UpdateReference(ciface::ExpressionParser::ControlEnvironment& env); |
| 48 |
std::string GetExpression() const; |
| 49 |
|
| 50 |
|
| 51 |
std::optional<std::string> SetExpression(std::string expr); |
| 52 |
|
| 53 |
ControlState range = 1; |
| 54 |
|
| 55 |
protected: |
| 56 |
ControlReference(); |
| 57 |
std::string m_expression; |
| 58 |
std::unique_ptr<ciface::ExpressionParser::Expression> m_parsed_expression; |
| 59 |
ciface::ExpressionParser::ParseStatus m_parse_status = |
| 60 |
ciface::ExpressionParser::ParseStatus::EmptyExpression; |
| 61 |
}; |
| 62 |
|
| 63 |
namespace ControllerEmu |
| 64 |
{ |
| 65 |
template <> |
| 66 |
inline bool ControlStateCast<bool>(ControlState value) |
| 67 |
{ |
| 68 |
|
| 69 |
return std::lround(value) > 0; |
| 70 |
} |
| 71 |
|
| 72 |
template <> |
| 73 |
inline int ControlStateCast<int>(ControlState value) |
| 74 |
{ |
| 75 |
return std::lround(value); |
| 76 |
} |
| 77 |
|
| 78 |
template <> |
| 79 |
inline ControlState ControlStateCast<ControlState>(ControlState value) |
| 80 |
{ |
| 81 |
return value; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
class InputReference : public ControlReference |
| 91 |
{ |
| 92 |
public: |
| 93 |
InputReference(); |
| 94 |
bool IsInput() const override; |
| 95 |
ControlState State(const ControlState state) override; |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
class OutputReference : public ControlReference |
| 104 |
{ |
| 105 |
public: |
| 106 |
OutputReference(); |
| 107 |
bool IsInput() const override; |
| 108 |
ControlState State(const ControlState state) override; |
| 109 |
}; |