1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

Continue implementing support for multiple ActionSets

This commit is contained in:
fgenesis 2016-07-16 03:09:44 +02:00
parent 520239a845
commit b438064517
12 changed files with 104 additions and 133 deletions

View file

@ -720,20 +720,18 @@ void AnimationEditor::update(float dt)
if (core->mouse.buttons.middle)
{
editSprite->position += core->mouse.change;
}
if (editingStrip)
{
if (isActing(ACTION_SWIMLEFT))
if (isActing(ACTION_SWIMLEFT, -1))
moveBoneStripPoint(Vector(-dt, 0));
if (isActing(ACTION_SWIMRIGHT))
if (isActing(ACTION_SWIMRIGHT, -1))
moveBoneStripPoint(Vector(dt, 0));
if (isActing(ACTION_SWIMUP))
if (isActing(ACTION_SWIMUP, -1))
moveBoneStripPoint(Vector(0, -dt));
if (isActing(ACTION_SWIMDOWN))
if (isActing(ACTION_SWIMDOWN, -1))
moveBoneStripPoint(Vector(0, dt));
}
int spd = 1;

View file

@ -151,10 +151,10 @@ void AquariaGuiElement::updateMovement(float dt)
StateObject *obj = dsq->getTopStateObject();
if (obj)
{
if (obj->isActing(ACTION_MENULEFT)) dir = DIR_LEFT;
else if (obj->isActing(ACTION_MENURIGHT)) dir = DIR_RIGHT;
else if (obj->isActing(ACTION_MENUUP)) dir = DIR_UP;
else if (obj->isActing(ACTION_MENUDOWN)) dir = DIR_DOWN;
if (obj->isActing(ACTION_MENULEFT, -1)) dir = DIR_LEFT;
else if (obj->isActing(ACTION_MENURIGHT, -1)) dir = DIR_RIGHT;
else if (obj->isActing(ACTION_MENUUP, -1)) dir = DIR_UP;
else if (obj->isActing(ACTION_MENUDOWN, -1)) dir = DIR_DOWN;
}
}
@ -373,9 +373,9 @@ bool AquariaSlider::doSliderInput(float dt)
inputAmount = -0.1f;
else if (jpos.x >= SLIDER_JOY_THRESHOLD)
inputAmount = +0.1f;
else if (obj && obj->isActing(ACTION_MENULEFT))
else if (obj && obj->isActing(ACTION_MENULEFT, -1))
inputAmount = -0.1f;
else if (obj && obj->isActing(ACTION_MENURIGHT))
else if (obj && obj->isActing(ACTION_MENURIGHT, -1))
inputAmount = +0.1f;
else
inputAmount = 0;

View file

