added configurable debug key shortcuts for changing game/menu frame rate
authorHolger Schemel <info@artsoft.org>
Mon, 13 Jun 2016 22:27:58 +0000 (00:27 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 13 Jun 2016 22:27:58 +0000 (00:27 +0200)
src/events.c
src/files.c
src/libgame/system.h
src/main.c
src/main.h

index ab6dc8ca9e30e06ab5e6e8a26ddb8443b4753fe0..3997764e0dfdb948517b13950db73e2eb260e0ac 100644 (file)
@@ -309,7 +309,7 @@ void EventLoop(void)
     BackToFront();
 
     /* reset video frame delay to default (may change again while playing) */
-    SetVideoFrameDelay(GAME_FRAME_DELAY);
+    SetVideoFrameDelay(MenuFrameDelay);
 
     if (game_status == GAME_MODE_QUIT)
       return;
@@ -1523,10 +1523,6 @@ void HandleKey(Key key, int key_status)
          break;
 
 #ifdef DEBUG
-       case KSYM_0:
-         GameFrameDelay = (GameFrameDelay == 500 ? GAME_FRAME_DELAY : 500);
-         break;
-
        case KSYM_b:
          setup.sp_show_border_elements = !setup.sp_show_border_elements;
          printf("Supaplex border elements %s\n",
@@ -1553,20 +1549,6 @@ void HandleKey(Key key, int key_status)
          break;
 
 #ifdef DEBUG
-       case KSYM_0:
-         if (key == KSYM_0)
-         {
-           if (GameFrameDelay == 500)
-             GameFrameDelay = GAME_FRAME_DELAY;
-           else
-             GameFrameDelay = 500;
-         }
-         else
-           GameFrameDelay = (key - KSYM_0) * 10;
-         printf("Game speed == %d%% (%d ms delay between two frames)\n",
-                GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
-         break;
-
        case KSYM_d:
          if (options.debug)
          {
@@ -1602,6 +1584,41 @@ void HandleKey(Key key, int key_status)
        return;
       }
   }
+
+#ifdef DEBUG
+  if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only)
+  {
+    boolean mod_key_pressed = ((GetKeyModState() & KMOD_Control) ||
+                              (GetKeyModState() & KMOD_Alt) ||
+                              (GetKeyModState() & KMOD_Meta));
+
+    for (i = 0; i < NUM_DEBUG_FRAME_DELAY_KEYS; i++)
+    {
+      if (key == setup.debug.frame_delay_key[i] &&
+         (mod_key_pressed || !setup.debug.frame_delay_use_mod_key))
+      {
+       GameFrameDelay = (GameFrameDelay != setup.debug.frame_delay[i] ?
+                         setup.debug.frame_delay[i] : GAME_FRAME_DELAY);
+
+       if (!setup.debug.frame_delay_game_only)
+         MenuFrameDelay = GameFrameDelay;
+
+       SetVideoFrameDelay(GameFrameDelay);
+
+       if (GameFrameDelay > ONE_SECOND_DELAY)
+         Error(ERR_DEBUG, "frame delay == %d ms", GameFrameDelay);
+       else if (GameFrameDelay != 0)
+         Error(ERR_DEBUG, "frame delay == %d ms (max. %d fps / %d %%)",
+               GameFrameDelay, ONE_SECOND_DELAY / GameFrameDelay,
+               GAME_FRAME_DELAY * 100 / GameFrameDelay);
+       else
+         Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)");
+
+       break;
+      }
+    }
+  }
+#endif
 }
 
 void HandleNoEvent()
index 97934c17f5dc1d13397c4aab2257310a3993f06a..ed5274695887f47821a88e08af6ab9366d579cdf 100644 (file)
@@ -8050,6 +8050,32 @@ void SaveScore(int nr)
 
 #define NUM_INTERNAL_SETUP_TOKENS              17
 
+/* debug setup */
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_0                0
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_1                1
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_2                2
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_3                3
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_4                4
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_5                5
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_6                6
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_7                7
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_8                8
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_9                9
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_0    10
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_1    11
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_2    12
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_3    13
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_4    14
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_5    15
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_6    16
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_7    17
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_8    18
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_9    19
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_USE_MOD_KEY 20
+#define SETUP_TOKEN_DEBUG_FRAME_DELAY_GAME_ONLY        21
+
+#define NUM_DEBUG_SETUP_TOKENS                 22
+
 /* options setup */
 #define SETUP_TOKEN_OPTIONS_VERBOSE            0
 
@@ -8063,6 +8089,7 @@ static struct SetupShortcutInfo ssi;
 static struct SetupInputInfo sii;
 static struct SetupSystemInfo syi;
 static struct SetupInternalInfo sxi;
+static struct SetupDebugInfo sdi;
 static struct OptionInfo soi;
 
 static struct TokenInfo global_setup_tokens[] =
@@ -8225,6 +8252,32 @@ static struct TokenInfo internal_setup_tokens[] =
   { TYPE_INTEGER,&sxi.default_window_height,   "default_window_height" },
 };
 
+static struct TokenInfo debug_setup_tokens[] =
+{
+  { TYPE_INTEGER, &sdi.frame_delay[0],         "debug.frame_delay_0"   },
+  { TYPE_INTEGER, &sdi.frame_delay[1],         "debug.frame_delay_1"   },
+  { TYPE_INTEGER, &sdi.frame_delay[2],         "debug.frame_delay_2"   },
+  { TYPE_INTEGER, &sdi.frame_delay[3],         "debug.frame_delay_3"   },
+  { TYPE_INTEGER, &sdi.frame_delay[4],         "debug.frame_delay_4"   },
+  { TYPE_INTEGER, &sdi.frame_delay[5],         "debug.frame_delay_5"   },
+  { TYPE_INTEGER, &sdi.frame_delay[6],         "debug.frame_delay_6"   },
+  { TYPE_INTEGER, &sdi.frame_delay[7],         "debug.frame_delay_7"   },
+  { TYPE_INTEGER, &sdi.frame_delay[8],         "debug.frame_delay_8"   },
+  { TYPE_INTEGER, &sdi.frame_delay[9],         "debug.frame_delay_9"   },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[0],     "debug.key.frame_delay_0" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[1],     "debug.key.frame_delay_1" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[2],     "debug.key.frame_delay_2" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[3],     "debug.key.frame_delay_3" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[4],     "debug.key.frame_delay_4" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[5],     "debug.key.frame_delay_5" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[6],     "debug.key.frame_delay_6" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[7],     "debug.key.frame_delay_7" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[8],     "debug.key.frame_delay_8" },
+  { TYPE_KEY_X11, &sdi.frame_delay_key[9],     "debug.key.frame_delay_9" },
+  { TYPE_BOOLEAN, &sdi.frame_delay_use_mod_key,"debug.frame_delay.use_mod_key"},
+  { TYPE_BOOLEAN, &sdi.frame_delay_game_only,  "debug.frame_delay.game_only" },
+};
+
 static struct TokenInfo options_setup_tokens[] =
 {
   { TYPE_BOOLEAN, &soi.verbose,                "options.verbose"               },
@@ -8389,6 +8442,31 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->internal.default_window_width  = WIN_XSIZE_DEFAULT;
   si->internal.default_window_height = WIN_YSIZE_DEFAULT;
 
+  si->debug.frame_delay[0] = DEFAULT_FRAME_DELAY_0;
+  si->debug.frame_delay[1] = DEFAULT_FRAME_DELAY_1;
+  si->debug.frame_delay[2] = DEFAULT_FRAME_DELAY_2;
+  si->debug.frame_delay[3] = DEFAULT_FRAME_DELAY_3;
+  si->debug.frame_delay[4] = DEFAULT_FRAME_DELAY_4;
+  si->debug.frame_delay[5] = DEFAULT_FRAME_DELAY_5;
+  si->debug.frame_delay[6] = DEFAULT_FRAME_DELAY_6;
+  si->debug.frame_delay[7] = DEFAULT_FRAME_DELAY_7;
+  si->debug.frame_delay[8] = DEFAULT_FRAME_DELAY_8;
+  si->debug.frame_delay[9] = DEFAULT_FRAME_DELAY_9;
+
+  si->debug.frame_delay_key[0] = DEFAULT_KEY_FRAME_DELAY_0;
+  si->debug.frame_delay_key[1] = DEFAULT_KEY_FRAME_DELAY_1;
+  si->debug.frame_delay_key[2] = DEFAULT_KEY_FRAME_DELAY_2;
+  si->debug.frame_delay_key[3] = DEFAULT_KEY_FRAME_DELAY_3;
+  si->debug.frame_delay_key[4] = DEFAULT_KEY_FRAME_DELAY_4;
+  si->debug.frame_delay_key[5] = DEFAULT_KEY_FRAME_DELAY_5;
+  si->debug.frame_delay_key[6] = DEFAULT_KEY_FRAME_DELAY_6;
+  si->debug.frame_delay_key[7] = DEFAULT_KEY_FRAME_DELAY_7;
+  si->debug.frame_delay_key[8] = DEFAULT_KEY_FRAME_DELAY_8;
+  si->debug.frame_delay_key[9] = DEFAULT_KEY_FRAME_DELAY_9;
+
+  si->debug.frame_delay_use_mod_key = DEFAULT_FRAME_DELAY_USE_MOD_KEY;
+  si->debug.frame_delay_game_only   = DEFAULT_FRAME_DELAY_GAME_ONLY;
+
   si->options.verbose = FALSE;
 
 #if defined(PLATFORM_ANDROID)
@@ -8477,6 +8555,13 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash)
                 getHashEntry(setup_file_hash, internal_setup_tokens[i].text));
   setup.internal = sxi;
 
