mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 17:53:47 +00:00
Correctly distinguish between action sources when evaluating ActionMapper
I'm not quite happy with the hackishness of this change; hope it doesn't incur too much runtime overhead with all these checks...
This commit is contained in:
parent
77e4bfd292
commit
dcf09343b5
8 changed files with 113 additions and 7 deletions
|
@ -224,7 +224,7 @@ DSQ::DSQ(const std::string& fileSystem, const std::string& extraDataDir)
|
|||
for (int i = 0; i < 16; i++)
|
||||
firstElementOnLayer[i] = 0;
|
||||
|
||||
|
||||
pActionSets = &user.control.actionSets;
|
||||
}
|
||||
|
||||
DSQ::~DSQ()
|
||||
|
|
|
@ -43,8 +43,22 @@ public:
|
|||
int key[INP_KEYSIZE];
|
||||
int joy[INP_JOYSIZE];
|
||||
|
||||
inline bool hasMouse(int actionID) const { return _has(mse, actionID); }
|
||||
inline bool hasKey(int actionID) const { return _has(key, actionID); }
|
||||
inline bool hasJoy(int actionID) const { return _has(joy, actionID); }
|
||||
|
||||
std::string toString() const;
|
||||
void fromString(const std::string &read);
|
||||
|
||||
private:
|
||||
template<size_t N>
|
||||
static inline bool _has(const int (&a)[N], int actionID)
|
||||
{
|
||||
for(size_t i = 0; i < N; ++i)
|
||||
if(a[i] == actionID)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
enum InputSetType
|
||||
|
|
|
@ -154,6 +154,7 @@ bool ActionMapper::_pollActionData(const ActionData& ad)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ActionMapper::getKeyState(int k)
|
||||
{
|
||||
if(!k)
|
||||
|
@ -222,6 +223,62 @@ bool ActionMapper::getKeyState(int k)
|
|||
return keyState;
|
||||
}
|
||||
|
||||
bool ActionMapper::getKeyState(int k, int source)
|
||||
{
|
||||
if(!k)
|
||||
return false;
|
||||
|
||||
ActionSet& as = (*core->pActionSets)[source];
|
||||
|
||||
bool keyState = false;
|
||||
if (k >= 0 && k < KEY_MAXARRAY)
|
||||
{
|
||||
keyState = core->getKeyState(k) && as.hasKey(k);
|
||||
}
|
||||
else if (k == MOUSE_BUTTON_LEFT)
|
||||
{
|
||||
keyState = core->mouse.buttons.left == DOWN && as.hasMouse(k);
|
||||
}
|
||||
else if (k == MOUSE_BUTTON_RIGHT)
|
||||
{
|
||||
keyState = core->mouse.buttons.right == DOWN && as.hasMouse(k);
|
||||
}
|
||||
else if (k == MOUSE_BUTTON_MIDDLE)
|
||||
{
|
||||
keyState = core->mouse.buttons.middle == DOWN && as.hasMouse(k);
|
||||
}
|
||||
else if (k >= MOUSE_BUTTON_EXTRA_START && k < MOUSE_BUTTON_EXTRA_START+mouseExtraButtons)
|
||||
{
|
||||
keyState = core->mouse.buttons.extra[k - MOUSE_BUTTON_EXTRA_START] && as.hasMouse(k);
|
||||
}
|
||||
else if (k >= JOY_BUTTON_0 && k < JOY_BUTTON_END)
|
||||
{
|
||||
Joystick *j = core->getJoystick(as.joystickID);
|
||||
if(j && j->isEnabled())
|
||||
keyState = j->getButton( - JOY_BUTTON_0);
|
||||
}
|
||||
else if (k >= JOY_AXIS_0_POS && k < JOY_AXIS_END_POS)
|
||||
{
|
||||
Joystick *j = core->getJoystick(as.joystickID);
|
||||
if(j && j->isEnabled())
|
||||
{
|
||||
float ax = j->getAxisUncalibrated(k - JOY_AXIS_0_POS);
|
||||
keyState = ax > JOY_AXIS_THRESHOLD;
|
||||
}
|
||||
}
|
||||
else if (k >= JOY_AXIS_0_NEG && k < JOY_AXIS_END_NEG)
|
||||
{
|
||||
Joystick *j = core->getJoystick(as.joystickID);
|
||||
if(j && j->isEnabled())
|
||||
{
|
||||
float ax = j->getAxisUncalibrated(k - JOY_AXIS_0_NEG);
|
||||
keyState = ax < -JOY_AXIS_THRESHOLD;
|
||||
}
|
||||
}
|
||||
|
||||
return keyState;
|
||||
}
|
||||
|
||||
void ActionMapper::onUpdate (float dt)
|
||||
{
|
||||
if (inUpdate) return;
|
||||
|
@ -237,17 +294,16 @@ void ActionMapper::onUpdate (float dt)
|
|||
for (; j != i->buttonList.end(); j++)
|
||||
{
|
||||
int k = (*j);
|
||||
int keyState=false;
|
||||
//joystick
|
||||
|
||||
keyState = getKeyState(k);
|
||||
ActionData *ad = &(*i);
|
||||
int keyState = ad->source < 0
|
||||
? getKeyState(k) // any source goes
|
||||
: getKeyState(k, ad->source); // specific source
|
||||
|
||||
if (keyState != oldKeyDownMap[k])
|
||||
{
|
||||
keyDownMap[k] = keyState;
|
||||
if (inputEnabled)
|
||||
{
|
||||
ActionData *ad = &(*i);
|
||||
if (ad->event)
|
||||
{
|
||||
if (ad->state==-1 || keyState == ad->state)
|
||||
|
|
|
@ -35,7 +35,11 @@ typedef std::vector<int> ButtonList;
|
|||
|
||||
struct ActionData
|
||||
{
|
||||
ActionData() { id=-1; state=-1; source = -1; event=0; }
|
||||
ActionData()
|
||||
: id(-1), state(-1), source(-1)
|
||||
, event(0)
|
||||
{
|
||||
}
|
||||
|
||||
int id, state, source;
|
||||
Event *event;
|
||||
|
@ -96,6 +100,7 @@ public:
|
|||
|
||||
bool pollAction(int actionID, int source);
|
||||
bool getKeyState(int k);
|
||||
bool getKeyState(int k, int sourceID);
|
||||
|
||||
ActionData *getActionDataByIDAndSource(int actionID, int source);
|
||||
protected:
|
||||
|
|
|
@ -251,3 +251,26 @@ std::string ActionSet::insertInputIntoString(const std::string &string)
|
|||
}
|
||||
*/
|
||||
|
||||
bool ActionSet::hasMouse(int actionID) const
|
||||
{
|
||||
for(size_t i = 0; i < inputSet.size(); ++i)
|
||||
if(inputSet[i].hasMouse(actionID))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActionSet::hasKey(int actionID) const
|
||||
{
|
||||
for(size_t i = 0; i < inputSet.size(); ++i)
|
||||
if(inputSet[i].hasKey(actionID))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActionSet::hasJoy(int actionID) const
|
||||
{
|
||||
for(size_t i = 0; i < inputSet.size(); ++i)
|
||||
if(inputSet[i].hasJoy(actionID))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@ public:
|
|||
void assignJoystickIdx(int idx, bool updateValues);
|
||||
void updateJoystick();
|
||||
|
||||
bool hasMouse(int actionID) const;
|
||||
bool hasKey(int actionID) const;
|
||||
bool hasJoy(int actionID) const;
|
||||
|
||||
ActionInput *addActionInput(const std::string &name);
|
||||
ActionInput *getActionInputByName(const std::string &name);
|
||||
|
||||
|
|
|
@ -399,6 +399,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
|||
afterEffectManager = 0;
|
||||
loopDone = false;
|
||||
core = this;
|
||||
pActionSets = NULL;
|
||||
|
||||
for (int i = 0; i < KEY_MAXARRAY; i++)
|
||||
{
|
||||
|
|
|
@ -558,6 +558,9 @@ protected:
|
|||
std::string _extraDataDir;
|
||||
|
||||
public:
|
||||
|
||||
std::vector<ActionSet> *pActionSets;
|
||||
|
||||
Joystick *getJoystick(int idx); // warning: may return NULL/contain holes
|
||||
// not the actual number of joysticks!
|
||||
size_t getNumJoysticks() const { return joysticks.size(); }
|
||||
|
|
Loading…
Reference in a new issue