1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Various improvements and fixes

This commit is contained in:
fgenesis 2016-07-17 05:54:09 +02:00
parent 411f8950e5
commit 77e4bfd292
9 changed files with 167 additions and 32 deletions

View file

@ -34,7 +34,7 @@ JoystickConfig::JoystickConfig()
ActionSet::ActionSet()
{
enabled = true;
joystickID = 0;
joystickID = ACTIONSET_REASSIGN_JOYSTICK;
}
void ActionSet::clearActions()
@ -42,35 +42,45 @@ void ActionSet::clearActions()
inputSet.clear();
}
int ActionSet::assignJoystickByName()
int ActionSet::assignJoystickByName(bool force)
{
int idx = _whichJoystickForName();
if(idx >= 0)
assignJoystickIdx(idx);
if(idx >= 0 || force)
assignJoystickIdx(idx, false);
return idx;
}
void ActionSet::assignJoystickIdx(int idx)
void ActionSet::assignJoystickIdx(int idx, bool updateValues)
{
if(idx < 0)
{
joystickID = -1;
joystickName.clear();
joystickGUID.clear();
if(updateValues && idx != ACTIONSET_REASSIGN_JOYSTICK)
{
joystickName.clear();
joystickGUID.clear();
}
}
else if(idx < (int)core->getNumJoysticks())
{
if(Joystick *j = core->getJoystick(idx))
{
joystickGUID = j->getGUID();
joystickName = j->getName();
joystickID = idx;
if(updateValues)
{
joystickGUID = j->getGUID();
joystickName = j->getName();
}
}
else
idx = -1;
}
joystickID = idx;
}
int ActionSet::_whichJoystickForName()
{
if(joystickName == "NONE")
return -1;
if(joystickGUID.length() && joystickName.length())
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
@ -89,11 +99,29 @@ int ActionSet::_whichJoystickForName()
if(joystickName == j->getName())
return int(i);
return -1;
// first attached
if(!joystickGUID.length() && !joystickName.length())
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
return i;
return ACTIONSET_REASSIGN_JOYSTICK;
}
void ActionSet::updateJoystick()
{
bool reassign = joystickID == ACTIONSET_REASSIGN_JOYSTICK;
if(joystickID >= 0)
{
Joystick *j = core->getJoystick(joystickID);
if(!j)
reassign = true;
}
if(reassign)
assignJoystickByName(true);
Joystick *j = core->getJoystick(joystickID);
if(j)
j->setEnabled(enabled);
@ -111,8 +139,6 @@ ActionInput *ActionSet::getActionInputByName(const std::string &name)
return 0;
}
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int actionID, int sourceID) const
{
if (!enabled) return;

View file

@ -32,6 +32,8 @@ typedef std::vector<ActionInput> ActionInputSet;
class ActionMapper;
class Event;
const int ACTIONSET_REASSIGN_JOYSTICK = -2;
struct JoystickConfig
{
JoystickConfig();
@ -48,14 +50,14 @@ public:
void importAction(ActionMapper *mapper, const std::string &name, Event *event, int state) const;
void importAction(ActionMapper *mapper, const std::string &name, int actionID, int sourceID) const;
void clearActions();
int assignJoystickByName(); // -1 if no such joystick found
void assignJoystickIdx(int idx);
int assignJoystickByName(bool force); // -1 if no such joystick found
void assignJoystickIdx(int idx, bool updateValues);
void updateJoystick();
ActionInput *addActionInput(const std::string &name);
ActionInput *getActionInputByName(const std::string &name);
int joystickID;
int joystickID; // >= 0: use that, -1 = no joystick, or ACTIONSET_REASSIGN_JOYSTICK
// --- Saved in config ---
ActionInputSet inputSet;

View file

@ -3019,20 +3019,20 @@ void Core::onJoystickAdded(int deviceID)
}
joysticks.push_back(j);
done:
; // TODO: fixup ActionMapper?
;
}
void Core::onJoystickRemoved(int instanceID)
{
debugLog("Joystick removed");
for(size_t i = 0; i < joysticks.size(); ++i)
if(joysticks[i]->getInstanceID() == instanceID)
{
joysticks[i]->shutdown();
delete joysticks[i];
joysticks[i] = NULL;
}
// TODO: fixup ActionMapper?
if(Joystick *j = joysticks[i])
if(j->getInstanceID() == instanceID)
{
j->shutdown();
delete j;
joysticks[i] = NULL;
}
}
Joystick *Core::getJoystick(int idx)

View file

@ -52,7 +52,7 @@ Joystick::Joystick()
s2ax = 4;
s2ay = 3;
enabled = true;
enabled = false;
}
const char *Joystick::getName() const