Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: 2 framelistener, one buffered, the second not  (Read 1311 times)

K20

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
2 framelistener, one buffered, the second not
« on: March 11, 2009, 01:14:01 PM »

Hi everyone,

I'm new here (and in the world Ogre3d and OIS) and I hurt a little trouble.

So, my application is coding with Ogre3D and I use OIS to manage the mouse and keyboard input, mouse allows me to rotate the camera (with the right-click) and keyboard to move in my map.

My game needs a 2D interface (a GUI so), I naturally chose CEGUI (supported by Ogre3D).
My worry is this:
I have 2 framelisteners, one manages the event for the map itself and the other manages the event on the GUI: click on a button, text field.

The problem is that I can not initialize the 2nd framelistener ... I tried creating 2 inputmanager but it has not rained in OIS ... So I took one InputManager and I use to manage my map and the GUI. I wanted to create a keyboard and a mouse buffered and others unbuffered. Except that once again I have a problem, I have this error:

Code: [Select]
terminate called after throwing an instance of 'OIS::Exception'
  what():  No devices match requested type.
Abandon

Hmm, ok ...

I wanted to know if anyone had this problem?

This is my code :

Code: [Select]
bool bufferedKeys = false;
bool bufferedMouse = false;
bool bufferedJoy = false;

inputManager_ = OIS::InputManager::createInputSystem (pl);

OIS::Keyboard* keyboard = static_cast<OIS::Keyboard*>(inputManager_->createInputObject( OIS::OISKeyboard, true));
OIS::Mouse* mouse = static_cast<OIS::Mouse*>(inputManager_->createInputObject( OIS::OISMouse, true));

keyboard_ = static_cast<OIS::Keyboard*> (inputManager_->createInputObject (OIS::OISKeyboard, bufferedKeys));
if (!bufferedKeys)
keyboard_->setEventCallback (this);

mouse_ = static_cast<OIS::Mouse*> (inputManager_->createInputObject (OIS::OISMouse, bufferedMouse));
if (!bufferedMouse)
mouse_->setEventCallback (this);

It works if I remove keyboard and mouse (and leave keyboard_ and mouse_)

Thank you in advance for your help:)
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: 2 framelistener, one buffered, the second not
« Reply #1 on: March 13, 2009, 08:39:28 PM »

You can only create one mouse & one keyboard in OIS. I'm not quite sure why you think you need more than that.

You can use your one callback to pass the event to multiple callbacks of your own creation, or pass to different objects, or do whatever you want. Also, you can use the mouse & keyboard's immediate accessors (isKeyDown, getMouseState) at any time.
Logged

K20

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: 2 framelistener, one buffered, the second not
« Reply #2 on: March 14, 2009, 05:41:50 AM »

Ok, but my problem is that I need one device buffered and one not buffered.
When I create the device like this : static_cast<OIS::Keyboard*>(inputManager_->createInputObject( OIS::OISKeyboard, true));

It's buffered right ? So I can use event like mouseMoved, mousePressed or mouseReleased but also getMouseState  ?

But if I am in buffered mode I can't use ma keyboard (for exemple) to move in my map with arrows, just use with my GUI to type text ...

So, I don't understand how use buffered mode et unbuffered mode in the same time for my GUI which need buffered input and my map which need unbuffered mode :s
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2653
    • View Profile
    • http://www.wreckedgames.com
Re: 2 framelistener, one buffered, the second not
« Reply #3 on: March 14, 2009, 10:26:47 AM »

You can use both modes at once with the one device. You simply create it as buffered, set your callback and your done. Now you will get buffered events in the callback, but at any time you can call the immediate mode methods (isKeyDown, etc) to get instant state. Even when buffered is turned on, all that means is that you get callback events - the state is still updated as events come in whether or not buffered is on - so you can query at any time.

HTH
Logged

K20

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: 2 framelistener, one buffered, the second not
« Reply #4 on: March 14, 2009, 04:08:42 PM »

Ok, i understand now ! :D
My vision of how to work OIS was wrong ...

I will test this, thx !
Logged

K20

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Re: 2 framelistener, one buffered, the second not
« Reply #5 on: March 16, 2009, 04:27:59 PM »

It's work perfectly !

Thanks a lot !
Logged