From a693d67515d34def0976a14fbd420760e1371860 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Sun, 23 Jun 2019 20:22:10 +0200 Subject: [PATCH] refactor into mapping into single class add paddle mappings --- src/common/JoyHatMap.cxx | 206 -------------------------- src/common/JoyHatMap.hxx | 117 --------------- src/common/JoyMap.cxx | 57 ++++++- src/common/JoyMap.hxx | 42 +++++- src/common/PJoystickHandler.cxx | 91 ++++++------ src/common/PJoystickHandler.hxx | 8 +- src/common/PhysicalJoystick.cxx | 12 +- src/common/PhysicalJoystick.hxx | 2 - src/common/module.mk | 1 - src/emucore/Console.cxx | 1 + src/emucore/EventHandlerConstants.hxx | 3 +- src/windows/Stella.vcxproj | 2 - src/windows/Stella.vcxproj.filters | 6 - 13 files changed, 147 insertions(+), 401 deletions(-) delete mode 100644 src/common/JoyHatMap.cxx delete mode 100644 src/common/JoyHatMap.hxx diff --git a/src/common/JoyHatMap.cxx b/src/common/JoyHatMap.cxx deleted file mode 100644 index 623fe77b9..000000000 --- a/src/common/JoyHatMap.cxx +++ /dev/null @@ -1,206 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#include "JoyHatMap.hxx" - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -JoyHatMap::JoyHatMap(void) -{ -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::add(const Event::Type event, const JoyHatMapping& mapping) -{ - myMap[mapping] = event; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::add(const Event::Type event, const EventMode mode, - const int button, const int hat, const JoyHat hdir) -{ - add(event, JoyHatMapping(mode, button, hat, hdir)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::erase(const JoyHatMapping& mapping) -{ - myMap.erase(mapping); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::erase(const EventMode mode, - const int button, const int hat, const JoyHat hdir) -{ - erase(JoyHatMapping(mode, button, hat, hdir)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type JoyHatMap::get(const JoyHatMapping& mapping) const -{ - auto find = myMap.find(mapping); - if (find != myMap.end()) - return find->second; - - // try without button as modifier - JoyHatMapping m = mapping; - - m.button = JOY_CTRL_NONE; - - find = myMap.find(m); - if (find != myMap.end()) - return find->second; - - return Event::Type::NoType; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Event::Type JoyHatMap::get(const EventMode mode, - const int button, const int hat, const JoyHat hdir) const -{ - return get(JoyHatMapping(mode, button, hat, hdir)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool JoyHatMap::check(const JoyHatMapping & mapping) const -{ - auto find = myMap.find(mapping); - - return (find != myMap.end()); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool JoyHatMap::check(const EventMode mode, - const int button, const int hat, const JoyHat hdir) const -{ - return check(JoyHatMapping(mode, button, hat, hdir)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping) const -{ - ostringstream buf; - - // hat description - if (mapping.hat != JOY_CTRL_NONE) - { - buf << "/H" << mapping.hat; - switch (mapping.hdir) - { - case JoyHat::UP: buf << "/up"; break; - case JoyHat::DOWN: buf << "/down"; break; - case JoyHat::LEFT: buf << "/left"; break; - case JoyHat::RIGHT: buf << "/right"; break; - default: break; - } - } - - - return buf.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string JoyHatMap::getDesc(const Event::Type event, const EventMode mode, - const int button, const int hat, const JoyHat hdir) const -{ - return getDesc(event, JoyHatMapping(mode, button, hat, hdir)); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string JoyHatMap::getEventMappingDesc(const int stick, const Event::Type event, const EventMode mode) const -{ - ostringstream buf; - - for (auto item : myMap) - { - if (item.second == event && item.first.mode == mode) - { - if (buf.str() != "") - buf << ", "; - buf << "J" << stick << getDesc(event, item.first); - } - } - return buf.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -JoyHatMap::JoyHatMappingArray JoyHatMap::getEventMapping(const Event::Type event, const EventMode mode) const -{ - JoyHatMappingArray map; - - for (auto item : myMap) - if (item.second == event && item.first.mode == mode) - map.push_back(item.first); - - return map; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -string JoyHatMap::saveMapping(const EventMode mode) const -{ - ostringstream buf; - - for (auto item : myMap) - { - if (item.first.mode == mode) - { - if (buf.str() != "") - buf << "|"; - buf << item.second << ":" << item.first.button << "," << - item.first.hat << "," << int(item.first.hdir); - } - } - return buf.str(); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -int JoyHatMap::loadMapping(string & list, const EventMode mode) -{ - // Since istringstream swallows whitespace, we have to make the - // delimiters be spaces - std::replace(list.begin(), list.end(), '|', ' '); - std::replace(list.begin(), list.end(), ':', ' '); - std::replace(list.begin(), list.end(), ',', ' '); - istringstream buf(list); - int event, button, hat, hdir, i = 0; - - while (buf >> event && buf >> button && buf >> hat && buf >> hdir && ++i) - add(Event::Type(event), EventMode(mode), button, hat, JoyHat(hdir)); - - return i; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::eraseMode(const EventMode mode) -{ - for (auto item = myMap.begin(); item != myMap.end();) - if (item->first.mode == mode) { - auto _item = item++; - erase(_item->first); - } - else item++; -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void JoyHatMap::eraseEvent(const Event::Type event, const EventMode mode) -{ - for (auto item = myMap.begin(); item != myMap.end();) - if (item->second == event && item->first.mode == mode) { - auto _item = item++; - erase(_item->first); - } - else item++; -} diff --git a/src/common/JoyHatMap.hxx b/src/common/JoyHatMap.hxx deleted file mode 100644 index 71f14eb8e..000000000 --- a/src/common/JoyHatMap.hxx +++ /dev/null @@ -1,117 +0,0 @@ -//============================================================================ -// -// SSSS tt lll lll -// SS SS tt ll ll -// SS tttttt eeee ll ll aaaa -// SSSS tt ee ee ll ll aa -// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" -// SS SS tt ee ll ll aa aa -// SSSS ttt eeeee llll llll aaaaa -// -// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony -// and the Stella Team -// -// See the file "License.txt" for information on usage and redistribution of -// this file, and for a DISCLAIMER OF ALL WARRANTIES. -//============================================================================ - -#ifndef JOYHATMAP_HXX -#define JOYHATMAP_HXX - -#include -#include "Event.hxx" -#include "EventHandlerConstants.hxx" - -/** - This class handles controller mappings in Stella. - - @author Thomas Jentzsch -*/ -class JoyHatMap -{ -public: - - struct JoyHatMapping - { - EventMode mode; - int button; // button number - int hat; // hat number - JoyHat hdir; // hat direction (left/right/up/down) - - JoyHatMapping() - : mode(EventMode(0)), button(0), hat(0), hdir(JoyHat(0)) { } - JoyHatMapping(const JoyHatMapping& m) - : mode(m.mode), button(m.button), hat(m.hat), hdir(m.hdir) { } - explicit JoyHatMapping(EventMode c_mode, int c_button, int c_hat, JoyHat c_hdir) - : mode(c_mode), button(c_button), hat(c_hat), hdir(c_hdir) { } - - bool operator==(const JoyHatMapping& other) const - { - return (mode == other.mode - && button == other.button - && hat == other.hat - && hdir == other.hdir - ); - } - }; - using JoyHatMappingArray = std::vector; - - JoyHatMap(); - virtual ~JoyHatMap() = default; - - /** Add new mapping for given event */ - void add(const Event::Type event, const JoyHatMapping& mapping); - void add(const Event::Type event, const EventMode mode, - const int button, const int hat, const JoyHat hdir); - - /** Erase mapping */ - void erase(const JoyHatMapping& mapping); - void erase(const EventMode mode, - const int button, const int hat, const JoyHat hdir); - - /** Get event for mapping */ - Event::Type get(const JoyHatMapping& mapping) const; - Event::Type get(const EventMode mode, - const int button, const int hat, const JoyHat hdir) const; - - /** Check if a mapping exists */ - bool check(const JoyHatMapping& mapping) const; - bool check(const EventMode mode, - const int button, const int hat, const JoyHat hdir) const; - - /** Get mapping description */ - string getDesc(const Event::Type event, const JoyHatMapping& mapping) const; - string getDesc(const Event::Type event, const EventMode mode, - const int button, const int hat, const JoyHat hdir) const; - - /** Get the mapping description(s) for given stick, event and mode */ - string getEventMappingDesc(const int stick, const Event::Type event, const EventMode mode) const; - - JoyHatMappingArray getEventMapping(const Event::Type event, const EventMode mode) const; - - string saveMapping(const EventMode mode) const; - int loadMapping(string& list, const EventMode mode); - - /** Erase all mappings for given mode */ - void eraseMode(const EventMode mode); - /** Erase given event's mapping for given mode */ - void eraseEvent(const Event::Type event, const EventMode mode); - /** clear all mappings for a modes */ - // void clear() { myMap.clear(); } - size_t size() { return myMap.size(); } - -private: - struct JoyHatHash { - size_t operator()(const JoyHatMapping& m)const { - return std::hash()((uInt64(m.mode)) // 3 bit - ^ ((uInt64(m.button)) << 3) // 2 bits - ^ ((uInt64(m.hat)) << 5) // 1 bit - ^ ((uInt64(m.hdir)) << 6) // 2 bits - ); - } - }; - - std::unordered_map myMap; -}; - -#endif diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 5e2759c05..bdb8dd4ec 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -30,9 +30,17 @@ void JoyMap::add(const Event::Type event, const JoyMapping& mapping) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void JoyMap::add(const Event::Type event, const EventMode mode, const int button, - const JoyAxis axis, const JoyDir adir) + const JoyAxis axis, const JoyDir adir, + const int hat, const JoyHat hdir) { - add(event, JoyMapping(mode, button, axis, adir)); + add(event, JoyMapping(mode, button, axis, adir, hat, hdir)); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void JoyMap::add(const Event::Type event, const EventMode mode, + const int button, const int hat, const JoyHat hdir) +{ + add(event, JoyMapping(mode, button, hat, hdir)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -48,6 +56,13 @@ void JoyMap::erase(const EventMode mode, const int button, erase(JoyMapping(mode, button, axis, adir)); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void JoyMap::erase(const EventMode mode, + const int button, const int hat, const JoyHat hdir) +{ + erase(JoyMapping(mode, button, hat, hdir)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Event::Type JoyMap::get(const JoyMapping& mapping) const { @@ -74,6 +89,13 @@ Event::Type JoyMap::get(const EventMode mode, const int button, return get(JoyMapping(mode, button, axis, adir)); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Event::Type JoyMap::get(const EventMode mode, + const int button, const int hat, const JoyHat hdir) const +{ + return get(JoyMapping(mode, button, hat, hdir)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool JoyMap::check(const JoyMapping & mapping) const { @@ -89,6 +111,13 @@ bool JoyMap::check(const EventMode mode, const int button, return check(JoyMapping(mode, button, axis, adir)); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool JoyMap::check(const EventMode mode, + const int button, const int hat, const JoyHat hdir) const +{ + return check(JoyMapping(mode, button, hat, hdir)); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const { @@ -120,6 +149,20 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const buf << "+"; } + // hat description + if (mapping.hat != JOY_CTRL_NONE) + { + buf << "/H" << mapping.hat; + switch (mapping.hdir) + { + case JoyHat::UP: buf << "/up"; break; + case JoyHat::DOWN: buf << "/down"; break; + case JoyHat::LEFT: buf << "/left"; break; + case JoyHat::RIGHT: buf << "/right"; break; + default: break; + } + } + return buf.str(); } @@ -171,7 +214,8 @@ string JoyMap::saveMapping(const EventMode mode) const if (buf.str() != "") buf << "|"; buf << item.second << ":" << item.first.button << "," - << int(item.first.axis) << "," << int(item.first.adir); + << int(item.first.axis) << "," << int(item.first.adir) << "," + << item.first.hat << "," << int(item.first.hdir); } } return buf.str(); @@ -186,11 +230,12 @@ 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, button, axis, adir, i = 0; + int event, button, axis, adir, hat, hdir, i = 0; while (buf >> event && buf >> button - && buf >> axis && buf >> adir && ++i) - add(Event::Type(event), EventMode(mode), button, JoyAxis(axis), JoyDir(adir)); + && buf >> axis && buf >> adir + && buf >> hat && buf >> hdir && ++i) + add(Event::Type(event), EventMode(mode), button, JoyAxis(axis), JoyDir(adir), hat, JoyHat(hdir)); return i; } diff --git a/src/common/JoyMap.hxx b/src/common/JoyMap.hxx index 095a5c04f..3a69c587d 100644 --- a/src/common/JoyMap.hxx +++ b/src/common/JoyMap.hxx @@ -37,17 +37,33 @@ class JoyMap int button; // button number JoyAxis axis; // horizontal/vertical JoyDir adir; // axis direction (neg/pos) + int hat; // hat number + JoyHat hdir; // hat direction (left/right/up/down) JoyMapping() : mode(EventMode(0)), button(0), - axis(JoyAxis(0)), adir(JoyDir(0)) { } + axis(JoyAxis(0)), adir(JoyDir(0)), + hat(0), hdir(JoyHat(0)) { } JoyMapping(const JoyMapping& m) : mode(m.mode), button(m.button), - axis(m.axis), adir(m.adir) { } + axis(m.axis), adir(m.adir), + hat(m.hat), hdir(m.hdir) { } explicit JoyMapping(EventMode c_mode, int c_button, - JoyAxis c_axis, JoyDir c_adir) + JoyAxis c_axis, JoyDir c_adir, + int c_hat, JoyHat c_hdir) : mode(c_mode), button(c_button), - axis(c_axis), adir(c_adir) { } + axis(c_axis), adir(c_adir), + hat(c_hat), hdir(c_hdir) { } + explicit JoyMapping(EventMode c_mode, int c_button, + JoyAxis c_axis, JoyDir c_adir) + : mode(c_mode), button(c_button), + axis(c_axis), adir(c_adir), + hat(JOY_CTRL_NONE), hdir(JoyHat::CENTER) { } + explicit JoyMapping(EventMode c_mode, int c_button, + int c_hat, JoyHat c_hdir) + : mode(c_mode), button(c_button), + axis(JoyAxis::NONE), adir(JoyDir::NONE), + hat(c_hat), hdir(c_hdir) { } bool operator==(const JoyMapping& other) const { @@ -55,6 +71,8 @@ class JoyMap && button == other.button && axis == other.axis && adir == other.adir + && hat == other.hat + && hdir == other.hdir ); } }; @@ -66,27 +84,39 @@ class JoyMap /** Add new mapping for given event */ void add(const Event::Type event, const JoyMapping& mapping); void add(const Event::Type event, const EventMode mode, const int button, - const JoyAxis axis, const JoyDir adir); + const JoyAxis axis, const JoyDir adir, + const int hat = JOY_CTRL_NONE, const JoyHat hdir = JoyHat::CENTER); + void add(const Event::Type event, const EventMode mode, + const int button, const int hat, const JoyHat hdir); /** Erase mapping */ void erase(const JoyMapping& mapping); void erase(const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir); + void erase(const EventMode mode, + const int button, const int hat, const JoyHat hdir); + /** Get event for mapping */ Event::Type get(const JoyMapping& mapping) const; Event::Type get(const EventMode mode, const int button, const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) const; + Event::Type get(const EventMode mode, + const int button, const int hat, const JoyHat hdir) const; /** Check if a mapping exists */ bool check(const JoyMapping& mapping) const; bool check(const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir) const; + bool check(const EventMode mode, + const int button, const int hat, const JoyHat hdir) const; /** Get mapping description */ string getDesc(const Event::Type event, const JoyMapping& mapping) const; string getDesc(const Event::Type event, const EventMode mode, const int button, const JoyAxis axis, const JoyDir adir) const; + string getDesc(const Event::Type event, const EventMode mode, + const int button, const int hat, const JoyHat hdir) const; /** Get the mapping description(s) for given stick, event and mode */ string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const; @@ -111,6 +141,8 @@ class JoyMap ^ ((uInt64(m.button)) << 2) // 2 bits ^ ((uInt64(m.axis)) << 4) // 1 bit ^ ((uInt64(m.adir)) << 5) // 1 bit + ^ ((uInt64(m.hat)) << 6) // 1 bit + ^ ((uInt64(m.hdir)) << 7) // 2 bits ); } }; diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 753a5546c..43c289c36 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -122,8 +122,8 @@ int PhysicalJoystickHandler::add(PhysicalJoystickPtr stick) { StickInfo info("", stick); myDatabase.emplace(stick->name, info); - setStickDefaultMapping(stick->ID, Event::NoType, kEmulationMode); - setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode); + setStickDefaultMapping(stick->ID, Event::NoType, kEmulationMode, true); + setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode, true); } /*// We're potentially swapping out an input device behind the back of @@ -269,10 +269,10 @@ void PhysicalJoystickHandler::setDefaultAction(EventMapping map, Event::Type eve // the default mapping for the event is unused, set default key for event if (hatAction) { - if (j->joyHatMap.getEventMapping(map.event, mode).size() == 0 || - !j->joyHatMap.check(mode, map.button, map.hat, map.hdir)) + if (j->joyMap.getEventMapping(map.event, mode).size() == 0 || + !j->joyMap.check(mode, map.button, map.hat, map.hdir)) { - j->joyHatMap.add(map.event, mode, map.button, map.hat, map.hdir); + j->joyMap.add(map.event, mode, map.button, map.hat, map.hdir); } } else @@ -286,16 +286,8 @@ void PhysicalJoystickHandler::setDefaultAction(EventMapping map, Event::Type eve } else if (eraseAll || map.event == event) { - if (hatAction) - { - j->joyHatMap.eraseEvent(map.event, mode); - j->joyHatMap.add(map.event, mode, map.button, map.hat, map.hdir); - } - else - { - j->joyMap.eraseEvent(map.event, mode); - j->joyMap.add(map.event, mode, map.button, map.axis, map.adir); - } + j->joyMap.eraseEvent(map.event, mode); + j->joyMap.add(map.event, mode, map.button, map.axis, map.adir, map.hat, map.hdir); } } } @@ -320,6 +312,8 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even // put all controller events into their own mode's mappings for (const auto& item : DefaultLeftJoystickMapping) setDefaultAction(item, event, kJoystickMode, updateDefaults); + for (const auto& item : DefaultLeftPaddlesMapping) + setDefaultAction(item, event, kPaddlesMode, updateDefaults); for (const auto& item : DefaultLeftKeypadMapping) setDefaultAction(item, event, kKeypadMode, updateDefaults); } @@ -328,6 +322,8 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick, Event::Type even // put all controller events into their own mode's mappings for (const auto& item : DefaultRightJoystickMapping) setDefaultAction(item, event, kJoystickMode, updateDefaults); + for (const auto& item : DefaultRightPaddlesMapping) + setDefaultAction(item, event, kPaddlesMode, updateDefaults); for (const auto& item : DefaultRightKeypadMapping) setDefaultAction(item, event, kKeypadMode, updateDefaults); } @@ -489,7 +485,6 @@ void PhysicalJoystickHandler::enableEmulationMappings() // start from scratch and enable common mappings j->joyMap.eraseMode(kEmulationMode); - j->joyHatMap.eraseMode(kEmulationMode); } enableCommonMappings(); @@ -566,11 +561,6 @@ void PhysicalJoystickHandler::enableMapping(const Event::Type event, EventMode m for (const auto& mapping : joyMappings) j->joyMap.add(event, kEmulationMode, mapping.button, mapping.axis, mapping.adir); - - JoyHatMap::JoyHatMappingArray joyHatMappings = j->joyHatMap.getEventMapping(event, mode); - - for (const auto& mapping : joyHatMappings) - j->joyHatMap.add(event, kEmulationMode, mapping.button, mapping.hat, mapping.hdir); } } @@ -667,20 +657,13 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode if (j) { - //Joystick button + axis mapping / labeling + //Joystick mapping / labeling if (j->joyMap.getEventMapping(event, mode).size()) { if (buf.str() != "") buf << ", "; buf << j->joyMap.getEventMappingDesc(stick, event, mode); } - // Joystick hat mapping / labeling - if (j->joyHatMap.getEventMapping(event, mode).size()) - { - if (buf.str() != "") - buf << ", "; - buf << j->joyHatMap.getEventMappingDesc(stick, event, mode); - } } } return buf.str(); @@ -700,16 +683,20 @@ bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, i // but analog events only affect one of the axis. if (Event::isAnalog(event)) { - j->joyMap.add(event, mode, button, axis, JoyDir::NEG); - j->joyMap.add(event, mode, button, axis, JoyDir::POS); + //j->joyMap.add(event, mode, button, axis, JoyDir::NEG); + //j->joyMap.add(event, mode, button, axis, JoyDir::POS); + j->joyMap.add(event, mode, button, axis, JoyDir::ANALOG); } else { // Otherwise, turn off the analog event(s) for this axis - if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::NEG))) + /*if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::NEG))) j->joyMap.erase(mode, button, axis, JoyDir::NEG); if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::POS))) - j->joyMap.erase(mode, button, axis, JoyDir::POS); + j->joyMap.erase(mode, button, axis, JoyDir::POS);*/ + if (Event::isAnalog(j->joyMap.get(mode, button, axis, JoyDir::ANALOG))) + j->joyMap.erase(mode, button, axis, JoyDir::ANALOG); + j->joyMap.add(event, mode, button, axis, convertAxisValue(value)); } @@ -728,7 +715,7 @@ bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode button >= JOY_CTRL_NONE && button < j->numButtons && hat >= 0 && hat < j->numHats && dir != JoyHat::CENTER) { - j->joyHatMap.add(event, mode, button, hat, dir); + j->joyMap.add(event, mode, button, hat, dir); return true; } return false; @@ -753,14 +740,12 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) case PhysicalJoystick::JT_2600DAPTOR_RIGHT: if (myHandler.state() == EventHandlerState::EMULATION) { - // 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); + Event::Type eventAxisAnalog = j->joyMap.get(kEmulationMode, button, JoyAxis(axis), JoyDir::ANALOG); // 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)) + switch (eventAxisAnalog) { case Event::PaddleZeroAnalog: myEvent.set(Event::SALeftAxis0Value, value); @@ -777,6 +762,10 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) default: { // Otherwise, we know the event is digital + // 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); + if (value > Joystick::deadzone()) myHandler.handleEvent(eventAxisPos); else if (value < -Joystick::deadzone()) @@ -937,13 +926,13 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value) if (myHandler.state() == EventHandlerState::EMULATION) { - myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::UP), + myHandler.handleEvent(j->joyMap.get(kEmulationMode, button, hat, JoyHat::UP), value & EVENT_HATUP_M); - myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::RIGHT), + myHandler.handleEvent(j->joyMap.get(kEmulationMode, button, hat, JoyHat::RIGHT), value & EVENT_HATRIGHT_M); - myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::DOWN), + myHandler.handleEvent(j->joyMap.get(kEmulationMode, button, hat, JoyHat::DOWN), value & EVENT_HATDOWN_M); - myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, button, hat, JoyHat::LEFT), + myHandler.handleEvent(j->joyMap.get(kEmulationMode, button, hat, JoyHat::LEFT), value & EVENT_HATLEFT_M); } #ifdef GUI_SUPPORT @@ -1080,6 +1069,24 @@ PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRight {Event::JoystickOneDown, JOY_CTRL_NONE, JoyAxis::NONE, JoyDir::NONE, 0, JoyHat::DOWN}, }; +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftPaddlesMapping = { + // TODO: How to handle this? + {Event::PaddleZeroAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG}, + //{Event::SALeftAxis0Value, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG}, + {Event::PaddleOneAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG}, + //{Event::SALeftAxis1Value, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG}, +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultRightPaddlesMapping = { + // TODO: How to handle this? + {Event::PaddleTwoAnalog, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG}, + //{Event::SARightAxis0Value, JOY_CTRL_NONE, JoyAxis::X, JoyDir::ANALOG}, + {Event::PaddleThreeAnalog, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG}, + //{Event::SARightAxis1Value, JOY_CTRL_NONE, JoyAxis::Y, JoyDir::ANALOG}, +}; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PhysicalJoystickHandler::EventMappingArray PhysicalJoystickHandler::DefaultLeftKeypadMapping = { {Event::KeyboardZero1, 0}, diff --git a/src/common/PJoystickHandler.hxx b/src/common/PJoystickHandler.hxx index e1ef3a9c4..ae6eba11c 100644 --- a/src/common/PJoystickHandler.hxx +++ b/src/common/PJoystickHandler.hxx @@ -100,7 +100,7 @@ class PhysicalJoystickHandler } Event::Type eventForHat(EventMode mode, int stick, int hat, JoyHat hatDir, int button) const { const PhysicalJoystickPtr j = joy(stick); - return j->joyHatMap.get(mode, button, hat, hatDir); + return j->joyMap.get(mode, button, hat, hatDir); } /** Returns a list of pairs consisting of joystick name and associated ID. */ @@ -174,11 +174,13 @@ class PhysicalJoystickHandler // Controller specific mappings static EventMappingArray DefaultLeftJoystickMapping; static EventMappingArray DefaultRightJoystickMapping; + static EventMappingArray DefaultLeftPaddlesMapping; + static EventMappingArray DefaultRightPaddlesMapping; static EventMappingArray DefaultLeftKeypadMapping; static EventMappingArray DefaultRightKeypadMapping; - // Static lookup tables for Stelladaptor/2600-daptor axis/button support - /*static const int NUM_JOY_BTN = 4; + /*// Static lookup tables for Stelladaptor/2600-daptor axis/button support + static const int NUM_JOY_BTN = 4; static const int NUM_KEY_BTN = 12; static const Event::Type SA_Axis[NUM_PORTS][NUM_JOY_AXIS]; diff --git a/src/common/PhysicalJoystick.cxx b/src/common/PhysicalJoystick.cxx index f3bf7656c..0c6643d4f 100644 --- a/src/common/PhysicalJoystick.cxx +++ b/src/common/PhysicalJoystick.cxx @@ -83,7 +83,6 @@ string PhysicalJoystick::getMap() const for (int m = 0; m < kNumModes; ++m) { joybuf << MODE_DELIM << m << "|" << joyMap.saveMapping(EventMode(m)); - joybuf << MODE_DELIM << m << "|" << joyHatMap.saveMapping(EventMode(m)); } return joybuf.str(); @@ -103,13 +102,12 @@ bool PhysicalJoystick::setMap(const string& mapString) mappings.push_back(map); } // Error checking - if(mappings.size() != 1 + kNumModes * 2) + if(mappings.size() != 1 + kNumModes) return false; for (int m = 0; m < kNumModes; ++m) { - joyMap.loadMapping(mappings[1 + m * 2], EventMode(m)); - joyHatMap.loadMapping(mappings[2 + m * 2], EventMode(m)); + joyMap.loadMapping(mappings[1 + m], EventMode(m)); } return true; @@ -118,19 +116,13 @@ bool PhysicalJoystick::setMap(const string& mapString) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalJoystick::eraseMap(EventMode mode) { - // Erase button and axis mappings joyMap.eraseMode(mode); - // Erase button and axis mappings - joyHatMap.eraseMode(mode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode) { - // Erase button and axis mappings joyMap.eraseEvent(event, mode); - // Erase hat mappings - joyHatMap.eraseEvent(event, mode); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/PhysicalJoystick.hxx b/src/common/PhysicalJoystick.hxx index dab46c5aa..d0b2f7f26 100644 --- a/src/common/PhysicalJoystick.hxx +++ b/src/common/PhysicalJoystick.hxx @@ -21,7 +21,6 @@ #include "Event.hxx" #include "EventHandlerConstants.hxx" #include "JoyMap.hxx" -#include "JoyHatMap.hxx" /** An abstraction of a physical (real) joystick in Stella. @@ -78,7 +77,6 @@ class PhysicalJoystick // Hashmaps of controller events JoyMap joyMap; - JoyHatMap joyHatMap; private: void getValues(const string& list, IntArray& map) const; diff --git a/src/common/module.mk b/src/common/module.mk index e61dc12fc..eec33213e 100644 --- a/src/common/module.mk +++ b/src/common/module.mk @@ -7,7 +7,6 @@ MODULE_OBJS := \ src/common/FrameBufferSDL2.o \ src/common/FSNodeZIP.o \ src/common/JoyMap.o \ - src/common/JoyHatMap.o \ src/common/KeyMap.o \ src/common/Logger.o \ src/common/main.o \ diff --git a/src/emucore/Console.cxx b/src/emucore/Console.cxx index 262a1df28..ad9bded9b 100644 --- a/src/emucore/Console.cxx +++ b/src/emucore/Console.cxx @@ -135,6 +135,7 @@ Console::Console(OSystem& osystem, unique_ptr& cart, setControllers(md5); // now that we know the controllers, enable the event mappings myOSystem.eventHandler().enableEmulationKeyMappings(); + myOSystem.eventHandler().enableEmulationJoyMappings(); // Mute audio and clear framebuffer while autodetection runs myOSystem.sound().mute(1); diff --git a/src/emucore/EventHandlerConstants.hxx b/src/emucore/EventHandlerConstants.hxx index cd951fdb2..78f184654 100644 --- a/src/emucore/EventHandlerConstants.hxx +++ b/src/emucore/EventHandlerConstants.hxx @@ -50,7 +50,8 @@ enum class JoyAxis { enum class JoyDir { NEG = -1, POS = 1, - NONE = 0 + NONE = 0, + ANALOG = 2 }; diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index 378b7b4f2..8d875739c 100644 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -377,7 +377,6 @@ - @@ -1076,7 +1075,6 @@ - diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index f713f1dd2..5cac7f543 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -978,9 +978,6 @@ Source Files\gui - - Source Files - Source Files @@ -2006,9 +2003,6 @@ Header Files - - Header Files - Header Files