Fixed bug in adding multiple joysticks with the same name, and

bumped version # for next beta test.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3114 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-12-21 16:47:50 +00:00
parent 2e7bf1dffa
commit 3b02c309c1
4 changed files with 27 additions and 21 deletions

View File

@ -22,7 +22,7 @@
#include <cstdlib>
#define STELLA_VERSION "4.5_beta1"
#define STELLA_VERSION "4.5_beta2"
#define STELLA_BUILD atoi("$Rev$" + 6)
#endif

View File

@ -135,8 +135,7 @@ void EventHandler::reset(State state)
void EventHandler::addJoystick(StellaJoystick* stick)
{
#ifdef JOYSTICK_SUPPORT
int idx = myJoyHandler->add(stick);
if(idx < 0)
if(!myJoyHandler->add(stick))
return;
setActionMappings(kEmulationMode);
@ -163,10 +162,10 @@ void EventHandler::addJoystick(StellaJoystick* stick)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::removeJoystick(int idx)
void EventHandler::removeJoystick(int id)
{
#ifdef JOYSTICK_SUPPORT
myJoyHandler->remove(idx);
myJoyHandler->remove(id);
#endif
}

View File

@ -429,8 +429,8 @@ class EventHandler
JoystickHandler(OSystem& system);
~JoystickHandler();
int add(StellaJoystick* stick);
int remove(int id);
bool add(StellaJoystick* stick);
bool remove(int id);
void mapStelladaptors(const string& saport);
void setDefaultMapping(Event::Type type, EventMode mode);
void eraseMapping(Event::Type event, EventMode mode);

View File

@ -281,11 +281,11 @@ void EventHandler::JoystickHandler::printDatabase() const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EventHandler::JoystickHandler::add(StellaJoystick* stick)
bool EventHandler::JoystickHandler::add(StellaJoystick* stick)
{
// Skip if we couldn't open it for any reason
if(stick->ID < 0)
return stick->ID;
return false;
// Figure out what type of joystick this is
bool specialAdaptor = false;
@ -313,15 +313,21 @@ int EventHandler::JoystickHandler::add(StellaJoystick* stick)
else
{
// We need unique names for mappable devices
// For non-unique names that already have a database entry,
// we append ' #x', where 'x' increases consecutively
int count = 0;
for(const auto& i: myDatabase)
if(BSPF_startsWithIgnoreCase(i.first, stick->name))
{
if(BSPF_startsWithIgnoreCase(i.first, stick->name) && i.second.joy)
{
++count;
if(count > 1)
break;
}
}
if(count > 0)
{
ostringstream name;
name << stick->name << " " << count;
name << stick->name << " #" << count+1;
stick->name = name.str();
}
stick->type = StellaJoystick::JT_REGULAR;
@ -348,11 +354,11 @@ int EventHandler::JoystickHandler::add(StellaJoystick* stick)
setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode);
}
return stick->ID;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int EventHandler::JoystickHandler::remove(int index)
bool EventHandler::JoystickHandler::remove(int id)
{
// When a joystick is removed, we delete the actual joystick object but
// remember its mapping, since it will eventually be saved to settings
@ -361,29 +367,30 @@ int EventHandler::JoystickHandler::remove(int index)
// So we use the 'active' joystick list to access them
try
{
StellaJoystick* stick = mySticks.at(index);
StellaJoystick* stick = mySticks.at(id);
auto it = myDatabase.find(stick->name);
if(it != myDatabase.end() && it->second.joy == stick)
{
ostringstream buf;
buf << "Removed joystick " << mySticks[index]->ID << ":" << endl
<< " " << mySticks[index]->about() << endl;
buf << "Removed joystick " << mySticks[id]->ID << ":" << endl
<< " " << mySticks[id]->about() << endl;
myOSystem.logMessage(buf.str(), 1);
// Remove joystick, but remember mapping
it->second.mapping = stick->getMap();
delete it->second.joy; it->second.joy = nullptr;
mySticks.erase(index);
mySticks.erase(id);
return index;
return true;
}
}
catch(std::out_of_range)
{
// fall through to indicate remove failed
}
return -1;
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -