Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Separating OIS into an individual class  (Read 486 times)

Floppy

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 1
    • View Profile
Separating OIS into an individual class
« on: September 18, 2009, 11:53:15 PM »

Hi,

I am pretty new to this so be gentle =)

I want to place my (M)OIS code in a separate class to avoid messy code.

I do not want to act upon the input in this class, only provide the user of the class with some handy functions for getting mouse positions and what keys are pressed etc.. I am thinking that I want my KeyPressed function to return a bool telling the caller whether the button passed to it is pressed or not.

Let me put it like this.. Currently, in my main class, I am initializing an IOHandler object and passing it *this*(the main class/object) so that I have access to all the member variables and can modify them when I handle all the input inside the IOHandler object. Is this good programming? I could just put the OIS code in my main class, but there is so much code there already..

Has anyone got any experience on separating the OIS code from the main code?

/Thanks in advance

EDIT:

Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: Separating OIS into an individual class
« Reply #1 on: October 03, 2009, 08:07:28 AM »

Adding another low level Input layer on top of OIS is not all that useful/good. However, you are right that cluttering one main class with everything is also not good.

I think what you need is a higher level view of input from your main loop. For instance, you can translate input events into action events (such as run, turn, jump, etc) in a secondary class. Pretty much what "Action Mapping" is. Then, your input class can worry about if the input was a keyboard, mouse or joystick, and just translate that into a higher message/event for other consumers.
Logged