rnd-19980918
[rocksndiamonds.git] / src / events.c
index edce9a9c4ac35ae3a8026938199847e2e3f24c10..02a13795d1573693e8dd55b6a7c89f1ad2267215 100644 (file)
@@ -65,12 +65,18 @@ void EventLoop(void)
     else                       /* got no event, but don't be lazy... */
     {
       HandleNoXEvent();
-      Delay(1000);             /* don't use all CPU time when idle */
-    }
 
-    XSync(display,FALSE);
+      /* don't use all CPU time when idle; the main loop while playing
+        has its own synchronization and is CPU friendly, too */
+
+      if (game_status != PLAYING)
+      {
+       XSync(display, FALSE);
+       Delay(10);
+      }
+    }
 
-    if (game_status==EXITGAME)
+    if (game_status == EXITGAME)
       return;
   }
 }
@@ -170,10 +176,17 @@ void HandleExposeEvent(XExposeEvent *event)
     SetDrawtoField(DRAW_DIRECT);
   }
 
-  if (soft_scrolling_on && game_status==PLAYING)
+  if (soft_scrolling_on && game_status == PLAYING)
+  {
+    int fx = FX, fy = FY;
+
+    fx += (PlayerMovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0);
+    fy += (PlayerMovDir & (MV_UP|MV_DOWN)    ? ScreenMovPos : 0);
+
     XCopyArea(display,fieldbuffer,backbuffer,gc,
-             FX,FY, SXSIZE,SYSIZE,
+             fx,fy, SXSIZE,SYSIZE,
              SX,SY);
+  }
 
   XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
 
@@ -285,9 +298,6 @@ void HandleButton(int mx, int my, int button)
   }
 }
 
-int GameSpeed = 2;
-int MoveSpeed = 8;
-
 void HandleKey(KeySym key, int key_status)
 {
   int joy = 0;
@@ -506,9 +516,9 @@ void HandleKey(KeySym key, int key_status)
        case XK_8:
        case XK_9:
          if (key == XK_0)
-           GameSpeed = 50;
+           GameSpeed = 500;
          else
-           GameSpeed = key - XK_0;
+           GameSpeed = (key - XK_0) * 10;
          printf("GameSpeed == %d\n", GameSpeed);
          break;
 
@@ -582,15 +592,15 @@ void HandleKey(KeySym key, int key_status)
                    }
                    else
                    {
-                     Delay(1000);
+                     Delay(1);
                    }
                  }
   
                  /*
-                 Delay(160000 / num_steps);
+                 Delay(160 / num_steps);
                  */
                  /*
-                 Delay(120000 / num_steps);
+                 Delay(120 / num_steps);
                  */
                }
              }
@@ -609,30 +619,7 @@ void HandleKey(KeySym key, int key_status)
                      0,0);
            XFlush(display);
            XSync(display,FALSE);
-           Delay(1000000);
-         }
-
-         break;
-
-       case XK_z:
-         {
-           static int test_picture_pos = 0;
-
-           printf("test picture %d\n", test_picture_pos);
-
-           XCopyArea(display,test_pix[test_picture_pos],window,gc,
-                     0,0, 100,100,
-                     0,0);
-           /*
-           XCopyArea(display,test_clipmask[test_picture_pos],window,gc,
-                     0,0, 100,100,
-                     100,0);
-                     */
-           XFlush(display);
-           XSync(display,FALSE);
-           Delay(1000000);
-
-           test_picture_pos = (test_picture_pos + 1) % test_picture_count;
+           Delay(1000);
          }
 
          break;
@@ -720,6 +707,7 @@ void HandleJoystick()
       break;
     case PLAYING:
     {
+      static int player_frame_reset_delay = 0;
       BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
 
       if (GameOver && newbutton)
@@ -735,6 +723,8 @@ void HandleJoystick()
 
       if (joy)
       {
+       player_frame_reset_delay = 0;
+
        if (button1)
          snapped = SnapField(dx,dy);
        else
@@ -757,7 +747,8 @@ void HandleJoystick()
       {
        DigField(0,0,0,0,DF_NO_PUSH);
        SnapField(0,0);
-       PlayerFrame = 0;
+       if (++player_frame_reset_delay > MoveSpeed)
+         PlayerFrame = 0;
       }
 
       if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)