rocksndiamonds-1.2.0
[rocksndiamonds.git] / src / events.c
index ed76f9a655beac4341b36a1cb80bb4cfda26b5fb..2d8eca3e861657b6442169036ac88d5395f08934 100644 (file)
 #include "joystick.h"
 #include "network.h"
 
+/* values for key_status */
+#define KEY_NOT_PRESSED                FALSE
+#define KEY_RELEASED           FALSE
+#define KEY_PRESSED            TRUE
+
 void EventLoop(void)
 {
   while(1)
@@ -253,9 +258,11 @@ void HandleFocusEvent(XFocusChangeEvent *event)
 
 void HandleClientMessageEvent(XClientMessageEvent *event)
 {
+#ifndef MSDOS
   if ((event->window == window) &&
       (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE)))
     CloseAllAndExit(0);
+#endif
 }
 
 void HandleButton(int mx, int my, int button)
@@ -272,23 +279,23 @@ void HandleButton(int mx, int my, int button)
     old_mx = mx;
     old_my = my;
 
-    HandleVideoButtons(mx,my,button);
-    HandleSoundButtons(mx,my,button);
-    HandleGameButtons(mx,my,button);
+    HandleVideoButtons(mx,my, button);
+    HandleSoundButtons(mx,my, button);
+    HandleGameButtons(mx,my, button);
   }
 
   switch(game_status)
   {
     case MAINMENU:
-      HandleMainMenu(mx,my,0,0,button);
+      HandleMainMenu(mx,my, 0,0, button);
       break;
 
     case TYPENAME:
-      HandleTypeName(0,XK_Return);
+      HandleTypeName(0, XK_Return);
       break;
 
     case CHOOSELEVEL:
-      HandleChooseLevel(mx,my,0,0,button);
+      HandleChooseLevel(mx,my, 0,0, button);
       break;
 
     case HALLOFFAME:
@@ -296,7 +303,7 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case LEVELED:
-      LevelEd(mx,my,button);
+      LevelEd(mx,my, button);
       break;
 
     case HELPSCREEN:
@@ -304,11 +311,11 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case SETUP:
-      HandleSetupScreen(mx,my,0,0,button);
+      HandleSetupScreen(mx,my, 0,0, button);
       break;
 
     case SETUPINPUT:
-      HandleSetupInputScreen(mx,my,0,0,button);
+      HandleSetupInputScreen(mx,my, 0,0, button);
       break;
 
     case PLAYING:
@@ -426,9 +433,17 @@ void HandleKey(KeySym key, int key_status)
     return;
   }
 
+
+
+#ifndef DEBUG
+
   if (game_status == PLAYING && (tape.playing || tape.pausing))
     return;
 
