From: P. F. Chimento Date: Sun, 30 Jan 2011 15:02:58 +0000 (+0100) Subject: Implement alternative resource loading for sound X-Git-Tag: v0.9~152^2~4 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=7c8f6a1f397d9be0127bf9a56e3bb0ff66d54d77;p=projects%2Fchimara%2Fchimara.git Implement alternative resource loading for sound Sound resources can now be loaded from an alternative location using the ChimaraGlk resource loading callback. This is tested in the test program. --- diff --git a/libchimara/schannel.c b/libchimara/schannel.c index d2df489..93146b1 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -400,8 +400,23 @@ glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) WARNING(_("No resource map has been loaded yet.")); return 0; } - WARNING(_("Loading sound resources from alternative location not yet supported.")); - return 0; + gchar *filename = glk_data->resource_load_callback(CHIMARA_RESOURCE_SOUND, snd, glk_data->resource_load_callback_data); + if(!filename) { + WARNING(_("Error loading resource from alternative location.")); + return 0; + } + + GError *err = NULL; + GFile *file = g_file_new_for_path(filename); + stream = G_INPUT_STREAM(g_file_read(file, NULL, &err)); + if(!stream) { + IO_WARNING(_("Error loading resource from file"), filename, err->message); + g_free(filename); + g_object_unref(file); + return 0; + } + g_free(filename); + g_object_unref(file); } else { giblorb_result_t resource; giblorb_err_t result = giblorb_load_resource(glk_data->resource_map, giblorb_method_Memory, &resource, giblorb_ID_Snd, snd); diff --git a/tests/SND3 b/tests/SND3 new file mode 100644 index 0000000..ddbf43d Binary files /dev/null and b/tests/SND3 differ diff --git a/tests/plugin-loader.c b/tests/plugin-loader.c index 766305d..a502af6 100644 --- a/tests/plugin-loader.c +++ b/tests/plugin-loader.c @@ -65,6 +65,19 @@ create_window(void) gtk_container_add(GTK_CONTAINER(window), glk); } +static gchar * +resource_load(ChimaraResourceType usage, guint32 resnum) +{ + char *resstr; + if(usage == CHIMARA_RESOURCE_IMAGE) + resstr = "PIC"; + else if(usage == CHIMARA_RESOURCE_SOUND) + resstr = "SND"; + else + resstr = "FCK"; + return g_strdup_printf("%s%d", resstr, resnum); +} + int main(int argc, char *argv[]) { @@ -86,6 +99,8 @@ main(int argc, char *argv[]) if(argc < 2) g_error("Must provide a plugin\n"); + + chimara_glk_set_resource_load_callback(CHIMARA_GLK(glk), (ChimaraResourceLoadFunc)resource_load, NULL); if( !chimara_glk_run(CHIMARA_GLK(glk), argv[1], argc - 1, argv + 1, &error) ) g_error("Error starting Glk library: %s\n", error->message); diff --git a/tests/soundtest.c b/tests/soundtest.c index b1588bc..d9ff17a 100644 --- a/tests/soundtest.c +++ b/tests/soundtest.c @@ -32,6 +32,7 @@ glk_main(void) nothing we can do without it, so exit. */ return; } + glk_set_window(mainwin); char buffer[1024]; int len;