Skip to content

Commit

Permalink
gotta mess with the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
briaguya-ai committed Jan 19, 2025
1 parent e5babe3 commit 4cf2d50
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 1,369 deletions.
6 changes: 0 additions & 6 deletions src/controller/controldeck/ControlDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include "utils/StringHelper.h"
#include "public/bridge/consolevariablebridge.h"
#include <imgui.h>
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h"

namespace Ship {

ControlDeck::ControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) : mSinglePlayerMappingMode(false) {
mDeviceIndexMappingManager = std::make_shared<ShipDeviceIndexMappingManager>();
mConnectedPhysicalDeviceManager = std::make_shared<ConnectedPhysicalDeviceManager>();
}

Expand Down Expand Up @@ -106,10 +104,6 @@ void ControlDeck::UnblockGameInput(int32_t blockId) {
mGameInputBlockers.erase(blockId);
}

std::shared_ptr<ShipDeviceIndexMappingManager> ControlDeck::GetDeviceIndexMappingManager() {
return mDeviceIndexMappingManager;
}

std::shared_ptr<ConnectedPhysicalDeviceManager> ControlDeck::GetConnectedPhysicalDeviceManager() {
return mConnectedPhysicalDeviceManager;
}
Expand Down
3 changes: 0 additions & 3 deletions src/controller/controldeck/ControlDeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <vector>
#include <config/Config.h>
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
#include "controller/physicaldevice/ConnectedPhysicalDeviceManager.h"

namespace Ship {
Expand All @@ -28,7 +27,6 @@ class ControlDeck {
bool ProcessKeyboardEvent(KbEventType eventType, KbScancode scancode);
bool ProcessMouseButtonEvent(bool isPressed, MouseBtn button);

std::shared_ptr<ShipDeviceIndexMappingManager> GetDeviceIndexMappingManager();
std::shared_ptr<ConnectedPhysicalDeviceManager> GetConnectedPhysicalDeviceManager();

protected:
Expand All @@ -39,7 +37,6 @@ class ControlDeck {
uint8_t* mControllerBits = nullptr;
bool mSinglePlayerMappingMode;
std::unordered_map<int32_t, bool> mGameInputBlockers;
std::shared_ptr<ShipDeviceIndexMappingManager> mDeviceIndexMappingManager;
std::shared_ptr<ConnectedPhysicalDeviceManager> mConnectedPhysicalDeviceManager;
};
} // namespace Ship
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "utils/StringHelper.h"
#include "libultraship/libultra/controller.h"
#include "Context.h"
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"

namespace Ship {
std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFromConfig(uint8_t portIndex,
Expand Down Expand Up @@ -46,66 +45,68 @@ std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFrom
std::shared_ptr<ControllerGyroMapping> GyroMappingFactory::CreateGyroMappingFromSDLInput(uint8_t portIndex) {
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithGyro;
std::shared_ptr<ControllerGyroMapping> mapping = nullptr;
for (auto [lusIndex, indexMapping] :
Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);

if (sdlIndexMapping == nullptr) {
// this LUS index isn't mapped to an SDL index
continue;
}

auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();

if (!SDL_IsGameController(sdlIndex)) {
// this SDL device isn't a game controller
continue;
}

auto controller = SDL_GameControllerOpen(sdlIndex);
if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)) {
sdlControllersWithGyro[lusIndex] = SDL_GameControllerOpen(sdlIndex);
} else {
SDL_GameControllerClose(controller);
}
}

for (auto [lusIndex, controller] : sdlControllersWithGyro) {
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
mapping->Recalibrate();
break;
}
}

if (mapping != nullptr) {
break;
}

for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
const auto axis = static_cast<SDL_GameControllerAxis>(i);
const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
int32_t axisDirection = 0;
if (axisValue < -0.7f) {
axisDirection = NEGATIVE;
} else if (axisValue > 0.7f) {
axisDirection = POSITIVE;
}

if (axisDirection == 0) {
continue;
}

mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
mapping->Recalibrate();
break;
}
}

for (auto [i, controller] : sdlControllersWithGyro) {
SDL_GameControllerClose(controller);
}
// todo: gyro
// for (auto [lusIndex, indexMapping] :
// Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
// auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);

// if (sdlIndexMapping == nullptr) {
// // this LUS index isn't mapped to an SDL index
// continue;
// }

// auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();

// if (!SDL_IsGameController(sdlIndex)) {
// // this SDL device isn't a game controller
// continue;
// }

// auto controller = SDL_GameControllerOpen(sdlIndex);
// if (SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)) {
// sdlControllersWithGyro[lusIndex] = SDL_GameControllerOpen(sdlIndex);
// } else {
// SDL_GameControllerClose(controller);
// }
// }

// for (auto [lusIndex, controller] : sdlControllersWithGyro) {
// for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
// if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
// mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
// mapping->Recalibrate();
// break;
// }
// }

// if (mapping != nullptr) {
// break;
// }

// for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
// const auto axis = static_cast<SDL_GameControllerAxis>(i);
// const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
// int32_t axisDirection = 0;
// if (axisValue < -0.7f) {
// axisDirection = NEGATIVE;
// } else if (axisValue > 0.7f) {
// axisDirection = POSITIVE;
// }

// if (axisDirection == 0) {
// continue;
// }

// mapping = std::make_shared<SDLGyroMapping>(portIndex, 1.0f, 0.0f, 0.0f, 0.0f);
// mapping->Recalibrate();
// break;
// }
// }

// for (auto [i, controller] : sdlControllersWithGyro) {
// SDL_GameControllerClose(controller);
// }

return mapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "utils/StringHelper.h"
#include "libultraship/libultra/controller.h"
#include "Context.h"
#include "controller/deviceindex/ShipDeviceIndexToSDLDeviceIndexMapping.h"

namespace Ship {
std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromConfig(uint8_t portIndex, std::string id) {
Expand Down Expand Up @@ -44,64 +43,66 @@ std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromCon
std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromSDLInput(uint8_t portIndex) {
std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithLEDs;
std::shared_ptr<ControllerLEDMapping> mapping = nullptr;
for (auto [lusIndex, indexMapping] :
Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);

if (sdlIndexMapping == nullptr) {
// this LUS index isn't mapped to an SDL index
continue;
}

auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();

if (!SDL_IsGameController(sdlIndex)) {
// this SDL device isn't a game controller
continue;
}

auto controller = SDL_GameControllerOpen(sdlIndex);
if (SDL_GameControllerHasLED(controller)) {
sdlControllersWithLEDs[lusIndex] = SDL_GameControllerOpen(sdlIndex);
} else {
SDL_GameControllerClose(controller);
}
}

for (auto [lusIndex, controller] : sdlControllersWithLEDs) {
for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
break;
}
}

if (mapping != nullptr) {
break;
}

for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
const auto axis = static_cast<SDL_GameControllerAxis>(i);
const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
int32_t axisDirection = 0;
if (axisValue < -0.7f) {
axisDirection = NEGATIVE;
} else if (axisValue > 0.7f) {
axisDirection = POSITIVE;
}

if (axisDirection == 0) {
continue;
}

mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
break;
}
}

for (auto [i, controller] : sdlControllersWithLEDs) {
SDL_GameControllerClose(controller);
}
// todo: LEDs
// for (auto [lusIndex, indexMapping] :
// Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
// auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);

// if (sdlIndexMapping == nullptr) {
// // this LUS index isn't mapped to an SDL index
// continue;
// }

// auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();

// if (!SDL_IsGameController(sdlIndex)) {
// // this SDL device isn't a game controller
// continue;
// }

// auto controller = SDL_GameControllerOpen(sdlIndex);
// if (SDL_GameControllerHasLED(controller)) {
// sdlControllersWithLEDs[lusIndex] = SDL_GameControllerOpen(sdlIndex);
// } else {
// SDL_GameControllerClose(controller);
// }
// }

// for (auto [lusIndex, controller] : sdlControllersWithLEDs) {
// for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
// if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
// mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
// break;
// }
// }

// if (mapping != nullptr) {
// break;
// }

// for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
// const auto axis = static_cast<SDL_GameControllerAxis>(i);
// const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
// int32_t axisDirection = 0;
// if (axisValue < -0.7f) {
// axisDirection = NEGATIVE;
// } else if (axisValue > 0.7f) {
// axisDirection = POSITIVE;
// }

// if (axisDirection == 0) {
// continue;
// }

// mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
// break;
// }
// }

// for (auto [i, controller] : sdlControllersWithLEDs) {
// SDL_GameControllerClose(controller);
// }

return mapping;
}
Expand Down
Loading

0 comments on commit 4cf2d50

Please sign in to comment.