* Initial controller hud ui * Reverted fbdemo changes * Moved config to json and implemented controller config * fix build on linux, gitignore new config file * fix build * Fix compilation and file directory paths * Call save on cvar save * Fixed cvar loading and added deck slots to the config * Changed control deck port 0 to use a physical device by default * Added gyro and rumble & fixed loading errors * Save config on toggle menubar * fix linux build * Fixed drift calculation * Controller config now saves when pressing F1 * Removed ExitGame hook from ImGuiImpl * Moved mappings to a map * Added GetKeyName * untranslate scancodes * Fixed hud layout on keyboard device * Fixed keyboard read on hud * Fixed crash when reloading controllers * Removed ConfigFile and changed file extension * Changed Dummy to Disconnected and fixed filters * Removed function leftover * Changed ControllerHud to InputEditor Co-authored-by: briaguya <briaguya@alice> Co-authored-by: David Chavez <david@dcvz.io>
88 lines
1.9 KiB
C++
88 lines
1.9 KiB
C++
#include "Controller.h"
|
|
#include <memory>
|
|
#include <algorithm>
|
|
#if __APPLE__
|
|
#include <SDL_events.h>
|
|
#else
|
|
#include <SDL2/SDL_events.h>
|
|
#endif
|
|
|
|
namespace Ship {
|
|
|
|
Controller::Controller() : isRumbling(false), wStickX(0), wStickY(0), wGyroX(0), wGyroY(0), dwPressedButtons(0){
|
|
Attachment = nullptr;
|
|
profiles.resize(MAXCONTROLLERS);
|
|
for(int slot = 0; slot < MAXCONTROLLERS; slot++) {
|
|
dwPressedButtons.push_back(0);
|
|
}
|
|
}
|
|
|
|
void Controller::Read(OSContPad* pad, int32_t slot) {
|
|
ReadFromSource(slot);
|
|
|
|
SDL_PumpEvents();
|
|
|
|
// Button Inputs
|
|
pad->button |= dwPressedButtons[slot] & 0xFFFF;
|
|
|
|
// Stick Inputs
|
|
if (pad->stick_x == 0) {
|
|
if (dwPressedButtons[slot] & BTN_STICKLEFT) {
|
|
pad->stick_x = -128;
|
|
}
|
|
else if (dwPressedButtons[slot] & BTN_STICKRIGHT) {
|
|
pad->stick_x = 127;
|
|
}
|
|
else {
|
|
pad->stick_x = wStickX;
|
|
}
|
|
}
|
|
|
|
if (pad->stick_y == 0) {
|
|
if (dwPressedButtons[slot] & BTN_STICKDOWN) {
|
|
pad->stick_y = -128;
|
|
}
|
|
else if (dwPressedButtons[slot] & BTN_STICKUP) {
|
|
pad->stick_y = 127;
|
|
}
|
|
else {
|
|
pad->stick_y = wStickY;
|
|
}
|
|
}
|
|
|
|
// Stick Inputs
|
|
if (pad->cam_x == 0) {
|
|
if (dwPressedButtons[slot] & BTN_VSTICKLEFT) {
|
|
pad->cam_x = -128 * 10.0f;
|
|
}
|
|
else if (dwPressedButtons[slot] & BTN_VSTICKRIGHT) {
|
|
pad->cam_x = 127 * 10.0f;
|
|
}
|
|
else {
|
|
pad->cam_x = wCamX;
|
|
}
|
|
}
|
|
if (pad->cam_y == 0) {
|
|
if (dwPressedButtons[slot] & BTN_VSTICKDOWN) {
|
|
pad->cam_y = -128 * 10.0f;
|
|
}
|
|
else if (dwPressedButtons[slot] & BTN_VSTICKUP) {
|
|
pad->cam_y = 127 * 10.0f;
|
|
}
|
|
else {
|
|
pad->cam_y = wCamY;
|
|
}
|
|
}
|
|
|
|
// Gyro
|
|
pad->gyro_x = wGyroX;
|
|
pad->gyro_y = wGyroY;
|
|
}
|
|
|
|
void Controller::SetButtonMapping(int slot, int32_t n64Button, int32_t dwScancode) {
|
|
std::map<int32_t, int32_t>& Mappings = profiles[slot].Mappings;
|
|
std::erase_if(Mappings, [n64Button](const std::pair<int32_t, int32_t>& bin) { return bin.second == n64Button; });
|
|
Mappings[dwScancode] = n64Button;
|
|
}
|
|
}
|