mirror of https://github.com/stella-emu/stella.git
refactor into mapping into single class
add paddle mappings
This commit is contained in:
parent
e4af4b8ff2
commit
4334d00d6d
|
@ -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++;
|
||||
}
|
|
@ -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 <unordered_map>
|
||||
#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<JoyHatMapping>;
|
||||
|
||||
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>()((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<JoyHatMapping, Event::Type, JoyHatHash> myMap;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -135,6 +135,7 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& 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);
|
||||
|
|
|
@ -50,7 +50,8 @@ enum class JoyAxis {
|
|||
enum class JoyDir {
|
||||
NEG = -1,
|
||||
POS = 1,
|
||||
NONE = 0
|
||||
NONE = 0,
|
||||
ANALOG = 2
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -377,7 +377,6 @@
|
|||
<ClCompile Include="..\common\FrameBufferSDL2.cxx" />
|
||||
<ClCompile Include="..\common\FSNodeZIP.cxx" />
|
||||
<ClCompile Include="..\common\JoyMap.cxx" />
|
||||
<ClCompile Include="..\common\JoyHatMap.cxx" />
|
||||
<ClCompile Include="..\common\KeyMap.cxx" />
|
||||
<ClCompile Include="..\common\Logger.cxx" />
|
||||
<ClCompile Include="..\common\main.cxx" />
|
||||
|
@ -1076,7 +1075,6 @@
|
|||
<ClInclude Include="..\common\FSNodeFactory.hxx" />
|
||||
<ClInclude Include="..\common\FSNodeZIP.hxx" />
|
||||
<ClInclude Include="..\common\JoyMap.hxx" />
|
||||
<ClInclude Include="..\common\JoyHatMap.hxx" />
|
||||
<ClInclude Include="..\common\KeyMap.hxx" />
|
||||
<ClInclude Include="..\common\LinkedObjectPool.hxx" />
|
||||
<ClInclude Include="..\common\Logger.hxx" />
|
||||
|
|
|
@ -978,9 +978,6 @@
|
|||
<ClCompile Include="..\gui\R77HelpDialog.cxx">
|
||||
<Filter>Source Files\gui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\common\JoyHatMap.cxx">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\common\JoyMap.cxx">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2006,9 +2003,6 @@
|
|||
<ClInclude Include="..\common\KeyMap.hxx">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\common\JoyHatMap.hxx">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\common\JoyMap.hxx">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue