[AD] SDL2 port

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I've been working on an SDL2 port for a while (unlike fixing actual
bugs, this is something I could do with only having 30 minutes or so
at a time). I started with it a few years ago, my main motivation back
then was that SDL2 already worked with emscripten and so it would have
been a way to get Allegro to work in a web browser as well. Of course
that's not necessary anymore as we do have a patch for that. So now I
just see this sort of as a reference port, mostly every Allegro
function will get to call an SDL function without having to actually
implement anything. And it might be useful for testing - if something
works with this port but not the "native" Allegro, we know the bug
must be in how our implementation differs from SDL's.

It's still very incomplete and probably always will be, but I figure
it wouldn't hurt committing it. It only works on Linux, there's no
sound (it will use Allegro's audio), no input devices other than
keyboard/mouse, and no graphics (it will use Allegro's OpenGL driver).

Also, there is one fundamental difference between how Allegro and SDL2
events works[1]:

SDL_PumpEvents documentation: "This should only be run in the thread
that initialized the video subsystem, and for extra safety, you should
consider only doing those things on the main thread in any case. "

So there was no easy way of making the Allegro way work where we can
receive events even when the user calls no Allegro functions at all. I
was considering adding an SDL specific function which would call
SDL_PumpEvents - but then figured we could just as well add a
mechanism for Allegro to call a system driver function which does
that. I made it get called from these functions:

sdl_get_keyboard_state
sdl_get_mouse_state
al_is_event_queue_empty
al_get_next_event
al_peek_next_event
al_drop_next_event
al_flush_event_queue
al_wait_for_event
al_wait_for_event_timed
al_wait_for_event_until

So at least in a typical game everything will work without changes. If
you have a loop without any of these functions (or wait on an event
queue which has no timer events) the application will freeze however.

My next steps will probably be implementing audio with SDL and getting
it to run under Windows and OSX (and maybe Android and IOS).

[1] http://wiki.libsdl.org/SDL_PumpEvents




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/