diff options
| author | Jacob Palecki <[email protected]> | 2020-07-28 17:21:39 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-28 17:21:39 -0700 |
| commit | cdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e (patch) | |
| tree | 64620804479337358e5c5d2dfd1e54407a032de2 | |
| parent | Rename acceleration constants, arguments (diff) | |
| download | rawaccel-cdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e.tar.xz rawaccel-cdd82efdfdd7c2e9b4c2ed9777792f9921eedb9e.zip | |
Get rid of enum and use types\tags directly
| -rw-r--r-- | common/rawaccel-userspace.hpp | 14 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 24 | ||||
| -rw-r--r-- | grapher/Form1.cs | 2 | ||||
| -rw-r--r-- | wrapper/wrapper.hpp | 4 |
4 files changed, 15 insertions, 29 deletions
diff --git a/common/rawaccel-userspace.hpp b/common/rawaccel-userspace.hpp index 5996364..82a9e98 100644 --- a/common/rawaccel-userspace.hpp +++ b/common/rawaccel-userspace.hpp @@ -68,34 +68,34 @@ mouse_modifier parse(int argc, char** argv) { // modes auto noaccel_mode = "no-accel mode" % ( - clipp::command("off", "noaccel").set(accel_args.accel_mode, mode::noaccel) + clipp::command("off", "noaccel").set(accel_args.accel_mode, accel_implementation_t::id<accel_noaccel>) ); auto lin_mode = "linear accel mode:" % ( - clipp::command("linear").set(accel_args.accel_mode, mode::linear), + clipp::command("linear").set(accel_args.accel_mode, accel_implementation_t::id<accel_linear>), accel_var ); auto classic_mode = "classic accel mode:" % ( - clipp::command("classic").set(accel_args.accel_mode, mode::classic), + clipp::command("classic").set(accel_args.accel_mode, accel_implementation_t::id<accel_classic>), accel_var, (clipp::required("exponent") & clipp::number("num", accel_args.lim_exp)) % "exponent" ); auto nat_mode = "natural accel mode:" % ( - clipp::command("natural").set(accel_args.accel_mode, mode::natural), + clipp::command("natural").set(accel_args.accel_mode, accel_implementation_t::id<accel_natural>), accel_var, limit_var ); auto log_mode = "logarithmic accel mode:" % ( - clipp::command("logarithmic").set(accel_args.accel_mode, mode::logarithmic), + clipp::command("logarithmic").set(accel_args.accel_mode, accel_implementation_t::id<accel_logarithmic>), accel_var ); auto sig_mode = "sigmoid accel mode:" % ( - clipp::command("sigmoid").set(accel_args.accel_mode, mode::sigmoid), + clipp::command("sigmoid").set(accel_args.accel_mode, accel_implementation_t::id<accel_sigmoid>), accel_var, limit_var, (clipp::required("midpoint") & clipp::number("speed", accel_args.midpoint)) % "midpoint" ); auto pow_mode = "power accel mode:" % ( - clipp::command("power").set(accel_args.accel_mode, mode::power) >> [&] { accel_args.accel = 1; }, + clipp::command("power").set(accel_args.accel_mode, accel_implementation_t::id<accel_power>) >> [&] { accel_args.accel = 1; }, (clipp::required("exponent") & clipp::number("num", accel_args.lim_exp)) % "exponent", (clipp::option("scale") & clipp::number("num", accel_args.accel)) % "scale factor" ); diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index e904350..08829dd 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -9,9 +9,6 @@ namespace rawaccel { - /// <summary> Enum to hold acceleration implementation types (i.e. types of curves.) </summary> - enum class mode { noaccel, linear, classic, natural, logarithmic, sigmoid, power }; - /// <summary> Struct to hold vector rotation details. </summary> struct rotator { @@ -80,7 +77,7 @@ namespace rawaccel { /// <summary> Struct to hold arguments for an acceleration function. </summary> struct accel_args { - mode accel_mode = mode::noaccel; + int accel_mode = 0; milliseconds time_min = 0.4; double offset = 0; double accel = 0; @@ -282,20 +279,8 @@ namespace rawaccel { vec2<accel_scale_clamp> clamp; accel_function(accel_args args) { - switch (args.accel_mode) - { - case mode::linear: accel = accel_linear(args); - break; - case mode::classic: accel = accel_classic(args); - break; - case mode::natural: accel = accel_natural(args); - break; - case mode::logarithmic: accel = accel_logarithmic(args); - break; - case mode::sigmoid: accel = accel_sigmoid(args); - break; - case mode::power: accel = accel_power(args); - } + accel.tag = args.accel_mode; + accel.visit([&](auto& a){ a = {args}; }); // Verification is performed by the accel_implementation object // and therefore must occur after the object has been instantiated @@ -365,7 +350,8 @@ namespace rawaccel { if (apply_rotate) rotate = rotator(degrees); else rotate = rotator(); - apply_accel = accel_args.accel_mode != mode::noaccel; + apply_accel = (accel_args.accel_mode != 0 && + accel_args.accel_mode != accel_implementation_t::id<accel_noaccel>); if (sens.x == 0) sens.x = 1; if (sens.y == 0) sens.y = 1; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 4165b0f..495640e 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -15,7 +15,7 @@ namespace grapher public RawAcceleration() { InitializeComponent(); - var managedAccel = new ManagedAccel(6, 0, 1.333, 0.05, 0); + var managedAccel = new ManagedAccel(5, 0, 0.3, 1.25, 15); var orderedPoints = new SortedDictionary<double, double>(); for (int i = 0; i < 100; i++) diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index 271b61b..727bfcc 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -16,13 +16,13 @@ public: { } - ManagedAccel(double mode, double offset, double accel, double lim_exp, double midpoint) + ManagedAccel(int mode, double offset, double accel, double lim_exp, double midpoint) { accel_args args{}; args.accel = accel; args.lim_exp = lim_exp; args.midpoint = midpoint; - args.accel_mode = (rawaccel::mode)mode; + args.accel_mode = mode; args.offset = offset; accel_instance = new accel_function(args); |