changeset 121:16fc6e6cf3b5

Move option handling to the simple demo engine.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Oct 2012 05:36:06 +0300
parents a4830b62ff5d
children 5ba672ebe014
files dmsimple.c
diffstat 1 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmsimple.c	Thu Oct 04 03:43:43 2012 +0300
+++ b/dmsimple.c	Thu Oct 04 05:36:06 2012 +0300
@@ -9,6 +9,61 @@
 DMFrameData frame;
 
 
+static DMOptArg optList[] =
+{
+    { 0, '?', "help",       "Show this help", OPT_NONE },
+    { 1, 'v', "verbose",    "Be more verbose", OPT_NONE },
+    { 2, 'f', "fs",         "Fullscreen", OPT_NONE },
+#ifdef DM_DEBUG
+    { 3, 'd', "debug",      "Debug mode", OPT_NONE },
+#endif
+};
+
+const int optListN = sizeof(optList) / sizeof(optList[0]);
+
+
+
+static void argShowHelp()
+{
+    dmPrintBanner(stdout, dmProgName, "[options]");
+    dmArgsPrintHelp(stdout, optList, optListN);
+}
+
+
+static BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
+{
+    (void) optArg;
+
+    switch (optN)
+    {
+        case 0:
+            argShowHelp();
+            exit(0);
+            break;
+
+        case 1:
+            dmVerbosity++;
+            break;
+        
+        case 2:
+            engine.optVFlags |= SDL_FULLSCREEN;
+            break;
+
+#ifdef DM_DEBUG
+        case 3:
+            engine.optDebug = TRUE;
+            break;
+#endif
+
+        default:
+            dmError("Unknown option '%s'.\n", currArg);
+            return FALSE;
+    }
+    
+    return TRUE;
+}
+
+
 int engineShowProgress(int loaded, int total)
 {
     int dx = 60,
@@ -374,6 +429,9 @@
     if ((err = demoPreInit(argc, argv)) != DMERR_OK)
         goto error_exit;
 
+    if (!dmArgsProcess(argc, argv, optList, optListN,
+        argHandleOpt, NULL, FALSE))
+        return DMERR_INIT_FAIL;
     // Initialize resource subsystem
     dmPrint(1, "Initializing resources subsystem.\n");
     if ((err = dmres_init(engine.optPackFilename, engine.optDataPath, engine.optResFlags, engineClassifier)) != DMERR_OK)