Plugins agregados

This commit is contained in:
2026-03-30 15:33:19 -06:00
parent df2b257d93
commit eefc67e50a
766 changed files with 107667 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#pragma once
#include "ControlPort.h"
#include <vector>
#include "ship/config/Config.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
#include "ship/controller/physicaldevice/ConnectedPhysicalDeviceManager.h"
#include "ship/controller/physicaldevice/GlobalSDLDeviceSettings.h"
#include "ship/controller/controldevice/controller/mapping/ControllerDefaultMappings.h"
namespace Ship {
class ControlDeck {
public:
ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks,
std::shared_ptr<ControllerDefaultMappings> controllerDefaultMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::string> buttonNames);
~ControlDeck();
void Init(uint8_t* controllerBits);
virtual void WriteToPad(void* pads) = 0;
uint8_t* GetControllerBits();
std::shared_ptr<Controller> GetControllerByPort(uint8_t port);
void BlockGameInput(int32_t blockId);
void UnblockGameInput(int32_t blockId);
bool GamepadGameInputBlocked();
bool KeyboardGameInputBlocked();
bool MouseGameInputBlocked();
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
std::shared_ptr<ConnectedPhysicalDeviceManager> GetConnectedPhysicalDeviceManager();
std::shared_ptr<GlobalSDLDeviceSettings> GetGlobalSDLDeviceSettings();
std::shared_ptr<ControllerDefaultMappings> GetControllerDefaultMappings();
const std::unordered_map<CONTROLLERBUTTONS_T, std::string>& GetAllButtonNames() const;
std::string GetButtonNameForBitmask(CONTROLLERBUTTONS_T bitmask);
protected:
bool AllGameInputBlocked();
std::vector<std::shared_ptr<ControlPort>> mPorts = {};
private:
uint8_t* mControllerBits = nullptr;
std::unordered_map<int32_t, bool> mGameInputBlockers;
std::shared_ptr<ConnectedPhysicalDeviceManager> mConnectedPhysicalDeviceManager;
std::shared_ptr<GlobalSDLDeviceSettings> mGlobalSDLDeviceSettings;
std::shared_ptr<ControllerDefaultMappings> mControllerDefaultMappings;
std::unordered_map<CONTROLLERBUTTONS_T, std::string> mButtonNames;
};
} // namespace Ship

View File

@@ -0,0 +1,24 @@
#pragma once
#include "ship/controller/controldevice/ControlDevice.h"
#include "ship/controller/controldevice/controller/Controller.h"
#include <memory>
namespace Ship {
class ControlPort {
public:
ControlPort(uint8_t portIndex);
ControlPort(uint8_t portIndex, std::shared_ptr<ControlDevice> device);
~ControlPort();
void Connect(std::shared_ptr<ControlDevice> device);
void Disconnect();
std::shared_ptr<ControlDevice> GetConnectedDevice();
std::shared_ptr<Controller> GetConnectedController();
private:
uint8_t mPortIndex;
std::shared_ptr<ControlDevice> mDevice;
};
} // namespace Ship

View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
namespace Ship {
class ControlDevice {
public:
ControlDevice(uint8_t portIndex);
virtual ~ControlDevice();
protected:
uint8_t mPortIndex;
};
} // namespace Ship

View File

@@ -0,0 +1,65 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <cstdint>
#include <queue>
#include <vector>
#include <map>
#include <unordered_map>
#include "ControllerButton.h"
#include "ControllerStick.h"
#include "ControllerGyro.h"
#include "ControllerRumble.h"
#include "ControllerLED.h"
#include "ship/controller/controldevice/ControlDevice.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class Controller : public ControlDevice {
public:
Controller(uint8_t portIndex, std::vector<CONTROLLERBUTTONS_T> bitmasks);
~Controller();
void ReloadAllMappingsFromConfig();
bool IsConnected() const;
void Connect();
void Disconnect();
void ClearAllMappings();
void ClearAllMappingsForDeviceType(PhysicalDeviceType physicalDeviceType);
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
std::unordered_map<CONTROLLERBUTTONS_T, std::shared_ptr<ControllerButton>> GetAllButtons();
std::shared_ptr<ControllerButton> GetButtonByBitmask(CONTROLLERBUTTONS_T bitmask);
std::shared_ptr<ControllerButton> GetButton(CONTROLLERBUTTONS_T bitmask);
std::shared_ptr<ControllerStick> GetLeftStick();
std::shared_ptr<ControllerStick> GetRightStick();
std::shared_ptr<ControllerGyro> GetGyro();
std::shared_ptr<ControllerRumble> GetRumble();
std::shared_ptr<ControllerLED> GetLED();
virtual void ReadToPad(void* pad) = 0;
bool HasConfig();
uint8_t GetPortIndex();
std::vector<std::shared_ptr<ControllerMapping>> GetAllMappings();
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
protected:
std::unordered_map<CONTROLLERBUTTONS_T, std::shared_ptr<ControllerButton>> mButtons;
private:
void LoadButtonMappingFromConfig(std::string id);
void SaveButtonMappingIdsToConfig();
std::shared_ptr<ControllerStick> mLeftStick, mRightStick;
std::shared_ptr<ControllerGyro> mGyro;
std::shared_ptr<ControllerRumble> mRumble;
std::shared_ptr<ControllerLED> mLED;
};
} // namespace Ship

View File

@@ -0,0 +1,49 @@
#pragma once
#include "mapping/ControllerButtonMapping.h"
#include <memory>
#include <unordered_map>
#include <string>
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class ControllerButton {
public:
ControllerButton(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask);
~ControllerButton();
std::shared_ptr<ControllerButtonMapping> GetButtonMappingById(std::string id);
std::unordered_map<std::string, std::shared_ptr<ControllerButtonMapping>> GetAllButtonMappings();
void AddButtonMapping(std::shared_ptr<ControllerButtonMapping> mapping);
void ClearButtonMappingId(std::string id);
void ClearButtonMapping(std::string id);
void ClearButtonMapping(std::shared_ptr<ControllerButtonMapping> mapping);
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
void LoadButtonMappingFromConfig(std::string id);
void SaveButtonMappingIdsToConfig();
void ReloadAllMappingsFromConfig();
void ClearAllButtonMappings();
void ClearAllButtonMappingsForDeviceType(PhysicalDeviceType physicalDeviceType);
bool AddOrEditButtonMappingFromRawPress(CONTROLLERBUTTONS_T bitmask, std::string id);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons);
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button);
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
private:
uint8_t mPortIndex;
CONTROLLERBUTTONS_T mBitmask;
std::unordered_map<std::string, std::shared_ptr<ControllerButtonMapping>> mButtonMappings;
std::string GetConfigNameFromBitmask(CONTROLLERBUTTONS_T bitmask);
bool mUseEventInputToCreateNewMapping;
KbScancode mKeyboardScancodeForNewMapping;
MouseBtn mMouseButtonForNewMapping;
};
} // namespace Ship

View File

@@ -0,0 +1,30 @@
#pragma once
#include <cstdint>
#include <memory>
#include "ship/controller/controldevice/controller/mapping/ControllerGyroMapping.h"
namespace Ship {
class ControllerGyro {
public:
ControllerGyro(uint8_t portIndex);
~ControllerGyro();
void ReloadGyroMappingFromConfig();
void ClearGyroMapping();
void SaveGyroMappingIdToConfig();
std::shared_ptr<ControllerGyroMapping> GetGyroMapping();
void SetGyroMapping(std::shared_ptr<ControllerGyroMapping> mapping);
bool SetGyroMappingFromRawPress();
void UpdatePad(float& x, float& y);
bool HasMappingForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
private:
uint8_t mPortIndex;
std::shared_ptr<ControllerGyroMapping> mGyroMapping;
};
} // namespace Ship

View File

@@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <string>
#include "ship/controller/controldevice/controller/mapping/ControllerLEDMapping.h"
namespace Ship {
class ControllerLED {
public:
ControllerLED(uint8_t portIndex);
~ControllerLED();
std::unordered_map<std::string, std::shared_ptr<ControllerLEDMapping>> GetAllLEDMappings();
void AddLEDMapping(std::shared_ptr<ControllerLEDMapping> mapping);
void ClearLEDMappingId(std::string id);
void ClearLEDMapping(std::string id);
void SaveLEDMappingIdsToConfig();
void ClearAllMappings();
void ClearAllMappingsForDeviceType(PhysicalDeviceType physicalDeviceType);
void LoadLEDMappingFromConfig(std::string id);
void ReloadAllMappingsFromConfig();
bool AddLEDMappingFromRawPress();
void SetLEDColor(Color_RGB8 color);
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
private:
uint8_t mPortIndex;
std::unordered_map<std::string, std::shared_ptr<ControllerLEDMapping>> mLEDMappings;
};
} // namespace Ship

View File

@@ -0,0 +1,38 @@
#pragma once
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <string>
#include "ship/controller/controldevice/controller/mapping/ControllerRumbleMapping.h"
namespace Ship {
class ControllerRumble {
public:
ControllerRumble(uint8_t portIndex);
~ControllerRumble();
std::unordered_map<std::string, std::shared_ptr<ControllerRumbleMapping>> GetAllRumbleMappings();
void AddRumbleMapping(std::shared_ptr<ControllerRumbleMapping> mapping);
void ClearRumbleMappingId(std::string id);
void ClearRumbleMapping(std::string id);
void SaveRumbleMappingIdsToConfig();
void ClearAllMappings();
void ClearAllMappingsForDeviceType(PhysicalDeviceType physicalDeviceType);
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
void LoadRumbleMappingFromConfig(std::string id);
void ReloadAllMappingsFromConfig();
bool AddRumbleMappingFromRawPress();
void StartRumble();
void StopRumble();
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
private:
uint8_t mPortIndex;
std::unordered_map<std::string, std::shared_ptr<ControllerRumbleMapping>> mRumbleMappings;
};
} // namespace Ship

View File

