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