rnd-19981227-1
[rocksndiamonds.git] / src / tools.c
index e6b8d9a9cb5f81de40340ab318b64ce60935f2f1..9d3b3fc0eb53582a865565f2b2ce189e395dcdc1 100644 (file)
@@ -89,11 +89,13 @@ void BackToFront()
      this could mean that we have to wait for the graphics to complete,
      although we could go on doing calculations for the next frame */
 
-  XSync(display,FALSE);
+  XSync(display, FALSE);
 
+  /*
 #ifdef MSDOS
   wait_for_vsync = TRUE;
 #endif
+  */
 
   if (redraw_mask & REDRAW_ALL)
   {
@@ -115,13 +117,15 @@ void BackToFront()
 
       if (setup.soft_scrolling)
       {
-       fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0);
-       fy += (ScreenMovDir & (MV_UP|MV_DOWN)    ? ScreenGfxPos : 0);
+       fx += (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0);
+       fy += (ScreenMovDir & (MV_UP | MV_DOWN)    ? ScreenGfxPos : 0);
       }
 
-      XCopyArea(display,buffer,window,gc,
-               fx,fy, SXSIZE,SYSIZE,
-               SX,SY);
+      if (setup.soft_scrolling ||
+         ABS(ScreenGfxPos) + ScrollStepSize == TILEX ||
+         ABS(ScreenGfxPos) == ScrollStepSize ||
+         redraw_tiles > REDRAWTILES_THRESHOLD)
+       XCopyArea(display, buffer, window, gc, fx, fy, SXSIZE, SYSIZE, SX, SY);
     }
     redraw_mask &= ~REDRAW_MAIN;
   }
@@ -157,6 +161,10 @@ void BackToFront()
                    VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS);
       }
     }
+    if (redraw_mask & REDRAW_DOOR_3)
+      XCopyArea(display, backbuffer, window, gc,
+               EX, EY, EXSIZE, EYSIZE,
+               EX, EY);
     redraw_mask &= ~REDRAW_DOORS;
   }
 
@@ -618,6 +626,14 @@ void DrawGraphicExt(Drawable d, GC gc, int x, int y, int graphic)
              SY + (graphic / GFX_PER_LINE) * TILEY,
              TILEX, TILEY, x, y);
   }
+  else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE)
+  {
+    graphic -= GFX_START_ROCKSMORE;
+    XCopyArea(display, pix[PIX_MORE], d, gc,
+             (graphic % MORE_PER_LINE) * TILEX,
+             (graphic / MORE_PER_LINE) * TILEY,
+             TILEX, TILEY, x, y);
+  }
   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
   {
     graphic -= GFX_START_ROCKSHEROES;
@@ -669,6 +685,14 @@ void DrawGraphicThruMaskExt(Drawable d, int dest_x, int dest_y, int graphic)
     src_x  = SX + (graphic % GFX_PER_LINE) * TILEX;
     src_y  = SY + (graphic / GFX_PER_LINE) * TILEY;
   }
+  else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE)
+  {
+    src_pixmap = pix[PIX_MORE];
+    drawing_gc = clip_gc[PIX_MORE];
+    graphic -= GFX_START_ROCKSMORE;
+    src_x  = (graphic % MORE_PER_LINE) * TILEX;
+    src_y  = (graphic / MORE_PER_LINE) * TILEY;
+  }
   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
   {
     src_pixmap = pix[PIX_HEROES];
@@ -718,6 +742,14 @@ void DrawMiniGraphicExt(Drawable d, GC gc, int x, int y, int graphic)
              MINI_GFX_STARTY + (graphic / MINI_GFX_PER_LINE) * MINI_TILEY,
              MINI_TILEX, MINI_TILEY, x, y);
   }
+  else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE)
+  {
+    graphic -= GFX_START_ROCKSMORE;
+    XCopyArea(display, pix[PIX_MORE], d, gc,
+             MINI_MORE_STARTX + (graphic % MINI_MORE_PER_LINE) * MINI_TILEX,
+             MINI_MORE_STARTY + (graphic / MINI_MORE_PER_LINE) * MINI_TILEY,
+             MINI_TILEX, MINI_TILEY, x, y);
+  }
   else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT)
   {
     graphic -= GFX_START_ROCKSFONT;
@@ -819,6 +851,14 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic,
     src_x  = SX + (graphic % GFX_PER_LINE) * TILEX + cx;
     src_y  = SY + (graphic / GFX_PER_LINE) * TILEY + cy;
   }
+  else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE)
+  {
+    src_pixmap = pix[PIX_MORE];
+    drawing_gc = clip_gc[PIX_MORE];
+    graphic -= GFX_START_ROCKSMORE;
+    src_x  = (graphic % MORE_PER_LINE) * TILEX + cx;
+    src_y  = (graphic / MORE_PER_LINE) * TILEY + cy;
+  }
   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
   {
     src_pixmap = pix[PIX_HEROES];
@@ -827,6 +867,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic,
     src_x  = (graphic % HEROES_PER_LINE) * TILEX + cx;
     src_y  = (graphic / HEROES_PER_LINE) * TILEY + cy;
   }