+  /* debug setup */
+  sdi = setup.debug;
+  for (i = 0; i < NUM_DEBUG_SETUP_TOKENS; i++)
+    setSetupInfo(debug_setup_tokens, i,
+                getHashEntry(setup_file_hash, debug_setup_tokens[i].text));
+  setup.debug = sdi;
+
   /* options setup */
   soi = setup.options;
   for (i = 0; i < NUM_OPTIONS_SETUP_TOKENS; i++)
@@ -8643,6 +8728,12 @@ void SaveSetup()
   /* internal setup */
   /* (internal setup values not saved to user setup file) */
 
+  /* debug setup */
+  sdi = setup.debug;
+  fprintf(file, "\n");
+  for (i = 0; i < NUM_DEBUG_SETUP_TOKENS; i++)
+    fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i));
+
   /* options setup */
   soi = setup.options;
   fprintf(file, "\n");
index 4710ea17d0962de0101021f129a623ba1ff996a9..0bd948bd640ff684c88f25ee3ddff7637a303b0a 100644 (file)
 #define DEFAULT_KEY_SNAP_UP            KSYM_UNDEFINED
 #define DEFAULT_KEY_SNAP_DOWN          KSYM_UNDEFINED
 
+/* default debug setup keys and values */
+#define DEFAULT_FRAME_DELAY_0          20              // 100 % speed
+#define DEFAULT_FRAME_DELAY_1          500             // 4 % speed
+#define DEFAULT_FRAME_DELAY_2          250             // 8 % speed
+#define DEFAULT_FRAME_DELAY_3          125             // 16 % speed
+#define DEFAULT_FRAME_DELAY_4          60              // 33 % speed
+#define DEFAULT_FRAME_DELAY_5          40              // 50 % speed
+#define DEFAULT_FRAME_DELAY_6          30              // 66 % speed
+#define DEFAULT_FRAME_DELAY_7          10              // 200 % speed
+#define DEFAULT_FRAME_DELAY_8          5               // 400 % speed
+#define DEFAULT_FRAME_DELAY_9          0               // maximum speed
+
+#define DEFAULT_KEY_FRAME_DELAY_0      KSYM_0
+#define DEFAULT_KEY_FRAME_DELAY_1      KSYM_1
+#define DEFAULT_KEY_FRAME_DELAY_2      KSYM_2
+#define DEFAULT_KEY_FRAME_DELAY_3      KSYM_3
+#define DEFAULT_KEY_FRAME_DELAY_4      KSYM_4
+#define DEFAULT_KEY_FRAME_DELAY_5      KSYM_5
+#define DEFAULT_KEY_FRAME_DELAY_6      KSYM_6
+#define DEFAULT_KEY_FRAME_DELAY_7      KSYM_7
+#define DEFAULT_KEY_FRAME_DELAY_8      KSYM_8
+#define DEFAULT_KEY_FRAME_DELAY_9      KSYM_9
+
+#define NUM_DEBUG_FRAME_DELAY_KEYS     10
+
+#define DEFAULT_FRAME_DELAY_USE_MOD_KEY        FALSE
+#define DEFAULT_FRAME_DELAY_GAME_ONLY  TRUE
+
 /* values for key_status */
 #define KEY_NOT_PRESSED                        FALSE
 #define KEY_RELEASED                   FALSE
 
 /* fundamental game speed values */
 #define ONE_SECOND_DELAY       1000    /* delay value for one second */
