mirror of https://github.com/stella-emu/stella.git
implement rudimentary mapping
This commit is contained in:
parent
529c1fe7de
commit
8210a25f40
|
@ -35,9 +35,10 @@ void JoyHatMap::add(const Event::Type event, const JoyHatMapping& mapping)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void JoyHatMap::add(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir)
|
||||
void JoyHatMap::add(const Event::Type event, const EventMode mode,
|
||||
const int button, const int hat, const JoyHat hdir)
|
||||
{
|
||||
add(event, JoyHatMapping(mode, hat, hdir));
|
||||
add(event, JoyHatMapping(mode, button, hat, hdir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -47,9 +48,10 @@ void JoyHatMap::erase(const JoyHatMapping& mapping)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void JoyHatMap::erase(const EventMode mode, const int hat, const JoyHat hdir)
|
||||
void JoyHatMap::erase(const EventMode mode,
|
||||
const int button, const int hat, const JoyHat hdir)
|
||||
{
|
||||
erase(JoyHatMapping(mode, hat, hdir));
|
||||
erase(JoyHatMapping(mode, button, hat, hdir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -63,9 +65,10 @@ Event::Type JoyHatMap::get(const JoyHatMapping& mapping) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Event::Type JoyHatMap::get(const EventMode mode, const int hat, const JoyHat hdir) const
|
||||
Event::Type JoyHatMap::get(const EventMode mode,
|
||||
const int button, const int hat, const JoyHat hdir) const
|
||||
{
|
||||
return get(JoyHatMapping(mode, hat, hdir));
|
||||
return get(JoyHatMapping(mode, button, hat, hdir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -77,9 +80,10 @@ bool JoyHatMap::check(const JoyHatMapping & mapping) const
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool JoyHatMap::check(const EventMode mode, const int hat, const JoyHat hdir) const
|
||||
bool JoyHatMap::check(const EventMode mode,
|
||||
const int button, const int hat, const JoyHat hdir) const
|
||||
{
|
||||
return check(JoyHatMapping(mode, hat, hdir));
|
||||
return check(JoyHatMapping(mode, button, hat, hdir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -90,7 +94,7 @@ string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping
|
|||
//buf << "J" << mapping.stick;
|
||||
|
||||
// hat description
|
||||
if (mapping.hat != CTRL_NONE)
|
||||
if (mapping.hat != JOY_CTRL_NONE)
|
||||
{
|
||||
buf << "/H" << mapping.hat;
|
||||
switch (mapping.hdir)
|
||||
|
@ -108,13 +112,14 @@ string JoyHatMap::getDesc(const Event::Type event, const JoyHatMapping & mapping
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string JoyHatMap::getDesc(const Event::Type event, const EventMode mode, const int hat, const JoyHat hdir) const
|
||||
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, hat, hdir));
|
||||
return getDesc(event, JoyHatMapping(mode, button, hat, hdir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string JoyHatMap::getEventMappingDesc(const Event::Type event, const EventMode mode) const
|
||||
string JoyHatMap::getEventMappingDesc(const int stick, const Event::Type event, const EventMode mode) const
|
||||
{
|
||||
ostringstream buf;
|
||||
|
||||
|
@ -124,7 +129,7 @@ string JoyHatMap::getEventMappingDesc(const Event::Type event, const EventMode m
|
|||
{
|
||||
if (buf.str() != "")
|
||||
buf << ", ";
|
||||
buf << getDesc(event, item.first);
|
||||
buf << "J" << stick << getDesc(event, item.first);
|
||||
}
|
||||
}
|
||||
return buf.str();
|
||||
|
@ -169,10 +174,10 @@ 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, hat, hdir, i = 0;
|
||||
int event, stick, button, hat, hdir, i = 0;
|
||||
|
||||
while (buf >> event && buf >> stick && buf >> hat && buf >> hdir && ++i)
|
||||
add(Event::Type(event), EventMode(mode), hat, JoyHat(hdir));
|
||||
while (buf >> event && buf >> stick && buf >> button && buf >> hat && buf >> hdir && ++i)
|
||||
add(Event::Type(event), EventMode(mode), button, hat, JoyHat(hdir));
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -34,19 +34,21 @@ 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)), hat(0), hdir(JoyHat(0)) { }
|
||||
: mode(EventMode(0)), button(0), hat(0), hdir(JoyHat(0)) { }
|
||||
JoyHatMapping(const JoyHatMapping& m)
|
||||
: mode(m.mode), hat(m.hat), hdir(m.hdir) { }
|
||||
explicit JoyHatMapping(EventMode c_mode, int c_hat, JoyHat c_hdir)
|
||||
: mode(c_mode), hat(c_hat), hdir(c_hdir) { }
|
||||
: 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
|
||||
);
|
||||
|
@ -59,26 +61,31 @@ public:
|
|||
|
||||
/** 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 hat, const JoyHat hdir);
|
||||
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 hat, const JoyHat hdir);
|
||||
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 hat, const JoyHat hdir) 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 hat, const JoyHat hdir) 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 hat, const JoyHat hdir) 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 event and mode */
|
||||
string getEventMappingDesc(const Event::Type event, const EventMode mode) 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;
|
||||
|
||||
|
@ -97,8 +104,9 @@ private:
|
|||
struct JoyHatHash {
|
||||
size_t operator()(const JoyHatMapping& m)const {
|
||||
return std::hash<uInt64>()((uInt64(m.mode)) // 3 bit
|
||||
^ ((uInt64(m.hat)) << 3) // 1 bit
|
||||
^ ((uInt64(m.hdir)) << 4) // 2 bits
|
||||
^ ((uInt64(m.button)) << 3) // 2 bits
|
||||
^ ((uInt64(m.hat)) << 5) // 1 bit
|
||||
^ ((uInt64(m.hdir)) << 6) // 2 bits
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ 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)
|
||||
{
|
||||
add(event, JoyMapping(mode, button, axis, adir));
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ void JoyMap::erase(const JoyMapping& mapping)
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void JoyMap::erase(const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir)
|
||||
const JoyAxis axis, const JoyDir adir)
|
||||
{
|
||||
erase(JoyMapping(mode, button, axis, adir));
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ Event::Type JoyMap::get(const JoyMapping& mapping) const
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Event::Type JoyMap::get(const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
{
|
||||
return get(JoyMapping(mode, button, axis, adir));
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ bool JoyMap::check(const JoyMapping & mapping) const
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool JoyMap::check(const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
{
|
||||
return check(JoyMapping(mode, button, axis, adir));
|
||||
}
|
||||
|
@ -94,18 +94,19 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const
|
|||
//buf << "J" << mapping.stick;
|
||||
|
||||
// button description
|
||||
if (mapping.button != CTRL_NONE)
|
||||
if (mapping.button != JOY_CTRL_NONE)
|
||||
buf << "/B" << mapping.button;
|
||||
|
||||
// axis description
|
||||
if (int(mapping.axis) != CTRL_NONE)
|
||||
if (mapping.axis != JoyAxis::NONE)
|
||||
{
|
||||
buf << "/A";
|
||||
switch (mapping.axis)
|
||||
{
|
||||
case JoyAxis::X: buf << "X"; break;
|
||||
case JoyAxis::Y: buf << "Y"; break;
|
||||
default: break;
|
||||
case JoyAxis::Z: buf << "Z"; break;
|
||||
default: buf << int(mapping.axis); break;
|
||||
}
|
||||
|
||||
if (Event::isAnalog(event))
|
||||
|
@ -121,13 +122,13 @@ string JoyMap::getDesc(const Event::Type event, const JoyMapping& mapping) const
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string JoyMap::getDesc(const Event::Type event, const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
const JoyAxis axis, const JoyDir adir) const
|
||||
{
|
||||
return getDesc(event, JoyMapping(mode, button, axis, adir));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
string JoyMap::getEventMappingDesc(const Event::Type event, const EventMode mode) const
|
||||
string JoyMap::getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const
|
||||
{
|
||||
ostringstream buf;
|
||||
|
||||
|
@ -137,7 +138,7 @@ string JoyMap::getEventMappingDesc(const Event::Type event, const EventMode mode
|
|||
{
|
||||
if (buf.str() != "")
|
||||
buf << ", ";
|
||||
buf << getDesc(event, item.first);
|
||||
buf << "J" << stick << getDesc(event, item.first);
|
||||
}
|
||||
}
|
||||
return buf.str();
|
||||
|
@ -166,7 +167,7 @@ string JoyMap::saveMapping(const EventMode mode) const
|
|||
{
|
||||
if (buf.str() != "")
|
||||
buf << "|";
|
||||
buf << item.second << ":" /*<< item.first.stick*/ << "," << item.first.button << ","
|
||||
buf << item.second << ":" << item.first.button << ","
|
||||
<< int(item.first.axis) << "," << int(item.first.adir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,30 +66,30 @@ 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);
|
||||
|
||||
/** Erase mapping */
|
||||
void erase(const JoyMapping& mapping);
|
||||
void erase(const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir);
|
||||
const JoyAxis axis, const JoyDir adir);
|
||||
|
||||
/** Get event for mapping */
|
||||
Event::Type get(const JoyMapping& mapping) const;
|
||||
Event::Type get(const EventMode mode, const int button,
|
||||
const JoyAxis axis, const JoyDir adir) const;
|
||||
const JoyAxis axis = JoyAxis::NONE, const JoyDir adir = JoyDir::NONE) 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;
|
||||
const JoyAxis axis, const JoyDir adir) 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;
|
||||
const JoyAxis axis, const JoyDir adir) const;
|
||||
|
||||
/** Get the mapping description(s) for given event and mode */
|
||||
string getEventMappingDesc(const Event::Type event, const EventMode mode) const;
|
||||
/** Get the mapping description(s) for given stick, event and mode */
|
||||
string getEventMappingDesc(int stick, const Event::Type event, const EventMode mode) const;
|
||||
|
||||
JoyMappingArray getEventMapping(const Event::Type event, const EventMode mode) const;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ PhysicalJoystickHandler::PhysicalJoystickHandler(
|
|||
|
||||
// First compare if event list version has changed, and disregard the entire mapping if true
|
||||
getline(buf, joymap, '^'); // event list size, ignore
|
||||
if(version == Event::VERSION)
|
||||
if(version != Event::VERSION)
|
||||
{
|
||||
// Otherwise, put each joystick mapping entry into the database
|
||||
while(getline(buf, joymap, '^'))
|
||||
|
@ -251,20 +251,29 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
|||
{
|
||||
bool eraseAll = (event == Event::NoType);
|
||||
|
||||
auto setDefaultAxis = [&](int a_stick, JoyAxis a_axis, JoyDir a_value, Event::Type a_event)
|
||||
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, a_stick, int(a_axis), int(a_value), false);
|
||||
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 = [&](int b_stick, int b_button, Event::Type b_event)
|
||||
auto setDefaultBtn = [&](Event::Type b_event, int stick, int button)
|
||||
{
|
||||
if(eraseAll || b_event == event)
|
||||
myHandler.addJoyButtonMapping(b_event, mode, b_stick, b_button, false);
|
||||
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 = [&](int h_stick, int h_hat, JoyHat h_dir, Event::Type h_event)
|
||||
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, h_stick, h_hat, h_dir, false);
|
||||
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)
|
||||
|
@ -275,54 +284,54 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
|||
case 0:
|
||||
case 2:
|
||||
// Left joystick left/right directions (assume joystick zero or two)
|
||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickZeroLeft);
|
||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickZeroRight);
|
||||
setDefaultAxis(Event::JoystickZeroLeft, stick, JoyAxis::X, JoyDir::NEG);
|
||||
setDefaultAxis(Event::JoystickZeroRight, stick, JoyAxis::X, JoyDir::POS);
|
||||
// Left joystick up/down directions (assume joystick zero or two)
|
||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickZeroUp);
|
||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickZeroDown);
|
||||
setDefaultAxis(Event::JoystickZeroUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||
setDefaultAxis(Event::JoystickZeroDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||
// Left joystick (assume joystick zero or two, buttons zero..two)
|
||||
setDefaultBtn(stick, 0, Event::JoystickZeroFire);
|
||||
setDefaultBtn(stick, 1, Event::JoystickZeroFire5);
|
||||
setDefaultBtn(stick, 2, Event::JoystickZeroFire9);
|
||||
setDefaultBtn(Event::JoystickZeroFire, stick, 0);
|
||||
setDefaultBtn(Event::JoystickZeroFire5, stick, 1);
|
||||
setDefaultBtn(Event::JoystickZeroFire9, stick, 2);
|
||||
// Left joystick left/right directions (assume joystick zero or two and hat 0)
|
||||
setDefaultHat(stick, 0, JoyHat::LEFT, Event::JoystickZeroLeft);
|
||||
setDefaultHat(stick, 0, JoyHat::RIGHT, Event::JoystickZeroRight);
|
||||
setDefaultHat(Event::JoystickZeroLeft, stick, 0, JoyHat::LEFT);
|
||||
setDefaultHat(Event::JoystickZeroRight, stick, 0, JoyHat::RIGHT);
|
||||
// Left joystick up/down directions (assume joystick zero or two and hat 0)
|
||||
setDefaultHat(stick, 0, JoyHat::UP, Event::JoystickZeroUp);
|
||||
setDefaultHat(stick, 0, JoyHat::DOWN, Event::JoystickZeroDown);
|
||||
setDefaultHat(Event::JoystickZeroUp, stick, 0, JoyHat::UP);
|
||||
setDefaultHat(Event::JoystickZeroDown, stick, 0, JoyHat::DOWN);
|
||||
#if defined(RETRON77)
|
||||
// Left joystick (assume joystick zero or two, buttons two..four)
|
||||
setDefaultBtn(stick, 2, Event::CmdMenuMode);
|
||||
setDefaultBtn(stick, 3, Event::OptionsMenuMode);
|
||||
setDefaultBtn(stick, 4, Event::ExitMode);
|
||||
setDefaultBtn(Event::CmdMenuMode, stick, 2);
|
||||
setDefaultBtn(Event::OptionsMenuMode, stick, 3);
|
||||
setDefaultBtn(Event::ExitMode, stick, 4);
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
case 3:
|
||||
// Right joystick left/right directions (assume joystick one or three)
|
||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::NEG, Event::JoystickOneLeft);
|
||||
setDefaultAxis(stick, JoyAxis::X, JoyDir::POS, Event::JoystickOneRight);
|
||||
setDefaultAxis(Event::JoystickOneLeft, stick, JoyAxis::X, JoyDir::NEG);
|
||||
setDefaultAxis(Event::JoystickOneRight, stick, JoyAxis::X, JoyDir::POS);
|
||||
// Right joystick left/right directions (assume joystick one or three)
|
||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::NEG, Event::JoystickOneUp);
|
||||
setDefaultAxis(stick, JoyAxis::Y, JoyDir::POS, Event::JoystickOneDown);
|
||||
setDefaultAxis(Event::JoystickOneUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||
setDefaultAxis(Event::JoystickOneDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||
// Right joystick (assume joystick one or three, buttons zero..two)
|
||||
setDefaultBtn(stick, 0, Event::JoystickOneFire);
|
||||
setDefaultBtn(stick, 1, Event::JoystickOneFire5);
|
||||
setDefaultBtn(stick, 2, Event::JoystickOneFire9);
|
||||
setDefaultBtn(Event::JoystickOneFire, stick, 0);
|
||||
setDefaultBtn(Event::JoystickOneFire5, stick, 1);
|
||||
setDefaultBtn(Event::JoystickOneFire9, stick, 2);
|
||||
// Right joystick left/right directions (assume joystick one or three and hat 0)
|
||||
setDefaultHat(stick, 0, JoyHat::LEFT, Event::JoystickOneLeft);
|
||||
setDefaultHat(stick, 0, JoyHat::RIGHT, Event::JoystickOneRight);
|
||||
setDefaultHat(Event::JoystickOneLeft, stick, 0, JoyHat::LEFT);
|
||||
setDefaultHat(Event::JoystickOneRight, stick, 0, JoyHat::RIGHT);
|
||||
// Right joystick up/down directions (assume joystick one or three and hat 0)
|
||||
setDefaultHat(stick, 0, JoyHat::UP, Event::JoystickOneUp);
|
||||
setDefaultHat(stick, 0, JoyHat::DOWN, Event::JoystickOneDown);
|
||||
setDefaultHat(Event::JoystickOneUp, stick, 0, JoyHat::UP);
|
||||
setDefaultHat(Event::JoystickOneDown, stick, 0, JoyHat::DOWN);
|
||||
#if defined(RETRON77)
|
||||
// Right joystick (assume joystick one or three, buttons two..four)
|
||||
setDefaultBtn(stick, 2, Event::CmdMenuMode);
|
||||
setDefaultBtn(stick, 3, Event::OptionsMenuMode);
|
||||
setDefaultBtn(stick, 4, Event::ExitMode);
|
||||
setDefaultBtn(stick, 5, Event::RewindPause);
|
||||
setDefaultBtn(stick, 7, Event::ConsoleSelect);
|
||||
setDefaultBtn(stick, 8, Event::ConsoleReset);
|
||||
setDefaultBtn(Event::CmdMenuMode, stick, 2);
|
||||
setDefaultBtn(Event::OptionsMenuMode, stick, 3);
|
||||
setDefaultBtn(Event::ExitMode, stick, 4);
|
||||
setDefaultBtn(Event::RewindPause, stick, 5);
|
||||
setDefaultBtn(Event::ConsoleSelect, stick, 7);
|
||||
setDefaultBtn(Event::ConsoleReset, stick, 8);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
|
@ -331,28 +340,27 @@ void PhysicalJoystickHandler::setStickDefaultMapping(int stick,
|
|||
break;
|
||||
|
||||
case kMenuMode: // Default menu/UI events
|
||||
setDefaultAxis( stick, JoyAxis::X, JoyDir::NEG, Event::UINavPrev );
|
||||
setDefaultAxis( stick, JoyAxis::X, JoyDir::POS, Event::UINavNext );
|
||||
setDefaultAxis( stick, JoyAxis::Y, JoyDir::NEG, Event::UIUp );
|
||||
setDefaultAxis( stick, JoyAxis::Y, JoyDir::POS, Event::UIDown );
|
||||
setDefaultAxis(Event::UINavPrev, stick, JoyAxis::X, JoyDir::NEG);
|
||||
setDefaultAxis(Event::UINavNext, stick, JoyAxis::X, JoyDir::POS);
|
||||
setDefaultAxis(Event::UIUp, stick, JoyAxis::Y, JoyDir::NEG);
|
||||
setDefaultAxis(Event::UIDown, stick, JoyAxis::Y, JoyDir::POS);
|
||||
|
||||
// joystick (assume buttons zero..three)
|
||||
setDefaultBtn( stick, 0, Event::UISelect );
|
||||
setDefaultBtn( stick, 1, Event::UIOK );
|
||||
setDefaultBtn( stick, 2, Event::UITabNext);
|
||||
setDefaultBtn( stick, 3, Event::UITabPrev );
|
||||
setDefaultBtn( stick, 5, Event::UICancel);
|
||||
setDefaultBtn(Event::UISelect, stick, 0);
|
||||
setDefaultBtn(Event::UIOK, stick, 1);
|
||||
setDefaultBtn(Event::UITabNext, stick, 2);
|
||||
setDefaultBtn(Event::UITabPrev, stick, 3);
|
||||
setDefaultBtn(Event::UICancel, stick, 5);
|
||||
|
||||
setDefaultHat( stick, 0, JoyHat::LEFT, Event::UINavPrev );
|
||||
setDefaultHat( stick, 0, JoyHat::RIGHT, Event::UINavNext );
|
||||
setDefaultHat( stick, 0, JoyHat::UP, Event::UIUp );
|
||||
setDefaultHat( stick, 0, JoyHat::DOWN, Event::UIDown );
|
||||
setDefaultHat(Event::UINavPrev, stick, 0, JoyHat::LEFT);
|
||||
setDefaultHat(Event::UINavNext, stick, 0, JoyHat::RIGHT);
|
||||
setDefaultHat(Event::UIUp, stick, 0, JoyHat::UP);
|
||||
setDefaultHat(Event::UIDown, stick, 0, JoyHat::DOWN);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -378,13 +386,14 @@ 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;
|
||||
//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 << map;
|
||||
}
|
||||
myOSystem.settings().setValue("joymap", joybuf.str());
|
||||
}
|
||||
|
@ -400,7 +409,7 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
|
|||
const PhysicalJoystickPtr j = s.second;
|
||||
if(!j) continue;
|
||||
|
||||
// Joystick button mapping/labeling
|
||||
/*// Joystick button mapping/labeling
|
||||
for(int button = 0; button < j->numButtons; ++button)
|
||||
{
|
||||
if(j->btnTable[button][mode] == event)
|
||||
|
@ -454,13 +463,21 @@ string PhysicalJoystickHandler::getMappingDesc(Event::Type event, EventMode mode
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// new:
|
||||
//Joystick button + axis mapping / labeling
|
||||
if (j->joyMap.getEventMapping(event, mode).size())
|
||||
buf << j->joyMap.getEventMappingDesc(stick, event, mode);
|
||||
// Joystick hat mapping/labeling
|
||||
if (j->joyHatMap.getEventMapping(event, mode).size())
|
||||
buf << j->joyHatMap.getEventMappingDesc(stick, event, mode);
|
||||
}
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
|
||||
/*bool PhysicalJoystickHandler::addAxisMapping(Event::Type event, EventMode mode,
|
||||
int stick, int axis, int value)
|
||||
{
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
|
@ -519,24 +536,55 @@ bool PhysicalJoystickHandler::addHatMapping(Event::Type event, EventMode mode,
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, JoyAxis axis, JoyDir adir)
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool PhysicalJoystickHandler::addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, JoyAxis axis, int value)
|
||||
{
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
|
||||
j->joyMap.add(event, mode, button, axis, adir);
|
||||
if (j && event < Event::LastType &&
|
||||
button >= JOY_CTRL_NONE && button < j->numButtons &&
|
||||
axis >= JoyAxis::NONE && int(axis) < j->numAxes)
|
||||
{
|
||||
// This confusing code is because each axis has two associated values,
|
||||
// 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, turn off the analog event(s) for this axis
|
||||
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.add(event, mode, button, axis, value == int(JoyDir::NONE) ? JoyDir::NONE : value > 0 ? JoyDir::POS : JoyDir::NEG);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||
int hat, JoyHat hdir)
|
||||
bool PhysicalJoystickHandler::addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, int hat, JoyHat dir)
|
||||
{
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
|
||||
j->joyHatMap.add(event, mode, hat, hdir);
|
||||
if (j && event < Event::LastType &&
|
||||
button >= JOY_CTRL_NONE && button < j->numButtons &&
|
||||
hat >= 0 && hat < j->numHats && dir != JoyHat::CENTER)
|
||||
{
|
||||
j->joyHatMap.add(event, mode, button, hat, dir);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -552,8 +600,10 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value)
|
|||
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->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);
|
||||
|
||||
// Check for analog events, which are handled differently
|
||||
// We'll pass them off as Stelladaptor events, and let the controllers
|
||||
|
@ -646,19 +696,22 @@ 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;
|
||||
if(!j) return;
|
||||
j->buttonLast[stick] = pressed ? button : JOY_CTRL_NONE;
|
||||
|
||||
// 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->btnTable[button][kEmulationMode]))
|
||||
//if(pressed && myHandler.changeStateByEvent(j->btnTable[button][kEmulationMode]))
|
||||
if (pressed && myHandler.changeStateByEvent(j->joyMap.get(kEmulationMode, button)))
|
||||
return;
|
||||
|
||||
// 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->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);
|
||||
|
@ -718,14 +771,17 @@ void PhysicalJoystickHandler::handleHatEvent(int stick, int hat, int value)
|
|||
const PhysicalJoystickPtr j = joy(stick);
|
||||
if(!j) return;
|
||||
|
||||
myHandler.handleEvent(j->hatTable[hat][int(JoyHat::UP)][kEmulationMode],
|
||||
/*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);
|
||||
value & EVENT_HATLEFT_M);*/
|
||||
|
||||
// TODO: 4 different events
|
||||
myHandler.handleEvent(j->joyHatMap.get(kEmulationMode, JOY_CTRL_NONE, hat, JoyHat(value)));
|
||||
}
|
||||
#ifdef GUI_SUPPORT
|
||||
else if(myHandler.hasOverlay())
|
||||
|
|
|
@ -74,15 +74,15 @@ 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 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 addHatMapping(Event::Type event, EventMode mode, int stick, int hat, JoyHat value);*/
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, JoyAxis axis, JoyDir adir);
|
||||
void addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||
int hat, JoyHat hdir);
|
||||
bool addJoyMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, JoyAxis axis, int value);
|
||||
bool addJoyHatMapping(Event::Type event, EventMode mode, int stick,
|
||||
int button, int hat, JoyHat hdir);
|
||||
|
||||
/** Handle a physical joystick event. */
|
||||
void handleAxisEvent(int stick, int axis, int value);
|
||||
|
@ -91,16 +91,19 @@ class PhysicalJoystickHandler
|
|||
|
||||
Event::Type eventForAxis(int stick, int axis, int joyDir, EventMode mode) const {
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
return (j && joyDir != int(JoyDir::NEG))
|
||||
? j->axisTable[axis][(joyDir > int(JoyDir::NEG))][mode] : Event::NoType;
|
||||
//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));
|
||||
}
|
||||
Event::Type eventForButton(int stick, int button, EventMode mode) const {
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
return j ? j->btnTable[button][mode] : Event::NoType;
|
||||
// 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 {
|
||||
const PhysicalJoystickPtr j = joy(stick);
|
||||
return j ? j->hatTable[hat][int(hatDir)][mode] : Event::NoType;
|
||||
//return j ? j->hatTable[hat][int(hatDir)][mode] : Event::NoType;
|
||||
return j->joyHatMap.get(mode, JOY_CTRL_NONE, hat, hatDir);
|
||||
}
|
||||
|
||||
/** Returns a list of pairs consisting of joystick name and associated ID. */
|
||||
|
|
|
@ -31,20 +31,22 @@ PhysicalJoystick::PhysicalJoystick()
|
|||
numAxes(0),
|
||||
numButtons(0),
|
||||
numHats(0),
|
||||
axisTable(nullptr),
|
||||
/*axisTable(nullptr),
|
||||
btnTable(nullptr),
|
||||
hatTable(nullptr),
|
||||
axisLastValue(nullptr)
|
||||
hatTable(nullptr),*/
|
||||
axisLastValue(nullptr),
|
||||
buttonLast(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
PhysicalJoystick::~PhysicalJoystick()
|
||||
{
|
||||
delete[] axisTable;
|
||||
/*delete[] axisTable;
|
||||
delete[] btnTable;
|
||||
delete[] hatTable;
|
||||
delete[] hatTable;*/
|
||||
delete[] axisLastValue;
|
||||
delete[] buttonLast;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -59,24 +61,28 @@ void PhysicalJoystick::initialize(int index, const string& desc,
|
|||
numAxes = axes;
|
||||
numButtons = buttons;
|
||||
numHats = hats;
|
||||
if(numAxes)
|
||||
/*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];
|
||||
hatTable = new Event::Type[numHats][NUM_JOY_HAT_DIRS][kNumModes];*/
|
||||
axisLastValue = new int[numAxes];
|
||||
buttonLast = new int[numButtons];
|
||||
|
||||
for (int b = 0; b < numButtons; ++b)
|
||||
buttonLast[b] = JOY_CTRL_NONE;
|
||||
|
||||
// Erase the joystick axis mapping array and last axis value
|
||||
for(int a = 0; a < numAxes; ++a)
|
||||
{
|
||||
axisLastValue[a] = 0;
|
||||
for(int m = 0; m < kNumModes; ++m)
|
||||
/*for(int m = 0; m < kNumModes; ++m)
|
||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||
axisTable[a][d][m] = Event::NoType;
|
||||
axisTable[a][d][m] = Event::NoType;*/
|
||||
}
|
||||
|
||||
// Erase the joystick button mapping array
|
||||
/*// 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;
|
||||
|
@ -85,7 +91,10 @@ void PhysicalJoystick::initialize(int index, const string& desc,
|
|||
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;
|
||||
hatTable[h][d][m] = Event::NoType;*/
|
||||
|
||||
for (int m = 0; m < kNumModes; ++m)
|
||||
eraseMap(EventMode(m));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -97,7 +106,7 @@ string PhysicalJoystick::getMap() const
|
|||
if(type == JT_REGULAR)
|
||||
{
|
||||
ostringstream joybuf;
|
||||
joybuf << name << "|" << numAxes;
|
||||
/*joybuf << name << "|" << numAxes;
|
||||
for(int m = 0; m < kNumModes; ++m)
|
||||
for(int a = 0; a < numAxes; ++a)
|
||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||
|
@ -110,7 +119,12 @@ string PhysicalJoystick::getMap() const
|
|||
for(int m = 0; m < kNumModes; ++m)
|
||||
for(int h = 0; h < numHats; ++h)
|
||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||
joybuf << " " << hatTable[h][d][m];
|
||||
joybuf << " " << hatTable[h][d][m];*/
|
||||
|
||||
// new:
|
||||
joybuf << name;
|
||||
for (int m = 0; m < kNumModes; ++m)
|
||||
joybuf << "|" << m << "|" << joyMap.saveMapping(EventMode(m));
|
||||
|
||||
return joybuf.str();
|
||||
}
|
||||
|
@ -133,7 +147,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
|||
IntArray map;
|
||||
|
||||
// Parse axis/button/hat values
|
||||
getValues(items[1], map);
|
||||
/*getValues(items[1], map);
|
||||
if(int(map.size()) == numAxes * NUM_JOY_DIRS * kNumModes)
|
||||
{
|
||||
// Fill the axes table with events
|
||||
|
@ -161,7 +175,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
|||
for(int h = 0; h < numHats; ++h)
|
||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||
hatTable[h][d][m] = Event::Type(*event++);
|
||||
}
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -169,7 +183,7 @@ bool PhysicalJoystick::setMap(const string& mapString)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void PhysicalJoystick::eraseMap(EventMode mode)
|
||||
{
|
||||
// Erase axis mappings
|
||||
/*// Erase axis mappings
|
||||
for(int a = 0; a < numAxes; ++a)
|
||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||
axisTable[a][d][mode] = Event::NoType;
|
||||
|
@ -181,13 +195,18 @@ void PhysicalJoystick::eraseMap(EventMode mode)
|
|||
// Erase hat mappings
|
||||
for(int h = 0; h < numHats; ++h)
|
||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||
hatTable[h][d][mode] = Event::NoType;
|
||||
hatTable[h][d][mode] = Event::NoType;*/
|
||||
|
||||
// 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 axis mappings
|
||||
/*// Erase axis mappings
|
||||
for(int a = 0; a < numAxes; ++a)
|
||||
for (int d = 0; d < NUM_JOY_DIRS; ++d)
|
||||
if(axisTable[a][d][mode] == event)
|
||||
|
@ -202,7 +221,12 @@ void PhysicalJoystick::eraseEvent(Event::Type event, EventMode mode)
|
|||
for(int h = 0; h < numHats; ++h)
|
||||
for (int d = 0; d < NUM_JOY_HAT_DIRS; ++d)
|
||||
if(hatTable[h][d][mode] == event)
|
||||
hatTable[h][d][mode] = Event::NoType;
|
||||
hatTable[h][d][mode] = Event::NoType;*/
|
||||
|
||||
// Erase button and axis mappings
|
||||
joyMap.eraseEvent(event, mode);
|
||||
// Erase hat mappings
|
||||
joyHatMap.eraseEvent(event, mode);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -67,10 +67,12 @@ class PhysicalJoystick
|
|||
int ID;
|
||||
string name;
|
||||
int numAxes, numButtons, numHats;
|
||||
Event::Type (*axisTable)[NUM_JOY_DIRS][kNumModes];
|
||||
/*Event::Type (*axisTable)[NUM_JOY_DIRS][kNumModes];
|
||||
Event::Type (*btnTable)[kNumModes];
|
||||
Event::Type (*hatTable)[NUM_JOY_HAT_DIRS][kNumModes];
|
||||
Event::Type (*hatTable)[NUM_JOY_HAT_DIRS][kNumModes];*/
|
||||
int* axisLastValue;
|
||||
int* buttonLast;
|
||||
|
||||
|
||||
// Hashmaps of controller events
|
||||
JoyMap joyMap;
|
||||
|
|
|
@ -1124,7 +1124,7 @@ bool EventHandler::addKeyMapping(Event::Type event, EventMode mode, StellaKey ke
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool EventHandler::addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||
/*bool EventHandler::addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||
int stick, int axis, int value,
|
||||
bool updateMenus)
|
||||
{
|
||||
|
@ -1169,8 +1169,41 @@ bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
|
|||
#else
|
||||
return false;
|
||||
#endif
|
||||
}*/
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool EventHandler::addJoyMapping(Event::Type event, EventMode mode,
|
||||
int stick, int button, JoyAxis axis, int value,
|
||||
bool updateMenus)
|
||||
{
|
||||
#ifdef JOYSTICK_SUPPORT
|
||||
bool mapped = myPJoyHandler->addJoyMapping(event, mode, stick, button, axis, value);
|
||||
if (mapped && updateMenus)
|
||||
setActionMappings(mode);
|
||||
|
||||
return mapped;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool EventHandler::addJoyHatMapping(Event::Type event, EventMode mode,
|
||||
int stick, int button, int hat, JoyHat dir,
|
||||
bool updateMenus)
|
||||
{
|
||||
#ifdef JOYSTICK_SUPPORT
|
||||
bool mapped = myPJoyHandler->addJoyHatMapping(event, mode, stick, button, hat, dir);
|
||||
if (mapped && updateMenus)
|
||||
setActionMappings(mode);
|
||||
|
||||
return mapped;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventHandler::eraseMapping(Event::Type event, EventMode mode)
|
||||
{
|
||||
|
|
|
@ -219,7 +219,7 @@ class EventHandler
|
|||
we want to do this, unless there are a batch of
|
||||
'adds', in which case it's delayed until the end
|
||||
*/
|
||||
bool addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||
/*bool addJoyAxisMapping(Event::Type event, EventMode mode,
|
||||
int stick, int axis, int value,
|
||||
bool updateMenus = true);
|
||||
|
||||
|
@ -235,7 +235,7 @@ class EventHandler
|
|||
we want to do this, unless there are a batch of
|
||||
'adds', in which case it's delayed until the end
|
||||
*/
|
||||
bool addJoyButtonMapping(Event::Type event, EventMode mode, int stick, int button,
|
||||
/*bool addJoyButtonMapping(Event::Type event, EventMode mode, int stick, int button,
|
||||
bool updateMenus = true);
|
||||
|
||||
/**
|
||||
|
@ -251,10 +251,18 @@ class EventHandler
|
|||
we want to do this, unless there are a batch of
|
||||
'adds', in which case it's delayed until the end
|
||||
*/
|
||||
bool addJoyHatMapping(Event::Type event, EventMode mode,
|
||||
/*bool addJoyHatMapping(Event::Type event, EventMode mode,
|
||||
int stick, int hat, JoyHat value,
|
||||
bool updateMenus = true);*/
|
||||
|
||||
bool addJoyMapping(Event::Type event, EventMode mode,
|
||||
int stick, int button, JoyAxis axis = JoyAxis::NONE, int value = 0,
|
||||
bool updateMenus = true);
|
||||
bool addJoyHatMapping(Event::Type event, EventMode mode,
|
||||
int stick, int button, int hat, JoyHat dir,
|
||||
bool updateMenus = true);
|
||||
|
||||
|
||||
/**
|
||||
Erase the specified mapping.
|
||||
|
||||
|
|
|
@ -38,16 +38,19 @@ enum class MouseButton {
|
|||
NONE
|
||||
};
|
||||
|
||||
static constexpr int CTRL_NONE = -1;
|
||||
static constexpr int JOY_CTRL_NONE = -1;
|
||||
|
||||
enum class JoyAxis {
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Z = 2,
|
||||
NONE = JOY_CTRL_NONE
|
||||
};
|
||||
|
||||
enum class JoyDir {
|
||||
NEG = 0,
|
||||
POS = 1,
|
||||
NONE = JOY_CTRL_NONE
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font,
|
|||
myLastAxis(0),
|
||||
myLastHat(0),
|
||||
myLastValue(0),
|
||||
myLastButton(JOY_CTRL_NONE),
|
||||
myFirstTime(true)
|
||||
{
|
||||
const int fontHeight = font.getFontHeight(),
|
||||
|
@ -159,9 +160,10 @@ void EventMappingWidget::startRemapping()
|
|||
|
||||
// Reset all previous events for determining correct axis/hat values
|
||||
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
||||
myLastButton = JOY_CTRL_NONE;
|
||||
|
||||
// Reset the previously aggregated key mappings
|
||||
myMod = myKey = 0;
|
||||
myMod = myLastKey = 0;
|
||||
|
||||
// Disable all other widgets while in remap mode, except enable 'Cancel'
|
||||
enableButtons(false);
|
||||
|
@ -213,6 +215,7 @@ void EventMappingWidget::stopRemapping()
|
|||
|
||||
// Reset all previous events for determining correct axis/hat values
|
||||
myLastStick = myLastAxis = myLastHat = myLastValue = -1;
|
||||
myLastButton = JOY_CTRL_NONE;
|
||||
|
||||
// And re-enable all the widgets
|
||||
enableButtons(true);
|
||||
|
@ -257,7 +260,7 @@ bool EventMappingWidget::handleKeyDown(StellaKey key, StellaMod mod)
|
|||
// Remap keys in remap mode
|
||||
if (myRemapStatus && myActionSelected >= 0)
|
||||
{
|
||||
myKey = key;
|
||||
myLastKey = key;
|
||||
myMod |= mod;
|
||||
}
|
||||
return true;
|
||||
|
@ -272,7 +275,7 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
|
|||
{
|
||||
Event::Type event =
|
||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
||||
if (instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myKey), StellaMod(myMod)))
|
||||
if (instance().eventHandler().addKeyMapping(event, myEventMode, StellaKey(myLastKey), StellaMod(myMod)))
|
||||
stopRemapping();
|
||||
}
|
||||
return true;
|
||||
|
@ -281,19 +284,42 @@ bool EventMappingWidget::handleKeyUp(StellaKey key, StellaMod mod)
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventMappingWidget::handleJoyDown(int stick, int button)
|
||||
{
|
||||
cerr << "handleJoyDown" << endl;
|
||||
// Remap joystick buttons in remap mode
|
||||
if(myRemapStatus && myActionSelected >= 0)
|
||||
{
|
||||
Event::Type event =
|
||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
||||
if(instance().eventHandler().addJoyButtonMapping(event, myEventMode, stick, button))
|
||||
stopRemapping();
|
||||
myLastStick = stick;
|
||||
myLastButton = button;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventMappingWidget::handleJoyUp(int stick, int button)
|
||||
{
|
||||
cerr << "handleJoyUp" << endl;
|
||||
// Remap joystick buttons in remap mode
|
||||
if (myRemapStatus && myActionSelected >= 0)
|
||||
{
|
||||
if (myLastStick == stick && myLastButton == button)
|
||||
{
|
||||
EventHandler& eh = instance().eventHandler();
|
||||
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||
|
||||
cerr << "remap" << endl;
|
||||
// This maps solo button presses only
|
||||
if (eh.addJoyMapping(event, myEventMode, stick, button)) // new
|
||||
stopRemapping();
|
||||
|
||||
//if (eh.addJoyButtonMapping(event, myEventMode, stick, button))
|
||||
// stopRemapping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
||||
{
|
||||
cerr << "handleJoyAxis:" << axis << ", " << value << ", (" << stick << ", " << myLastStick << "), (" << axis << ", " << myLastAxis << ")" << endl;
|
||||
// Remap joystick axes in remap mode
|
||||
// There are two phases to detection:
|
||||
// First, detect an axis 'on' event
|
||||
|
@ -301,8 +327,9 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
|||
if(myRemapStatus && myActionSelected >= 0)
|
||||
{
|
||||
// Detect the first axis event that represents 'on'
|
||||
if(myLastStick == -1 && myLastAxis == -1 && value != 0)
|
||||
if((myLastStick == -1 || myLastStick == stick) && myLastAxis == -1 && value != 0)
|
||||
{
|
||||
cerr << "remap start" << endl;
|
||||
myLastStick = stick;
|
||||
myLastAxis = axis;
|
||||
myLastValue = value;
|
||||
|
@ -311,13 +338,15 @@ void EventMappingWidget::handleJoyAxis(int stick, int axis, int value)
|
|||
// stick and axis, but turns the axis 'off'
|
||||
else if(myLastStick == stick && axis == myLastAxis && value == 0)
|
||||
{
|
||||
value = myLastValue;
|
||||
EventHandler& eh = instance().eventHandler();
|
||||
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||
|
||||
Event::Type event =
|
||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
||||
if(instance().eventHandler().addJoyAxisMapping(event, myEventMode,
|
||||
stick, axis, value))
|
||||
stopRemapping();
|
||||
cerr << "remap stop" << endl;
|
||||
if (eh.addJoyMapping(event, myEventMode, stick, myLastButton, JoyAxis(axis), myLastValue))
|
||||
stopRemapping(); // new
|
||||
|
||||
//if(eh.addJoyAxisMapping(event, myEventMode, stick, axis, myLastValue))
|
||||
// stopRemapping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,7 +361,7 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value)
|
|||
if(myRemapStatus && myActionSelected >= 0)
|
||||
{
|
||||
// Detect the first hat event that represents a valid direction
|
||||
if(myLastStick == -1 && myLastHat == -1 && value != JoyHat::CENTER)
|
||||
if((myLastStick == -1 || myLastStick == stick) && myLastHat == -1 && value != JoyHat::CENTER)
|
||||
{
|
||||
myLastStick = stick;
|
||||
myLastHat = hat;
|
||||
|
@ -344,16 +373,19 @@ bool EventMappingWidget::handleJoyHat(int stick, int hat, JoyHat value)
|
|||
// stick and hat, but centers the hat
|
||||
else if(myLastStick == stick && hat == myLastHat && value == JoyHat::CENTER)
|
||||
{
|
||||
value = JoyHat(myLastValue);
|
||||
EventHandler& eh = instance().eventHandler();
|
||||
Event::Type event = eh.eventAtIndex(myActionSelected, myEventMode);
|
||||
|
||||
Event::Type event =
|
||||
instance().eventHandler().eventAtIndex(myActionSelected, myEventMode);
|
||||
if(instance().eventHandler().addJoyHatMapping(event, myEventMode,
|
||||
stick, hat, value))
|
||||
if (eh.addJoyHatMapping(event, myEventMode, stick, myLastButton, hat, JoyHat(myLastValue)))
|
||||
{
|
||||
stopRemapping();
|
||||
return true;
|
||||
}
|
||||
/*if(eh.addJoyHatMapping(event, myEventMode, stick, hat, myLastValue))
|
||||
{
|
||||
stopRemapping();
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ class EventMappingWidget : public Widget, public CommandSender
|
|||
bool handleKeyDown(StellaKey key, StellaMod mod) override;
|
||||
bool handleKeyUp(StellaKey key, StellaMod mod) override;
|
||||
void handleJoyDown(int stick, int button) override;
|
||||
void handleJoyUp(int stick, int button) override;
|
||||
void handleJoyAxis(int stick, int axis, int value) override;
|
||||
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
||||
|
||||
|
@ -108,7 +109,9 @@ class EventMappingWidget : public Widget, public CommandSender
|
|||
// Aggregates the modifier flags of the mapping
|
||||
int myMod;
|
||||
// Saves the last *pressed* key
|
||||
int myKey;
|
||||
int myLastKey;
|
||||
// Saves the last *pressed* button
|
||||
int myLastButton;
|
||||
|
||||
bool myFirstTime;
|
||||
|
||||
|
|
|
@ -480,6 +480,18 @@ void InputDialog::handleJoyDown(int stick, int button)
|
|||
Dialog::handleJoyDown(stick, button);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void InputDialog::handleJoyUp(int stick, int button)
|
||||
{
|
||||
// Remap joystick buttons in remap mode, otherwise pass to parent dialog
|
||||
if (myEmulEventMapper->remapMode())
|
||||
myEmulEventMapper->handleJoyUp(stick, button);
|
||||
else if (myMenuEventMapper->remapMode())
|
||||
myMenuEventMapper->handleJoyUp(stick, button);
|
||||
else
|
||||
Dialog::handleJoyUp(stick, button);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void InputDialog::handleJoyAxis(int stick, int axis, int value)
|
||||
{
|
||||
|
|
|
@ -46,6 +46,7 @@ class InputDialog : public Dialog
|
|||
void handleKeyDown(StellaKey key, StellaMod mod) override;
|
||||
void handleKeyUp(StellaKey key, StellaMod mod) override;
|
||||
void handleJoyDown(int stick, int button) override;
|
||||
void handleJoyUp(int stick, int button) override;
|
||||
void handleJoyAxis(int stick, int axis, int value) override;
|
||||
bool handleJoyHat(int stick, int hat, JoyHat value) override;
|
||||
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
|
||||
|
|
Loading…
Reference in New Issue