From e8417a29fb2153ea035a757f36bfa300cf8b480d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 30 Jul 2020 17:07:35 -0400 Subject: add tweaks for st-refactor --- common/accel-base.hpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 common/accel-base.hpp (limited to 'common/accel-base.hpp') diff --git a/common/accel-base.hpp b/common/accel-base.hpp new file mode 100644 index 0000000..ed79bdb --- /dev/null +++ b/common/accel-base.hpp @@ -0,0 +1,50 @@ +#pragma once + +namespace rawaccel { + + // Error throwing calls std libraries which are unavailable in kernel mode. + void error(const char* s); + + using milliseconds = double; + + /// Struct to hold arguments for an acceleration function. + struct accel_args { + double offset = 0; + double accel = 0; + double limit = 2; + double exponent = 2; + double midpoint = 0; + double power_scale = 1; + }; + + /// + /// Struct to hold common acceleration curve implementation details. + /// + struct accel_base { + + /// Generally, the acceleration ramp rate. + double speed_coeff = 0; + + /// + /// Initializes a new instance of the struct. + /// + /// + /// + accel_base(accel_args args) { + verify(args); + + speed_coeff = args.accel; + } + + /// + /// Verifies arguments as valid. Errors if not. + /// + /// Arguments to verified. + void verify(accel_args args) const { + if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate"); + } + + accel_base() = default; + }; + +} -- cgit v1.2.3 From b59cf98c2f326abeb6b993d8ecc5759d23096253 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 30 Jul 2020 22:04:44 -0400 Subject: Make weight a member of accel_base This exposes weight to derived accel types, which now supply a method to transform acceleration into scale. --- common/accel-base.hpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'common/accel-base.hpp') diff --git a/common/accel-base.hpp b/common/accel-base.hpp index ed79bdb..e87b463 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -1,5 +1,7 @@ #pragma once +#include "vec2.h" + namespace rawaccel { // Error throwing calls std libraries which are unavailable in kernel mode. @@ -15,14 +17,18 @@ namespace rawaccel { double exponent = 2; double midpoint = 0; double power_scale = 1; + vec2d weight = { 1, 1 }; }; /// /// Struct to hold common acceleration curve implementation details. /// struct accel_base { - - /// Generally, the acceleration ramp rate. + + /// Coefficients applied to acceleration per axis. + vec2d weight = { 1, 1 }; + + /// Generally, the acceleration ramp rate. double speed_coeff = 0; /// @@ -34,6 +40,17 @@ namespace rawaccel { verify(args); speed_coeff = args.accel; + weight = args.weight; + } + + /// + /// Default transformation of acceleration -> mouse input multipliers. + /// + inline vec2d scale(double accel_val) const { + return { + weight.x * accel_val + 1, + weight.y * accel_val + 1 + }; } /// -- cgit v1.2.3 From b3ed8fd4e4fcad0b749126dee62588260d74b106 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 31 Jul 2020 01:37:41 -0400 Subject: add more tweaks for st-refactor --- common/accel-base.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'common/accel-base.hpp') diff --git a/common/accel-base.hpp b/common/accel-base.hpp index e87b463..da2c96b 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -31,18 +31,20 @@ namespace rawaccel { /// Generally, the acceleration ramp rate. double speed_coeff = 0; - /// - /// Initializes a new instance of the struct. - /// - /// - /// - accel_base(accel_args args) { + accel_base(const accel_args& args) { verify(args); speed_coeff = args.accel; weight = args.weight; } + /// + /// Default transformation of speed -> acceleration. + /// + inline double accelerate(double speed) const { + return speed_coeff * speed; + } + /// /// Default transformation of acceleration -> mouse input multipliers. /// @@ -57,7 +59,7 @@ namespace rawaccel { /// Verifies arguments as valid. Errors if not. /// /// Arguments to verified. - void verify(accel_args args) const { + void verify(const accel_args& args) const { if (args.accel < 0) error("accel can not be negative, use a negative weight to compensate"); } -- cgit v1.2.3