Implement alternative resource loading for sound
authorP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 15:02:58 +0000 (16:02 +0100)
committerP. F. Chimento <philip.chimento@gmail.com>
Sun, 30 Jan 2011 15:02:58 +0000 (16:02 +0100)
Sound resources can now be loaded from an alternative location using the
ChimaraGlk resource loading callback. This is tested in the test
program.

libchimara/schannel.c
tests/SND3 [new file with mode: 0644]
tests/plugin-loader.c
tests/soundtest.c

index d2df4892a49d77a3b724d23e89cc116fd2c5914d..93146b1ed843db80046aa8a8f30e9235e7df66a5 100644 (file)
@@ -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 (file)
index 0000000..ddbf43d
Binary files /dev/null and b/tests/SND3 differ
index 766305df5216a28a0d9eaf864ff1fcab4accbc17..a502af6d9556000d1c33ba89d9a81faf658c8a5d 100644 (file)
@@ -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);
index b1588bc2c75cd47e007b9d9a5e338dc2a01eafa4..d9ff17aa941d29ff51dc75acab1959bb47279094 100644 (file)
@@ -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;