rnd-20001125-3-src
[rocksndiamonds.git] / src / tools.c
index 51ba20555a210ed3419bc2f6c98972b48dbb92bd..77f574db3c25be10c396853295bf822bf25191ea 100644 (file)
@@ -99,6 +99,36 @@ void BackToFront()
   if (!redraw_mask)
     return;
 
+  if (global.fps_slowdown && game_status == PLAYING)
+  {
+    static boolean last_frame_skipped = FALSE;
+    boolean skip_even_when_not_scrolling = TRUE;
+    boolean just_scrolling = (ScreenMovDir != 0);
+    boolean verbose = FALSE;
+
+    if (global.fps_slowdown_factor > 1 &&
+       (FrameCounter % global.fps_slowdown_factor) &&
+       (just_scrolling || skip_even_when_not_scrolling))
+    {
+      redraw_mask &= ~REDRAW_MAIN;
+
+      last_frame_skipped = TRUE;
+
+      if (verbose)
+       printf("FRAME SKIPPED\n");
+    }
+    else
+    {
+      if (last_frame_skipped)
+       redraw_mask |= REDRAW_FIELD;
+
+      last_frame_skipped = FALSE;
+
+      if (verbose)
+       printf("frame not skipped\n");
+    }
+  }
+
   /* synchronize X11 graphics at this point; if we would synchronize the
      display immediately after the buffer switching (after the XFlush),
      this could mean that we have to wait for the graphics to complete,
@@ -151,6 +181,7 @@ void BackToFront()
 #endif
       }
     }
+
     redraw_mask &= ~REDRAW_MAIN;
   }
 
@@ -207,6 +238,19 @@ void BackToFront()
                     SX + x * TILEX, SY + y * TILEY);
   }
 
+  if (redraw_mask & REDRAW_FPS)                /* display frames per second */
+  {
+    char text[100];
+    char info1[100];
+
+    sprintf(info1, " (only every %d. frame)", global.fps_slowdown_factor);
+    if (!global.fps_slowdown)
+      info1[0] = '\0';
+
+    sprintf(text, "%.1f fps%s", global.frames_per_second, info1);
+    DrawTextExt(window, gc, SX, SY, text, FS_SMALL, FC_YELLOW);
+  }
+
   FlushDisplay();
 
   for(x=0; x<MAX_BUF_XSIZE; x++)
@@ -330,23 +374,13 @@ int getFontHeight(int font_size, int font_type)
 
 void DrawInitText(char *text, int ypos, int color)
 {
-#ifdef USE_SDL_LIBRARY
   if (window && pix[PIX_SMALLFONT])
-  {
-    ClearRectangle(window, 0, ypos, WIN_XSIZE, FONT2_YSIZE);
-    DrawTextExt(window, gc, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2,
-               ypos, text, FS_SMALL, color);
-    SDL_Flip(window);
-  }
-#else
-  if (display && window && pix[PIX_SMALLFONT])
   {
     ClearRectangle(window, 0, ypos, WIN_XSIZE, FONT2_YSIZE);
     DrawTextExt(window, gc, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2,
                ypos, text, FS_SMALL, color);
     FlushDisplay();
   }
-#endif
 }
 
 void DrawTextFCentered(int y, int font_type, char *format, ...)
@@ -893,7 +927,7 @@ void DrawGraphicThruMaskExt(DrawBuffer d, int dest_x, int dest_y, int graphic)
   else
   {
 #if DEBUG
-#ifndef USE_SDL_LIBRARY
+#ifndef TARGET_SDL
     printf("DrawGraphicThruMask(): tile '%d' needs clipping!\n", tile);
 #endif
 #endif
@@ -1076,7 +1110,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic,
     else
     {
 #if DEBUG
-#ifndef        USE_SDL_LIBRARY
+#ifndef        TARGET_SDL
       printf("DrawGraphicShifted(): tile '%d' needs clipping!\n", tile);
 #endif
 #endif
@@ -1793,7 +1827,7 @@ boolean Request(char *text, unsigned int req_state)
   int mx, my, ty, result = -1;
   unsigned int old_door_state;
 
-#ifndef MSDOS
+#if !defined(MSDOS) && !defined(WIN32)
   /* pause network game while waiting for request to answer */
   if (options.network &&
       game_status == PLAYING &&
@@ -1898,9 +1932,7 @@ boolean Request(char *text, unsigned int req_state)
        {
          if (event.type == EVENT_MOTIONNOTIFY)
          {
-           int win_x, win_y;
-
-           if (!QueryPointer(window, &win_x, &win_y))
+           if (!PointerInWindow(window))
              continue; /* window and pointer are on different screens */
 
            if (!button_status)
@@ -1957,14 +1989,13 @@ boolean Request(char *text, unsigned int req_state)
        }
 
        case EVENT_KEYPRESS:
-         switch(XLookupKeysym((KeyEvent *)&event,
-                              ((KeyEvent *)&event)->state))
+         switch(GetEventKey((KeyEvent *)&event, TRUE))
          {
-           case XK_Return:
+           case KEY_Return:
              result = 1;
              break;
 
-           case XK_Escape:
+           case KEY_Escape:
              result = 0;
              break;
 
@@ -2020,7 +2051,7 @@ boolean Request(char *text, unsigned int req_state)
 
   RemapAllGadgets();
 
-#ifndef MSDOS
+#if !defined(MSDOS) && !defined(WIN32)
   /* continue network game after request */
   if (options.network &&
       game_status == PLAYING &&
@@ -2218,7 +2249,7 @@ void UndrawSpecialEditorDoor()
   redraw_mask |= REDRAW_ALL;
 }
 
-#ifndef        USE_SDL_LIBRARY
+#ifndef        TARGET_SDL
 int ReadPixel(DrawBuffer d, int x, int y)
 {
   XImage *pixel_image;