@@ -0,0 +1,83 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include <cstdint>
#include <memory>
#include <unordered_map>
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
#define DEFAULT_STICK_SENSITIVITY_PERCENTAGE 100
#define DEFAULT_STICK_DEADZONE_PERCENTAGE 20
#define DEFAULT_NOTCH_SNAP_ANGLE 0
class ControllerStick {
public:
ControllerStick(uint8_t portIndex, StickIndex stickIndex);
~ControllerStick();
void ReloadAllMappingsFromConfig();
void AddDefaultMappings(PhysicalDeviceType physicalDeviceType);
void ClearAllMappings();
void ClearAllMappingsForDeviceType(PhysicalDeviceType physicalDeviceType);
void UpdatePad(int8_t& x, int8_t& y);
std::shared_ptr<ControllerAxisDirectionMapping> GetAxisDirectionMappingById(Direction direction, std::string id);
std::unordered_map<Direction, std::unordered_map<std::string, std::shared_ptr<ControllerAxisDirectionMapping>>>
GetAllAxisDirectionMappings();
std::unordered_map<std::string, std::shared_ptr<ControllerAxisDirectionMapping>>
GetAllAxisDirectionMappingByDirection(Direction direction);
void AddAxisDirectionMapping(Direction direction, std::shared_ptr<ControllerAxisDirectionMapping> mapping);
void ClearAxisDirectionMappingId(Direction direction, std::string id);
void ClearAxisDirectionMapping(Direction direction, std::string id);
void ClearAxisDirectionMapping(Direction direction, std::shared_ptr<ControllerAxisDirectionMapping> mapping);
void SaveAxisDirectionMappingIdsToConfig();
bool AddOrEditAxisDirectionMappingFromRawPress(Direction direction, std::string id);
void Process(int8_t& x, int8_t& y);
void ResetSensitivityToDefault();
void SetSensitivity(uint8_t sensitivityPercentage);
uint8_t GetSensitivityPercentage();
bool SensitivityIsDefault();
void ResetDeadzoneToDefault();
void SetDeadzone(uint8_t deadzonePercentage);
uint8_t GetDeadzonePercentage();
bool DeadzoneIsDefault();
void ResetNotchSnapAngleToDefault();
void SetNotchSnapAngle(uint8_t notchSnapAngle);
uint8_t GetNotchSnapAngle();
bool NotchSnapAngleIsDefault();
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
bool ProcessMouseButtonEvent(bool isPressed, Ship::MouseBtn button);
bool HasMappingsForPhysicalDeviceType(PhysicalDeviceType physicalDeviceType);
StickIndex GetStickIndex();
private:
double GetClosestNotch(double angle, double approximationThreshold);
void LoadAxisDirectionMappingFromConfig(std::string id);
float GetAxisDirectionValue(Direction direction);
uint8_t mPortIndex;
StickIndex mStickIndex;
uint8_t mSensitivityPercentage;
float mSensitivity;
// TODO: handle deadzones separately for X and Y?
uint8_t mDeadzonePercentage;
float mDeadzone;
uint8_t mNotchSnapAngle;
std::unordered_map<Direction, std::unordered_map<std::string, std::shared_ptr<ControllerAxisDirectionMapping>>>
mAxisDirectionMappings;
bool mUseEventInputToCreateNewMapping;
KbScancode mKeyboardScancodeForNewMapping;
MouseBtn mMouseButtonForNewMapping;
};
} // namespace Ship

View File

@@ -0,0 +1,34 @@
#pragma once
#include <cstdint>
#include <string>
#include "ControllerInputMapping.h"
#define MAX_AXIS_RANGE 85.0f
namespace Ship {
enum StickIndex { LEFT_STICK, RIGHT_STICK };
enum Direction { LEFT, RIGHT, UP, DOWN };
class ControllerAxisDirectionMapping : virtual public ControllerInputMapping {
public:
ControllerAxisDirectionMapping(PhysicalDeviceType physicalDeviceType, uint8_t portIndex, StickIndex stickIndex,
Direction direction);
virtual ~ControllerAxisDirectionMapping();
virtual float GetNormalizedAxisDirectionValue() = 0;
virtual int8_t GetMappingType();
virtual std::string GetAxisDirectionMappingId() = 0;
virtual void SaveToConfig() = 0;
virtual void EraseFromConfig() = 0;
Direction GetDirection();
void SetPortIndex(uint8_t portIndex);
protected:
uint8_t mPortIndex;
StickIndex mStickIndex;
Direction mDirection;
};
} // namespace Ship

View File

@@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include <string>
#include "ControllerInputMapping.h"
namespace Ship {
#ifndef CONTROLLERBUTTONS_T
#define CONTROLLERBUTTONS_T uint16_t
#endif
class ControllerButtonMapping : virtual public ControllerInputMapping {
public:
ControllerButtonMapping(PhysicalDeviceType physicalDeviceType, uint8_t portIndex, CONTROLLERBUTTONS_T bitmask);
virtual ~ControllerButtonMapping();
virtual std::string GetButtonMappingId() = 0;
CONTROLLERBUTTONS_T GetBitmask();
virtual void UpdatePad(CONTROLLERBUTTONS_T& padButtons) = 0;
virtual int8_t GetMappingType();
void SetPortIndex(uint8_t portIndex);
virtual void SaveToConfig() = 0;
virtual void EraseFromConfig() = 0;
protected:
uint8_t mPortIndex;
CONTROLLERBUTTONS_T mBitmask;
};
} // namespace Ship

View File

