How to inherint SelectorProtocol CallFunc functions properly

I’m trying to create a class that responds to callfunc but I don’t understand how the thing work exactly.
I just spend 5 hours on it and the code confuses me too much.
I could find example for schedule stuff, but it’s using CCScheduler which can’’t be used for callfunc.

Any hint on what to put in the following when overridden ?
virtual void callfunc();
virtual void callfunc(cocos2d::CCNode* pSender);
virtual void callfunc(cocos2d::CCNode* pSender, void* pData);

Thanks in advance.

If you are writing a observer/listener module in your game, I recommend you to forget shceduler_callback mechanism, please implement your own register/notify-callback/unregister logic. You can find the code in any book about “Design pattern”.

Thanks.
I hoped to use cocos2dx stuff to keep the code as portable as possible following the library. But I guess I will have to work my way around.

Implementation of observer/listener module in pure c++ is still portable between platforms.
Inheriting selector_protocol will trap you into the complexity of message system of cocos2d-x, and will waste you more time on this.

Oh I know that my code will be portable for other platforms, I meant it won’t be part of the official cocos2d-x library.
I’m coding for someone and I would prefer to use the cocos2d stuff when possible… but no worries. That will have to do.

For the Info, I used this -> http://www.partow.net/programming/templatecallback/index.html
It’s very easy to use and can be easily modified to fit pretty much anyone’s need for callback in C++.

Hope that helps.

Hello Fabien

do you have an usage sample to share ?

Kind regards
david

I can share my code with you, but it’s really note the best way to use it.
I’m working on another problem with my code atm, so it’s not perfect.

In any case, what I’m using it for is for async http request with a server.
With the help of the sample below and the source files, you should see how I implemented the thing

This is the code I have in my AppDelegate:
appdelegate_connector1_type callback(this, &AppDelegate::loginLoadedData); AppDelegate_Connector1* c = new AppDelegate_Connector1(); c->initWithURL(urlStr, dataString); c->callback_func = callback; this->addConnectorToStack(c);

To explain quickly, I create a base class Connector which handle/interface the request with the device.
Connector as a virtual function “execute” which is called when the request returns something.
I subclass Connector (AppDelegate_Connector1 in my case) which take a custom callback type and override “execute” to call that callback function when “execute” is called in the base class.

A better implementation to have Connector class changed into a template that takes the method/class info in it’s template and just triggered the template callback in execute.
This to avoid to have a subclass for each type of callback the connector need to use.

Hope it helps in any kind of way.

Thanks alot Fabien

merci bcps