added optcfg and fixed camera xform
[cyberay] / src / game.c
1 #include "game.h"
2 #include "optcfg.h"
3
4 struct level lvl;
5 struct options opt;
6
7 enum { OPT_SIZE, OPT_HELP };
8
9 static struct optcfg_option options[] = {
10         {'s', "size", OPT_SIZE, "rendering resolution (WxH)"},
11         {'h', "help", OPT_HELP, "print usage and exit"},
12         OPTCFG_OPTIONS_END
13 };
14
15 static int opt_handler(struct optcfg *o, int opt, void *cls);
16
17 int init_options(int argc, char **argv)
18 {
19         struct optcfg *optcfg;
20
21         opt.width = 1280;
22         opt.height = 800;
23
24         optcfg = optcfg_init(options);
25         optcfg_set_opt_callback(optcfg, opt_handler, argv[0]);
26         optcfg_parse_config_file(optcfg, "cyberay.conf");
27         if(optcfg_parse_args(optcfg, argc, argv) == -1) {
28                 return -1;
29         }
30
31         optcfg_destroy(optcfg);
32         return 0;
33 }
34
35 static int opt_handler(struct optcfg *o, int optid, void *cls)
36 {
37         char *val;
38
39         switch(optid) {
40         case OPT_SIZE:
41                 if(!(val = optcfg_next_value(o)) || sscanf(val, "%dx%d", &opt.width, &opt.height) != 2) {
42                         fprintf(stderr, "size: expected <width>x<height>\n");
43                         return -1;
44                 }
45                 break;
46
47         case OPT_HELP:
48                 printf("Usage: %s [options]\n", (char*)cls);
49                 printf("Options:\n");
50                 optcfg_print_options(o);
51                 exit(0);
52         }
53         return 0;
54 }