Oi! I'm making my own system for SFML. I've run into some problems and would like some help on it.
Anyway here's the basic how it works. We have a 3 Base objects. SignalSender, SignalReciver, SignalBase. SignalBase represents a signal which is sent by SignalSender to a SignalReciver. And the SignalReciver can subscribe to different levels of signals. Every signal is associated with a string name. For instance QuitSignal's name is "Signal.Window.Quit" and represents a Closed event. A Receiver can subscribe to "Signal.Window" to receive all Window associated events. Or he can be precise and say that he only wants "Signal.Window.Quit" or he can subscribe to "Signal" to get all signals. The biggest point with the system is that the developer can create his/her own signal classes.
See it as a extension to the already in place system.
Anyway here's problem number one. Data... Data data data. Since I store all events in a std::queue<SignalBase> some data seems to be lost when I pump the extended SignalBase class in there. (Like MouseMovedSignal). I guess it's because the queue only copies the SignalBase part of the entire object?
Here's some code:
class SignalSender {
private:
std::multimap<std::string, SignalReciver *> subscribers;
std::queue<SignalBase> signalQueue;
protected:
void SendToObjects(const SignalBase& signal, const std::string& currentNamespace);
SignalBase ConvertSFMLToSignal(const sf::Event& event, sf::Window * window);
public:
SignalSender();
void SubscribeReciver(SignalReciver * reciver, const std::string& type);
void SubscribeReciver(SignalReciver * reciver, const SignalBase& type);
bool IsReciverSubscribed(SignalReciver * reciver, const std::string& type);
void AddSignal(const SignalBase& signal);
void SendSignals();
void FetchEventsFromWindow(sf::Window * window);
};
void SignalSender::AddSignal(const SignalBase& signal) {
this->signalQueue.push(signal);
}
I was thinking of like, adding like some resource object in the SignalBase where we stuff in all signal specific data though I'm wondering if there's a more gracious method to do it. Also, is there some class I can use in the stl already?
Thx for the help on before hand
PS: Oh yeah Laurent, I fixed so it can calculate relative movement for ya now in multiple windows
