I am creating a messaging system for a game engine, where the end user of the engine can create a message object and pass it to the game object, which will be interpreted by listener objects containing components attached to the game object. if the message corresponds to the message that the listener is listening to, the listener must call the function pointer and pass the message that was received to it. The basic structure looks something like this:
class Message
{
std::string message;
};
class Listener
{
std::string target;
void (*fn)(Message*);
};
with a game object code to get a message that looks something like this:
if (messageQueue.empty())
{
return;
}
Message* newMessage = messageQueue.front();
messageQueue.pop();
for (std::vector<Component*>::iterator i = ComponentList.begin(); i < ComponentList.end(); i++)
{
Component* itemp = *i;
for (std::vector<Listener*>::iterator j = itemp->Listeners.begin(); j < itemp->Listeners.end(); j++)
{
Listener* jtemp = *j;
if (jtemp->name == newMessage->name)
{
jtemp->function(newMessage);
}
}
}
, , , , , - , Listener.fn Component::foo .
, - , , , lambdas, std::function - .
-, , , , lambda , , . std::function , , std::function , , .
lambdas, std::function , , , void ?