2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#ifndef _actionmapper_
|
|
|
|
#define _actionmapper_
|
|
|
|
|
|
|
|
#include "Base.h"
|
2018-01-21 11:47:32 +00:00
|
|
|
#include "ActionInput.h"
|
2017-01-14 21:53:20 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
class Event;
|
|
|
|
class ActionMapper;
|
|
|
|
|
|
|
|
#include "ActionSet.h"
|
2016-06-25 21:59:34 +00:00
|
|
|
#include "Joystick.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
struct LegacyActionData;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
class ActionMapper
|
|
|
|
{
|
|
|
|
public:
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
// funcs
|
|
|
|
ActionMapper();
|
|
|
|
virtual ~ActionMapper();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
// Overridden to react to events (both legacy and input-mapped)
|
|
|
|
virtual void action(int actionID, int state, int playerID, InputDeviceType device) = 0;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
|
|
|
|
// Legacy actions -- binds keys directly to actions.
|
|
|
|
// This bypasses the input mapper and checks for keys directly!
|
|
|
|
void addAction(Event *event, unsigned k, int state = -1);
|
|
|
|
void addAction(unsigned actionID, unsigned k);
|
|
|
|
bool isActing(unsigned actionID) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void clearActions();
|
|
|
|
|
|
|
|
bool isInputEnabled() { return inputEnabled; }
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
// vars
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
typedef std::vector<LegacyActionData> ActionDataSet;
|
2011-08-03 20:05:33 +00:00
|
|
|
ActionDataSet actionData;
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
bool cleared;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
virtual void enableInput();
|
|
|
|
virtual void disableInput();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
Event *addCreatedEvent(Event *event);
|
|
|
|
void clearCreatedEvents();
|
|
|
|
|
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
// called by InputMapper whenever stuff happens
|
|
|
|
void recvAction(unsigned actionID, bool state, int playerID, InputDeviceType device);
|
|
|
|
void recvDirectInput(unsigned k, bool state);
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
protected:
|
2020-08-11 16:02:19 +00:00
|
|
|
/*template<size_t N> void importInput(const NamedAction (&a)[N])
|
2020-08-11 10:04:15 +00:00
|
|
|
{
|
2020-08-11 16:02:19 +00:00
|
|
|
importInput(&a[0], N);
|
2020-08-11 10:04:15 +00:00
|
|
|
}
|
2021-01-11 18:00:37 +00:00
|
|
|
void importInput(const NamedAction *actions, size_t N);*/ // TODO controllerfixup: remove this everywhere
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2020-08-11 10:04:15 +00:00
|
|
|
std::vector<Event*> createdEvents;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
bool inputEnabled;
|
|
|
|
void onUpdate (float dt);
|
2020-08-11 10:04:15 +00:00
|
|
|
|
2016-07-16 01:09:44 +00:00
|
|
|
private:
|
2020-08-11 10:04:15 +00:00
|
|
|
void updateDirectInput();
|
|
|
|
void updateActions();
|
|
|
|
|
|
|
|
LegacyActionData *getActionDataByID(int actionID);
|
|
|
|
|
|
|
|
struct ActionUpdate
|
|
|
|
{
|
|
|
|
unsigned id;
|
|
|
|
int playerID;
|
|
|
|
bool state;
|
|
|
|
InputDeviceType device;
|
|
|
|
};
|
|
|
|
std::vector<ActionUpdate> _actionChanges;
|
|
|
|
std::vector<int> _inputChanges; // >0: pressed, <0: released
|
|
|
|
|
|
|
|
bool inUpdate;
|
2020-08-11 16:02:19 +00:00
|
|
|
std::vector<unsigned> _activeActions;
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|