diff options
| author | a1xd <[email protected]> | 2021-03-29 19:41:42 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-03-29 19:41:42 -0400 |
| commit | 5a0db3165d1ad050fd5e3f48d290f5ec7289a4f2 (patch) | |
| tree | bbe885a5a8626c0ff3af0e6828394c39b478bc25 | |
| parent | formatting + file renames (diff) | |
| download | rawaccel-5a0db3165d1ad050fd5e3f48d290f5ec7289a4f2.tar.xz rawaccel-5a0db3165d1ad050fd5e3f48d290f5ec7289a4f2.zip | |
add jump type
| -rw-r--r-- | common/accel-jump.hpp | 73 | ||||
| -rw-r--r-- | common/accel-union.hpp | 9 | ||||
| -rw-r--r-- | common/common.vcxitems | 1 | ||||
| -rw-r--r-- | common/rawaccel-base.hpp | 2 |
4 files changed, 85 insertions, 0 deletions
diff --git a/common/accel-jump.hpp b/common/accel-jump.hpp new file mode 100644 index 0000000..2d13cae --- /dev/null +++ b/common/accel-jump.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "rawaccel-base.hpp" + +#define _USE_MATH_DEFINES +#include <math.h> + +namespace rawaccel { + + struct jump_base { + vec2d step; + double smooth_rate; + + jump_base(const accel_args& args) : + step({ args.offset, args.cap - 1 }) + { + if (args.smooth == 0 || args.offset == 0) { + smooth_rate = 0; + } + else { + smooth_rate = 2 * M_PI / (args.offset * args.smooth); + } + + } + + bool is_smooth() const + { + return smooth_rate != 0; + } + + double decay(double x) const + { + return exp(smooth_rate * (step.x - x)); + } + + double smooth(double x) const + { + return step.y * 1 / (1 + decay(x)); + } + + double smooth_antideriv(double x) const + { + return step.y * (x + log(1 + decay(x)) / smooth_rate); + } + }; + + struct jump_legacy : jump_base { + using jump_base::jump_base; + + double operator()(double x) const + { + if (is_smooth()) return smooth(x) + 1; + else if (x < step.x) return 1; + else return step.y; + } + }; + + struct jump : jump_base { + double C; + + jump(const accel_args& args) : + jump_base(args), + C(-smooth_antideriv(0)) {} + + double operator()(double x) const + { + if (is_smooth()) return 1 + (smooth_antideriv(x) + C) / x; + else if (x < step.x) return 1; + else return 1 + step.y * (x - step.x) / x; + } + }; + +} diff --git a/common/accel-union.hpp b/common/accel-union.hpp index 86d0cf4..97496e1 100644 --- a/common/accel-union.hpp +++ b/common/accel-union.hpp @@ -1,6 +1,7 @@ #pragma once #include "accel-classic.hpp" +#include "accel-jump.hpp" #include "accel-natural.hpp" #include "accel-power.hpp" #include "accel-motivity.hpp" @@ -11,6 +12,8 @@ namespace rawaccel { enum class internal_mode { classic_lgcy, classic_gain, + jump_lgcy, + jump_gain, natural_lgcy, natural_gain, power, @@ -23,6 +26,8 @@ namespace rawaccel { switch (m) { case accel_mode::classic: return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain; + case accel_mode::jump: + return legacy ? internal_mode::jump_lgcy : internal_mode::jump_gain; case accel_mode::natural: return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain; case accel_mode::power: @@ -45,6 +50,8 @@ namespace rawaccel { switch (var.tag) { case internal_mode::classic_lgcy: return vis(var.u.classic_l); case internal_mode::classic_gain: return vis(var.u.classic_g); + case internal_mode::jump_lgcy: return vis(var.u.jump_l); + case internal_mode::jump_gain: return vis(var.u.jump_g); case internal_mode::natural_lgcy: return vis(var.u.natural_l); case internal_mode::natural_gain: return vis(var.u.natural_g); case internal_mode::power: return vis(var.u.power); @@ -61,6 +68,8 @@ namespace rawaccel { union union_t { classic classic_g; classic_legacy classic_l; + jump jump_g; + jump_legacy jump_l; natural natural_g; natural_legacy natural_l; power power; diff --git a/common/common.vcxitems b/common/common.vcxitems index 9e0d971..6ee47ed 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -15,6 +15,7 @@ </ItemGroup> <ItemGroup> <ClInclude Include="$(MSBuildThisFileDirectory)accel-classic.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-jump.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-motivity.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" /> diff --git a/common/rawaccel-base.hpp b/common/rawaccel-base.hpp index 308a3fc..ac60ff0 100644 --- a/common/rawaccel-base.hpp +++ b/common/rawaccel-base.hpp @@ -15,6 +15,7 @@ namespace rawaccel { enum class accel_mode { classic, + jump, natural, motivity, power, @@ -37,6 +38,7 @@ namespace rawaccel { double exponent = 0.05; double limit = 1.5; double midpoint = 5; + double smooth = 0.5; }; struct domain_args { |