X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fresource.c;fp=libchimara%2Fresource.c;h=c6b4d34dc0cd4433c74461a48f91b988b2847a2e;hb=78652af29a2f39e626febd5f4213da57d3a13901;hp=0000000000000000000000000000000000000000;hpb=91214934fbcdfd363202a65c142194506604ff7b;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/resource.c b/libchimara/resource.c new file mode 100644 index 0000000..c6b4d34 --- /dev/null +++ b/libchimara/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; +}