Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QtCore/QObject>
- #include <QtCore/QList>
- #include <gluon/core/singleton.h>
- enum State
- {
- None,
- Up,
- Down
- };
- /*
- * An input action component.
- *
- * This defines a base action, such as "jump" or "attack".
- */
- class InputAction : public QObject
- {
- Q_OBJECT
- /*
- * Connect this to an input device's button changed event.
- *
- * Override in your own subclass.
- */
- virtual State checkActionState() = 0;
- signals:
- void actionStateChanged(State state);
- public:
- void update()
- {
- State state = this->checkActionState();
- if(state != None) emit this->actionStateChanged(state);
- }
- };
- /*
- * Manager for all input actions.
- *
- * Runs update as necessary.
- */
- class InputActionManager : public GluonCore::Singleton<InputActionManager>
- {
- Q_OBJECT
- QList<InputAction *> m_actions;
- public:
- InputActionManager()
- : GluonCore::Singleton<InputActionManager>()
- {
- this->m_actions = QList<InputAction *>();
- }
- /*
- * Call update on all child actions.
- */
- void update()
- {
- foreach(InputAction *action_p, this->m_actions)
- {
- action_p->update();
- }
- }
- /*
- * Register an action with the InputActionManager.
- */
- void registerAction(InputAction *action_p)
- {
- this->m_actions.append(action_p);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment