From 33317e79489848ae537ac78b9c9e70372857aee8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 00:35:39 -0700 Subject: Separate accel implementations into files --- common/accel_types.hpp | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 common/accel_types.hpp (limited to 'common/accel_types.hpp') diff --git a/common/accel_types.hpp b/common/accel_types.hpp new file mode 100644 index 0000000..c931097 --- /dev/null +++ b/common/accel_types.hpp @@ -0,0 +1,130 @@ +#pragma once + +#define _USE_MATH_DEFINES +#include + +namespace rawaccel { + +// Error throwing calls std libraries which are unavailable in kernel mode. +#ifdef _KERNEL_MODE + void error(const char*) {} +#else + void error(const char* s); +#endif + + using milliseconds = double; + + /// Struct to hold arguments for an acceleration function. + struct accel_args { + milliseconds time_min = 0.4; + double offset = 0; + double accel = 0; + double lim_exp = 2; + double midpoint = 0; + }; + + /// + /// Struct to hold acceleration curve implementation details. + /// + /// Type of acceleration. + template + struct accel_implentation { + + /// First constant for use in acceleration curves. Generally, the acceleration ramp rate. + double curve_constant_one = 0; + + /// Second constant for use in acceleration curves. Generally, the limit or exponent in the curve. + double curve_constant_two = 0; + + /// Third constant for use in acceleration curves. The midpoint in sigmoid mode. + double curve_constant_three = 0; + + /// The offset past which acceleration is applied. Used in power mode. + double offset = 0; + + /// + /// Initializes a new instance of the struct. + /// + /// + /// + accel_implentation(accel_args args) + { + curve_constant_one = args.accel; + curve_constant_two = args.lim_exp - 1; + curve_constant_three = args.midpoint; + offset = args.offset; + } + + /// + /// Returns accelerated value of speed as a ratio of magnitude. + /// + /// Mouse speed at which to calculate acceleration. + /// Ratio of accelerated movement magnitude to input movement magnitude. + double accelerate(double speed) { return 0; } + + /// + /// Verifies arguments as valid. Errors if not. + /// + /// Arguments to verified. + void verify(accel_args args) { + if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate"); + if (args.time_min <= 0) error("min time must be positive"); + } + + /// + /// + /// + /// + accel_implentation() = default; + }; + + /// Struct to hold linear acceleration implementation. + struct accel_linear : accel_implentation { + accel_linear(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold "classic" (linear raised to power) acceleration implementation. + struct accel_classic : accel_implentation { + accel_classic(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold "natural" (vanishing difference) acceleration implementation. + struct accel_natural : accel_implentation { + accel_natural(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold logarithmic acceleration implementation. + struct accel_logarithmic : accel_implentation { + accel_logarithmic(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold sigmoid (s-shaped) acceleration implementation. + struct accel_sigmoid : accel_implentation { + accel_sigmoid(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold power (non-additive) acceleration implementation. + struct accel_power : accel_implentation { + accel_power(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + + /// Struct to hold acceleration implementation which applies no acceleration. + struct accel_noaccel : accel_implentation { + accel_noaccel(accel_args args); + double accelerate(double speed); + void verify(accel_args args); + }; + +} -- cgit v1.2.3 From 7963edee802d5a7b51f1867a5133857c403c8ef6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 01:10:29 -0700 Subject: Inline methods for linking, and fix sens application bug --- common/accel_types.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common/accel_types.hpp') diff --git a/common/accel_types.hpp b/common/accel_types.hpp index c931097..15f5a50 100644 --- a/common/accel_types.hpp +++ b/common/accel_types.hpp @@ -7,7 +7,7 @@ namespace rawaccel { // Error throwing calls std libraries which are unavailable in kernel mode. #ifdef _KERNEL_MODE - void error(const char*) {} + inline void error(const char*) {} #else void error(const char* s); #endif -- cgit v1.2.3