@@ -0,0 +1,81 @@
#pragma once
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <SDL2/SDL.h>
#include "ControllerAxisDirectionMapping.h"
#ifndef CONTROLLERBUTTONS_T
#define CONTROLLERBUTTONS_T uint16_t
#endif
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class ControllerDefaultMappings {
public:
ControllerDefaultMappings(
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<KbScancode>> defaultKeyboardKeyToButtonMappings,
std::unordered_map<StickIndex, std::vector<std::pair<Direction, KbScancode>>>
defaultKeyboardKeyToAxisDirectionMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<SDL_GameControllerButton>>
defaultSDLButtonToButtonMappings,
std::unordered_map<StickIndex, std::vector<std::pair<Direction, SDL_GameControllerButton>>>
defaultSDLButtonToAxisDirectionMappings,
std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::pair<SDL_GameControllerAxis, int32_t>>>
defaultSDLAxisDirectionToButtonMappings,
std::unordered_map<StickIndex, std::vector<std::pair<Direction, std::pair<SDL_GameControllerAxis, int32_t>>>>
defaultSDLAxisDirectionToAxisDirectionMappings);
ControllerDefaultMappings();
~ControllerDefaultMappings();
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<KbScancode>> GetDefaultKeyboardKeyToButtonMappings();
std::unordered_map<StickIndex, std::vector<std::pair<Direction, KbScancode>>>
GetDefaultKeyboardKeyToAxisDirectionMappings();
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<SDL_GameControllerButton>>
GetDefaultSDLButtonToButtonMappings();
std::unordered_map<StickIndex, std::vector<std::pair<Direction, SDL_GameControllerButton>>>
GetDefaultSDLButtonToAxisDirectionMappings();
std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::pair<SDL_GameControllerAxis, int32_t>>>
GetDefaultSDLAxisDirectionToButtonMappings();
std::unordered_map<StickIndex, std::vector<std::pair<Direction, std::pair<SDL_GameControllerAxis, int32_t>>>>
GetDefaultSDLAxisDirectionToAxisDirectionMappings();
protected:
virtual void SetDefaultKeyboardKeyToButtonMappings(
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<KbScancode>> defaultKeyboardKeyToButtonMappings);
virtual void SetDefaultKeyboardKeyToAxisDirectionMappings(
std::unordered_map<StickIndex, std::vector<std::pair<Direction, KbScancode>>>
defaultKeyboardKeyToAxisDirectionMappings);
virtual void SetDefaultSDLButtonToButtonMappings(
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<SDL_GameControllerButton>>
defaultSDLButtonToButtonMappings);
virtual void SetDefaultSDLButtonToAxisDirectionMappings(
std::unordered_map<StickIndex, std::vector<std::pair<Direction, SDL_GameControllerButton>>>
defaultSDLButtonToAxisDirectionMappings);
virtual void SetDefaultSDLAxisDirectionToButtonMappings(
std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::pair<SDL_GameControllerAxis, int32_t>>>
defaultSDLAxisDirectionToButtonMappings);
virtual void SetDefaultSDLAxisDirectionToAxisDirectionMappings(
std::unordered_map<StickIndex, std::vector<std::pair<Direction, std::pair<SDL_GameControllerAxis, int32_t>>>>
defaultSDLAxisDirectionToAxisDirectionMappings);
private:
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<KbScancode>> mDefaultKeyboardKeyToButtonMappings;
std::unordered_map<StickIndex, std::vector<std::pair<Direction, KbScancode>>>
mDefaultKeyboardKeyToAxisDirectionMappings;
std::unordered_map<CONTROLLERBUTTONS_T, std::unordered_set<SDL_GameControllerButton>>
mDefaultSDLButtonToButtonMappings;
std::unordered_map<StickIndex, std::vector<std::pair<Direction, SDL_GameControllerButton>>>
mDefaultSDLButtonToAxisDirectionMappings;
std::unordered_map<CONTROLLERBUTTONS_T, std::vector<std::pair<SDL_GameControllerAxis, int32_t>>>
mDefaultSDLAxisDirectionToButtonMappings;
std::unordered_map<StickIndex, std::vector<std::pair<Direction, std::pair<SDL_GameControllerAxis, int32_t>>>>
mDefaultSDLAxisDirectionToAxisDirectionMappings;
};
} // namespace Ship

View File

@@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <string>
#include "ControllerInputMapping.h"
namespace Ship {
#define GYRO_SENSITIVITY_DEFAULT 100
class ControllerGyroMapping : virtual public ControllerInputMapping {
public:
ControllerGyroMapping(PhysicalDeviceType physicalDeviceType, uint8_t portIndex, float sensitivity);
virtual ~ControllerGyroMapping();
virtual void UpdatePad(float& x, float& y) = 0;
virtual void SaveToConfig() = 0;
virtual void EraseFromConfig() = 0;
virtual void Recalibrate() = 0;
virtual std::string GetGyroMappingId() = 0;
float GetSensitivity();
uint8_t GetSensitivityPercent();
void SetSensitivity(uint8_t sensitivityPercent);
void ResetSensitivityToDefault();
bool SensitivityIsDefault();
void SetPortIndex(uint8_t portIndex);
protected:
uint8_t mPortIndex;
uint8_t mSensitivityPercent;
float mSensitivity;
};
} // namespace Ship

View File

@@ -0,0 +1,14 @@
#pragma once
#include <string>
#include "ControllerMapping.h"
namespace Ship {
class ControllerInputMapping : public ControllerMapping {
public:
ControllerInputMapping(PhysicalDeviceType physicalDeviceType);
~ControllerInputMapping();
virtual std::string GetPhysicalInputName();
};
} // namespace Ship

View File

@@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <string>
#include "ControllerMapping.h"
#include "ship/utils/color.h"
namespace Ship {
#define LED_COLOR_SOURCE_OFF 0
#define LED_COLOR_SOURCE_SET 1
#define LED_COLOR_SOURCE_GAME 2
class ControllerLEDMapping : public ControllerMapping {
public:
ControllerLEDMapping(PhysicalDeviceType physicalDeviceType, uint8_t portIndex, uint8_t colorSource,
Color_RGB8 savedColor);
~ControllerLEDMapping();
void SetColorSource(uint8_t colorSource);
uint8_t GetColorSource();
virtual void SetLEDColor(Color_RGB8 color) = 0;
void SetSavedColor(Color_RGB8 colorToSave);
Color_RGB8 GetSavedColor();
void SetPortIndex(uint8_t portIndex);
virtual std::string GetLEDMappingId() = 0;
virtual void SaveToConfig() = 0;
virtual void EraseFromConfig() = 0;
protected:
uint8_t mPortIndex;
uint8_t mColorSource;
Color_RGB8 mSavedColor;
};
} // namespace Ship

View File

@@ -0,0 +1,23 @@
#pragma once
#include <string>
#include "ship/controller/physicaldevice/PhysicalDeviceType.h"
namespace Ship {
#define MAPPING_TYPE_UNKNOWN -1
#define MAPPING_TYPE_GAMEPAD 0
#define MAPPING_TYPE_KEYBOARD 1
#define MAPPING_TYPE_MOUSE 2
class ControllerMapping {
public:
ControllerMapping(PhysicalDeviceType physicalDeviceType);
~ControllerMapping();
virtual std::string GetPhysicalDeviceName();
PhysicalDeviceType GetPhysicalDeviceType();
protected:
PhysicalDeviceType mPhysicalDeviceType;
};
} // namespace Ship

View File

