aboutsummaryrefslogtreecommitdiffstats
path: root/c_src/sdl_window.c
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-02 14:09:18 +0200
committerLoïc Hoguin <[email protected]>2014-04-02 14:09:18 +0200
commit77d0e9d9ca8ed451a40f9b54f20365727ad76f5e (patch)
tree018650dcdf59e7976a1ae018754fd04d4a583ee0 /c_src/sdl_window.c
parent608acbb03f976b0fbf23877d8b4b6ad7529e1d53 (diff)
downloadesdl2-77d0e9d9ca8ed451a40f9b54f20365727ad76f5e.tar.gz
esdl2-77d0e9d9ca8ed451a40f9b54f20365727ad76f5e.tar.bz2
esdl2-77d0e9d9ca8ed451a40f9b54f20365727ad76f5e.zip
Add a bullet engine example
A function sdl_renderer:set_logical_size/3 has been added. All the functions relative to the window, the renderer, textures and events now run in a separate thread inside the NIF. A few helper functions and macros have been added in order to abstract this out. The code reads like it is doing call or cast to the main thread. In the case of call, the result is then sent back to the calling process as a message (Erlang side catches it directly before returning). The functions relative to SDL init and surfaces have not been threaded yet. It may still be needed from the point of view of SDL or Erlang, but it seems to work fine as it is so they were left alone for now. The bullet example originally came from my submission to Spawnfest 2011, and has been reactualized to work with a modern Erlang, and SDL2.
Diffstat (limited to 'c_src/sdl_window.c')
-rw-r--r--c_src/sdl_window.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c
index 0a130f3..9319270 100644
--- a/c_src/sdl_window.c
+++ b/c_src/sdl_window.c
@@ -37,22 +37,17 @@ void dtor_Window(ErlNifEnv* env, void* obj)
NIF_LIST_TO_FLAGS_FUNCTION(list_to_window_flags, Uint32, WINDOW_FLAGS)
-NIF_FUNCTION(create_window)
+// create_window
+
+NIF_CALL_HANDLER(thread_create_window)
{
- char title[255];
- int x, y, w, h;
- Uint32 flags = 0;
SDL_Window* window;
ERL_NIF_TERM term;
- BADARG_IF(!enif_get_string(env, argv[0], title, 255, ERL_NIF_LATIN1));
- BADARG_IF(!enif_get_int(env, argv[1], &x));
- BADARG_IF(!enif_get_int(env, argv[2], &y));
- BADARG_IF(!enif_get_int(env, argv[3], &w));
- BADARG_IF(!enif_get_int(env, argv[4], &h));
- BADARG_IF(!list_to_window_flags(env, argv[5], &flags));
+ window = SDL_CreateWindow(args[0], (long)args[1], (long)args[2], (long)args[3], (long)args[4], (long)args[5]);
+
+ enif_free(args[0]);
- window = SDL_CreateWindow(title, x, y, w, h, flags);
if (!window)
return sdl_error_tuple(env);
@@ -63,3 +58,20 @@ NIF_FUNCTION(create_window)
term
);
}
+
+NIF_FUNCTION(create_window)
+{
+ char* title = (char*)enif_alloc(255);
+ int x, y, w, h;
+ Uint32 flags = 0;
+
+ BADARG_IF(!enif_get_string(env, argv[0], title, 255, ERL_NIF_LATIN1));
+ BADARG_IF(!enif_get_int(env, argv[1], &x));
+ BADARG_IF(!enif_get_int(env, argv[2], &y));
+ BADARG_IF(!enif_get_int(env, argv[3], &w));
+ BADARG_IF(!enif_get_int(env, argv[4], &h));
+ BADARG_IF(!list_to_window_flags(env, argv[5], &flags));
+
+ return nif_thread_call(env, thread_create_window, 6,
+ title, x, y, w, h, flags);
+}