aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-08-04 22:00:04 +0200
committerDavid Robillard <d@drobilla.net>2019-09-03 08:34:39 +0200
commit4c6ac6b1c3e9f7ac04b5f6ba0b30eb8eacfcce9c (patch)
tree42f39dfb66004b2153ab36a77fcfb13508d9f5dc /test/test_utils.h
parent36f9c9dd7bc2f3d986b90477238c24e121936a25 (diff)
downloadpugl-4c6ac6b1c3e9f7ac04b5f6ba0b30eb8eacfcce9c.tar.gz
pugl-4c6ac6b1c3e9f7ac04b5f6ba0b30eb8eacfcce9c.tar.bz2
pugl-4c6ac6b1c3e9f7ac04b5f6ba0b30eb8eacfcce9c.zip
Factor out parsing test options
Diffstat (limited to 'test/test_utils.h')
-rw-r--r--test/test_utils.h58
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)