From d8140fb31ba622f48756986d4d66db6b6ab8b511 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 23:28:41 -0400 Subject: use callbacks for applying accel --- common/accel-invoke.hpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 common/accel-invoke.hpp (limited to 'common/accel-invoke.hpp') 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; + + template + static double invoke_impl(const accel_union& u, double x, double w) + { + return apply_weighted(reinterpret_cast(u), x, w); + } + + public: + + accel_invoker(const accel_args& args) + { + cb = visit_accel([](auto&& arg) { + return &invoke_impl>; + }, 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 invokers(const settings& args) + { + return { + accel_invoker(args.argsv.x), + accel_invoker(args.argsv.y) + }; + } + +} -- cgit v1.2.3 From c55d1bfd01147fa014ac07d4b03ef3cad8427ae6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Apr 2021 02:30:01 -0400 Subject: optimize a bit/refactor modify --- common/accel-invoke.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'common/accel-invoke.hpp') diff --git a/common/accel-invoke.hpp b/common/accel-invoke.hpp index 0e264c1..f2a95dc 100644 --- a/common/accel-invoke.hpp +++ b/common/accel-invoke.hpp @@ -20,7 +20,16 @@ namespace rawaccel { accel_invoker(const accel_args& args) { cb = visit_accel([](auto&& arg) { - return &invoke_impl>; + using T = remove_ref_t; + + if constexpr (is_same_v) { + static_assert(sizeof motivity == sizeof binlog_lut); + return &invoke_impl; + } + else { + return &invoke_impl; + } + }, make_mode(args), accel_union{}); } -- cgit v1.2.3