From 50176172d18ae72d019181725c5629d45d21c548 Mon Sep 17 00:00:00 2001 From: rodin Date: Fri, 22 May 2009 13:08:23 +0000 Subject: [PATCH] * Implemented the library-dependant functionality of BLORBs --- src/Makefile.am | 3 ++- src/chimara-glk-private.h | 5 ++++ src/glk.c | 7 +++++ src/resource.c | 54 +++++++++++++++++++++++++++++++++++++++ src/resource.h | 10 ++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/resource.c create mode 100644 src/resource.h diff --git a/src/Makefile.am b/src/Makefile.am index 894db95..6da19f9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,7 +32,8 @@ libchimara_la_SOURCES = \ style.c \ timer.c timer.h \ window.c window.h \ - gi_blorb.c gi_blorb.h + gi_blorb.c gi_blorb.h \ + resource.c resource.h libchimara_la_CPPFLAGS = \ -DG_LOG_DOMAIN=\"Chimara\" libchimara_la_CFLAGS = @CHIMARA_CFLAGS@ $(AM_CFLAGS) diff --git a/src/chimara-glk-private.h b/src/chimara-glk-private.h index 35fac92..9520f1b 100644 --- a/src/chimara-glk-private.h +++ b/src/chimara-glk-private.h @@ -5,6 +5,7 @@ #include #include #include "glk.h" +#include "gi_blorb.h" #include "chimara-glk.h" G_BEGIN_DECLS @@ -48,6 +49,10 @@ struct _ChimaraGlkPrivate { GList *stream_list; /* Current timer */ guint timer_id; + /* Current resource blorb map */ + giblorb_map_t *resource_map; + /* File stream pointing to the blorb used as current resource map */ + strid_t *resource_file; }; #define CHIMARA_GLK_PRIVATE(obj) \ diff --git a/src/glk.c b/src/glk.c index 1c29ebb..c4f3954 100644 --- a/src/glk.c +++ b/src/glk.c @@ -4,6 +4,7 @@ #include "abort.h" #include "chimara-glk.h" #include "chimara-glk-private.h" +#include "gi_blorb.h" ChimaraGlkPrivate *glk_data = NULL; @@ -46,6 +47,12 @@ glk_exit(void) /* Stop any timers */ glk_request_timer_events(0); + /* Close any open resource files */ + if(glk_data->resource_map != NULL) { + giblorb_destroy_map(glk_data->resource_map); + glk_stream_close(glk_data->resource_file, NULL); + } + glk_data = NULL; g_thread_exit(NULL); } diff --git a/src/resource.c b/src/resource.c new file mode 100644 index 0000000..c6b4d34 --- /dev/null +++ b/src/resource.c @@ -0,0 +1,54 @@ +#include "resource.h" + +extern ChimaraGlkPrivate *glk_data; + +/** + * giblorb_set_resource_map: + * @file The file stream to read the resource map from + * + * This function tells the library that the file is indeed the Blorby source + * of all resource goodness. Whenever your program calls an image or sound + * function, such as glk_image_draw(), the library will search this file for + * the resource you request. + * + * Do not close the stream after calling this function. The library is + * responsible for closing the stream at shutdown time. + */ +giblorb_err_t +giblorb_set_resource_map(strid_t file) +{ + giblorb_map_t *newmap; /* create map allocates memory */ + giblorb_err_t error = giblorb_create_map(file, &newmap); + + if(error != giblorb_err_None) { + g_free(newmap); + return error; + } + + /* Check if there was already an existing resource map */ + if(glk_data->resource_map != NULL) { + WARNING("Overwriting existing resource map.\n"); + giblorb_destroy_map(glk_data->resource_map); + glk_stream_close(glk_data->resource_file, NULL); + } + + glk_data->resource_map = newmap; + glk_data->resource_file = file; + return giblorb_err_None; +} + +/** + * giblorb_get_resource_map: + * + * This function returns the current resource map being used. Returns NULL + * if #giblorb_set_resource_map() has not been called yet. + */ +giblorb_map_t* +giblorb_get_resource_map() +{ + if(glk_data->resource_map == NULL) { + WARNING("Resource map not set yet.\n"); + } + + return glk_data->resource_map; +} diff --git a/src/resource.h b/src/resource.h new file mode 100644 index 0000000..7db741e --- /dev/null +++ b/src/resource.h @@ -0,0 +1,10 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#include +#include "glk.h" +#include "gi_blorb.h" +#include "chimara-glk-private.h" +#include "magic.h" + +#endif -- 2.30.2