Skip to content

Commit

Permalink
Set notch prox angle onto device profile instead of cvar (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez committed Mar 1, 2023
1 parent 80e558c commit c2e8b39
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/controller/ControlDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ControlDeck::LoadControllerSettings() {

profile->Mappings.clear();
profile->AxisDeadzones.clear();
profile->AxisDeadzones.clear();
profile->AxisMinimumPress.clear();
profile->GyroData.clear();

profile->Version = config->getInt(NESTED("Version", ""), DEVICE_PROFILE_VERSION_V0);
Expand All @@ -165,6 +165,7 @@ void ControlDeck::LoadControllerSettings() {
profile->UseRumble = config->getBool(NESTED("Rumble.Enabled", ""));
profile->RumbleStrength = config->getFloat(NESTED("Rumble.Strength", ""));
profile->UseGyro = config->getBool(NESTED("Gyro.Enabled", ""));
profile->NotchProximityThreshold = config->getInt(NESTED("Notches.ProximityThreshold", ""));

for (auto const& val : rawProfile["AxisDeadzones"].items()) {
profile->AxisDeadzones[std::stoi(val.key())] = val.value();
Expand Down Expand Up @@ -218,6 +219,7 @@ void ControlDeck::SaveControllerSettings() {
config->setBool(NESTED("Rumble.Enabled", ""), profile->UseRumble);
config->setFloat(NESTED("Rumble.Strength", ""), profile->RumbleStrength);
config->setBool(NESTED("Gyro.Enabled", ""), profile->UseGyro);
config->setInt(NESTED("Notches.ProximityThreshold", ""), profile->NotchProximityThreshold);

for (auto const& val : rawProfile["Mappings"].items()) {
config->setInt(NESTED("Mappings.%s", val.key().c_str()), -1);
Expand Down
11 changes: 6 additions & 5 deletions src/controller/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int8_t Controller::ReadStick(int32_t virtualSlot, Stick stick, Axis axis) {
return 0;
}

void Controller::ProcessStick(int8_t& x, int8_t& y, uint16_t deadzoneX, uint16_t deadzoneY) {
void Controller::ProcessStick(int8_t& x, int8_t& y, float deadzoneX, float deadzoneY, int32_t notchProxmityThreshold) {
auto ux = fabs(x);
auto uy = fabs(y);

Expand Down Expand Up @@ -122,8 +122,7 @@ void Controller::ProcessStick(int8_t& x, int8_t& y, uint16_t deadzoneX, uint16_t
}

// map to virtual notches
double notchProximityVal = CVarGetInteger("gNotchProximityThreshold", 0);
const double notchProximityValRadians = notchProximityVal * M_TAU / 360;
const double notchProximityValRadians = notchProxmityThreshold * M_TAU / 360;

const double distance = std::sqrt((ux * ux) + (uy * uy)) / MAX_AXIS_RANGE;
if (distance >= MINIMUM_RADIUS_TO_MAP_NOTCH) {
Expand Down Expand Up @@ -158,8 +157,10 @@ void Controller::Read(OSContPad* pad, int32_t virtualSlot) {
int8_t rightStickY = ReadStick(virtualSlot, RIGHT, Y);

auto profile = getProfile(virtualSlot);
ProcessStick(leftStickX, leftStickY, profile->AxisDeadzones[0], profile->AxisDeadzones[1]);
ProcessStick(rightStickX, rightStickY, profile->AxisDeadzones[2], profile->AxisDeadzones[3]);
ProcessStick(leftStickX, leftStickY, profile->AxisDeadzones[0], profile->AxisDeadzones[1],
profile->NotchProximityThreshold);
ProcessStick(rightStickX, rightStickY, profile->AxisDeadzones[2], profile->AxisDeadzones[3],
profile->NotchProximityThreshold);

if (pad == nullptr) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/controller/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct DeviceProfile {
bool UseRumble = false;
bool UseGyro = false;
float RumbleStrength = 1.0f;
int32_t NotchProximityThreshold = 0;
std::unordered_map<int32_t, float> AxisDeadzones;
std::unordered_map<int32_t, float> AxisMinimumPress;
std::unordered_map<int32_t, float> GyroData;
Expand Down Expand Up @@ -67,7 +68,7 @@ class Controller {

void LoadBinding();
int8_t ReadStick(int32_t virtualSlot, Stick stick, Axis axis);
void ProcessStick(int8_t& x, int8_t& y, uint16_t deadzoneX, uint16_t deadzoneY);
void ProcessStick(int8_t& x, int8_t& y, float deadzoneX, float deadzoneY, int32_t notchProxmityThreshold);

private:
struct Buttons {
Expand Down
17 changes: 5 additions & 12 deletions src/menu/InputEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,24 +327,17 @@ void InputEditor::DrawControllerSchema() {
}

if (!isKeyboard) {
const char* notchProximityCvar = "gNotchProximityThreshold";
int notchProximityVal = CVarGetInteger(notchProximityCvar, 0);
auto nda = notchProximityVal;

ImGui::SetCursorPosX(cursorX);
ImGui::Text("Notch Snap Angle: %d", nda);
ImGui::Text("Notch Snap Angle: %d", profile->NotchProximityThreshold);
ImGui::SetCursorPosX(cursorX);

#ifdef __WIIU__
ImGui::PushItemWidth(135.0f * 2);
#else
ImGui::PushItemWidth(135.0f);
#endif
ImGui::SliderInt("##NotchProximityThreshold", &notchProximityVal, 0, 45, "", ImGuiSliderFlags_AlwaysClamp);
{
CVarSetInteger(notchProximityCvar, notchProximityVal);
SohImGui::RequestCvarSaveOnNextTick();
}
ImGui::SliderInt("##NotchProximityThreshold", &profile->NotchProximityThreshold, 0, 45, "",
ImGuiSliderFlags_AlwaysClamp);
ImGui::PopItemWidth();
if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(
Expand All @@ -368,10 +361,10 @@ void InputEditor::DrawHud() {
ImVec2 maxSize = ImVec2(2200, 505);
#elif defined(__WIIU__)
ImVec2 minSize = ImVec2(641 * 2, 250 * 2);
ImVec2 maxSize = ImVec2(1200 * 2, 290 * 2);
ImVec2 maxSize = ImVec2(1200 * 2, 330 * 2);
#else
ImVec2 minSize = ImVec2(641, 250);
ImVec2 maxSize = ImVec2(1200, 290);
ImVec2 maxSize = ImVec2(1200, 330);
#endif

ImGui::SetNextWindowSizeConstraints(minSize, maxSize);
Expand Down

0 comments on commit c2e8b39

Please sign in to comment.