X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=demo_prior;a=blobdiff_plain;f=src%2Fopt.c;fp=src%2Fopt.c;h=796722cc58a42701cdc6d8293fad7731a1b44659;hp=0000000000000000000000000000000000000000;hb=44a7a61d2bec54ed741930572e63e5015326daca;hpb=ec776ad8bf37d25b9308e2c770d66247135b46ea diff --git a/src/opt.c b/src/opt.c new file mode 100644 index 0000000..796722c --- /dev/null +++ b/src/opt.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include "opt.h" +#include "treestore.h" + +static void print_usage(const char *argv0); + +struct options opt = { + 1280, 800, + 1, /* fullscreen */ + 1, /* music */ + 1, /* sRGB */ + 1 /* anti-aliasing */ +}; + +int parse_args(int argc, char **argv) +{ + int i; + + for(i=1; ix\n", argv[-1]); + return -1; + } + } else if(strcmp(argv[i], "-fs") == 0) { + opt.fullscr = 1; + } else if(strcmp(argv[i], "-win") == 0) { + opt.fullscr = 0; + } else if(strcmp(argv[i], "-srgb") == 0) { + opt.srgb = 1; + } else if(strcmp(argv[i], "-nosrgb") == 0) { + opt.srgb = 0; + } else if(strcmp(argv[i], "-aa") == 0) { + opt.msaa = 1; + } else if(strcmp(argv[i], "-noaa") == 0) { + opt.msaa = 0; + } else if(strcmp(argv[i], "-music") == 0) { + opt.music = 1; + } else if(strcmp(argv[i], "-nomusic") == 0) { + opt.music = 0; + } else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) { + print_usage(argv[0]); + exit(0); + } else { + fprintf(stderr, "invalid argument: %s\n", argv[i]); + print_usage(argv[0]); + return -1; + } + } + return 0; +} + +static void print_usage(const char *argv0) +{ + printf("Usage: %s [options]\n", argv0); + printf(" -fs: fullscr\n"); + printf(" -win: windowed\n"); + printf(" -s,-size : windowed resolution\n"); + printf(" -srgb/-nosrgb: enable/disable sRGB framebuffer\n"); + printf(" -aa/-noaa: enable/disable multisample anti-aliasing\n"); + printf(" -music/-nomusic: enable/disable music playback\n"); + printf(" -h,-help: print usage and exit\n"); +} + +int read_cfg(const char *fname) +{ + struct ts_node *ts; + + if(!(ts = ts_load(fname))) { + return -1; + } + opt.width = ts_lookup_int(ts, "demo.width", opt.width); + opt.height = ts_lookup_int(ts, "demo.height", opt.height); + opt.fullscr = ts_lookup_int(ts, "demo.fullscreen", opt.fullscr); + opt.music = ts_lookup_int(ts, "demo.music", opt.music); + opt.srgb = ts_lookup_int(ts, "demo.srgb", opt.srgb); + opt.msaa = ts_lookup_int(ts, "demo.aa", opt.msaa); + + ts_free_tree(ts); + return 0; +}