diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 4a423e5e3..8d66a0211 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -4,6 +4,7 @@ #include "GameExtractor.h" #include "ui/ImguiUI.h" #include "libultraship/src/Context.h" +#include "libultraship/src/controller/controldevice/controller/mapping/ControllerDefaultMappings.h" #include "resource/type/ResourceType.h" #include "resource/importers/GenericArrayFactory.h" #include "resource/importers/AudioBankFactory.h" @@ -112,7 +113,60 @@ GameEngine::GameEngine() { this->context->InitConsoleVariables(); // without this line the controldeck constructor failes in // ShipDeviceIndexMappingManager::UpdateControllerNamesFromConfig() - auto controlDeck = std::make_shared(); + auto defaultMappings = std::make_shared( + // KeyboardKeyToButtonMappings + std::unordered_map>{ + { BTN_A, { Ship::KbScancode::LUS_KB_SHIFT} }, + { BTN_B, { Ship::KbScancode::LUS_KB_CONTROL} }, + { BTN_L, { Ship::KbScancode::LUS_KB_Q} }, + { BTN_R, { Ship::KbScancode::LUS_KB_SPACE} }, + { BTN_Z, { Ship::KbScancode::LUS_KB_Z} }, + { BTN_START, { Ship::KbScancode::LUS_KB_ENTER} }, + { BTN_CUP, { Ship::KbScancode::LUS_KB_T} }, + { BTN_CDOWN, { Ship::KbScancode::LUS_KB_G} }, + { BTN_CLEFT, { Ship::KbScancode::LUS_KB_F} }, + { BTN_CRIGHT, { Ship::KbScancode::LUS_KB_H} }, + { BTN_DUP, { Ship::KbScancode::LUS_KB_NUMPAD8} }, + { BTN_DDOWN, { Ship::KbScancode::LUS_KB_NUMPAD2} }, + { BTN_DLEFT, { Ship::KbScancode::LUS_KB_NUMPAD4} }, + { BTN_DRIGHT, { Ship::KbScancode::LUS_KB_NUMPAD6} } + }, + // KeyboardKeyToAxisDirectionMappings - use built-in LUS defaults + std::unordered_map>>{ + { Ship::StickIndex::LEFT_STICK, { + { Ship::Direction::UP, Ship::KbScancode::LUS_KB_ARROWKEY_UP}, + { Ship::Direction::DOWN, Ship::KbScancode::LUS_KB_ARROWKEY_DOWN}, + { Ship::Direction::LEFT, Ship::KbScancode::LUS_KB_ARROWKEY_LEFT}, + { Ship::Direction::RIGHT, Ship::KbScancode::LUS_KB_ARROWKEY_RIGHT} + }} + }, + // SDLButtonToButtonMappings + std::unordered_map>{ + { BTN_A, { SDL_CONTROLLER_BUTTON_A } }, + { BTN_B, { SDL_CONTROLLER_BUTTON_X } }, + { BTN_START, { SDL_CONTROLLER_BUTTON_START } }, + { BTN_CLEFT, { SDL_CONTROLLER_BUTTON_Y } }, + { BTN_CDOWN, { SDL_CONTROLLER_BUTTON_B } }, + { BTN_DUP, { SDL_CONTROLLER_BUTTON_DPAD_UP } }, + { BTN_DDOWN, { SDL_CONTROLLER_BUTTON_DPAD_DOWN } }, + { BTN_DLEFT, { SDL_CONTROLLER_BUTTON_DPAD_LEFT } }, + { BTN_DRIGHT, { SDL_CONTROLLER_BUTTON_DPAD_RIGHT } }, + { BTN_R, { SDL_CONTROLLER_BUTTON_RIGHTSHOULDER } }, + { BTN_L, { SDL_CONTROLLER_BUTTON_LEFTSHOULDER } } + }, + // SDLButtonToAxisDirectionMappings - use built-in LUS defaults + std::unordered_map>>(), + // SDLAxisDirectionToButtonMappings + std::unordered_map>>{ + { BTN_R, { { SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 1 } } }, + { BTN_Z, { { SDL_CONTROLLER_AXIS_TRIGGERLEFT, 1 } } }, + { BTN_CUP, { { SDL_CONTROLLER_AXIS_RIGHTY, -1 } } }, + { BTN_CRIGHT, { { SDL_CONTROLLER_AXIS_RIGHTX, 1 } } } + }, + // SDLAxisDirectionToAxisDirectionMappings - use built-in LUS defaults + std::unordered_map>>>() + ); + auto controlDeck = std::make_shared(std::vector(), defaultMappings); this->context->InitResourceManager(archiveFiles, {}, 3); // without this line InitWindow fails in Gui::Init() this->context->InitConsole(); // without this line the GuiWindow constructor fails in ConsoleWindow::InitElement() @@ -744,4 +798,4 @@ extern "C" uint32_t OTRGetGameViewportWidth() { extern "C" uint32_t OTRGetGameViewportHeight() { return GetInterpreter()->mGameWindowViewport.height; -} \ No newline at end of file +}