diff options
author | Loïc Hoguin <[email protected]> | 2015-10-20 03:26:40 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-10-20 03:26:40 +0200 |
commit | 8f19fb094712dd6a871136c8522e0cf87fb3025e (patch) | |
tree | a87bb9cfdd2f08e44f2d87eb4af4bf817df5d3c4 | |
parent | fe01cad4cc1bbe97431d999db28a2943b5f18e1c (diff) | |
download | esdl2-8f19fb094712dd6a871136c8522e0cf87fb3025e.tar.gz esdl2-8f19fb094712dd6a871136c8522e0cf87fb3025e.tar.bz2 esdl2-8f19fb094712dd6a871136c8522e0cf87fb3025e.zip |
Implement sdl:which_subsystems/0
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | c_src/sdl.c | 17 | ||||
-rw-r--r-- | src/sdl.erl | 6 |
3 files changed, 13 insertions, 13 deletions
@@ -22,9 +22,6 @@ The following ideas need to be investigated: The following tasks remain to be done: -* http://hg.libsdl.org/SDL/file/default/include/SDL.h - * We need a function which_subsystems() which lists started subsystems. - * http://hg.libsdl.org/SDL/file/default/include/SDL_hints.h * We need to implement everything. diff --git a/c_src/sdl.c b/c_src/sdl.c index 835b0f6..26a1d0e 100644 --- a/c_src/sdl.c +++ b/c_src/sdl.c @@ -14,17 +14,21 @@ #include "esdl2.h" -#define INIT_FLAGS(F) \ +#define BASE_INIT_FLAGS(F) \ F(timer, SDL_INIT_TIMER) \ F(audio, SDL_INIT_AUDIO) \ F(video, SDL_INIT_VIDEO) \ F(joystick, SDL_INIT_JOYSTICK) \ F(haptic, SDL_INIT_HAPTIC) \ F(game_controller, SDL_INIT_GAMECONTROLLER) \ - F(events, SDL_INIT_EVENTS) \ + F(events, SDL_INIT_EVENTS) + +#define INIT_FLAGS(F) \ + BASE_INIT_FLAGS(F) \ F(everything, SDL_INIT_EVERYTHING) NIF_LIST_TO_FLAGS_FUNCTION(list_to_init_flags, Uint32, INIT_FLAGS) +NIF_FLAGS_TO_LIST_FUNCTION(init_flags_to_list, Uint32, BASE_INIT_FLAGS) // init @@ -105,23 +109,16 @@ NIF_FUNCTION(set_main_ready) } // was_init -// @todo Implement the case where we want to receive a list of everything init. NIF_CALL_HANDLER(thread_was_init) { - if (SDL_WasInit((long)args[0])) - return atom_true; - - return atom_false; + return init_flags_to_list(env, SDL_WasInit((long)args[0])); } NIF_FUNCTION(was_init) { - unsigned int length; Uint32 flags = 0; - BADARG_IF(!enif_get_list_length(env, argv[0], &length)); - BADARG_IF(length == 0); BADARG_IF(!list_to_init_flags(env, argv[0], &flags)); return nif_thread_call(env, thread_was_init, 1, flags); diff --git a/src/sdl.erl b/src/sdl.erl index 5fd965f..5391d32 100644 --- a/src/sdl.erl +++ b/src/sdl.erl @@ -21,6 +21,7 @@ -export([start_subsystems/1]). -export([stop_subsystems/1]). -export([is_started/1]). +-export([which_subsystems/0]). -type error() :: {error, string()}. -export_type([error/0]). @@ -64,4 +65,9 @@ stop_subsystems(Subsystems) -> -spec is_started(subsystem()) -> boolean(). is_started(Subsystem) -> esdl2:was_init([Subsystem]), + receive {'_nif_thread_ret_', Ret} -> Ret =:= [Subsystem] end. + +-spec which_subsystems() -> [subsystem()]. +which_subsystems() -> + esdl2:was_init([]), receive {'_nif_thread_ret_', Ret} -> Ret end. |