@@ -0,0 +1,40 @@
#pragma once
#include <cstdint>
#include <string>
#include "ControllerMapping.h"
namespace Ship {
#define DEFAULT_HIGH_FREQUENCY_RUMBLE_PERCENTAGE 50
#define DEFAULT_LOW_FREQUENCY_RUMBLE_PERCENTAGE 50
class ControllerRumbleMapping : public ControllerMapping {
public:
ControllerRumbleMapping(PhysicalDeviceType physicalDeviceType, uint8_t portIndex,
uint8_t lowFrequencyIntensityPercentage, uint8_t highFrequencyIntensityPercentage);
~ControllerRumbleMapping();
virtual void StartRumble() = 0;
virtual void StopRumble() = 0;
virtual void SetLowFrequencyIntensity(uint8_t intensityPercentage);
virtual void SetHighFrequencyIntensity(uint8_t intensityPercentage);
uint8_t GetLowFrequencyIntensityPercentage();
uint8_t GetHighFrequencyIntensityPercentage();
bool HighFrequencyIntensityIsDefault();
bool LowFrequencyIntensityIsDefault();
void ResetHighFrequencyIntensityToDefault();
void ResetLowFrequencyIntensityToDefault();
void SetPortIndex(uint8_t portIndex);
virtual std::string GetRumbleMappingId() = 0;
virtual void SaveToConfig() = 0;
virtual void EraseFromConfig() = 0;
protected:
uint8_t mPortIndex;
uint8_t mLowFrequencyIntensityPercentage;
uint8_t mHighFrequencyIntensityPercentage;
};
} // namespace Ship

View File

@@ -0,0 +1,26 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include <memory>
#include <string>
#include <vector>
namespace Ship {
class AxisDirectionMappingFactory {
public:
static std::shared_ptr<ControllerAxisDirectionMapping>
CreateAxisDirectionMappingFromConfig(uint8_t portIndex, StickIndex stickIndex, std::string id);
static std::vector<std::shared_ptr<ControllerAxisDirectionMapping>>
CreateDefaultKeyboardAxisDirectionMappings(uint8_t portIndex, StickIndex stickIndex);
static std::vector<std::shared_ptr<ControllerAxisDirectionMapping>>
CreateDefaultSDLAxisDirectionMappings(uint8_t portIndex, StickIndex stickIndex);
static std::shared_ptr<ControllerAxisDirectionMapping>
CreateAxisDirectionMappingFromSDLInput(uint8_t portIndex, StickIndex stickIndex, Direction direction);
static std::shared_ptr<ControllerAxisDirectionMapping>
CreateAxisDirectionMappingFromMouseWheelInput(uint8_t portIndex, StickIndex stickIndex, Direction direction);
};
} // namespace Ship

View File

@@ -0,0 +1,25 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include <memory>
#include <string>
#include <vector>
namespace Ship {
class ButtonMappingFactory {
public:
static std::shared_ptr<ControllerButtonMapping> CreateButtonMappingFromConfig(uint8_t portIndex, std::string id);
static std::vector<std::shared_ptr<ControllerButtonMapping>>
CreateDefaultKeyboardButtonMappings(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask);
static std::vector<std::shared_ptr<ControllerButtonMapping>>
CreateDefaultSDLButtonMappings(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask);
static std::shared_ptr<ControllerButtonMapping> CreateButtonMappingFromSDLInput(uint8_t portIndex,
CONTROLLERBUTTONS_T bitmask);
static std::shared_ptr<ControllerButtonMapping> CreateButtonMappingFromMouseWheelInput(uint8_t portIndex,
CONTROLLERBUTTONS_T bitmask);
};
} // namespace Ship

View File

@@ -0,0 +1,13 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerGyroMapping.h"
#include <memory>
#include <string>
namespace Ship {
class GyroMappingFactory {
public:
static std::shared_ptr<ControllerGyroMapping> CreateGyroMappingFromConfig(uint8_t portIndex, std::string id);
static std::shared_ptr<ControllerGyroMapping> CreateGyroMappingFromSDLInput(uint8_t portIndex);
};
} // namespace Ship

View File

@@ -0,0 +1,14 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerLEDMapping.h"
#include <memory>
#include <string>
#include <vector>
namespace Ship {
class LEDMappingFactory {
public:
static std::shared_ptr<ControllerLEDMapping> CreateLEDMappingFromConfig(uint8_t portIndex, std::string id);
static std::shared_ptr<ControllerLEDMapping> CreateLEDMappingFromSDLInput(uint8_t portIndex);
};
} // namespace Ship

View File

@@ -0,0 +1,18 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerRumbleMapping.h"
#include <memory>
#include <string>
#include <vector>
namespace Ship {
class RumbleMappingFactory {
public:
static std::shared_ptr<ControllerRumbleMapping> CreateRumbleMappingFromConfig(uint8_t portIndex, std::string id);
static std::vector<std::shared_ptr<ControllerRumbleMapping>>
CreateDefaultSDLRumbleMappings(PhysicalDeviceType physicalDeviceType, uint8_t portIndex);
static std::shared_ptr<ControllerRumbleMapping> CreateRumbleMappingFromSDLInput(uint8_t portIndex);
};
} // namespace Ship

View File

