summaryrefslogtreecommitdiff
path: root/common/rawaccel.hpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-03-29 18:01:20 -0400
committera1xd <[email protected]>2021-03-29 18:01:20 -0400
commited0bbc22681681a16b7d45b05133c38a0b82006f (patch)
tree3c883ad3c85608cd167efded8cce09733527f835 /common/rawaccel.hpp
parentrefactor common/settings (diff)
downloadrawaccel-ed0bbc22681681a16b7d45b05133c38a0b82006f.tar.xz
rawaccel-ed0bbc22681681a16b7d45b05133c38a0b82006f.zip
formatting + file renames
Diffstat (limited to 'common/rawaccel.hpp')
-rw-r--r--common/rawaccel.hpp94
1 files changed, 3 insertions, 91 deletions
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index cb30820..67b4e61 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -1,16 +1,11 @@
#pragma once
+#include "accel-union.hpp"
+#include "utility.hpp"
+
#define _USE_MATH_DEFINES
#include <math.h>
-#include "x64-util.hpp"
-
-#include "accel-classic.hpp"
-#include "accel-natural.hpp"
-#include "accel-power.hpp"
-#include "accel-motivity.hpp"
-#include "accel-noaccel.hpp"
-
namespace rawaccel {
/// <summary> Struct to hold vector rotation details. </summary>
@@ -66,89 +61,6 @@ namespace rawaccel {
v.y *= ratio;
}
- enum class internal_mode {
- classic_lgcy,
- classic_gain,
- natural_lgcy,
- natural_gain,
- power,
- motivity,
- noaccel
- };
-
- constexpr internal_mode make_mode(accel_mode m, bool legacy) {
- switch (m) {
- case accel_mode::classic:
- return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain;
- case accel_mode::natural:
- return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain;
- case accel_mode::power:
- return internal_mode::power;
- case accel_mode::motivity:
- return internal_mode::motivity;
- default:
- return internal_mode::noaccel;
- }
- }
-
- constexpr internal_mode make_mode(const accel_args& args) {
- return make_mode(args.mode, args.legacy);
- }
-
- template <typename Visitor, typename Variant>
- inline auto visit_accel(Visitor vis, Variant&& var) {
- switch (var.tag) {
- case internal_mode::classic_lgcy: return vis(var.u.classic_l);
- case internal_mode::classic_gain: return vis(var.u.classic_g);
- case internal_mode::natural_lgcy: return vis(var.u.natural_l);
- case internal_mode::natural_gain: return vis(var.u.natural_g);
- case internal_mode::power: return vis(var.u.power);
- case internal_mode::motivity: return vis(var.u.motivity);
- default: return vis(var.u.noaccel);
- }
- }
-
- struct accel_variant {
- si_pair* lookup;
-
- internal_mode tag = internal_mode::noaccel;
-
- union union_t {
- classic classic_g;
- classic_legacy classic_l;
- natural natural_g;
- natural_legacy natural_l;
- power power;
- motivity motivity;
- accel_noaccel noaccel = {};
- } u = {};
-
- accel_variant(const accel_args& args, si_pair* lut = nullptr) :
- tag(make_mode(args)), lookup(lut)
- {
- visit_accel([&](auto& impl) {
- impl = { args };
- }, *this);
-
- if (lookup && tag == internal_mode::motivity) {
- u.motivity.fill(lookup);
- }
-
- }
-
- inline double apply(double speed) const {
- if (lookup && tag == internal_mode::motivity) {
- return u.motivity.apply(lookup, speed);
- }
-
- return visit_accel([=](auto&& impl) {
- return impl(speed);
- }, *this);
- }
-
- accel_variant() = default;
- };
-
struct weighted_distance {
double p = 2.0;
double p_inverse = 0.5;