conworlds

view 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 source
1 /* XXX this might become partly auto-generated in the future */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "vr_impl.h"
6 struct vr_module *vr_module_libovr(void);
7 struct vr_module *vr_module_null(void);
9 static struct vr_module *modules;
10 static int num_modules, modules_max_size;
12 static int *active_modules;
13 static int num_act_modules, act_modules_max_size;
16 void vr_init_modules(void)
17 {
18 struct vr_module *m;
20 vr_clear_modules();
22 if((m = vr_module_libovr())) {
23 vr_register_module(m);
24 }
26 if((m = vr_module_null())) {
27 vr_register_module(m);
28 }
30 /* more ... */
31 }
33 void vr_clear_modules(void)
34 {
35 free(modules);
36 free(active_modules);
37 modules = 0;
38 num_modules = modules_max_size = 0;
39 active_modules = 0;
40 num_act_modules = act_modules_max_size = 0;
41 }
43 void vr_register_module(struct vr_module *mod)
44 {
45 if(num_modules >= modules_max_size) {
46 int newsz = modules_max_size ? modules_max_size * 2 : 2;
47 struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods);
48 if(!newmods) {
49 fprintf(stderr, "failed to resize modules array up to %d\n", newsz);
50 return;
51 }
52 modules = newmods;
53 modules_max_size = newsz;
54 }
55 modules[num_modules++] = *mod;
56 }
58 int vr_get_num_modules(void)
59 {
60 return num_modules;
61 }
63 struct vr_module *vr_get_module(int idx)
64 {
65 return modules + idx;
66 }
68 void vr_activate_module(int idx)
69 {
70 if(num_act_modules >= act_modules_max_size) {
71 int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2;
72 int *newact = realloc(active_modules, newsz * sizeof *newact);
73 if(!newact) {
74 fprintf(stderr, "failed to resize active modules array up to %d\n", newsz);
75 return;
76 }
77 active_modules = newact;
78 act_modules_max_size = newsz;
79 }
80 active_modules[num_act_modules++] = idx;
81 }
83 int vr_get_num_active_modules(void)
84 {
85 return num_act_modules;
86 }
88 struct vr_module *vr_get_active_module(int idx)
89 {
90 return modules + active_modules[idx];
91 }