@@ -0,0 +1,19 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerInputMapping.h"
#include "KeyboardScancodes.h"
namespace Ship {
class KeyboardKeyToAnyMapping : virtual public ControllerInputMapping {
public:
KeyboardKeyToAnyMapping(KbScancode scancode);
virtual ~KeyboardKeyToAnyMapping();
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
protected:
KbScancode mKeyboardScancode;
bool mKeyPressed;
};
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "KeyboardKeyToAnyMapping.h"
namespace Ship {
class KeyboardKeyToAxisDirectionMapping final : public KeyboardKeyToAnyMapping, public ControllerAxisDirectionMapping {
public:
KeyboardKeyToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction,
KbScancode scancode);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
int8_t GetMappingType() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,16 @@
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "KeyboardKeyToAnyMapping.h"
namespace Ship {
class KeyboardKeyToButtonMapping final : public KeyboardKeyToAnyMapping, public ControllerButtonMapping {
public:
KeyboardKeyToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, KbScancode scancode);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
int8_t GetMappingType() override;
std::string GetButtonMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,148 @@
#pragma once
#ifdef __cplusplus
#include <string>
namespace Ship {
#endif
typedef enum KbEventType {
LUS_KB_EVENT_KEY_DOWN = 0,
LUS_KB_EVENT_KEY_UP = 1,
LUS_KB_EVENT_ALL_KEYS_UP = 2,
LUS_KB_EVENT_MAX
} KbEventType;
typedef enum KbScancode {
LUS_KB_UNKNOWN = 0,
LUS_KB_ESCAPE = 1,
LUS_KB_1 = 2,
LUS_KB_2 = 3,
LUS_KB_3 = 4,
LUS_KB_4 = 5,
LUS_KB_5 = 6,
LUS_KB_6 = 7,
LUS_KB_7 = 8,
LUS_KB_8 = 9,
LUS_KB_9 = 10,
LUS_KB_0 = 11,
LUS_KB_OEM_MINUS = 12,
LUS_KB_OEM_PLUS = 13,
LUS_KB_BACKSPACE = 14,
LUS_KB_TAB = 15,
LUS_KB_Q = 16,
LUS_KB_W = 17,
LUS_KB_E = 18,
LUS_KB_R = 19,
LUS_KB_T = 20,
LUS_KB_Y = 21,
LUS_KB_U = 22,
LUS_KB_I = 23,
LUS_KB_O = 24,
LUS_KB_P = 25,
LUS_KB_OEM_4 = 26, // open bracket([)/brace({) on US keyboard
LUS_KB_OEM_6 = 27, // backslash(\)/pipe(|) on US keyboard
LUS_KB_ENTER = 28,
LUS_KB_CONTROL = 29,
LUS_KB_A = 30,
LUS_KB_S = 31,
LUS_KB_D = 32,
LUS_KB_F = 33,
LUS_KB_G = 34,
LUS_KB_H = 35,
LUS_KB_J = 36,
LUS_KB_K = 37,
LUS_KB_L = 38,
LUS_KB_OEM_1 = 39, // semicolon (;)/colon (:) on US keyboard
LUS_KB_OEM_7 = 40, // single quote(')/double quote(") on US keyboard
LUS_KB_OEM_3 = 41, // grave (`)/tilde(~) on US keyboard
LUS_KB_SHIFT = 42,
LUS_KB_OEM_5 = 43, // backslash(\)/pipe(|) on US keyboard
LUS_KB_Z = 44,
LUS_KB_X = 45,
LUS_KB_C = 46,
LUS_KB_V = 47,
LUS_KB_B = 48,
LUS_KB_N = 49,
LUS_KB_M = 50,
LUS_KB_OEM_COMMA = 51,
LUS_KB_OEM_PERIOD = 52,
LUS_KB_OEM_2 = 53, // slash (/)/question mark (?) on US keyboard
LUS_KB_RSHIFT = 54,
LUS_KB_MULTIPLY = 55, // '*' on numpad
LUS_KB_ALT = 56,
LUS_KB_SPACE = 57,
LUS_KB_CAPSLOCK = 58,
LUS_KB_F1 = 59,
LUS_KB_F2 = 60,
LUS_KB_F3 = 61,
LUS_KB_F4 = 62,
LUS_KB_F5 = 63,
LUS_KB_F6 = 64,
LUS_KB_F7 = 65,
LUS_KB_F8 = 66,
LUS_KB_F9 = 67,
LUS_KB_F10 = 68, // Generally inadvised to use this as it's a windows system key.
LUS_KB_PAUSE = 69,
LUS_KB_SCROLL = 70,
LUS_KB_NUMPAD7 = 71,
LUS_KB_NUMPAD8 = 72,
LUS_KB_NUMPAD9 = 73,
LUS_KB_SUBTRACT = 74, // - on numpad
LUS_KB_NUMPAD4 = 75,
LUS_KB_NUMPAD5 = 76,
LUS_KB_NUMPAD6 = 77,
LUS_KB_ADD = 78, // + on numpad
LUS_KB_NUMPAD1 = 79,
LUS_KB_NUMPAD2 = 80,
LUS_KB_NUMPAD3 = 81,
LUS_KB_NUMPAD0 = 82,
LUS_KB_NUMPAD_DEL = 83,
LUS_KB_PRINTSCREEN = 84,
LUS_KB_F11 = 87,
LUS_KB_F12 = 88,
LUS_KB_F13 = 124,
LUS_KB_F14 = 125,
LUS_KB_F15 = 126,
LUS_KB_F16 = 127,
LUS_KB_F17 = 128,
LUS_KB_F18 = 129,
LUS_KB_F19 = 130,
LUS_KB_F20 = 131,
LUS_KB_F21 = 132,
LUS_KB_F22 = 133,
LUS_KB_F23 = 134,
LUS_KB_F24 = 135,
LUS_KB_ARROWKEY_UP = 328,
LUS_KB_ARROWKEY_LEFT = 331,
LUS_KB_ARROWKEY_RIGHT = 333,
LUS_KB_ARROWKEY_DOWN = 336,
LUS_KB_MAX
} KbScancode;
typedef enum MouseBtn {
LUS_MOUSE_BTN_LEFT,
LUS_MOUSE_BTN_MIDDLE,
LUS_MOUSE_BTN_RIGHT,
LUS_MOUSE_BTN_BACKWARD,
LUS_MOUSE_BTN_FORWARD,
LUS_MOUSE_BTN_COUNT,
LUS_MOUSE_BTN_UNKNOWN
} MouseBtn;
typedef enum WheelDirection {
LUS_WHEEL_NONE,
LUS_WHEEL_LEFT,
LUS_WHEEL_RIGHT,
LUS_WHEEL_UP,
LUS_WHEEL_DOWN,
LUS_WHEEL_UNKNOWN
} WheelDirection;
#ifdef __cplusplus
static std::string mouseBtnNames[7] = { "MouseLeft", "MouseMiddle", "MouseRight", "MouseBackward",
"MouseForward", "MOUSE_BTN_COUNT", "MOUSE_BTN_UNKNOWN" };
static std::string wheelDirectionNames[6] = { "LUS_WHEEL_NONE", "WheelLeft", "WheelRight",
"WheelUp", "WheelDown", "LUS_WHEEL_UNKNOWN" };
} // namespace Ship
#endif

View File

@@ -0,0 +1,19 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerInputMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseButtonToAnyMapping : virtual public ControllerInputMapping {
public:
MouseButtonToAnyMapping(MouseBtn button);
virtual ~MouseButtonToAnyMapping();
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
protected:
MouseBtn mButton;
bool mKeyPressed;
};
} // namespace Ship

View File

@@ -0,0 +1,19 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "MouseButtonToAnyMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseButtonToAxisDirectionMapping final : public MouseButtonToAnyMapping, public ControllerAxisDirectionMapping {
public:
MouseButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction, MouseBtn button);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
int8_t GetMappingType() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,19 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "MouseButtonToAnyMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseButtonToButtonMapping final : public MouseButtonToAnyMapping, public ControllerButtonMapping {
public:
MouseButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, MouseBtn button);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
int8_t GetMappingType() override;
std::string GetButtonMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/ControllerInputMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseWheelToAnyMapping : virtual public ControllerInputMapping {
public:
MouseWheelToAnyMapping(WheelDirection wheelDirection);
virtual ~MouseWheelToAnyMapping();
std::string GetPhysicalInputName() override;
std::string GetPhysicalDeviceName() override;
protected:
WheelDirection mWheelDirection;
};
} // namespace Ship