+  else /* big font graphics currently not allowed (and not needed) */
+    return;
 
   dest_x = FX + x * TILEX + dx;
   dest_y = FY + y * TILEY + dy;
@@ -929,7 +971,8 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
   }
   else if ((element == EL_FELSBROCKEN || IS_GEM(element)) && !cut_mode)
   {
-    graphic += phase * (element == EL_FELSBROCKEN ? 2 : 1);
+    if (element != EL_SP_INFOTRON)
+      graphic += phase * (element == EL_FELSBROCKEN ? 2 : 1);
   }
   else if ((element == EL_SIEB_LEER || element == EL_SIEB2_LEER ||
            element == EL_SIEB_VOLL || element == EL_SIEB2_VOLL) && SiebAktiv)
@@ -1249,10 +1292,19 @@ void DrawMicroElement(int xpos, int ypos, int element)
 
   graphic = el2gfx(element);
 
-  XCopyArea(display, pix[PIX_BACK], drawto, gc,
-           MICRO_GFX_STARTX + (graphic % MICRO_GFX_PER_LINE) * MICRO_TILEX,
-           MICRO_GFX_STARTY + (graphic / MICRO_GFX_PER_LINE) * MICRO_TILEY,
-           MICRO_TILEX, MICRO_TILEY, xpos, ypos);
+  if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE)
+  {
+    graphic -= GFX_START_ROCKSMORE;
+    XCopyArea(display, pix[PIX_MORE], drawto, gc,
+             MICRO_MORE_STARTX + (graphic % MICRO_MORE_PER_LINE) *MICRO_TILEX,
+             MICRO_MORE_STARTY + (graphic / MICRO_MORE_PER_LINE) *MICRO_TILEY,
+             MICRO_TILEX, MICRO_TILEY, xpos, ypos);
+  }
+  else
+    XCopyArea(display, pix[PIX_BACK], drawto, gc,
+             MICRO_GFX_STARTX + (graphic % MICRO_GFX_PER_LINE) * MICRO_TILEX,
+             MICRO_GFX_STARTY + (graphic / MICRO_GFX_PER_LINE) * MICRO_TILEY,
+             MICRO_TILEX, MICRO_TILEY, xpos, ypos);
 }
 
 void DrawLevel()
@@ -1338,11 +1390,13 @@ boolean Request(char *text, unsigned int req_state)
   int mx, my, ty, result = -1;
   unsigned int old_door_state;
 
+#ifndef MSDOS
   /* pause network game while waiting for request to answer */
   if (options.network &&
       game_status == PLAYING &&
       req_state & REQUEST_WAIT_FOR)
     SendToServer_PausePlaying();
+#endif
 
   old_door_state = GetDoorState();
 
@@ -1544,11 +1598,13 @@ boolean Request(char *text, unsigned int req_state)
     }
   }
 
+#ifndef MSDOS
   /* continue network game after request */
   if (options.network &&
       game_status == PLAYING &&
       req_state & REQUEST_WAIT_FOR)
     SendToServer_ContinuePlaying();
+#endif
 
   return(result);
 }
@@ -1591,11 +1647,11 @@ unsigned int GetDoorState()
 
 unsigned int MoveDoor(unsigned int door_state)
 {
-  static unsigned int door1 = DOOR_OPEN_1;
-  static unsigned int door2 = DOOR_CLOSE_2;
-  static long door_delay = 0;
+  static int door1 = DOOR_OPEN_1;
+  static int door2 = DOOR_CLOSE_2;
+  static unsigned long door_delay = 0;
   int x, start, stepsize = 2;
-  long door_delay_value = stepsize * 5;
+  unsigned long door_delay_value = stepsize * 5;
 
   if (door_state == DOOR_GET_STATE)
     return(door1 | door2);
@@ -1722,10 +1778,15 @@ unsigned int MoveDoor(unsigned int door_state)
 
 int ReadPixel(Drawable d, int x, int y)
 {
-  static XImage *pixelimage;
+  XImage *pixel_image;
+  unsigned long pixel_value;
+
+  pixel_image = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap);
+  pixel_value = XGetPixel(pixel_image, 0, 0);
+
+  XDestroyImage(pixel_image);
 
-  pixelimage = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap);
-  return(XGetPixel(pixelimage, 0, 0));
+  return pixel_value;
 }
 
 int el2gfx(int element)
@@ -1858,6 +1919,8 @@ int el2gfx(int element)
     {
       if (IS_CHAR(element))
        return GFX_CHAR_START + (element - EL_CHAR_START);
+      else if (element >= EL_SP_START && element <= EL_SP_END)
+       return GFX_START_ROCKSMORE + (element - EL_SP_START);
       else
        return -1;
     }