diff --git a/src/common/JoyHatMap.cxx b/src/common/JoyHatMap.cxx index a000eb9c2..6f480ddc4 100644 --- a/src/common/JoyHatMap.cxx +++ b/src/common/JoyHatMap.cxx @@ -17,12 +17,6 @@ #include "JoyHatMap.hxx" -// TODOs -// - two maps per controller (joydirs, hatdirs) -// - both maps combined with buttons -// - directions can work alone and with a button combination -// - buttons can work without a direction (mapped in joydir) - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - JoyHatMap::JoyHatMap(void) { @@ -91,8 +85,6 @@ string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping { ostringstream buf; - //buf << "J" << mapping.stick; - // hat description if (mapping.hat != JOY_CTRL_NONE) { @@ -158,7 +150,7 @@ string JoyHatMap::saveMapping(const EventMode mode) const { if (buf.str() != "") buf << "|"; - buf << item.second << ":" /*<< item.first.stick*/ << "," << + buf << item.second << ":" << item.first.button << "," << item.first.hat << "," << int(item.first.hdir); } } @@ -174,9 +166,9 @@ int JoyHatMap::loadMapping(string & list, const EventMode mode) std::replace(list.begin(), list.end(), ':', ' '); std::replace(list.begin(), list.end(), ',', ' '); istringstream buf(list); - int event, stick, button, hat, hdir, i = 0; + int event, button, hat, hdir, i = 0; - while (buf >> event && buf >> stick && buf >> button && buf >> hat && buf >> hdir && ++i) + while (buf >> event && buf >> button && buf >> hat && buf >> hdir && ++i) add(Event::Type(event), EventMode(mode), button, hat, JoyHat(hdir)); return i; diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 311b552da..945091688 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -17,12 +17,6 @@ #include "JoyMap.hxx" -// TODOs -// - two maps per controller (joydirs, hatdirs) -// - both maps combined with buttons -// - directions can work alone and with a button combination -// - buttons can work without a direction (mapped in joydir) - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - JoyMap::JoyMap(void) { @@ -183,9 +177,9 @@ int JoyMap::loadMapping(string& list, const EventMode mode) std::replace(list.begin(), list.end(), ':', ' '); std::replace(list.begin(), list.end(), ',', ' '); istringstream buf(list); - int event, stick, button, axis, adir, i = 0; + int event, button, axis, adir, i = 0; - while (buf >> event && buf >> stick && buf >> button + while (buf >> event && buf >> button && buf >> axis && buf >> adir && ++i) add(Event::Type(event), EventMode(mode), button, JoyAxis(axis), JoyDir(adir)); diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 47d598c95..8d3158611 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -27,6 +27,8 @@ #include "DialogContainer.hxx" #endif +static constexpr char CTRL_DELIM = '^'; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PhysicalJoystickHandler::PhysicalJoystickHandler( OSystem& system, EventHandler& handler, Event& event) @@ -40,14 +42,14 @@ PhysicalJoystickHandler::PhysicalJoystickHandler( string joymap, joyname; // First compare if event list version has changed, and disregard the entire mapping if true - getline(buf, joymap, '^'); // event list size, ignore + getline(buf, joymap, CTRL_DELIM); // event list size, ignore if(version != Event::VERSION) { // Otherwise, put each joystick mapping entry into the database - while(getline(buf, joymap, '^')) + while(getline(buf, joymap, CTRL_DELIM)) { istringstream namebuf(joymap); - getline(namebuf, joyname, '|'); + getline(namebuf, joyname, PhysicalJoystick::MODE_DELIM); if(joyname.length() != 0) myDatabase.emplace(joyname, StickInfo(joymap)); } @@ -205,6 +207,12 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport) for(auto& stick: mySticks) { + // remove previously added emulated ports + size_t pos = stick.second->name.find(" (emulates "); + + if (pos != std::string::npos) + stick.second->name.erase(pos); + if(BSPF::startsWithIgnoreCase(stick.second->name, "Stelladaptor")) { if(saOrder[saCount] == 1) @@ -254,26 +262,17 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, auto setDefaultAxis = [&](Event::Type a_event, int stick, JoyAxis axis, JoyDir value, int button = JOY_CTRL_NONE) { if (eraseAll || a_event == event) - { - //myHandler.addJoyAxisMapping(a_event, mode, stick, int(axis), int(value), false); myHandler.addJoyMapping(a_event, mode, stick, button, axis, int(value), false); - } }; auto setDefaultBtn = [&](Event::Type b_event, int stick, int button) { if (eraseAll || b_event == event) - { - //myHandler.addJoyButtonMapping(b_event, mode, stick, button, false); myHandler.addJoyMapping(b_event, mode, stick, button, JoyAxis::NONE, int(JoyDir::NONE), false); - } }; auto setDefaultHat = [&](Event::Type h_event, int stick, int hat, JoyHat dir, int button = JOY_CTRL_NONE) { if (eraseAll || h_event == event) - { - //myHandler.addJoyHatMapping(h_event, mode, stick, hat, dir, false); myHandler.addJoyHatMapping(h_event, mode, stick, button, hat, dir, false); - } }; switch(mode) @@ -386,14 +385,12 @@ void PhysicalJoystickHandler::saveMapping() // Save the joystick mapping hash table, making sure to update it with // any changes that have been made during the program run ostringstream joybuf; - //joybuf << Event::LastType; for(const auto& i: myDatabase) { const string& map = i.second.joy ? i.second.joy->getMap() : i.second.mapping; if(map != "") - //joybuf << "^" << map; - joybuf << map; + joybuf << CTRL_DELIM << map; } myOSystem.settings().setValue("joymap", joybuf.str()); } @@ -467,6 +464,8 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode // new: //Joystick button + axis mapping / labeling + if (buf.str() != "") + buf << ", "; if (j->joyMap.getEventMapping(event, mode).size()) buf << j->joyMap.getEventMappingDesc(stick, event, mode); // Joystick hat mapping/labeling @@ -564,7 +563,8 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::POS))) j->joyMap.erase(mode, button, axis, JoyDir::POS); - j->joyMap.add(event, mode, button, axis, value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG); + j->joyMap.add(event, mode, button, axis, + value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG); } return true; } @@ -591,104 +591,106 @@ bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) { const PhysicalJoystickPtr j = joy(stick); - if(!j) return; - // Stelladaptors handle axis differently than regular joysticks - switch(j->type) + if (j) { - case PhysicalJoystick::JT_REGULAR: - if(myHandler.state() == EventHandlerState::EMULATION) - { - // Every axis event has two associated values, negative and positive - //Event::Type eventAxisNeg = j->axisTable[axis][int(JoyDir::NEG)][kEmulationMode]; - //Event::Type eventAxisPos = j->axisTable[axis][int(JoyDir::POS)][kEmulationMode]; - Event::Type eventAxisNeg = j->joyMap.get(kEmulationMode, j->buttonLast[stick], JoyAxis(axis), JoyDir::NEG); - Event::Type eventAxisPos = j->joyMap.get(kEmulationMode, j->buttonLast[stick], JoyAxis(axis), JoyDir::POS); + int button = j->buttonLast[stick]; - // Check for analog events, which are handled differently - // We'll pass them off as Stelladaptor events, and let the controllers - // handle it - switch(int(eventAxisNeg)) + // Stelladaptors handle axis differently than regular joysticks + switch (j->type) + { + case PhysicalJoystick::JT_REGULAR: + if (myHandler.state() == EventHandlerState::EMULATION) { - case Event::PaddleZeroAnalog: - myEvent.set(Event::SALeftAxis0Value, value); - break; - case Event::PaddleOneAnalog: - myEvent.set(Event::SALeftAxis1Value, value); - break; - case Event::PaddleTwoAnalog: - myEvent.set(Event::SARightAxis0Value, value); - break; - case Event::PaddleThreeAnalog: - myEvent.set(Event::SARightAxis1Value, value); - break; - default: - { - // Otherwise, we know the event is digital - if(value > Joystick::deadzone()) - myHandler.handleEvent(eventAxisPos); - else if(value < -Joystick::deadzone()) - myHandler.handleEvent(eventAxisNeg); - else - { - // Treat any deadzone value as zero - value = 0; + // Every axis event has two associated values, negative and positive + Event::Type eventAxisNeg = j->joyMap.get(kEmulationMode, button, JoyAxis(axis), JoyDir::NEG); + Event::Type eventAxisPos = j->joyMap.get(kEmulationMode, button, JoyAxis(axis), JoyDir::POS); - // Now filter out consecutive, similar values - // (only pass on the event if the state has changed) - if(j->axisLastValue[axis] != value) + // Check for analog events, which are handled differently + // We'll pass them off as Stelladaptor events, and let the controllers + // handle it + switch (int(eventAxisNeg)) + { + case Event::PaddleZeroAnalog: + myEvent.set(Event::SALeftAxis0Value, value); + break; + case Event::PaddleOneAnalog: + myEvent.set(Event::SALeftAxis1Value, value); + break; + case Event::PaddleTwoAnalog: + myEvent.set(Event::SARightAxis0Value, value); + break; + case Event::PaddleThreeAnalog: + myEvent.set(Event::SARightAxis1Value, value); + break; + default: + { + // Otherwise, we know the event is digital + if (value > Joystick::deadzone()) + myHandler.handleEvent(eventAxisPos); + else if (value < -Joystick::deadzone()) + myHandler.handleEvent(eventAxisNeg); + else { - // Turn off both events, since we don't know exactly which one - // was previously activated. - myHandler.handleEvent(eventAxisNeg, false); - myHandler.handleEvent(eventAxisPos, false); + // Treat any deadzone value as zero + value = 0; + + // Now filter out consecutive, similar values + // (only pass on the event if the state has changed) + if (j->axisLastValue[axis] != value) + { + // Turn off both events, since we don't know exactly which one + // was previously activated. + myHandler.handleEvent(eventAxisNeg, false); + myHandler.handleEvent(eventAxisPos, false); + } } + j->axisLastValue[axis] = value; + break; } - j->axisLastValue[axis] = value; - break; } } - } - else if(myHandler.hasOverlay()) - { - // First, clamp the values to simulate digital input - // (the only thing that the underlying code understands) - if(value > Joystick::deadzone()) - value = 32000; - else if(value < -Joystick::deadzone()) - value = -32000; - else - value = 0; - - // Now filter out consecutive, similar values - // (only pass on the event if the state has changed) - if(value != j->axisLastValue[axis]) + else if (myHandler.hasOverlay()) { - #ifdef GUI_SUPPORT - myHandler.overlay().handleJoyAxisEvent(stick, axis, value); - #endif - j->axisLastValue[axis] = value; - } - } - break; // Regular joystick axis + // First, clamp the values to simulate digital input + // (the only thing that the underlying code understands) + if (value > Joystick::deadzone()) + value = 32000; + else if (value < -Joystick::deadzone()) + value = -32000; + else + value = 0; - // Since the various controller classes deal with Stelladaptor - // devices differently, we send the raw X and Y axis data directly, - // and let the controller handle it - // These events don't have to pass through handleEvent, since - // they can never be remapped - case PhysicalJoystick::JT_STELLADAPTOR_LEFT: - case PhysicalJoystick::JT_2600DAPTOR_LEFT: - if(axis < NUM_JOY_AXIS) - myEvent.set(SA_Axis[int(Controller::Jack::Left)][axis], value); - break; // axis on left controller (0) - case PhysicalJoystick::JT_STELLADAPTOR_RIGHT: - case PhysicalJoystick::JT_2600DAPTOR_RIGHT: - if(axis < NUM_JOY_AXIS) - myEvent.set(SA_Axis[int(Controller::Jack::Right)][axis], value); - break; // axis on right controller (1) - default: - break; + // Now filter out consecutive, similar values + // (only pass on the event if the state has changed) + if (value != j->axisLastValue[axis]) + { + #ifdef GUI_SUPPORT + myHandler.overlay().handleJoyAxisEvent(stick, axis, value, button); + #endif + j->axisLastValue[axis] = value; + } + } + break; // Regular joystick axis + + // Since the various controller classes deal with Stelladaptor + // devices differently, we send the raw X and Y axis data directly, + // and let the controller handle it + // These events don't have to pass through handleEvent, since + // they can never be remapped + case PhysicalJoystick::JT_STELLADAPTOR_LEFT: + case PhysicalJoystick::JT_2600DAPTOR_LEFT: + if (axis < NUM_JOY_AXIS) + myEvent.set(SA_Axis[int(Controller::Jack::Left)][axis], value); + break; // axis on left controller (0) + case PhysicalJoystick::JT_STELLADAPTOR_RIGHT: + case PhysicalJoystick::JT_2600DAPTOR_RIGHT: + if (axis < NUM_JOY_AXIS) + myEvent.set(SA_Axis[int(Controller::Jack::Right)][axis], value); + break; // axis on right controller (1) + default: + break; + } } } @@ -696,67 +698,70 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) void PhysicalJoystickHandler::handleBtnEvent(int stick, int button, bool pressed) { const PhysicalJoystickPtr j = joy(stick); - if(!j) return; - j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE; - // Stelladaptors handle buttons differently than regular joysticks - switch(j->type) + if (j) { - case PhysicalJoystick::JT_REGULAR: - // Handle buttons which switch eventhandler state - //if(pressed && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode])) - if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button))) - return; + j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE; - // Determine which mode we're in, then send the event to the appropriate place - if(myHandler.state() == EventHandlerState::EMULATION) - //myHandler.handleEvent(j->btnTable[button][kEmulationMode], pressed); - myHandler.handleEvent(j->joyMap.get(kEmulationMode, button), pressed); - #ifdef GUI_SUPPORT - else if(myHandler.hasOverlay()) - myHandler.overlay().handleJoyBtnEvent(stick, button, pressed); - #endif - break; // Regular button + // Stelladaptors handle buttons differently than regular joysticks + switch (j->type) + { + case PhysicalJoystick::JT_REGULAR: + // Handle buttons which switch eventhandler state + if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button))) + return; - // These events don't have to pass through handleEvent, since - // they can never be remapped - case PhysicalJoystick::JT_STELLADAPTOR_LEFT: - case PhysicalJoystick::JT_STELLADAPTOR_RIGHT: - // The 'type-2' here refers to the fact that 'PhysicalJoystick::JT_STELLADAPTOR_LEFT' - // and 'PhysicalJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType - // enum; subtracting two gives us Controller 0 and 1 - if(button < 2) - myEvent.set(SA_Button[j->type-PhysicalJoystick::JT_STELLADAPTOR_LEFT][button], pressed ? 1 : 0); - break; // Stelladaptor button - case PhysicalJoystick::JT_2600DAPTOR_LEFT: - case PhysicalJoystick::JT_2600DAPTOR_RIGHT: - // The 'type-4' here refers to the fact that 'PhysicalJoystick::JT_2600DAPTOR_LEFT' - // and 'PhysicalJoystick::JT_2600DAPTOR_RIGHT' are at index 4 and 5 in the JoyType - // enum; subtracting four gives us Controller 0 and 1 - if(myHandler.state() == EventHandlerState::EMULATION) - { - switch(myOSystem.console().leftController().type()) + // Determine which mode we're in, then send the event to the appropriate place + if (myHandler.state() == EventHandlerState::EMULATION) + myHandler.handleEvent(j->joyMap.get(kEmulationMode, button), pressed); + #ifdef GUI_SUPPORT + else if (myHandler.hasOverlay()) + myHandler.overlay().handleJoyBtnEvent(stick, button, pressed); + #endif + break; // Regular button + + // These events don't have to pass through handleEvent, since + // they can never be remapped + case PhysicalJoystick::JT_STELLADAPTOR_LEFT: + case PhysicalJoystick::JT_STELLADAPTOR_RIGHT: + // The 'type-2' here refers to the fact that 'PhysicalJoystick::JT_STELLADAPTOR_LEFT' + // and 'PhysicalJoystick::JT_STELLADAPTOR_RIGHT' are at index 2 and 3 in the JoyType + // enum; subtracting two gives us Controller 0 and 1 + if (button < 2) + myEvent.set(SA_Button[j->type - PhysicalJoystick::JT_STELLADAPTOR_LEFT][button], pressed ? 1 : 0); + break; // Stelladaptor button + + case PhysicalJoystick::JT_2600DAPTOR_LEFT: + case PhysicalJoystick::JT_2600DAPTOR_RIGHT: + // The 'type-4' here refers to the fact that 'PhysicalJoystick::JT_2600DAPTOR_LEFT' + // and 'PhysicalJoystick::JT_2600DAPTOR_RIGHT' are at index 4 and 5 in the JoyType + // enum; subtracting four gives us Controller 0 and 1 + if (myHandler.state() == EventHandlerState::EMULATION) { - case Controller::Type::Keyboard: - if(button < NUM_KEY_BTN) - myEvent.set(SA_Key[j->type-PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); - break; - default: - if(button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type-PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); + switch (myOSystem.console().leftController().type()) + { + case Controller::Type::Keyboard: + if (button < NUM_KEY_BTN) + myEvent.set(SA_Key[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); + break; + default: + if (button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); + } + switch (myOSystem.console().rightController().type()) + { + case Controller::Type::Keyboard: + if (button < NUM_KEY_BTN) + myEvent.set(SA_Key[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); + break; + default: + if (button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type - PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); + } } - switch(myOSystem.console().rightController().type()) - { - case Controller::Type::Keyboard: - if(button < NUM_KEY_BTN) - myEvent.set(SA_Key[j->type-PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); - break; - default: - if(button < NUM_JOY_BTN) myEvent.set(SA_Button[j->type-PhysicalJoystick::JT_2600DAPTOR_LEFT][button], pressed ? 1 : 0); - } - } - break; // 2600DAPTOR button - default: - break; + break; // 2600DAPTOR button + + default: + break; + } } } @@ -766,38 +771,40 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value) // Preprocess all hat events, converting to Stella JoyHat type // Generate multiple equivalent hat events representing combined direction // when we get a diagonal hat event - if(myHandler.state() == EventHandlerState::EMULATION) - { - const PhysicalJoystickPtr j = joy(stick); - if(!j) return; - /*myHandler.handleEvent(j->hatTable[hat][int(JoyHat::UP)][kEmulationMode], - value & EVENT_HATUP_M); - myHandler.handleEvent(j->hatTable[hat][int(JoyHat::RIGHT)][kEmulationMode], - value & EVENT_HATRIGHT_M); - myHandler.handleEvent(j->hatTable[hat][int(JoyHat::DOWN)][kEmulationMode], - value & EVENT_HATDOWN_M); - myHandler.handleEvent(j->hatTable[hat][int(JoyHat::LEFT)][kEmulationMode], - value & EVENT_HATLEFT_M);*/ + const PhysicalJoystickPtr j = joy(stick); - // TODO: 4 different events - myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, JOY_CTRL_NONE, hat, JoyHat(value))); - } -#ifdef GUI_SUPPORT - else if(myHandler.hasOverlay()) + if (j) { - if(value == EVENT_HATCENTER_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::CENTER); - else + const int button = j->buttonLast[stick]; + + if (myHandler.state() == EventHandlerState::EMULATION) { - if(value & EVENT_HATUP_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::UP); - if(value & EVENT_HATRIGHT_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::RIGHT); - if(value & EVENT_HATDOWN_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::DOWN); - if(value & EVENT_HATLEFT_M) - myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::LEFT); + myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::UP), + value & EVENT_HATUP_M); + myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::RIGHT), + value & EVENT_HATRIGHT_M); + myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::DOWN), + value & EVENT_HATDOWN_M); + myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::LEFT), + value & EVENT_HATLEFT_M); + } + #ifdef GUI_SUPPORT + else if (myHandler.hasOverlay()) + { + if (value == EVENT_HATCENTER_M) + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::CENTER, button); + else + { + if (value & EVENT_HATUP_M) + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::UP, button); + if (value & EVENT_HATRIGHT_M) + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::RIGHT, button); + if (value & EVENT_HATDOWN_M) + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::DOWN, button); + if (value & EVENT_HATLEFT_M) + myHandler.overlay().handleJoyHatEvent(stick, hat, JoyHat::LEFT, button); + } } } #endif diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index ebd8e79f8..0438162c0 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -41,7 +41,7 @@ using PhysicalJoystickPtr = shared_ptr; Essentially, this class is an extension of the EventHandler class, but handling only joystick-specific functionality. - @author Stephen Anthony + @author Stephen Anthony, Thomas Jentzsch */ class PhysicalJoystickHandler { @@ -74,11 +74,6 @@ class PhysicalJoystickHandler string getMappingDesc(Event::Type, EventMode mode) const; /** Bind a physical joystick event to a virtual event/action. */ - /*bool addAxisMapping(Event::Type event, EventMode mode, int stick, int axis, int value); - bool addBtnMapping(Event::Type event, EventMode mode, int stick, int button); - bool addHatMapping(Event::Type event, EventMode mode, int stick, int hat, JoyHat value);*/ - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool addJoyMapping(Event::Type event, EventMode mode, int stick, int button, JoyAxis axis, int value); bool addJoyHatMapping(Event::Type event, EventMode mode, int stick, @@ -89,21 +84,18 @@ class PhysicalJoystickHandler void handleBtnEvent(int stick, int button, bool pressed); void handleHatEvent(int stick, int hat, int value); - Event::Type eventForAxis(int stick, int axis, int joyDir, EventMode mode) const { + Event::Type eventForAxis(EventMode mode, int stick, int axis, int value, int button) const { const PhysicalJoystickPtr j = joy(stick); - //return (j && joyDir != int(JoyDir::NEG)) - // ? j->axisTable[axis][(joyDir > int(JoyDir::NEG))][mode] : Event::NoType; - return j->joyMap.get(mode, JOY_CTRL_NONE, JoyAxis(axis), JoyDir(joyDir)); + return j->joyMap.get(mode, button, JoyAxis(axis), + value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG); } - Event::Type eventForButton(int stick, int button, EventMode mode) const { + Event::Type eventForButton(EventMode mode, int stick, int button) const { const PhysicalJoystickPtr j = joy(stick); - // return j ? j->btnTable[button][mode] : Event::NoType; return j->joyMap.get(mode, button); } - Event::Type eventForHat(int stick, int hat, JoyHat hatDir, EventMode mode) const { + Event::Type eventForHat(EventMode mode, int stick, int hat, JoyHat hatDir, int button) const { const PhysicalJoystickPtr j = joy(stick); - //return j ? j->hatTable[hat][int(hatDir)][mode] : Event::NoType; - return j->joyHatMap.get(mode, JOY_CTRL_NONE, hat, hatDir); + return j->joyHatMap.get(mode, button, hat, hatDir); } /** Returns a list of pairs consisting of joystick name and associated ID. */ diff --git a/src/common/PKeyboardHandler.hxx b/src/common/PKeyboardHandler.hxx index ffe869d21..7b3a6a6fb 100644 --- a/src/common/PKeyboardHandler.hxx +++ b/src/common/PKeyboardHandler.hxx @@ -40,7 +40,7 @@ using EventSet = std::set; Essentially, this class is an extension of the EventHandler class, but handling only keyboard-specific functionality. - @author Stephen Anthony + @author Stephen Anthony, Thomas Jentzsch */ class PhysicalKeyboardHandler { diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index 753fa0b41..62d652b45 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -31,9 +31,6 @@ PhysicalJoystick::PhysicalJoystick() numAxes(0), numButtons(0), numHats(0), - /*axisTable(nullptr), - btnTable(nullptr), - hatTable(nullptr),*/ axisLastValue(nullptr), buttonLast(nullptr) { @@ -42,9 +39,6 @@ PhysicalJoystick::PhysicalJoystick() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PhysicalJoystick::~PhysicalJoystick() { - /*delete[] axisTable; - delete[] btnTable; - delete[] hatTable;*/ delete[] axisLastValue; delete[] buttonLast; } @@ -61,38 +55,18 @@ void PhysicalJoystick::initialize(int index, const string& desc, numAxes = axes; numButtons = buttons; numHats = hats; - /*if(numAxes) - axisTable = new Event::Type[numAxes][NUM_JOY_DIRS][kNumModes]; - if(numButtons) - btnTable = new Event::Type[numButtons][kNumModes]; - if(numHats) - hatTable = new Event::Type[numHats][NUM_JOY_HAT_DIRS][kNumModes];*/ axisLastValue = new int[numAxes]; buttonLast = new int[numButtons]; + // Erase the last button for (int b = 0; b < numButtons; ++b) buttonLast[b] = JOY_CTRL_NONE; - // Erase the joystick axis mapping array and last axis value + // Erase the last axis value for(int a = 0; a < numAxes; ++a) - { axisLastValue[a] = 0; - /*for(int m = 0; m < kNumModes; ++m) - for (int d = 0; d < NUM_JOY_DIRS; ++d) - axisTable[a][d][m] = Event::NoType;*/ - } - - /*// Erase the joystick button mapping array - for(int b = 0; b < numButtons; ++b) - for(int m = 0; m < kNumModes; ++m) - btnTable[b][m] = Event::NoType; - - // Erase the joystick hat mapping array - for(int h = 0; h < numHats; ++h) - for(int m = 0; m < kNumModes; ++m) - for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d) - hatTable[h][d][m] = Event::NoType;*/ + // Erase the mappings for (int m = 0; m < kNumModes; ++m) eraseMap(EventMode(m)); } @@ -101,102 +75,54 @@ void PhysicalJoystick::initialize(int index, const string& desc, string PhysicalJoystick::getMap() const { // The mapping structure (for remappable devices) is defined as follows: - // NAME | AXIS # + values | BUTTON # + values | HAT # + values, - // where each subsection of values is separated by ':' - if(type == JT_REGULAR) - { + // '$'['|'(':'