changeset 25:98dcf1847e75

Cleanups, add the debug mode enabling option.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Oct 2012 18:17:52 +0300
parents 01f3af410abb
children 077d08c442f7
files krapula.c
diffstat 1 files changed, 46 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/krapula.c	Tue Oct 02 06:23:56 2012 +0300
+++ b/krapula.c	Tue Oct 02 18:17:52 2012 +0300
@@ -1,17 +1,16 @@
 #include "dmsimple.h"
 #include "dmvecmat.h"
-
 #include <math.h>
 
 
-#define DM_COLORS (256)
-
-
 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]);
@@ -27,30 +26,39 @@
 
 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
 {
-    switch (optN) {
-    case 0:
-        argShowHelp();
-        exit(0);
-        break;
+    (void) optArg;
+
+    switch (optN)
+    {
+        case 0:
+            argShowHelp();
+            exit(0);
+            break;
 
-    case 1:
-        dmVerbosity++;
-        break;
-    
-    case 2:
-        engine.optVFlags |= SDL_FULLSCREEN;
-        break;
+        case 1:
+            dmVerbosity++;
+            break;
+        
+        case 2:
+            engine.optVFlags |= SDL_FULLSCREEN;
+            break;
 
-    default:
-        dmError("Unknown option '%s'.\n", currArg);
-        return FALSE;
+#ifdef DM_DEBUG
+        case 3:
+            engine.optDebug = TRUE;
+            break;
+#endif
+
+        default:
+            dmError("Unknown option '%s'.\n", currArg);
+            return FALSE;
     }
     
     return TRUE;
 }
 
 
-
+#define DM_COLORS (256)
 
 void dmMakePalette(SDL_Surface *scr)
 {
@@ -85,25 +93,6 @@
 }
 
 
-void dmPerlin(SDL_Surface *screen, float f)
-{
-    Uint8 *pix = screen->pixels;
-    int xc, yc;
-
-    for (yc = 0; yc < screen->h; yc++)
-    {
-        Uint8 *dp = pix;
-
-        for (xc = 0; xc < screen->w; xc++)
-        {
-            *dp++ = 128 + dmPerlinNoise2D(xc, yc, 0.01, 0.1, 3) / 34.0;
-        }
-
-        pix += screen->pitch;
-    }
-}
-
-
 #define QWIDTH	256
 #define QHEIGHT	160
 
@@ -120,11 +109,13 @@
 {
     int x, y;
     for (y = 0; y < QHEIGHT; y++)
+    {
         for (x = 0; x < QWIDTH; x++)
         {
             DMFloat f = 0.40f + dmPerlinNoise2D(x, y, 1.1f, q, 2);
             map[y][x] = (int) (dmClip(f) * m);
         }
+    }
 }
 
 
@@ -400,7 +391,9 @@
     engine.optScrHeight = 480;
     engine.optBitDepth  = 32;
     engine.optVFlags    = SDL_SWSURFACE | SDL_HWPALETTE;
-
+#ifdef DM_DEBUG
+    engine.demoDuration = 150;
+#endif
 
     if (!dmArgsProcess(argc, argv, optList, optListN,
         argHandleOpt, NULL, FALSE))
@@ -414,7 +407,7 @@
 }
 
 
-int demoGlobalInit()
+int demoInit()
 {
     int i;
 
@@ -454,6 +447,18 @@
 }
 
 
+void demoShutdown()
+{
+    SDL_FreeSurface(bmap);
+}
+
+
+void demoQuit()
+{
+    dmPrint(0, "Krapulassa on kivaa.\n");
+}
+
+
 int demoMainTick()
 {
     float t = engineGetTimeDT();
@@ -735,9 +740,3 @@
 
     return DMERR_OK;
 }
-
-
-void demoFinish()
-{
-    dmPrint(0, "Krapulassa on kivaa.\n");
-}