rnd-19981017-1
[rocksndiamonds.git] / src / events.c
index 505e7457fa71d4f05cd03200b00994f72ac0e8a1..d4ec480279066e2a8759ed0b82c1fd23d8cf8de3 100644 (file)
@@ -62,6 +62,21 @@ void EventLoop(void)
          break;
       }
     }
+
+    HandleNoXEvent();
+
+    /* 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 0
     else                       /* got no event, but don't be lazy... */
     {
       HandleNoXEvent();
@@ -75,6 +90,9 @@ void EventLoop(void)
        Delay(10);
       }
     }
+#endif
+
+
 
     if (game_status == EXITGAME)
       return;
@@ -118,7 +136,7 @@ void ClearEventQueue()
 
 void SleepWhileUnmapped()
 {
-  BOOL window_unmapped = TRUE;
+  boolean window_unmapped = TRUE;
 
   XAutoRepeatOn(display);
 
@@ -159,7 +177,7 @@ void HandleExposeEvent(XExposeEvent *event)
   int x = event->x, y = event->y;
   int width = event->width, height = event->height;
 
-  if (direct_draw_on && game_status==PLAYING)
+  if (setup.direct_draw_on && game_status==PLAYING)
   {
     int xx,yy;
     int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
@@ -176,7 +194,7 @@ void HandleExposeEvent(XExposeEvent *event)
     SetDrawtoField(DRAW_DIRECT);
   }
 
-  if (soft_scrolling_on && game_status == PLAYING)
+  if (setup.soft_scrolling_on && game_status == PLAYING)
   {
     int fx = FX, fy = FY;
 
@@ -245,7 +263,7 @@ void HandleClientMessageEvent(XClientMessageEvent *event)
 {
   if ((event->window == window) &&
       (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
-    CloseAll();
+    game_status = EXITGAME;
 }
 
 void HandleButton(int mx, int my, int button)
@@ -314,7 +332,13 @@ void HandleButton(int mx, int my, int button)
       HandleSetupScreen(mx,my,0,0,button);
       break;
     case PLAYING:
+
+      /* --> NoXEvent() will follow */
+
+      /*
       HandleGameActions(0);
+      */
+
       break;
     default:
       break;
@@ -648,7 +672,7 @@ void HandleKey(KeySym key, int key_status)
          }
          */
 
-         printf("direct_draw_on == %d\n", direct_draw_on);
+         printf("direct_draw_on == %d\n", setup.direct_draw_on);
 
          break;
 
@@ -702,7 +726,8 @@ void HandleNoXEvent()
     return;
   }
 
-  HandleNetworking();
+  if (options.network)
+    HandleNetworking();
 
   switch(game_status)
   {
@@ -730,11 +755,6 @@ void HandleJoystick()
 {
   int joystick = Joystick();
   int keyboard = key_joystick_mapping;
-
-  /*
-  int joy      = (tape.playing ? TapePlayAction() : (joystick | keyboard));
-  */
-
   int joy      = (joystick | keyboard);
   int left     = joy & JOY_LEFT;
   int right    = joy & JOY_RIGHT;
@@ -788,7 +808,7 @@ void HandleJoystick()
       if (tape.pausing || AllPlayersGone)
        joy = 0;
 
-      HandleGameActions(joy);
+      HandleGameActions((byte)joy);
       break;
 
     default: