diff options
| author | a1xd <[email protected]> | 2021-04-01 23:28:41 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-04-01 23:28:41 -0400 |
| commit | d8140fb31ba622f48756986d4d66db6b6ab8b511 (patch) | |
| tree | 8faa873d4468882c63f1f8fa02b94f4b6b3a65f6 /common/accel-invoke.hpp | |
| parent | check for safe mode before hooking into dev stack (diff) | |
| download | rawaccel-d8140fb31ba622f48756986d4d66db6b6ab8b511.tar.xz rawaccel-d8140fb31ba622f48756986d4d66db6b6ab8b511.zip | |
use callbacks for applying accel
Diffstat (limited to 'common/accel-invoke.hpp')
| -rw-r--r-- | common/accel-invoke.hpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/common/accel-invoke.hpp b/common/accel-invoke.hpp new file mode 100644 index 0000000..0e264c1 --- /dev/null +++ b/common/accel-invoke.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include "accel-union.hpp" + +namespace rawaccel { + + class accel_invoker { + using callback_t = double (*)(const accel_union&, double, double); + + callback_t cb = &invoke_impl<accel_noaccel>; + + template <typename T> + static double invoke_impl(const accel_union& u, double x, double w) + { + return apply_weighted(reinterpret_cast<const T&>(u), x, w); + } + + public: + + accel_invoker(const accel_args& args) + { + cb = visit_accel([](auto&& arg) { + return &invoke_impl<remove_ref_t<decltype(arg)>>; + }, make_mode(args), accel_union{}); + } + + accel_invoker() = default; + + double invoke(const accel_union& u, double x, double weight = 1) const + { + return (*cb)(u, x, weight); + } + }; + + inline vec2<accel_invoker> invokers(const settings& args) + { + return { + accel_invoker(args.argsv.x), + accel_invoker(args.argsv.y) + }; + } + +} |