+#endif
+
+
+
   switch(game_status)
   {
     case TYPENAME:
@@ -496,7 +511,12 @@ void HandleKey(KeySym key, int key_status)
        case XK_8:
        case XK_9:
          if (key == XK_0)
-           GameFrameDelay = 500;
+         {
+           if (GameFrameDelay == 500)
+             GameFrameDelay = GAME_FRAME_DELAY;
+           else
+             GameFrameDelay = 500;
+         }
          else
            GameFrameDelay = (key - XK_0) * 10;
          printf("Game speed == %d%% (%d ms delay between two frames)\n",
@@ -545,80 +565,6 @@ void HandleKey(KeySym key, int key_status)
 
 #if 0
 
-       case XK_x:
-
-         {
-           int i,j,k, num_steps = 8, step_size = TILEX / num_steps;
-           static long scroll_delay=0;
-           long scroll_delay_value = 4*4 / num_steps;
-
-           printf("Scroll test\n");
-
-           for(i=0;i<3;i++)
-           {
-             for(j=0;j<SCR_FIELDX;j++)
-             {
-               for(k=0;k<num_steps;k++)
-               {
-                 int xxx = j*TILEX+k*step_size;
-                 int done = 0;
-
-                 while(!done)
-                 {
-                   if (DelayReached(&scroll_delay, scroll_delay_value))
-                   {
-                     XCopyArea(display,fieldbuffer,window,gc,
-                               SX+xxx,SY,
-                               SXSIZE-xxx,SYSIZE,
-                               SX,SY);
-                     XCopyArea(display,fieldbuffer,window,gc,
-                               SX,SY,
-                               xxx,SYSIZE,
-                               SX+SXSIZE-xxx,SY);
-  
-                     XFlush(display);
-                     XSync(display,FALSE);
-
-                     done = 1;
-                   }
-                   else
-                   {
-                     Delay(1);
-                   }
-                 }
-  
-                 /*
-                 Delay(160 / num_steps);
-                 */
-                 /*
-                 Delay(120 / num_steps);
-                 */
-               }
-             }
-           }
-         }
-
-         break;
-
-       case XK_y:
-         /*
-         {
-           printf("FX = %d, FY = %d\n", FX,FY);
-
-           XCopyArea(display,fieldbuffer,window,gc,
-                     0,0,
-                     MIN(WIN_XSIZE,FXSIZE),MIN(WIN_YSIZE,FYSIZE),
-                     0,0);
-           XFlush(display);
-           XSync(display,FALSE);
-           Delay(1000);
-         }
-         */
-
-         printf("direct_draw == %d\n", setup.direct_draw);
-
-         break;
-
        case XK_z:
          {
            int i;
@@ -634,20 +580,6 @@ void HandleKey(KeySym key, int key_status)
            printf("\n");
          }
 
-         break;
-
-       case XK_t:
-         {
-           char *color[] = { "yellow", "red", "green", "blue" };
-
-           do
-             TestPlayer = (TestPlayer + 1) % MAX_PLAYERS;
-           while(!stored_player[TestPlayer].active);
-
-           printf("TestPlayer = %d (%s player)\n",
-                  TestPlayer, color[TestPlayer]);
-         }
-
          break;
 #endif
 #endif
@@ -666,36 +598,19 @@ void HandleNoXEvent()
 {
   if (button_status && game_status != PLAYING)
   {
-    HandleButton(-1,-1,button_status);
+    HandleButton(-1,-1, button_status);
     return;
   }
 
+#ifndef MSDOS
   if (options.network)
     HandleNetworking();
+#endif
 
-  switch(game_status)
-  {
-    case MAINMENU:
-    case CHOOSELEVEL:
-    case HALLOFFAME:
-    case HELPSCREEN:
-    case SETUP:
-    case SETUPINPUT:
-      HandleJoystick();
-      break;
-
-    case PLAYING:
-      HandleJoystick();
-
-      /*
-      HandleGameActions(0);
-      */
-
-      break;
+  HandleJoystick();
 
-    default:
-      break;
-  }
+  if (game_status == PLAYING)
+    HandleGameActions();
 }
 
 static int HandleJoystickForAllPlayers()
@@ -707,12 +622,19 @@ static int HandleJoystickForAllPlayers()
   {
     byte joy_action = 0;
 
+    /*
     if (!setup.input[i].use_joystick)
       continue;
+      */
 
     joy_action = Joystick(i);
     result |= joy_action;
 
+
+    if (!setup.input[i].use_joystick)
+      continue;
+
+
     stored_player[i].action = joy_action;
   }
 
@@ -740,9 +662,9 @@ void HandleJoystick()
     case SETUP:
     case SETUPINPUT:
     {
-      static long joystickmove_delay = 0;
+      static unsigned long joystickmove_delay = 0;
 
-      if (joystick && !button && !DelayReached(&joystickmove_delay,150))
+      if (joystick && !button && !DelayReached(&joystickmove_delay, 150))
        newbutton = dx = dy = 0;
 
       if (game_status==MAINMENU)
@@ -777,7 +699,6 @@ void HandleJoystick()
        return;
       }
 
-      HandleGameActions();
       break;
 
     default: