libgoatvr

view src/vr_modules.c @ 21:7f9cc8a4d3a5

ported the libovr backend to 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 12 Jan 2015 07:16:39 +0200
parents
children
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_openhmd(void);
8 struct vr_module *vr_module_null(void);
10 static struct vr_module *modules;
11 static int num_modules, modules_max_size;
13 static int *active_modules;
14 static int num_act_modules, act_modules_max_size;
17 void vr_init_modules(void)
18 {
19 struct vr_module *m;
21 vr_clear_modules();
23 if((m = vr_module_libovr())) {
24 vr_register_module(m);
25 }
27 if((m = vr_module_openhmd())) {
28 vr_register_module(m);
29 }
31 if((m = vr_module_null())) {
32 vr_register_module(m);
33 }
34 }
36 void vr_clear_modules(void)
37 {
38 free(modules);
39 free(active_modules);
40 modules = 0;
41 num_modules = modules_max_size = 0;
42 active_modules = 0;
43 num_act_modules = act_modules_max_size = 0;
44 }
46 void vr_register_module(struct vr_module *mod)
47 {
48 if(num_modules >= modules_max_size) {
49 int newsz = modules_max_size ? modules_max_size * 2 : 2;
50 struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods);
51 if(!newmods) {
52 fprintf(stderr, "failed to resize modules array up to %d\n", newsz);
53 return;
54 }
55 modules = newmods;
56 modules_max_size = newsz;
57 }
58 modules[num_modules++] = *mod;
59 }
61 int vr_get_num_modules(void)
62 {
63 return num_modules;
64 }
66 struct vr_module *vr_get_module(int idx)
67 {
68 return modules + idx;
69 }
71 void vr_activate_module(int idx)
72 {
73 if(num_act_modules >= act_modules_max_size) {
74 int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2;
75 int *newact = realloc(active_modules, newsz * sizeof *newact);
76 if(!newact) {
77 fprintf(stderr, "failed to resize active modules array up to %d\n", newsz);
78 return;
79 }
80 active_modules = newact;
81 act_modules_max_size = newsz;
82 }
83 active_modules[num_act_modules++] = idx;
84 }
86 int vr_get_num_active_modules(void)
87 {
88 return num_act_modules;
89 }
91 struct vr_module *vr_get_active_module(int idx)
92 {
93 return modules + active_modules[idx];
94 }