libgoatvr
annotate src/vr_modules.c @ 20:827ec716c275
god I miss glew...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 11 Oct 2014 07:18:07 +0300 |
parents | |
children |
rev | line source |
---|---|
nuclear@0 | 1 /* XXX this might become partly auto-generated in the future */ |
nuclear@0 | 2 #include <stdio.h> |
nuclear@0 | 3 #include <stdlib.h> |
nuclear@0 | 4 #include "vr_impl.h" |
nuclear@0 | 5 |
nuclear@0 | 6 struct vr_module *vr_module_libovr(void); |
nuclear@0 | 7 struct vr_module *vr_module_openhmd(void); |
nuclear@0 | 8 struct vr_module *vr_module_null(void); |
nuclear@0 | 9 |
nuclear@0 | 10 static struct vr_module *modules; |
nuclear@0 | 11 static int num_modules, modules_max_size; |
nuclear@0 | 12 |
nuclear@0 | 13 static int *active_modules; |
nuclear@0 | 14 static int num_act_modules, act_modules_max_size; |
nuclear@0 | 15 |
nuclear@0 | 16 |
nuclear@0 | 17 void vr_init_modules(void) |
nuclear@0 | 18 { |
nuclear@0 | 19 struct vr_module *m; |
nuclear@0 | 20 |
nuclear@0 | 21 vr_clear_modules(); |
nuclear@0 | 22 |
nuclear@0 | 23 if((m = vr_module_libovr())) { |
nuclear@0 | 24 vr_register_module(m); |
nuclear@0 | 25 } |
nuclear@0 | 26 |
nuclear@0 | 27 if((m = vr_module_openhmd())) { |
nuclear@0 | 28 vr_register_module(m); |
nuclear@0 | 29 } |
nuclear@0 | 30 |
nuclear@0 | 31 if((m = vr_module_null())) { |
nuclear@0 | 32 vr_register_module(m); |
nuclear@0 | 33 } |
nuclear@0 | 34 } |
nuclear@0 | 35 |
nuclear@0 | 36 void vr_clear_modules(void) |
nuclear@0 | 37 { |
nuclear@0 | 38 free(modules); |
nuclear@0 | 39 free(active_modules); |
nuclear@0 | 40 modules = 0; |
nuclear@0 | 41 num_modules = modules_max_size = 0; |
nuclear@0 | 42 active_modules = 0; |
nuclear@0 | 43 num_act_modules = act_modules_max_size = 0; |
nuclear@0 | 44 } |
nuclear@0 | 45 |
nuclear@0 | 46 void vr_register_module(struct vr_module *mod) |
nuclear@0 | 47 { |
nuclear@0 | 48 if(num_modules >= modules_max_size) { |
nuclear@0 | 49 int newsz = modules_max_size ? modules_max_size * 2 : 2; |
nuclear@0 | 50 struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods); |
nuclear@0 | 51 if(!newmods) { |
nuclear@0 | 52 fprintf(stderr, "failed to resize modules array up to %d\n", newsz); |
nuclear@0 | 53 return; |
nuclear@0 | 54 } |
nuclear@0 | 55 modules = newmods; |
nuclear@0 | 56 modules_max_size = newsz; |
nuclear@0 | 57 } |
nuclear@0 | 58 modules[num_modules++] = *mod; |
nuclear@0 | 59 } |
nuclear@0 | 60 |
nuclear@0 | 61 int vr_get_num_modules(void) |
nuclear@0 | 62 { |
nuclear@0 | 63 return num_modules; |
nuclear@0 | 64 } |
nuclear@0 | 65 |
nuclear@0 | 66 struct vr_module *vr_get_module(int idx) |
nuclear@0 | 67 { |
nuclear@0 | 68 return modules + idx; |
nuclear@0 | 69 } |
nuclear@0 | 70 |
nuclear@0 | 71 void vr_activate_module(int idx) |
nuclear@0 | 72 { |
nuclear@0 | 73 if(num_act_modules >= act_modules_max_size) { |
nuclear@0 | 74 int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2; |
nuclear@0 | 75 int *newact = realloc(active_modules, newsz * sizeof *newact); |
nuclear@0 | 76 if(!newact) { |
nuclear@0 | 77 fprintf(stderr, "failed to resize active modules array up to %d\n", newsz); |
nuclear@0 | 78 return; |
nuclear@0 | 79 } |
nuclear@0 | 80 active_modules = newact; |
nuclear@0 | 81 act_modules_max_size = newsz; |
nuclear@0 | 82 } |
nuclear@0 | 83 active_modules[num_act_modules++] = idx; |
nuclear@0 | 84 } |
nuclear@0 | 85 |
nuclear@0 | 86 int vr_get_num_active_modules(void) |
nuclear@0 | 87 { |
nuclear@0 | 88 return num_act_modules; |
nuclear@0 | 89 } |
nuclear@0 | 90 |
nuclear@0 | 91 struct vr_module *vr_get_active_module(int idx) |
nuclear@0 | 92 { |
nuclear@0 | 93 return modules + active_modules[idx]; |
nuclear@0 | 94 } |