conworlds

annotate 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
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@4 7 struct vr_module *vr_module_null(void);
nuclear@4 8
nuclear@4 9 static struct vr_module *modules;
nuclear@4 10 static int num_modules, modules_max_size;
nuclear@4 11
nuclear@4 12 static int *active_modules;
nuclear@4 13 static int num_act_modules, act_modules_max_size;
nuclear@4 14
nuclear@4 15
nuclear@4 16 void vr_init_modules(void)
nuclear@4 17 {
nuclear@4 18 struct vr_module *m;
nuclear@4 19
nuclear@4 20 vr_clear_modules();
nuclear@4 21
nuclear@4 22 if((m = vr_module_libovr())) {
nuclear@4 23 vr_register_module(m);
nuclear@4 24 }
nuclear@4 25
nuclear@4 26 if((m = vr_module_null())) {
nuclear@4 27 vr_register_module(m);
nuclear@4 28 }
nuclear@4 29
nuclear@4 30 /* more ... */
nuclear@4 31 }
nuclear@4 32
nuclear@4 33 void vr_clear_modules(void)
nuclear@4 34 {
nuclear@4 35 free(modules);
nuclear@4 36 free(active_modules);
nuclear@4 37 modules = 0;
nuclear@4 38 num_modules = modules_max_size = 0;
nuclear@4 39 active_modules = 0;
nuclear@4 40 num_act_modules = act_modules_max_size = 0;
nuclear@4 41 }
nuclear@4 42
nuclear@4 43 void vr_register_module(struct vr_module *mod)
nuclear@4 44 {
nuclear@4 45 if(num_modules >= modules_max_size) {
nuclear@4 46 int newsz = modules_max_size ? modules_max_size * 2 : 2;
nuclear@4 47 struct vr_module *newmods = realloc(modules, newsz * sizeof *newmods);
nuclear@4 48 if(!newmods) {
nuclear@4 49 fprintf(stderr, "failed to resize modules array up to %d\n", newsz);
nuclear@4 50 return;
nuclear@4 51 }
nuclear@4 52 modules = newmods;
nuclear@4 53 modules_max_size = newsz;
nuclear@4 54 }
nuclear@4 55 modules[num_modules++] = *mod;
nuclear@4 56 }
nuclear@4 57
nuclear@4 58 int vr_get_num_modules(void)
nuclear@4 59 {
nuclear@4 60 return num_modules;
nuclear@4 61 }
nuclear@4 62
nuclear@4 63 struct vr_module *vr_get_module(int idx)
nuclear@4 64 {
nuclear@4 65 return modules + idx;
nuclear@4 66 }
nuclear@4 67
nuclear@4 68 void vr_activate_module(int idx)
nuclear@4 69 {
nuclear@4 70 if(num_act_modules >= act_modules_max_size) {
nuclear@4 71 int newsz = act_modules_max_size ? act_modules_max_size * 2 : 2;
nuclear@4 72 int *newact = realloc(active_modules, newsz * sizeof *newact);
nuclear@4 73 if(!newact) {
nuclear@4 74 fprintf(stderr, "failed to resize active modules array up to %d\n", newsz);
nuclear@4 75 return;
nuclear@4 76 }
nuclear@4 77 active_modules = newact;
nuclear@4 78 act_modules_max_size = newsz;
nuclear@4 79 }
nuclear@4 80 active_modules[num_act_modules++] = idx;
nuclear@4 81 }
nuclear@4 82
nuclear@4 83 int vr_get_num_active_modules(void)
nuclear@4 84 {
nuclear@4 85 return num_act_modules;
nuclear@4 86 }
nuclear@4 87
nuclear@4 88 struct vr_module *vr_get_active_module(int idx)
nuclear@4 89 {
nuclear@4 90 return modules + active_modules[idx];
nuclear@4 91 }