-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hello everyone,
I would like to announce sdl++, a work-in-progress C++ wrapper for SDL events
and timers. It provides an object-oriented interface to the SDL Event and
Timer API and encourages type-safety for user data through templates. For example:
typedef SDL_ExtUserEvent<int*> IntEvent;
This introduces a new event subtype whose listeners only accept pointers to
int in their callback. For a listener to be compatible with the event source,
it must provide an implementation of the SDL_Callback<int*> interface:
class IntCallback : public SDL_Callback<int*>
{
public:
Uint32 invoke(SDL_Source*, int* data, void*)
{
cout << *data << endl;
return 0;
}
};
Listeners are attached to a notification source (either a timer or an event)
and data is dispatched to them:
IntEvent myEvent; /* Note that two instances don’t share listeners. */
IntCallback myCallback;
myEvent.attach(&myCallback);
int myData = 42;
myEvent.notifyNow(&myData);
myData = 23;
myEvent.notifyLater(&myData);
SDL_EventHandle::waitEvent();
Since the algorithmic complexity of the dispatch is O(1) (a vector lookup), I
would consider this wrapper an acceptable trade-off between code complexity
and speed penalty at runtime. I’m very much looking forward to your comments,
suggestions, and questions.
You can find a bzip2’ed tarball of the wrapper at
http://www.chriseineke.com/sdl++/index.html
Some things I’d like to do in the future:
- Add an SDL_Task class that unifies events and timers (it would push an
event onto the queue when the timer fires). - The build infrastructure is broken. I need a “nice” file structure and
need to fix the Autoconf/Automake files. For now "g++ *.ccsdl-config --libs
" is enough. - Write a test harness. There is none at the moment.
- My solution to the static initialization order fiasco of the instances for
built-in events sucks. It’s quite ugly and I’m certain a better way
exists. - Add a typedef for the type of the necessary callback to the event
template. - Decide if to stay with camelCase naming convention or to convert to
stl-like.*
- -- Christopher C. Eineke -- Email: chris at chriseineke.com -*-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEAREKAAYFAkpHEsAACgkQPOmqd0kEEbstiwCfSUgDn28RQiH4zuLnW7uChVlf
89sAn1iWmVpqis4uSt2g8Kn1TTNKrZz7
=M8rI
-----END PGP SIGNATURE-----