rnd-19981016-1
[rocksndiamonds.git] / src / events.c
index d0684ed3d220061fbcb3076b55b6ddd1c97054b2..088650b17f2242a38244c4ccd944c74ebd6f46d3 100644 (file)
 #include "misc.h"
 #include "tape.h"
 #include "joystick.h"
+#include "network.h"
 
 void EventLoop(void)
 {
   while(1)
   {
-    if (XPending(display))     /* got an event */
+    if (XPending(display))     /* got event from X server */
     {
       XEvent event;
 
@@ -61,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();
@@ -74,6 +90,9 @@ void EventLoop(void)
        Delay(10);
       }
     }
+#endif
+
+
 
     if (game_status == EXITGAME)
       return;
@@ -244,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)
@@ -313,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;
@@ -701,6 +726,9 @@ void HandleNoXEvent()
     return;
   }
 
+  if (network)
+    HandleNetworking();
+
   switch(game_status)
   {
     case MAINMENU:
@@ -727,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;
@@ -785,7 +808,7 @@ void HandleJoystick()
       if (tape.pausing || AllPlayersGone)
        joy = 0;
 
-      HandleGameActions(joy);
+      HandleGameActions((byte)joy);
       break;
 
     default: