Skip to content

Commit 5dba443

Browse files
committed
found a spot for axis thresholds
1 parent e5babe3 commit 5dba443

File tree

5 files changed

+88
-14
lines changed

5 files changed

+88
-14
lines changed

src/controller/controldeck/ControlDeck.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Ship {
1313
ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) : mSinglePlayerMappingMode(false) {
1414
mDeviceIndexMappingManager = std::make_shared<ShipDeviceIndexMappingManager>();
1515
mConnectedPhysicalDeviceManager = std::make_shared<ConnectedPhysicalDeviceManager>();
16+
mGlobalSDLDeviceSettings = std::make_shared<GlobalSDLDeviceSettings>();
1617
}
1718

1819
ControlDeck::~ControlDeck() {
@@ -114,6 +115,10 @@ std::shared_ptr<ConnectedPhysicalDeviceManager> ControlDeck::GetConnectedPhysica
114115
return mConnectedPhysicalDeviceManager;
115116
}
116117

118+
std::shared_ptr<GlobalSDLDeviceSettings> ControlDeck::GetGlobalSDLDeviceSettings() {
119+
return mGlobalSDLDeviceSettings;
120+
}
121+
117122
void ControlDeck::SetSinglePlayerMappingMode(bool singlePlayer) {
118123
mSinglePlayerMappingMode = singlePlayer;
119124
}

src/controller/controldeck/ControlDeck.h

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
77
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
88
#include "controller/physicaldevice/ConnectedPhysicalDeviceManager.h"
9+
#include "controller/physicaldevice/GlobalSDLDeviceSettings.h"
910

1011
namespace Ship {
1112

@@ -30,6 +31,7 @@ class ControlDeck {
3031

3132
std::shared_ptr<ShipDeviceIndexMappingManager> GetDeviceIndexMappingManager();
3233
std::shared_ptr<ConnectedPhysicalDeviceManager> GetConnectedPhysicalDeviceManager();
34+
std::shared_ptr<GlobalSDLDeviceSettings> GetGlobalSDLDeviceSettings();
3335

3436
protected:
3537
bool AllGameInputBlocked();
@@ -41,6 +43,7 @@ class ControlDeck {
4143
std::unordered_map<int32_t, bool> mGameInputBlockers;
4244
std::shared_ptr<ShipDeviceIndexMappingManager> mDeviceIndexMappingManager;
4345
std::shared_ptr<ConnectedPhysicalDeviceManager> mConnectedPhysicalDeviceManager;
46+
std::shared_ptr<GlobalSDLDeviceSettings> mGlobalSDLDeviceSettings;
4447
};
4548
} // namespace Ship
4649

src/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToButtonMapping.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,12 @@ void SDLAxisDirectionToButtonMapping::UpdatePad(CONTROLLERBUTTONS_T& padButtons)
1818
return;
1919
}
2020

21-
// todo: threshold percentages
2221
int32_t axisThresholdPercentage = 25;
23-
// auto indexMapping = Context::GetInstance()
24-
// ->GetControlDeck()
25-
// ->GetDeviceIndexMappingManager()
26-
// ->GetDeviceIndexMappingFromShipDeviceIndex(ControllerInputMapping::mPhysicalDeviceType);
27-
// auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
28-
29-
// if (sdlIndexMapping != nullptr) {
30-
// if (AxisIsStick()) {
31-
// axisThresholdPercentage = sdlIndexMapping->GetStickAxisThresholdPercentage();
32-
// } else if (AxisIsTrigger()) {
33-
// axisThresholdPercentage = sdlIndexMapping->GetTriggerAxisThresholdPercentage();
34-
// }
35-
// }
22+
if (AxisIsStick()) {
23+
axisThresholdPercentage = Ship::Context::GetInstance()->GetControlDeck()->GetGlobalSDLDeviceSettings()->GetStickAxisThresholdPercentage();
24+
} else if (AxisIsTrigger()) {
25+
axisThresholdPercentage = Ship::Context::GetInstance()->GetControlDeck()->GetGlobalSDLDeviceSettings()->GetTriggerAxisThresholdPercentage();
26+
}
3627

3728
for (const auto& [instanceId, gamepad] :
3829
Context::GetInstance()->GetControlDeck()->GetConnectedPhysicalDeviceManager()->GetConnectedSDLGamepadsForPort(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "GlobalSDLDeviceSettings.h"
2+
3+
#include <string>
4+
#include "utils/StringHelper.h"
5+
#include "public/bridge/consolevariablebridge.h"
6+
7+
namespace Ship {
8+
GlobalSDLDeviceSettings::GlobalSDLDeviceSettings() {
9+
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".GlobalSDLDeviceSettings";
10+
const int32_t defaultAxisThresholdPercentage = 25;
11+
mStickAxisThresholdPercentage = CVarGetInteger(StringHelper::Sprintf("%s.StickAxisThresholdPercentage", mappingCvarKey.c_str()).c_str(), defaultAxisThresholdPercentage);
12+
mTriggerAxisThresholdPercentage = CVarGetInteger(StringHelper::Sprintf("%s.TriggerAxisThresholdPercentage", mappingCvarKey.c_str()).c_str(), defaultAxisThresholdPercentage);
13+
}
14+
15+
GlobalSDLDeviceSettings::~GlobalSDLDeviceSettings() {
16+
}
17+
18+
int32_t GlobalSDLDeviceSettings::GetStickAxisThresholdPercentage() {
19+
return mStickAxisThresholdPercentage;
20+
}
21+
22+
void GlobalSDLDeviceSettings::SetStickAxisThresholdPercentage(int32_t stickAxisThresholdPercentage) {
23+
mStickAxisThresholdPercentage = stickAxisThresholdPercentage;
24+
}
25+
26+
int32_t GlobalSDLDeviceSettings::GetTriggerAxisThresholdPercentage() {
27+
return mTriggerAxisThresholdPercentage;
28+
}
29+
30+
void GlobalSDLDeviceSettings::SetTriggerAxisThresholdPercentage(int32_t triggerAxisThresholdPercentage) {
31+
mTriggerAxisThresholdPercentage = triggerAxisThresholdPercentage;
32+
}
33+
34+
void GlobalSDLDeviceSettings::SaveToConfig() {
35+
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".GlobalSDLDeviceSettings";
36+
CVarSetInteger(StringHelper::Sprintf("%s.StickAxisThresholdPercentage", mappingCvarKey.c_str()).c_str(),
37+
mStickAxisThresholdPercentage);
38+
CVarSetInteger(StringHelper::Sprintf("%s.TriggerAxisThresholdPercentage", mappingCvarKey.c_str()).c_str(),
39+
mTriggerAxisThresholdPercentage);
40+
CVarSave();
41+
}
42+
43+
void GlobalSDLDeviceSettings::EraseFromConfig() {
44+
const std::string mappingCvarKey = CVAR_PREFIX_CONTROLLERS ".GlobalSDLDeviceSettings";
45+
CVarClear(StringHelper::Sprintf("%s.StickAxisThresholdPercentage", mappingCvarKey.c_str()).c_str());
46+
CVarClear(StringHelper::Sprintf("%s.TriggerAxisThresholdPercentage", mappingCvarKey.c_str()).c_str());
47+
48+
CVarSave();
49+
}
50+
} // namespace Ship
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace Ship {
6+
7+
class GlobalSDLDeviceSettings {
8+
public:
9+
GlobalSDLDeviceSettings();
10+
~GlobalSDLDeviceSettings();
11+
12+
int32_t GetStickAxisThresholdPercentage();
13+
void SetStickAxisThresholdPercentage(int32_t stickAxisThresholdPercentage);
14+
15+
int32_t GetTriggerAxisThresholdPercentage();
16+
void SetTriggerAxisThresholdPercentage(int32_t triggerAxisThresholdPercentage);
17+
18+
void SaveToConfig();
19+
void EraseFromConfig();
20+
21+
private:
22+
int32_t mStickAxisThresholdPercentage;
23+
int32_t mTriggerAxisThresholdPercentage;
24+
};
25+
} // namespace Ship

0 commit comments

Comments
 (0)