View File

@@ -0,0 +1,20 @@
#pragma once
#include "MouseWheelToAnyMapping.h"
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseWheelToAxisDirectionMapping final : public MouseWheelToAnyMapping, public ControllerAxisDirectionMapping {
public:
MouseWheelToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction,
WheelDirection wheelDirection);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
int8_t GetMappingType() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,19 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/mouse/MouseWheelToAnyMapping.h"
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
class MouseWheelToButtonMapping final : public MouseWheelToAnyMapping, public ControllerButtonMapping {
public:
MouseWheelToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, WheelDirection wheelDirection);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
int8_t GetMappingType() override;
std::string GetButtonMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,36 @@
#pragma once
#include <memory>
#include "ship/window/Window.h"
#include "ship/controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
namespace Ship {
struct WheelDirections {
WheelDirection x;
WheelDirection y;
};
class WheelHandler {
public:
WheelHandler();
~WheelHandler();
static std::shared_ptr<WheelHandler> GetInstance();
void Update();
CoordsF GetCoords();
WheelDirections GetDirections();
float GetDirectionValue(WheelDirection direction);
float GetBufferedDirectionValue(WheelDirection direction);
private:
float CalcDirectionValue(CoordsF& coords, WheelDirection direction);
void UpdateAxisBuffer(float* buf, float input);
static std::shared_ptr<WheelHandler> mInstance;
WheelDirections mDirections;
CoordsF mCoords;
CoordsF mBufferedCoords;
};
} // namespace Ship

View File

@@ -0,0 +1,20 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/sdl/SDLMapping.h"
#include "ship/controller/controldevice/controller/mapping/ControllerInputMapping.h"
namespace Ship {
class SDLAxisDirectionToAnyMapping : virtual public ControllerInputMapping {
public:
SDLAxisDirectionToAnyMapping(int32_t sdlControllerAxis, int32_t axisDirection);
virtual ~SDLAxisDirectionToAnyMapping();
std::string GetPhysicalInputName() override;
std::string GetPhysicalDeviceName() override;
bool AxisIsTrigger();
bool AxisIsStick();
protected:
SDL_GameControllerAxis mControllerAxis;
AxisDirection mAxisDirection;
};
} // namespace Ship

View File

