Guest User

Untitled

a guest
Nov 30th, 2010
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <QtCore/QObject>
  2. #include <QtCore/QList>
  3.  
  4. #include <gluon/core/singleton.h>
  5.  
  6. enum State
  7. {
  8.     None,
  9.     Up,
  10.     Down
  11. };
  12.  
  13. /*
  14.  * An input action component.
  15.  *
  16.  * This defines a base action, such as "jump" or "attack".
  17.  */
  18. class InputAction : public QObject
  19. {
  20.     Q_OBJECT
  21.  
  22.     /*
  23.      * Connect this to an input device's button changed event.
  24.      *
  25.      * Override in your own subclass.
  26.      */
  27.     virtual State checkActionState() = 0;
  28.  
  29. signals:
  30.     void actionStateChanged(State state);
  31.  
  32. public:
  33.     void update()
  34.     {
  35.         State state = this->checkActionState();
  36.         if(state != None) emit this->actionStateChanged(state);
  37.     }
  38. };
  39.  
  40. /*
  41.  * Manager for all input actions.
  42.  *
  43.  * Runs update as necessary.
  44.  */
  45. class InputActionManager : public GluonCore::Singleton<InputActionManager>
  46. {
  47.     Q_OBJECT
  48.    
  49.     QList<InputAction *> m_actions;
  50.    
  51. public:
  52.     InputActionManager()
  53.         : GluonCore::Singleton<InputActionManager>()
  54.     {
  55.         this->m_actions = QList<InputAction *>();
  56.     }
  57.  
  58.     /*
  59.      * Call update on all child actions.
  60.      */
  61.     void update()
  62.     {
  63.         foreach(InputAction *action_p, this->m_actions)
  64.         {
  65.             action_p->update();
  66.         }
  67.     }
  68.  
  69.     /*
  70.      * Register an action with the InputActionManager.
  71.      */
  72.     void registerAction(InputAction *action_p)
  73.     {
  74.         this->m_actions.append(action_p);
  75.     }
  76. };
Advertisement
Add Comment
Please, Sign In to add comment