rnd-20001201-1-src
[rocksndiamonds.git] / src / tools.c
index 3bf2c5a5ad9644c6587e4a4b1655528ff763a7e9..61e1bac133ce0f63ba0183b775097a5d5515a4b3 100644 (file)
 
 #include <stdarg.h>
 
-#ifdef __FreeBSD__
+#if defined(PLATFORM_FREEBSD)
 #include <machine/joystick.h>
 #endif
 
+#include "libgame/libgame.h"
+
 #include "tools.h"
 #include "game.h"
 #include "events.h"
-#include "sound.h"
-#include "misc.h"
-#include "buttons.h"
 #include "joystick.h"
 #include "cartoons.h"
 #include "network.h"
 
-#ifdef MSDOS
+#if defined(PLATFORM_MSDOS)
 extern boolean wait_for_vsync;
 #endif
 
@@ -99,6 +98,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 +180,7 @@ void BackToFront()
 #endif
       }
     }
+
     redraw_mask &= ~REDRAW_MAIN;
   }
 
@@ -207,6 +237,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++)
@@ -308,6 +351,8 @@ void ClearWindow()
   redraw_mask |= REDRAW_FIELD;
 }
 
+
+#if 0
 int getFontWidth(int font_size, int font_type)
 {
   return (font_size == FS_BIG ? FONT1_XSIZE :
@@ -445,6 +490,8 @@ void DrawTextExt(DrawBuffer d, GC gc, int x, int y,
     x += font_width;
   }
 }
+#endif
+
 
 void DrawAllPlayers()
 {
@@ -883,7 +930,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
@@ -1066,7 +1113,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
@@ -1783,7 +1830,7 @@ boolean Request(char *text, unsigned int req_state)
   int mx, my, ty, result = -1;
   unsigned int old_door_state;
 
-#ifndef MSDOS
+#if defined(PLATFORM_UNIX)
   /* pause network game while waiting for request to answer */
   if (options.network &&
       game_status == PLAYING &&
@@ -1888,9 +1935,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)
@@ -1949,11 +1994,11 @@ boolean Request(char *text, unsigned int req_state)
        case EVENT_KEYPRESS:
          switch(GetEventKey((KeyEvent *)&event, TRUE))
          {
-           case KEY_Return:
+           case KSYM_Return:
              result = 1;
              break;
 
-           case KEY_Escape:
+           case KSYM_Escape:
              result = 0;
              break;
 
@@ -2009,7 +2054,7 @@ boolean Request(char *text, unsigned int req_state)
 
   RemapAllGadgets();
 
-#ifndef MSDOS
+#if defined(PLATFORM_UNIX)
   /* continue network game after request */
   if (options.network &&
       game_status == PLAYING &&
@@ -2207,7 +2252,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;
@@ -2323,10 +2368,12 @@ static struct
   }
 };
 
+#if 0
 static void DoNotDisplayInfoText(void *ptr)
 {
   return;
 }
+#endif
 
 void CreateToolButtons()
 {
@@ -2374,8 +2421,12 @@ void CreateToolButtons()
                      GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY,
                      GDI_DECORATION_SHIFTING, 1, 1,
                      GDI_EVENT_MASK, event_mask,
-                     GDI_CALLBACK_ACTION, HandleToolButtons,
+
+#if 0
                      GDI_CALLBACK_INFO, DoNotDisplayInfoText,
+#endif
+
+                     GDI_CALLBACK_ACTION, HandleToolButtons,
                      GDI_END);
 
     if (gi == NULL)