• Advertisement
Sign in to follow this  

Input handling system

This topic is 2030 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings,

I know there has been qute a few topics like this but none of them turned out to be useful for my case. I'm in the middle of the development of my simple engine but I'm struggling with creating a fast reliable input manager. To illustrate my case let me show you my choose of design.

Main Entry -> Instantiates a SystemClass that encapsulates the following factories:

  • InputManager
  • GraphicsManager - Handles Direct3D related code.

    • CameraManager
    • TextureManager
    • EffectManader
    • LightManager
    • MeshManager
    • TimerManager
    • Demo Projects - Derives from DirectXManager

      To handle user input I'm using the WINAPI Message handler like:
      [source lang="cpp"]LRESULT CALLBACK SystemClass::MsgHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
      {
      switch (uMsg)
      {
      case WM_KEYDOWN:
      case WM_KEYUP:

      case WM_LBUTTONDOWN:
      case WM_MBUTTONDOWN:
      case WM_RBUTTONDOWN:

      case WM_LBUTTONUP:
      case WM_MBUTTONUP:
      case WM_RBUTTONUP:

      case WM_MOUSEMOVE:
      m_GraphicsHandler->OnMouseMove(wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
      break;
      }[/source]
      You can see the basic idea. The GraphicsHandler has the necessary functions which handles the user Events. My last attempt was something like this:

      [source lang="cpp"]class InputFactory
      {
      static InputFactory* Instance;
      InputFactory(void);
      public:
      static InputFactory* GetInstance(void);
      IHandler* CreateHandler(HandlerType hType = HandlerType::MouseHandler);

      ~InputFactory(void)
      };

      class IHandler
      {
      friend class InputFactory;
      protected:
      struct Event
      {
      private:
      EventType eType;
      void (*Handler)(MappedKey mKey, State* hState);
      };
      private:
      std::queue<Event> Interactions;
      public:
      void RegisterEvent(EventType eType = EventType::MouseEvent, ...);
      void ProcessEvent(void);
      };[/source]
      I think you get the main idea. My problem with this approach is that it's way too complex and hard to add new features. Not to mention that to modify the keybindings it's a nightmare. I found an article about inputmanager here on gamedev.net but I can't apply it to my case. Edited by Wrath87

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement