diff options
Diffstat (limited to 'test/test_utils.h')
-rw-r--r-- | test/test_utils.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/test_utils.h b/test/test_utils.h index bf058ac..f4f6c31 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -19,11 +19,21 @@ #include <math.h> #include <stdint.h> #include <stdio.h> +#include <string.h> typedef struct { double lastReportTime; } PuglFpsPrinter; +typedef struct { + int samples; + int doubleBuffer; + bool continuous; + bool help; + bool ignoreKeyRepeat; + bool resizable; +} PuglTestOptions; + static const float cubeStripVertices[] = { -1.0f, 1.0f, 1.0f, // Front top left 1.0f, 1.0f, 1.0f, // Front top right @@ -143,6 +153,54 @@ printEvent(const PuglEvent* event, const char* prefix) } static inline void +puglPrintTestUsage(const char* prog, const char* posHelp) +{ + printf("Usage: %s [OPTION]... %s\n\n" + " -a Enable anti-aliasing\n" + " -c Continuously animate and draw\n" + " -d Enable double-buffering\n" + " -h Display this help\n" + " -i Ignore key repeat\n" + " -r Resizable window\n", + prog, posHelp); +} + +static inline PuglTestOptions +puglParseTestOptions(int* pargc, char*** pargv) +{ + PuglTestOptions opts = { 0, 0, false, false, false, false }; + + char** const argv = *pargv; + int i = 1; + for (; i < *pargc; ++i) { + if (!strcmp(argv[i], "-a")) { + opts.samples = 4; + } else if (!strcmp(argv[i], "-c")) { + opts.continuous = true; + } else if (!strcmp(argv[i], "-d")) { + opts.doubleBuffer = PUGL_TRUE; + } else if (!strcmp(argv[i], "-h")) { + opts.help = true; + return opts; + } else if (!strcmp(argv[i], "-i")) { + opts.ignoreKeyRepeat = true; + } else if (!strcmp(argv[i], "-r")) { + opts.resizable = true; + } else if (argv[i][0] != '-') { + break; + } else { + opts.help = true; + fprintf(stderr, "error: Unknown option: %s\n", argv[i]); + } + } + + *pargc -= i; + *pargv += i; + + return opts; +} + +static inline void puglPrintFps(const PuglWorld* world, PuglFpsPrinter* printer, unsigned* const framesDrawn) |