rnd-19980909
[rocksndiamonds.git] / src / tools.c
index befacb27d300fe6b6cb142b4ef7af1621dad0a8a..499469d696a4972e429ac92e9185ab8161725c36 100644 (file)
 
 #include <math.h>
 
+#ifdef MSDOS
+extern BOOL wait_for_vsync;
+#endif
+
 void SetDrawtoField(int mode)
 {
   if (mode == DRAW_BUFFERED && soft_scrolling_on)
@@ -74,6 +78,17 @@ void BackToFront()
   if (!redraw_mask)
     return;
 
+  /* 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,
+     although we could go on doing calculations for the next frame */
+
+  XSync(display,FALSE);
+
+#ifdef MSDOS
+  wait_for_vsync = TRUE;
+#endif
+
   if (redraw_mask & REDRAW_ALL)
   {
     XCopyArea(display,backbuffer,window,gc,
@@ -101,15 +116,6 @@ void BackToFront()
       XCopyArea(display,buffer,window,gc,
                fx,fy, SXSIZE,SYSIZE,
                SX,SY);
-
-
-
-#if 0
-      printf("FULL SCREEN REDRAW [%d]\n", ScreenMovPos);
-#endif
-
-
-
     }
     redraw_mask &= ~REDRAW_MAIN;
   }
@@ -1465,10 +1471,16 @@ BOOL AreYouSure(char *text, unsigned int ays_state)
              break;
          }
          break;
+       case KeyRelease:
+         key_joystick_mapping = 0;
+         break;
        case FocusIn:
        case FocusOut:
          HandleFocusEvent((XFocusChangeEvent *) &event);
          break;
+        case ClientMessage:
+         HandleClientMessageEvent((XClientMessageEvent *) &event);
+         break;
        default:
          break;
       }
@@ -1517,10 +1529,6 @@ unsigned int OpenDoor(unsigned int door_state)
 
   new_door_state = MoveDoor(door_state);
 
-/*
-  ClearEventQueue();
-*/
-
   return(new_door_state);
 }
 
@@ -1535,10 +1543,6 @@ unsigned int CloseDoor(unsigned int door_state)
 
   new_door_state = MoveDoor(door_state);
 
-/*
-  ClearEventQueue();
-*/
-
   return(new_door_state);
 }
 
@@ -1551,7 +1555,9 @@ unsigned int MoveDoor(unsigned int door_state)
 {
   static unsigned int door1 = DOOR_OPEN_1;
   static unsigned int door2 = DOOR_CLOSE_2;
-  int x, start, stepsize = 4, door_anim_delay = stepsize*5000;
+  static long door_delay = 0;
+  int x, start, stepsize = 2;
+  long door_delay_value = stepsize * 5000;
 
   if (door_state == DOOR_GET_STATE)
     return(door1 | door2);
@@ -1568,7 +1574,7 @@ unsigned int MoveDoor(unsigned int door_state)
   if (quick_doors)
   {
     stepsize = 20;
-    door_anim_delay = 0;
+    door_delay_value = 0;
     StopSound(SND_OEFFNEN);
   }
 
@@ -1579,8 +1585,11 @@ unsigned int MoveDoor(unsigned int door_state)
 
     start = ((door_state & DOOR_NO_DELAY) ? DXSIZE : 0);
 
-    for(x=start;x<=DXSIZE;x+=stepsize)
+    for(x=start; x<=DXSIZE; x+=stepsize)
     {
+      while(!DelayReached(&door_delay, door_delay_value/10000))
+       Delay(1000);
+
       if (door_state & DOOR_ACTION_1)
       {
        int i = (door_state & DOOR_OPEN_1 ? DXSIZE-x : x);
@@ -1656,7 +1665,6 @@ unsigned int MoveDoor(unsigned int door_state)
       }
 
       BackToFront();
-      Delay(door_anim_delay);
 
       if (game_status==MAINMENU)
        DoAnimation();