mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-19 12:59:36 +00:00
Continue implementing support for multiple ActionSets
This commit is contained in:
parent
520239a845
commit
b438064517
12 changed files with 104 additions and 133 deletions
|
@ -31,19 +31,32 @@ ActionMapper::~ActionMapper()
|
|||
clearCreatedEvents();
|
||||
}
|
||||
|
||||
ActionData *ActionMapper::getActionDataByID(int actionID)
|
||||
ActionData *ActionMapper::getActionDataByIDAndSource(int actionID, int source)
|
||||
{
|
||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); i++)
|
||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); ++i)
|
||||
{
|
||||
if ((*i).id == actionID)
|
||||
if (i->id == actionID && i->source == source)
|
||||
return &(*i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ActionMapper::isActing(int actionID)
|
||||
bool ActionMapper::isActing(int actionID, int source)
|
||||
{
|
||||
ActionData *ad = getActionDataByID(actionID);
|
||||
if(source < 0)
|
||||
{
|
||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); ++i)
|
||||
{
|
||||
ActionData& ad = *i;
|
||||
if(ad.id == actionID)
|
||||
for (ButtonList::iterator ii = ad.buttonList.begin(); ii != ad.buttonList.end(); ++ii)
|
||||
if (keyDownMap[*ii])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||
if (ad)
|
||||
{
|
||||
ButtonList::iterator i = ad->buttonList.begin();
|
||||
|
@ -58,21 +71,15 @@ bool ActionMapper::isActing(int actionID)
|
|||
|
||||
void ActionMapper::addAction(int actionID, int k, int source)
|
||||
{
|
||||
ActionData *ad = getActionDataByID(actionID);
|
||||
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||
|
||||
if (!ad)
|
||||
{
|
||||
ActionData data;
|
||||
data.id = actionID;
|
||||
data.source = source;
|
||||
actionData.push_back(data);
|
||||
ad = getActionDataByID(actionID);
|
||||
if (!ad)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Could not create action for Action ID [" << actionID << "]";
|
||||
errorLog(os.str());
|
||||
return;
|
||||
}
|
||||
ad = &actionData.back();
|
||||
}
|
||||
|
||||
if (ad)
|
||||
|
@ -83,8 +90,6 @@ void ActionMapper::addAction(int actionID, int k, int source)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ActionMapper::addAction(Event *event, int k, int state)
|
||||
{
|
||||
ActionData data;
|
||||
|
@ -116,8 +121,6 @@ void ActionMapper::clearCreatedEvents()
|
|||
createdEvents.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ActionMapper::enableInput()
|
||||
{
|
||||
inputEnabled = true;
|
||||
|
@ -128,52 +131,27 @@ void ActionMapper::disableInput()
|
|||
inputEnabled = false;
|
||||
}
|
||||
|
||||
void ActionMapper::removeAction(int actionID)
|
||||
bool ActionMapper::pollAction(int actionID, int source)
|
||||
{
|
||||
ActionData *ad = getActionDataByID(actionID);
|
||||
if (ad)
|
||||
if(source < 0)
|
||||
{
|
||||
ButtonList::iterator i = ad->buttonList.begin();
|
||||
for (; i != ad->buttonList.end(); i++)
|
||||
{
|
||||
int k = (*i);
|
||||
cleared = true; // it's a hack, but it works
|
||||
keyDownMap.erase(k);
|
||||
}
|
||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end();)
|
||||
{
|
||||
if (i->id == actionID)
|
||||
i = actionData.erase(i);
|
||||
else
|
||||
i++;
|
||||
}
|
||||
for (ActionDataSet::iterator i = actionData.begin(); i != actionData.end(); i++)
|
||||
if(i->id == actionID && _pollActionData(*i))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
ActionData *ad = getActionDataByIDAndSource(actionID, source);
|
||||
return ad && _pollActionData(*ad);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ActionMapper::pollAction(int actionID)
|
||||
bool ActionMapper::_pollActionData(const ActionData& ad)
|
||||
{
|
||||
bool down = false;
|
||||
|
||||
ActionData *ad = getActionDataByID(actionID);
|
||||
if (ad)
|
||||
{
|
||||
ButtonList *blist = &ad->buttonList;
|
||||
ButtonList::iterator j;
|
||||
j = blist->begin();
|
||||
|
||||
for (; j != blist->end(); j++)
|
||||
{
|
||||
if (getKeyState((*j)))
|
||||
{
|
||||
down = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return down;
|
||||
const ButtonList& blist = ad.buttonList;
|
||||
for (ButtonList::const_iterator j = blist.begin(); j != blist.end(); j++)
|
||||
if (getKeyState((*j)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActionMapper::getKeyState(int k)
|
||||
|
@ -296,18 +274,3 @@ void ActionMapper::clearActions()
|
|||
keyDownMap.clear();
|
||||
actionData.clear();
|
||||
}
|
||||
|
||||
void ActionMapper::removeAllActions()
|
||||
{
|
||||
std::vector <int> deleteList;
|
||||
ActionDataSet::iterator i;
|
||||
for (i = actionData.begin(); i != actionData.end(); i++)
|
||||
{
|
||||
deleteList.push_back(i->id);
|
||||
}
|
||||
for (int c = 0; c < deleteList.size(); c++)
|
||||
{
|
||||
removeAction (deleteList[c]);
|
||||
}
|
||||
actionData.clear();
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ typedef std::vector<int> ButtonList;
|
|||
|
||||
struct ActionData
|
||||
{
|
||||
ActionData() { id=-1; state=-1; event=0; }
|
||||
ActionData() { id=-1; state=-1; source = -1; event=0; }
|
||||
|
||||
int id, state;
|
||||
int id, state, source;
|
||||
Event *event;
|
||||
ButtonList buttonList;
|
||||
};
|
||||
|
@ -70,10 +70,7 @@ public:
|
|||
void addAction(Event *event, int k, int state=-1);
|
||||
void addAction(int actionID, int k, int source);
|
||||
|
||||
void removeAction(int actionID);
|
||||
void removeAllActions();
|
||||
|
||||
bool isActing(int actionID);
|
||||
bool isActing(int actionID, int source);
|
||||
virtual void action(int actionID, int state, int source) = 0;
|
||||
|
||||
|
||||
|
@ -83,7 +80,7 @@ public:
|
|||
|
||||
// vars
|
||||
|
||||
typedef std::list<ActionData> ActionDataSet;
|
||||
typedef std::vector<ActionData> ActionDataSet;
|
||||
ActionDataSet actionData;
|
||||
|
||||
typedef std::map <int, int> KeyDownMap;
|
||||
|
@ -97,10 +94,10 @@ public:
|
|||
Event *addCreatedEvent(Event *event);
|
||||
void clearCreatedEvents();
|
||||
|
||||
bool pollAction(int actionID);
|
||||
bool pollAction(int actionID, int source);
|
||||
bool getKeyState(int k);
|
||||
|
||||
ActionData *getActionDataByID(int actionID);
|
||||
ActionData *getActionDataByIDAndSource(int actionID, int source);
|
||||
protected:
|
||||
|
||||
std::vector<Event*>createdEvents;
|
||||
|
@ -108,6 +105,8 @@ protected:
|
|||
bool inUpdate;
|
||||
bool inputEnabled;
|
||||
void onUpdate (float dt);
|
||||
private:
|
||||
bool _pollActionData(const ActionData& ad);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,6 +71,12 @@ void ActionSet::assignJoystickIdx(int idx)
|
|||
|
||||
int ActionSet::_whichJoystickForName()
|
||||
{
|
||||
if(joystickGUID.length() && joystickName.length())
|
||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||
if(Joystick *j = core->getJoystick(i))
|
||||
if(j->getGUID()[0] && joystickGUID == j->getGUID() && joystickName == j->getName())
|
||||
return int(i);
|
||||
|
||||
if(joystickGUID.length())
|
||||
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
|
||||
if(Joystick *j = core->getJoystick(i))
|
||||
|
|
|
@ -103,8 +103,8 @@ bool Joystick::init(int stick)
|
|||
name = n ? n : "<?>";
|
||||
SDL_JoystickGUID jg = SDL_JoystickGetGUID(sdl_joy);
|
||||
char guidbuf[40];
|
||||
guid = &guidbuf[0];
|
||||
SDL_JoystickGetGUIDString(jg, &guidbuf[0], sizeof(guidbuf));
|
||||
guid = &guidbuf[0];
|
||||
debugLog(std::string("Initialized Joystick [") + name + "], GUID [" + guid + "]");
|
||||
if (sdl_controller)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue