conworlds
diff src/vr/vr_modules.c @ 4:e6948e131526
adding a vr wrapper
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 20 Aug 2014 06:33:43 +0300 |
parents | |
children | e3f0ca1d008a |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/vr/vr_modules.c Wed Aug 20 06:33:43 2014 +0300 1.3 @@ -0,0 +1,91 @@ 1.4 +/* XXX this might become partly auto-generated in the future */ 1.5 +#include <stdio.h> 1.6 +#include <stdlib.h> 1.7 +#include "vr_impl.h" 1.8 + 1.9 +struct vr_module *vr_module_libovr(void); 1.10 +struct vr_module *vr_module_null(void); 1.11 + 1.12 +static struct vr_module *modules; 1.13 +static int num_modules, modules_max_size; 1.14 + 1.15 +static int *active_modules; 1.16 +static int num_act_modules, act_modules_max_size; 1.17 + 1.18 + 1.19 +void vr_init_modules(void) 1.20 +{ 1.21 + struct vr_module *m; 1.22 + 1.23 + vr_clear_modules(); 1.24 + 1.25 + if((m = vr_module_libovr())) { 1.26 + vr_register_module(m); 1.27 + } 1.28 + 1.29 + if((m = vr_module_null())) { 1.30 + vr_register_module(m); 1.31 + } 1.32 + 1.33 + /* more ... */ 1.34 +} 1.35 + 1.36 +void vr_clear_modules(void) 1.37 +{ 1.38 + free(modules); 1.39 + free(active_modules); 1.40 + modules = 0; 1.41 + num_modules = modules_max_size = 0; 1.42 + active_modules = 0; 1.43 + num_act_modules = act_modules_max_size = 0; 1.44 +} 1.45 + 1.46 +void vr_register_module(struct vr_module *mod) 1.47 +{ 1.48 + if(num_modules >= modules_max_size) { 1.49 + int newsz = modules_max_size ? modules_max_size * 2 : 2; 1.50 + struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods); 1.51 + if(!newmods) { 1.52 + fprintf(stderr, "failed to resize modules array up to %d\n", newsz); 1.53 + return; 1.54 + } 1.55 + modules = newmods; 1.56 + modules_max_size = newsz; 1.57 + } 1.58 + modules[num_modules++] = *mod; 1.59 +} 1.60 + 1.61 +int vr_get_num_modules(void) 1.62 +{ 1.63 + return num_modules; 1.64 +} 1.65 + 1.66 +struct vr_module *vr_get_module(int idx) 1.67 +{ 1.68 + return modules + idx; 1.69 +} 1.70 + 1.71 +void vr_activate_module(int idx) 1.72 +{ 1.73 + if(num_act_modules >= act_modules_max_size) { 1.74 + int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2; 1.75 + int *newact = realloc(active_modules, newsz * sizeof *newact); 1.76 + if(!newact) { 1.77 + fprintf(stderr, "failed to resize active modules array up to %d\n", newsz); 1.78 + return; 1.79 + } 1.80 + active_modules = newact; 1.81 + act_modules_max_size = newsz; 1.82 + } 1.83 + active_modules[num_act_modules++] = idx; 1.84 +} 1.85 + 1.86 +int vr_get_num_active_modules(void) 1.87 +{ 1.88 + return num_act_modules; 1.89 +} 1.90 + 1.91 +struct vr_module *vr_get_active_module(int idx) 1.92 +{ 1.93 + return modules + active_modules[idx]; 1.94 +}