@ -4055,7 +4055,7 @@ void Avatar::startBurst()
{
if (!riding && canBurst() && (joystickMove || getVectorToCursor().getSquaredLength2D() > sqr(BURST_DISTANCE))
&& getState() != STATE_PUSH && (!skeletalSprite.getCurrentAnimation() || (skeletalSprite.getCurrentAnimation()->name != "spin"))
&& _isUnderWater && !isActing(ACTION_ROLL))
&& _isUnderWater && !isActing(ACTION_ROLL, -1))
{
if (!bursting && burst == 1)
{
@ -4171,13 +4171,13 @@ void Avatar::startWallBurst(bool useCursor)
Vector Avatar::getKeyDir()
{
Vector dir;
if (isActing(ACTION_SWIMLEFT))
if (isActing(ACTION_SWIMLEFT, -1))
dir += Vector(-1,0);
if (isActing(ACTION_SWIMRIGHT))
if (isActing(ACTION_SWIMRIGHT, -1))
dir += Vector(1,0);
if (isActing(ACTION_SWIMUP))
if (isActing(ACTION_SWIMUP, -1))
dir += Vector(0,-1);
if (isActing(ACTION_SWIMDOWN))
if (isActing(ACTION_SWIMDOWN, -1))
dir += Vector(0,1);
if (dir.x != 0 && dir.y != 0)
@ -4975,13 +4975,13 @@ void Avatar::updateRoll(float dt)
stopRoll();
}
}
if (!_isUnderWater && isActing(ACTION_ROLL))
const bool rollact = isActing(ACTION_ROLL, -1);
if (!_isUnderWater && rollact)
{
stopRoll();
}
if (!core->mouse.buttons.left && dsq->inputMode == INPUT_MOUSE && !isActing(ACTION_ROLL))
if (!core->mouse.buttons.left && dsq->inputMode == INPUT_MOUSE && !rollact)
{
if (rolling)
stopRoll();
@ -5022,7 +5022,7 @@ void Avatar::updateRoll(float dt)
stopRoll();
}
if (isActing(ACTION_ROLL))
if (rollact)
{
if (_isUnderWater)
{
@ -5373,7 +5373,7 @@ void Avatar::onUpdate(float dt)
}
}
if (!dsq->game->isPaused() && isActing(ACTION_LOOK) && !dsq->game->avatar->isSinging() && dsq->game->avatar->isInputEnabled() && !dsq->game->isInGameMenu())
if (!dsq->game->isPaused() && isActing(ACTION_LOOK, -1) && !dsq->game->avatar->isSinging() && dsq->game->avatar->isInputEnabled() && !dsq->game->isInGameMenu())
{
looking = 1;
}
@ -6109,7 +6109,7 @@ void Avatar::onUpdate(float dt)
float len = 0;
if (dsq->isMiniMapCursorOkay() && !isActing(ACTION_ROLL) &&
if (dsq->isMiniMapCursorOkay() && !isActing(ACTION_ROLL, -1) &&
_isUnderWater && !riding && !boneLock.on &&
(movingOn || ((dsq->inputMode == INPUT_JOYSTICK || dsq->inputMode== INPUT_KEYBOARD) || (core->mouse.buttons.left || bursting))))
{
@ -6120,7 +6120,7 @@ void Avatar::onUpdate(float dt)
if (dsq->inputMode == INPUT_MOUSE)
{
static Vector lastAddVec;
if (!isActing(ACTION_PRIMARY) && bursting)
if (!isActing(ACTION_PRIMARY, -1) && bursting)
{
addVec = lastAddVec;
}
@ -6162,7 +6162,7 @@ void Avatar::onUpdate(float dt)
// For joystick/keyboard control, don't stop unless
// the Swim (primary action) button is pressed with
// no movement input. --achurch
if ((dsq->inputMode == INPUT_MOUSE || isActing(ACTION_PRIMARY))
if ((dsq->inputMode == INPUT_MOUSE || isActing(ACTION_PRIMARY, -1))
&& addVec.isLength2DIn(STOP_DISTANCE))
{
vel *= 0.9f;
@ -6221,7 +6221,7 @@ void Avatar::onUpdate(float dt)
currentMaxSpeed = vars->maxWallJumpSpeed;
else
{
if (isActing(ACTION_SLOW) || isMovingSlow)
if (isMovingSlow)
{
currentMaxSpeed = vars->maxSlowSwimSpeed;
}
@ -6250,7 +6250,7 @@ void Avatar::onUpdate(float dt)
// here for roll key?
// seems like this isn't reached
//if (isActing("roll"))
if (isActing(ACTION_ROLL))
if (isActing(ACTION_ROLL, -1))
{
//debugLog("here");
}

View file

@ -3834,7 +3834,7 @@ void DSQ::onUpdate(float dt)
if (dsq->game && watchForQuit && isNested())
{
if (dsq->game->isActing(ACTION_ESC))
if (dsq->game->isActing(ACTION_ESC, -1))
{
watchQuitFlag = true;
quitNestedMain();
@ -3921,10 +3921,10 @@ void DSQ::onUpdate(float dt)
}
if (dsq->game->avatar)
{
if (dsq->game->avatar->isActing(ACTION_SWIMUP) ||
dsq->game->avatar->isActing(ACTION_SWIMDOWN) ||
dsq->game->avatar->isActing(ACTION_SWIMLEFT) ||
dsq->game->avatar->isActing(ACTION_SWIMRIGHT))
if (dsq->game->avatar->isActing(ACTION_SWIMUP, -1) ||
dsq->game->avatar->isActing(ACTION_SWIMDOWN, -1) ||
dsq->game->avatar->isActing(ACTION_SWIMLEFT, -1) ||
dsq->game->avatar->isActing(ACTION_SWIMRIGHT, -1))
{
dsq->setInputMode(INPUT_KEYBOARD);
}

View file

@ -4520,7 +4520,7 @@ void Game::update(float dt)
if (inHelpScreen)
{
const float helpTextScrollSpeed = 400.0f;
if (isActing(ACTION_SWIMDOWN))
if (isActing(ACTION_SWIMDOWN, -1))
{
helpText->offset.stop();
helpText->offset.y -= helpTextScrollSpeed * dt;
@ -4529,7 +4529,7 @@ void Game::update(float dt)
helpText->offset.y = -helpText->getHeight() + core->getVirtualHeight();
}
}
if (isActing(ACTION_SWIMUP))
if (isActing(ACTION_SWIMUP, -1))
{
helpText->offset.stop();
helpText->offset.y += helpTextScrollSpeed * dt;

View file

@ -2786,11 +2786,11 @@ void SceneEditor::update(float dt)
{
case ET_ELEMENTS:
editingEntity = 0;
if (isActing(ACTION_MULTISELECT) || !selectedElements.empty())
if (isActing(ACTION_MULTISELECT, -1) || !selectedElements.empty())
{
editingElement = 0;
}
if (state == ES_SELECTING && !isActing(ACTION_MULTISELECT))
if (state == ES_SELECTING && !isActing(ACTION_MULTISELECT, -1))
editingElement = this->getElementAtCursor();
if (editingElement)
@ -2819,13 +2819,13 @@ void SceneEditor::update(float dt)
int camSpeed = 500/zoom.x;
if (core->getShiftState())
camSpeed = 5000/zoom.x;
if (isActing(ACTION_CAMLEFT))
if (isActing(ACTION_CAMLEFT, -1))
dsq->cameraPos.x -= dt*camSpeed;
if (isActing(ACTION_CAMRIGHT))
if (isActing(ACTION_CAMRIGHT, -1))
dsq->cameraPos.x += dt*camSpeed;
if (isActing(ACTION_CAMUP))
if (isActing(ACTION_CAMUP, -1))
dsq->cameraPos.y -= dt*camSpeed;
if (isActing(ACTION_CAMDOWN))
if (isActing(ACTION_CAMDOWN, -1))
dsq->cameraPos.y += dt*camSpeed;
if (core->mouse.buttons.middle && !core->mouse.change.isZero())
{
@ -2835,9 +2835,9 @@ void SceneEditor::update(float dt)
float spd = 0.5;
const Vector oldZoom = zoom;
if (isActing(ACTION_ZOOMOUT))
if (isActing(ACTION_ZOOMOUT, -1))
zoom /= (1 + spd*dt);
else if (isActing(ACTION_ZOOMIN))
else if (isActing(ACTION_ZOOMIN, -1))
zoom *= (1 + spd*dt);
else if (core->mouse.scrollWheelChange < 0)
{

View file

@ -4962,19 +4962,24 @@ luaFunc(screenFadeGo)
luaFunc(isEscapeKey)
{
bool isDown = dsq->game->isActing(ACTION_ESC);
int source = lua_tointeger(L, 1) - 1;
bool isDown = dsq->game->isActing(ACTION_ESC, source);
luaReturnBool(isDown);
}
luaFunc(isLeftMouse)
{
bool isDown = core->mouse.buttons.left || (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_PRIMARY));
int source = lua_tointeger(L, 1) - 1;
bool isDown = (source < 0 && core->mouse.buttons.left)
|| (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_PRIMARY, source));
luaReturnBool(isDown);
}
luaFunc(isRightMouse)
{
bool isDown = core->mouse.buttons.right || (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_SECONDARY));
int source = lua_tointeger(L, 1) - 1;
bool isDown = (source < 0 && core->mouse.buttons.right)
|| (dsq->game->avatar && dsq->game->avatar->pollAction(ACTION_SECONDARY, source));
luaReturnBool(isDown);
}

View file

@ -992,15 +992,15 @@ void WorldMapRender::onUpdate(float dt)
{
float scrollSpeed = 2.0f;
float amt = (400*dt)/scale.x;
if (isActing(ACTION_SWIMLEFT))
if (isActing(ACTION_SWIMLEFT, -1))
{
internalOffset += Vector(amt, 0);
}
if (isActing(ACTION_SWIMRIGHT))
if (isActing(ACTION_SWIMRIGHT, -1))
{
internalOffset += Vector(-amt, 0);
}
if (isActing(ACTION_SWIMDOWN))
if (isActing(ACTION_SWIMDOWN, -1))
{
if (core->getShiftState())
{
@ -1012,7 +1012,7 @@ void WorldMapRender::onUpdate(float dt)
internalOffset += Vector(0, -amt);
}
}
if (isActing(ACTION_SWIMUP))
if (isActing(ACTION_SWIMUP, -1))
{
if (core->getShiftState())
{
@ -1027,7 +1027,7 @@ void WorldMapRender::onUpdate(float dt)
if (core->joystickEnabled)
{
if (isActing(ACTION_SECONDARY))
if (isActing(ACTION_SECONDARY, -1))
{
Vector jpos;
for(size_t i = 0; i < core->getNumJoysticks(); ++i)

View file

@ -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();
}

View file

@ -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

View file

@ -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))

View file

@ -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)
{