aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:49:17 +0100
committerHarry Jeffery <harry@exec64.co.uk>2017-04-14 16:49:17 +0100
commit5a8932cb21f63af86dffa419ec5da5f4a5d29d70 (patch)
tree87a1832eec5ad21f993fe551c511fcf14ad5a125 /src
parent50759fb279b38c5db7cacf88206188b827f564b2 (diff)
downloadimv-5a8932cb21f63af86dffa419ec5da5f4a5d29d70.tar.gz
Refactor loader to new style
Diffstat (limited to 'src')
-rw-r--r--src/loader.c7
-rw-r--r--src/loader.h8
-rw-r--r--src/main.c18
3 files changed, 18 insertions, 15 deletions
diff --git a/src/loader.c b/src/loader.c
index d70b66d..c5b64a6 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -44,15 +44,17 @@ static int is_thread_cancelled(void)
return sigismember(&sigmask, SIGUSR1);
}
-void imv_init_loader(struct imv_loader *ldr)
+struct imv_loader *imv_loader_create(void)
{
+ struct imv_loader *ldr = malloc(sizeof(struct imv_loader));
memset(ldr, 0, sizeof(struct imv_loader));
pthread_mutex_init(&ldr->lock, NULL);
/* ignore this signal in case we accidentally receive it */
block_usr1_signal();
+ return ldr;
}
-void imv_destroy_loader(struct imv_loader *ldr)
+void imv_loader_free(struct imv_loader *ldr)
{
/* wait for any existing bg thread to finish */
pthread_join(ldr->bg_thread, NULL);
@@ -70,6 +72,7 @@ void imv_destroy_loader(struct imv_loader *ldr)
if(ldr->path) {
free(ldr->path);
}
+ free(ldr);
}
void imv_loader_load(struct imv_loader *ldr, const char *path,
diff --git a/src/loader.h b/src/loader.h
index d2418a2..04dc640 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -44,11 +44,11 @@ struct imv_loader {
double frame_time;
};
-/* Initialises an instance of imv_loader */
-void imv_init_loader(struct imv_loader *img);
+/* Creates an instance of imv_loader */
+struct imv_loader *imv_loader_create(void);
-/* Cleans up all resources owned by a imv_loader instance */
-void imv_destroy_loader(struct imv_loader *img);
+/* Cleans up an imv_loader instance */
+void imv_loader_free(struct imv_loader *ldr);
/* Asynchronously load the given file */
void imv_loader_load(struct imv_loader *ldr, const char *path,
diff --git a/src/main.c b/src/main.c
index 56971c1..e2c0654 100644
--- a/src/main.c
+++ b/src/main.c
@@ -174,7 +174,7 @@ static void parse_args(int argc, char** argv)
struct {
struct imv_navigator nav;
- struct imv_loader ldr;
+ struct imv_loader *ldr;
struct imv_texture tex;
struct imv_viewport view;
struct imv_commands *cmds;
@@ -354,8 +354,8 @@ int main(int argc, char** argv)
fprintf(stderr, "Error loading font: %s\n", TTF_GetError());
}
- /* create our main classes on the stack*/
- imv_init_loader(&g_state.ldr);
+ /* create our main classes */
+ g_state.ldr = imv_loader_create();
imv_init_texture(&g_state.tex, g_state.renderer);
@@ -506,7 +506,7 @@ int main(int argc, char** argv)
}
break;
case SDLK_PERIOD:
- imv_loader_load_next_frame(&g_state.ldr);
+ imv_loader_load_next_frame(g_state.ldr);
break;
case SDLK_SPACE:
if(!e.key.repeat) {
@@ -557,7 +557,7 @@ int main(int argc, char** argv)
}
/* check if an image failed to load, if so, remove it from our image list */
- char *err_path = imv_loader_get_error(&g_state.ldr);
+ char *err_path = imv_loader_get_error(g_state.ldr);
if(err_path) {
imv_navigator_remove(&g_state.nav, err_path);
if (strncmp(err_path, "-", 2) == 0) {
@@ -593,7 +593,7 @@ int main(int argc, char** argv)
scaling_label[g_options.scaling]);
imv_viewport_set_title(&g_state.view, title);
- imv_loader_load(&g_state.ldr, current_path, stdin_buffer, stdin_buffer_size);
+ imv_loader_load(g_state.ldr, current_path, stdin_buffer, stdin_buffer_size);
g_state.view.playing = 1;
}
@@ -604,7 +604,7 @@ int main(int argc, char** argv)
/* check if a new image is available to display */
FIBITMAP *bmp;
int is_new_image;
- if(imv_loader_get_image(&g_state.ldr, &bmp, &is_new_image)) {
+ if(imv_loader_get_image(g_state.ldr, &bmp, &is_new_image)) {
imv_texture_set_image(&g_state.tex, bmp);
iw = FreeImage_GetWidth(bmp);
ih = FreeImage_GetHeight(bmp);
@@ -635,7 +635,7 @@ int main(int argc, char** argv)
if(dt > 100) {
dt = 100;
}
- imv_loader_time_passed(&g_state.ldr, dt / 1000.0);
+ imv_loader_time_passed(g_state.ldr, dt / 1000.0);
}
/* handle slideshow */
@@ -770,7 +770,7 @@ int main(int argc, char** argv)
free(g_state.command_buffer);
}
- imv_destroy_loader(&g_state.ldr);
+ imv_loader_free(g_state.ldr);
imv_destroy_texture(&g_state.tex);
imv_navigator_destroy(&g_state.nav);
imv_destroy_viewport(&g_state.view);