+#define MENU_FRAME_DELAY       20      /* frame delay in milliseconds */
 #define GAME_FRAME_DELAY       20      /* frame delay in milliseconds */
 #define FFWD_FRAME_DELAY       10      /* 200% speed for fast forward */
 #define FRAMES_PER_SECOND      (ONE_SECOND_DELAY / GAME_FRAME_DELAY)
@@ -1010,6 +1039,14 @@ struct SetupInternalInfo
   boolean choose_from_top_leveldir;
 };
 
+struct SetupDebugInfo
+{
+  int frame_delay[10];
+  Key frame_delay_key[10];
+  boolean frame_delay_use_mod_key;
+  boolean frame_delay_game_only;
+};
+
 struct SetupInfo
 {
   char *player_name;
@@ -1063,6 +1100,8 @@ struct SetupInfo
   struct SetupTouchInfo touch;
   struct SetupSystemInfo system;
   struct SetupInternalInfo internal;
+  struct SetupDebugInfo debug;
+
   struct OptionInfo options;
 };
 
index 047c1cb2b93fadc01d628f521b27eec3dc84481c..d29a341a9a24b7223bdbf868fbe76b75b73c2e17 100644 (file)
@@ -118,6 +118,7 @@ int                 ScrollStepSize;
 int                    ScreenMovDir = MV_NONE, ScreenMovPos = 0;
 int                    ScreenGfxPos = 0;
 int                    BorderElement = EL_STEELWALL;
+int                    MenuFrameDelay = MENU_FRAME_DELAY;
 int                    GameFrameDelay = GAME_FRAME_DELAY;
 int                    FfwdFrameDelay = FFWD_FRAME_DELAY;
 int                    BX1, BY1;
index 2da455841722274ed5917a087faff9a539f173ce..c3a0ab046e78054dfb7aa3bf99f6063e18386be0 100644 (file)
@@ -3058,6 +3058,7 @@ extern int                        FX, FY;
 extern int                     ScrollStepSize;
 extern int                     ScreenMovDir, ScreenMovPos, ScreenGfxPos;
 extern int                     BorderElement;
+extern int                     MenuFrameDelay;
 extern int                     GameFrameDelay;
 extern int                     FfwdFrameDelay;
 extern int                     BX1, BY1;