@@ -0,0 +1,18 @@
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "SDLAxisDirectionToAnyMapping.h"
namespace Ship {
class SDLAxisDirectionToAxisDirectionMapping final : public ControllerAxisDirectionMapping,
public SDLAxisDirectionToAnyMapping {
public:
SDLAxisDirectionToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction,
int32_t sdlControllerAxis, int32_t axisDirection);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
int8_t GetMappingType() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "ship/controller/controldevice/controller/mapping/sdl/SDLAxisDirectionToAnyMapping.h"
namespace Ship {
class SDLAxisDirectionToButtonMapping final : public ControllerButtonMapping, public SDLAxisDirectionToAnyMapping {
public:
SDLAxisDirectionToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, int32_t sdlControllerAxis,
int32_t axisDirection);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
int8_t GetMappingType() override;
std::string GetButtonMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,20 @@
#pragma once
#include "ship/controller/controldevice/controller/mapping/sdl/SDLMapping.h"
#include "ship/controller/controldevice/controller/mapping/ControllerInputMapping.h"
namespace Ship {
class SDLButtonToAnyMapping : virtual public ControllerInputMapping {
public:
SDLButtonToAnyMapping(int32_t sdlControllerButton);
virtual ~SDLButtonToAnyMapping();
std::string GetPhysicalInputName() override;
std::string GetPhysicalDeviceName() override;
protected:
SDL_GameControllerButton mControllerButton;
private:
std::string GetGenericButtonName();
};
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#include "ship/controller/controldevice/controller/mapping/ControllerAxisDirectionMapping.h"
#include "SDLButtonToAnyMapping.h"
namespace Ship {
class SDLButtonToAxisDirectionMapping final : public ControllerAxisDirectionMapping, public SDLButtonToAnyMapping {
public:
SDLButtonToAxisDirectionMapping(uint8_t portIndex, StickIndex stickIndex, Direction direction,
int32_t sdlControllerButton);
float GetNormalizedAxisDirectionValue() override;
std::string GetAxisDirectionMappingId() override;
int8_t GetMappingType() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,16 @@
#include "ship/controller/controldevice/controller/mapping/ControllerButtonMapping.h"
#include "ship/controller/controldevice/controller/mapping/sdl/SDLButtonToAnyMapping.h"
namespace Ship {
class SDLButtonToButtonMapping final : public SDLButtonToAnyMapping, public ControllerButtonMapping {
public:
SDLButtonToButtonMapping(uint8_t portIndex, CONTROLLERBUTTONS_T bitmask, int32_t sdlControllerButton);
void UpdatePad(CONTROLLERBUTTONS_T& padButtons) override;
int8_t GetMappingType() override;
std::string GetButtonMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
std::string GetPhysicalInputName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,21 @@
#include "ship/controller/controldevice/controller/mapping/ControllerGyroMapping.h"
#include "SDLMapping.h"
namespace Ship {
class SDLGyroMapping final : public ControllerGyroMapping {
public:
SDLGyroMapping(uint8_t portIndex, float sensitivity, float neutralPitch, float neutralYaw, float neutralRoll);
void UpdatePad(float& x, float& y) override;
void SaveToConfig() override;
void EraseFromConfig() override;
void Recalibrate() override;
std::string GetGyroMappingId() override;
std::string GetPhysicalDeviceName() override;
private:
float mNeutralPitch;
float mNeutralYaw;
float mNeutralRoll;
};
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#include "ship/controller/controldevice/controller/mapping/ControllerLEDMapping.h"
#include "SDLMapping.h"
namespace Ship {
class SDLLEDMapping final : public ControllerLEDMapping {
public:
SDLLEDMapping(uint8_t portIndex, uint8_t colorSource, Color_RGB8 savedColor);
void SetLEDColor(Color_RGB8 color) override;
std::string GetLEDMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
};
} // namespace Ship

View File

@@ -0,0 +1,10 @@
#pragma once
#include <SDL2/SDL.h>
namespace Ship {
enum Axis { X = 0, Y = 1 };
enum AxisDirection { NEGATIVE = -1, POSITIVE = 1 };
} // namespace Ship

View File

@@ -0,0 +1,25 @@
#include "ship/controller/controldevice/controller/mapping/ControllerRumbleMapping.h"
#include "SDLMapping.h"
namespace Ship {
class SDLRumbleMapping final : public ControllerRumbleMapping {
public:
SDLRumbleMapping(uint8_t portIndex, uint8_t lowFrequencyIntensityPercentage,
uint8_t highFrequencyIntensityPercentage);
void StartRumble() override;
void StopRumble() override;
void SetLowFrequencyIntensity(uint8_t intensityPercentage) override;
void SetHighFrequencyIntensity(uint8_t intensityPercentage) override;
std::string GetRumbleMappingId() override;
void SaveToConfig() override;
void EraseFromConfig() override;
std::string GetPhysicalDeviceName() override;
private:
uint16_t mLowFrequencyIntensity;
uint16_t mHighFrequencyIntensity;
};
} // namespace Ship

View File

@@ -0,0 +1,32 @@
#pragma once
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
#include <SDL2/SDL.h>
namespace Ship {
class ConnectedPhysicalDeviceManager {
public:
ConnectedPhysicalDeviceManager();
~ConnectedPhysicalDeviceManager();
std::unordered_map<int32_t, SDL_GameController*> GetConnectedSDLGamepadsForPort(uint8_t portIndex);
std::unordered_map<int32_t, std::string> GetConnectedSDLGamepadNames();
std::unordered_set<int32_t> GetIgnoredInstanceIdsForPort(uint8_t portIndex);
bool PortIsIgnoringInstanceId(uint8_t portIndex, int32_t instanceId);
void IgnoreInstanceIdForPort(uint8_t portIndex, int32_t instanceId);
void UnignoreInstanceIdForPort(uint8_t portIndex, int32_t instanceId);
void HandlePhysicalDeviceConnect(int32_t sdlDeviceIndex);
void HandlePhysicalDeviceDisconnect(int32_t sdlJoystickInstanceId);
void RefreshConnectedSDLGamepads();
private:
std::unordered_map<int32_t, SDL_GameController*> mConnectedSDLGamepads;
std::unordered_map<int32_t, std::string> mConnectedSDLGamepadNames;
std::unordered_map<uint8_t, std::unordered_set<int32_t>> mIgnoredInstanceIds;
};
} // namespace Ship

View File

@@ -0,0 +1,25 @@
#pragma once
#include <cstdint>
namespace Ship {
class GlobalSDLDeviceSettings {
public:
GlobalSDLDeviceSettings();
~GlobalSDLDeviceSettings();
int32_t GetStickAxisThresholdPercentage();
void SetStickAxisThresholdPercentage(int32_t stickAxisThresholdPercentage);
int32_t GetTriggerAxisThresholdPercentage();
void SetTriggerAxisThresholdPercentage(int32_t triggerAxisThresholdPercentage);
void SaveToConfig();
void EraseFromConfig();
private:
int32_t mStickAxisThresholdPercentage;
int32_t mTriggerAxisThresholdPercentage;
};
} // namespace Ship

View File

@@ -0,0 +1,7 @@
#pragma once
namespace Ship {
enum PhysicalDeviceType { Keyboard = 0, Mouse = 1, SDLGamepad = 2, Max = 3 };
} // namespace Ship

View File

@@ -0,0 +1,17 @@
#pragma once
#include "ship/window/gui/GuiWindow.h"
namespace Ship {
class SDLAddRemoveDeviceEventHandler : public GuiWindow {
public:
using GuiWindow::GuiWindow;
virtual ~SDLAddRemoveDeviceEventHandler();
protected:
void InitElement() override;
void DrawElement() override;
void UpdateElement() override;
};
} // namespace Ship