Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: boost::function callbacks?  (Read 619 times)

kingIZZZY

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
boost::function callbacks?
« on: November 16, 2009, 04:18:56 PM »

(Noob alert; i'm assuming i understand how OIS works well enough. I prolly have no idea what i'm talking about half of the time.)

One modification to OIS i'm thinking of coding is making the buffered callbacks (like mouseMoved and keyPressed) boost::function pointers instead of plain virtual functions, and making a RegisterCallback function which will boost::bind them.

Just a fancier way of interfacing OIS to client code. For example, I dont want my "InputListener" class (which inherits from OIS input listeners) to execute code as a result of input events, such as calling mouseMoved or keyPressed. Rather, I'd want my OIS listeners to pass the signal on to client code through function pointers

So i was just
1) Sharing thoughts. comments?
2) Suggestion to edit main OIS source code? just wondering if this kind of interfacing makes sense in general.
3) If i'll change my OIS code as described, is there anything else in OIS i should be aware of which may conflict with or depend on etc the things i'll be modifying? As of now, looks like i'll just be removing the virtual functions from the class declarations, add boost::functions named exactly like those functions, and add (non-virtual) RegisterCallback functions which do no more than assign the bound function. Something like this;

Code: [Select]
// in MouseListener class i'll replace the virtual functions with these

boost::function<void (const OIS::MouseEvent &)> mouseMoved;
boost::function<void (const OIS::MouseEvent &evt, OIS::MouseButtonID btn)> mousePressed;
boost::function<void (const OIS::MouseEvent &evt, OIS::MouseButtonID btn)> mouseReleased;


// in Mouse class i'll replace setEventCallback with

void registerCallback(const boost::function<void(const OIS::MouseEvent &)> & boundFunction);
void registerCallback(const boost::function<void(const OIS::MouseEvent &evt, OIS::MouseButtonID btn)> & boundFunction);
void registerCallback(const boost::function<void(const OIS::MouseEvent &evt, OIS::MouseButtonID btn)> & boundFunction);

// all they do is "mouseMoved = boundFunction;" (moved/pressed/released respectively)


// Users of OIS will implement mouseMoved / mousePressed / mouseReleased functions in their own client code, such as

void MyClass::MyFunctionLol(const OIS::MouseEvent & evt)
{

}


// then register callback insted of seteventcallback

p_Mouse->registerCallback(boost::bind(&MyClass::MyFunctionLol, this, _1));


*ducks*
« Last Edit: November 17, 2009, 05:22:25 PM by kingIZZZY »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: boost::function callbacks?
« Reply #1 on: November 22, 2009, 08:32:42 AM »

Unfortunately, I don't think introducing boost into OIS is necessary, and many people would not use it. However, a wrapper layer/class could exist on top of OIS that provides these higher level event registrations. I wouldn't be opposed to an example application project which used boost to provide such a layer.

Logged