mirror of
https://github.com/RawAccelOfficial/rawaccel.git
synced 2025-05-11 18:36:46 +02:00
formatting + file renames
This commit is contained in:
parent
16dc4df3d4
commit
ed0bbc2268
13 changed files with 158 additions and 126 deletions
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "rawaccel-base.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
/// <summary> Struct to hold "classic" (linear raised to power) acceleration implementation. </summary>
|
||||
|
@ -18,7 +19,8 @@ namespace rawaccel {
|
|||
power(args.power),
|
||||
accel_raised(pow(args.accel_classic, power - 1)) {}
|
||||
|
||||
double base_fn(double x) const {
|
||||
double base_fn(double x) const
|
||||
{
|
||||
return accel_raised * pow(x - offset, power) / x;
|
||||
}
|
||||
};
|
||||
|
@ -40,7 +42,8 @@ namespace rawaccel {
|
|||
}
|
||||
}
|
||||
|
||||
inline double operator()(double x) const {
|
||||
double operator()(double x) const
|
||||
{
|
||||
if (x <= offset) return 1;
|
||||
return sign * minsd(base_fn(x), sens_cap) + 1;
|
||||
}
|
||||
|
@ -67,7 +70,8 @@ namespace rawaccel {
|
|||
}
|
||||
}
|
||||
|
||||
double operator()(double x) const {
|
||||
double operator()(double x) const
|
||||
{
|
||||
double output;
|
||||
|
||||
if (x <= offset) return 1;
|
||||
|
@ -81,7 +85,7 @@ namespace rawaccel {
|
|||
|
||||
return sign * output + 1;
|
||||
}
|
||||
|
||||
|
||||
static double gain(double x, double accel, double power, double offset)
|
||||
{
|
||||
return power * pow(accel * (x - offset), power - 1);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
#include <math.h>
|
||||
|
||||
#define RA_LOOKUP
|
||||
|
||||
|
@ -23,24 +23,27 @@ namespace rawaccel {
|
|||
double subtractive_constant;
|
||||
|
||||
motivity(const accel_args& args) :
|
||||
rate(pow(10,args.accel_motivity)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint))
|
||||
rate(pow(10,args.accel_motivity)),
|
||||
limit(2*log10(args.limit)),
|
||||
midpoint(log10(args.midpoint))
|
||||
{
|
||||
subtractive_constant = limit / 2;
|
||||
}
|
||||
|
||||
inline double operator()(double speed) const {
|
||||
double operator()(double speed) const
|
||||
{
|
||||
double log_speed = log10(speed);
|
||||
return pow(10, limit / (exp(-rate * (log_speed - midpoint)) + 1) - subtractive_constant);
|
||||
|
||||
}
|
||||
|
||||
inline double apply(si_pair* lookup, double speed) const
|
||||
double apply(si_pair* lookup, double speed) const
|
||||
{
|
||||
si_pair pair = lookup[map(speed)];
|
||||
return pair.slope + pair.intercept / speed;
|
||||
}
|
||||
|
||||
inline int map(double speed) const
|
||||
int map(double speed) const
|
||||
{
|
||||
int index = speed > 0 ? (int)(100 * log10(speed) + 201) : 0;
|
||||
|
||||
|
@ -50,7 +53,7 @@ namespace rawaccel {
|
|||
return index;
|
||||
}
|
||||
|
||||
inline void fill(si_pair* lookup) const
|
||||
void fill(si_pair* lookup) const
|
||||
{
|
||||
double lookup_speed = 0;
|
||||
double integral_interval = 0;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
|
@ -22,7 +22,8 @@ namespace rawaccel {
|
|||
|
||||
struct natural_legacy : natural_base {
|
||||
|
||||
double operator()(double x) const {
|
||||
double operator()(double x) const
|
||||
{
|
||||
if (x <= offset) return 1;
|
||||
|
||||
double offset_x = x - offset;
|
||||
|
@ -36,7 +37,8 @@ namespace rawaccel {
|
|||
struct natural : natural_base {
|
||||
double constant;
|
||||
|
||||
double operator()(double x) const {
|
||||
double operator()(double x) const
|
||||
{
|
||||
if (x <= offset) return 1;
|
||||
|
||||
double offset_x = x - offset;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
|
@ -10,7 +10,7 @@ namespace rawaccel {
|
|||
accel_noaccel(const accel_args&) {}
|
||||
accel_noaccel() = default;
|
||||
|
||||
inline double operator()(double) const { return 1; }
|
||||
double operator()(double) const { return 1; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
#include <math.h>
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
|
@ -17,7 +17,8 @@ namespace rawaccel {
|
|||
exponent(args.exponent),
|
||||
post_scale(args.weight) {}
|
||||
|
||||
inline double operator()(double speed) const {
|
||||
double operator()(double speed) const
|
||||
{
|
||||
// f(x) = (mx)^k
|
||||
return post_scale * pow(speed * pre_scale, exponent);
|
||||
}
|
||||
|
|
98
common/accel-union.hpp
Normal file
98
common/accel-union.hpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
#pragma once
|
||||
|
||||
#include "accel-classic.hpp"
|
||||
#include "accel-natural.hpp"
|
||||
#include "accel-power.hpp"
|
||||
#include "accel-motivity.hpp"
|
||||
#include "accel-noaccel.hpp"
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
enum class internal_mode {
|
||||
classic_lgcy,
|
||||
classic_gain,
|
||||
natural_lgcy,
|
||||
natural_gain,
|
||||
power,
|
||||
motivity,
|
||||
noaccel
|
||||
};
|
||||
|
||||
constexpr internal_mode make_mode(accel_mode m, bool legacy)
|
||||
{
|
||||
switch (m) {
|
||||
case accel_mode::classic:
|
||||
return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain;
|
||||
case accel_mode::natural:
|
||||
return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain;
|
||||
case accel_mode::power:
|
||||
return internal_mode::power;
|
||||
case accel_mode::motivity:
|
||||
return internal_mode::motivity;
|
||||
default:
|
||||
return internal_mode::noaccel;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr internal_mode make_mode(const accel_args& args)
|
||||
{
|
||||
return make_mode(args.mode, args.legacy);
|
||||
}
|
||||
|
||||
template <typename Visitor, typename Variant>
|
||||
inline auto visit_accel(Visitor vis, Variant&& var)
|
||||
{
|
||||
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::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);
|
||||
case internal_mode::motivity: return vis(var.u.motivity);
|
||||
default: return vis(var.u.noaccel);
|
||||
}
|
||||
}
|
||||
|
||||
struct accel_variant {
|
||||
si_pair* lookup;
|
||||
|
||||
internal_mode tag = internal_mode::noaccel;
|
||||
|
||||
union union_t {
|
||||
classic classic_g;
|
||||
classic_legacy classic_l;
|
||||
natural natural_g;
|
||||
natural_legacy natural_l;
|
||||
power power;
|
||||
motivity motivity;
|
||||
accel_noaccel noaccel = {};
|
||||
} u = {};
|
||||
|
||||
accel_variant(const accel_args& args, si_pair* lut = nullptr) :
|
||||
tag(make_mode(args)), lookup(lut)
|
||||
{
|
||||
visit_accel([&](auto& impl) {
|
||||
impl = { args };
|
||||
}, *this);
|
||||
|
||||
if (lookup && tag == internal_mode::motivity) {
|
||||
u.motivity.fill(lookup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double apply(double speed) const
|
||||
{
|
||||
if (lookup && tag == internal_mode::motivity) {
|
||||
return u.motivity.apply(lookup, speed);
|
||||
}
|
||||
|
||||
return visit_accel([=](auto&& impl) {
|
||||
return impl(speed);
|
||||
}, *this);
|
||||
}
|
||||
|
||||
accel_variant() = default;
|
||||
};
|
||||
|
||||
}
|
|
@ -19,15 +19,16 @@
|
|||
<ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)accel-union.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io-def.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-settings.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-base.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility-rawinput.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)x64-util.hpp" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -6,7 +6,7 @@
|
|||
#include <Windows.h>
|
||||
|
||||
#include "rawaccel-io-def.h"
|
||||
#include "rawaccel-settings.h"
|
||||
#include "rawaccel-base.hpp"
|
||||
#include "rawaccel-version.h"
|
||||
#include "rawaccel-error.hpp"
|
||||
|
||||
|
@ -15,7 +15,8 @@
|
|||
|
||||
namespace rawaccel {
|
||||
|
||||
void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) {
|
||||
inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size)
|
||||
{
|
||||
HANDLE ra_handle = INVALID_HANDLE_VALUE;
|
||||
|
||||
ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
|
@ -44,19 +45,22 @@ namespace rawaccel {
|
|||
}
|
||||
}
|
||||
|
||||
settings read() {
|
||||
inline settings read()
|
||||
{
|
||||
settings args;
|
||||
io_control(RA_READ, NULL, 0, &args, sizeof(settings));
|
||||
return args;
|
||||
}
|
||||
|
||||
|
||||
void write(const settings& args) {
|
||||
inline void write(const settings& args)
|
||||
{
|
||||
auto in_ptr = const_cast<settings*>(&args);
|
||||
io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0);
|
||||
}
|
||||
|
||||
version_t get_version() {
|
||||
inline version_t get_version()
|
||||
{
|
||||
version_t ver;
|
||||
io_control(RA_GET_VERSION, NULL, 0, &ver, sizeof(version_t));
|
||||
return ver;
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "accel-union.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "x64-util.hpp"
|
||||
|
||||
#include "accel-classic.hpp"
|
||||
#include "accel-natural.hpp"
|
||||
#include "accel-power.hpp"
|
||||
#include "accel-motivity.hpp"
|
||||
#include "accel-noaccel.hpp"
|
||||
|
||||
namespace rawaccel {
|
||||
|
||||
/// <summary> Struct to hold vector rotation details. </summary>
|
||||
|
@ -66,89 +61,6 @@ namespace rawaccel {
|
|||
v.y *= ratio;
|
||||
}
|
||||
|
||||
enum class internal_mode {
|
||||
classic_lgcy,
|
||||
classic_gain,
|
||||
natural_lgcy,
|
||||
natural_gain,
|
||||
power,
|
||||
motivity,
|
||||
noaccel
|
||||
};
|
||||
|
||||
constexpr internal_mode make_mode(accel_mode m, bool legacy) {
|
||||
switch (m) {
|
||||
case accel_mode::classic:
|
||||
return legacy ? internal_mode::classic_lgcy : internal_mode::classic_gain;
|
||||
case accel_mode::natural:
|
||||
return legacy ? internal_mode::natural_lgcy : internal_mode::natural_gain;
|
||||
case accel_mode::power:
|
||||
return internal_mode::power;
|
||||
case accel_mode::motivity:
|
||||
return internal_mode::motivity;
|
||||
default:
|
||||
return internal_mode::noaccel;
|
||||
}
|
||||
}
|
||||
|
||||
constexpr internal_mode make_mode(const accel_args& args) {
|
||||
return make_mode(args.mode, args.legacy);
|
||||
}
|
||||
|
||||
template <typename Visitor, typename Variant>
|
||||
inline auto visit_accel(Visitor vis, Variant&& var) {
|
||||
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::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);
|
||||
case internal_mode::motivity: return vis(var.u.motivity);
|
||||
default: return vis(var.u.noaccel);
|
||||
}
|
||||
}
|
||||
|
||||
struct accel_variant {
|
||||
si_pair* lookup;
|
||||
|
||||
internal_mode tag = internal_mode::noaccel;
|
||||
|
||||
union union_t {
|
||||
classic classic_g;
|
||||
classic_legacy classic_l;
|
||||
natural natural_g;
|
||||
natural_legacy natural_l;
|
||||
power power;
|
||||
motivity motivity;
|
||||
accel_noaccel noaccel = {};
|
||||
} u = {};
|
||||
|
||||
accel_variant(const accel_args& args, si_pair* lut = nullptr) :
|
||||
tag(make_mode(args)), lookup(lut)
|
||||
{
|
||||
visit_accel([&](auto& impl) {
|
||||
impl = { args };
|
||||
}, *this);
|
||||
|
||||
if (lookup && tag == internal_mode::motivity) {
|
||||
u.motivity.fill(lookup);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline double apply(double speed) const {
|
||||
if (lookup && tag == internal_mode::motivity) {
|
||||
return u.motivity.apply(lookup, speed);
|
||||
}
|
||||
|
||||
return visit_accel([=](auto&& impl) {
|
||||
return impl(speed);
|
||||
}, *this);
|
||||
}
|
||||
|
||||
accel_variant() = default;
|
||||
};
|
||||
|
||||
struct weighted_distance {
|
||||
double p = 2.0;
|
||||
double p_inverse = 0.5;
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
#include <initguid.h> // needed for devpkey.h to parse properly
|
||||
#include <devpkey.h>
|
||||
|
||||
std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEVPROPKEY* key) {
|
||||
inline
|
||||
std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEVPROPKEY* key)
|
||||
{
|
||||
ULONG size = 0;
|
||||
DEVPROPTYPE type;
|
||||
CONFIGRET cm_res;
|
||||
|
@ -37,14 +39,17 @@ std::wstring dev_prop_wstr_from_interface(const WCHAR* interface_name, const DEV
|
|||
return prop;
|
||||
}
|
||||
|
||||
std::wstring dev_id_from_interface(const WCHAR* interface_name) {
|
||||
inline
|
||||
std::wstring dev_id_from_interface(const WCHAR* interface_name)
|
||||
{
|
||||
auto id = dev_prop_wstr_from_interface(interface_name, &DEVPKEY_Device_InstanceId);
|
||||
id.resize(id.find_last_of('\\'));
|
||||
return id;
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE) {
|
||||
void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE)
|
||||
{
|
||||
const UINT RI_ERROR = -1;
|
||||
|
||||
UINT num_devs = 0;
|
||||
|
@ -75,7 +80,9 @@ void rawinput_foreach_with_interface(Func fn, DWORD input_type = RIM_TYPEMOUSE)
|
|||
|
||||
// returns device handles corresponding to a "device id"
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/install/device-ids
|
||||
std::vector<HANDLE> rawinput_handles_from_dev_id(const std::wstring& device_id, DWORD input_type = RIM_TYPEMOUSE) {
|
||||
inline
|
||||
std::vector<HANDLE> rawinput_handles_from_dev_id(const std::wstring& device_id, DWORD input_type = RIM_TYPEMOUSE)
|
||||
{
|
||||
std::vector<HANDLE> handles;
|
||||
|
||||
rawinput_foreach_with_interface([&](const auto& dev, const WCHAR* name) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "rawaccel-base.hpp"
|
||||
|
||||
#include <ntddk.h>
|
||||
#include <kbdmou.h>
|
||||
#include <wdf.h>
|
||||
|
||||
#include "rawaccel-settings.h"
|
||||
|
||||
#if DBG
|
||||
#define DebugPrint(_x_) DbgPrint _x_
|
||||
#else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue