rnd-19980828
[rocksndiamonds.git] / src / events.c
index 63856e59f6480535de10aa9de2440577df04db7c..4fecf14437dd6b978217d74840d7f6fcc37734d0 100644 (file)
@@ -61,7 +61,7 @@ void EventLoop(void)
     else                       /* got no event, but don't be lazy... */
     {
       HandleNoXEvent();
-      Delay(10000);            /* don't use all CPU time when idle */
+      Delay(1000);             /* don't use all CPU time when idle */
     }
 
     XSync(display,FALSE);
@@ -149,7 +149,7 @@ void HandleExposeEvent(XExposeEvent *event)
     int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY;
     int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY;
 
-    drawto_field = backbuffer;
+    SetDrawtoField(DRAW_BACKBUFFER);
 
     for(xx=0;xx<SCR_FIELDX;xx++)
       for(yy=0;yy<SCR_FIELDY;yy++)
@@ -157,9 +157,14 @@ void HandleExposeEvent(XExposeEvent *event)
          DrawScreenField(xx,yy);
     DrawPlayerField();
 
-    drawto_field = window;
+    SetDrawtoField(DRAW_DIRECT);
   }
 
+  if (soft_scrolling_on && game_status==PLAYING)
+    XCopyArea(display,fieldbuffer,backbuffer,gc,
+             FX,FY, SXSIZE,SYSIZE,
+             SX,SY);
+
   XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
 
   XFlush(display);
@@ -202,6 +207,7 @@ void HandleFocusEvent(XFocusChangeEvent *event)
     XAutoRepeatOn(display);
     old_joystick_status = joystick_status;
     joystick_status = JOYSTICK_OFF;
+    key_joystick_mapping = 0;
   }
   else if (event->type == FocusIn)
   {
@@ -262,9 +268,8 @@ void HandleButton(int mx, int my, int button)
   }
 }
 
-int Gamespeed = 4;
-int Movemethod = 0;
-int Movespeed[2] = { 10, 3 };
+int GameSpeed = 2;
+int MoveSpeed = 8;
 
 void HandleKey(KeySym key, int key_status)
 {
@@ -351,9 +356,17 @@ void HandleKey(KeySym key, int key_status)
       joy |= JOY_BUTTON_1 | JOY_DOWN;
       break;
     case XK_Shift_L:           /* Linker Feuerknopf */
+    case XK_Control_L:
+    case XK_Alt_L:
+    case XK_Meta_L:
       joy |= JOY_BUTTON_1;
       break;
     case XK_Shift_R:           /* Rechter Feuerknopf */
+    case XK_Control_R:
+    case XK_Alt_R:
+    case XK_Meta_R:
+    case XK_Mode_switch:
+    case XK_Multi_key:
     case XK_B:                 /* (Bombe legen) */
     case XK_b:
       joy |= JOY_BUTTON_2;
@@ -370,11 +383,11 @@ void HandleKey(KeySym key, int key_status)
       key_joystick_mapping &= ~joy;
 
     HandleJoystick();
-
-    if (game_status != PLAYING)
-      key_joystick_mapping = 0;
   }
 
+  if (game_status != PLAYING)
+    key_joystick_mapping = 0;
+
   if (key_status == KEY_RELEASED)
     return;
 
@@ -455,71 +468,113 @@ void HandleKey(KeySym key, int key_status)
        case XK_7:
        case XK_8:
        case XK_9:
-         Movespeed[Movemethod] = (Movemethod == 0 ? 4 : 0) + (key - XK_0);
-         printf("method == %d, speed == %d\n",
-                Movemethod, Movespeed[Movemethod]);
+         if (key == XK_0)
+           GameSpeed = 50;
+         else
+           GameSpeed = key - XK_0;
+         printf("GameSpeed == %d\n", GameSpeed);
          break;
 
        case XK_a:
-         Movemethod = !Movemethod;
-         printf("method == %d, speed == %d\n",
-                Movemethod, Movespeed[Movemethod]);
+         if (ScrollStepSize == TILEX/8)
+           ScrollStepSize = TILEX/4;
+         else
+           ScrollStepSize = TILEX/8;
+         printf("ScrollStepSize == %d\n", ScrollStepSize);
          break;
 
        case XK_f:
-         Gamespeed = 2;
-         printf("gamespeed == %d\n", Gamespeed);
+         ScrollStepSize = TILEX/8;
+         printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
          break;
        case XK_g:
-         Gamespeed = 3;
-         printf("gamespeed == %d\n", Gamespeed);
+         ScrollStepSize = TILEX/4;
+         printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
          break;
        case XK_h:
-         Gamespeed = 4;
-         printf("gamespeed == %d\n", Gamespeed);
+         ScrollStepSize = TILEX/2;
+         printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
          break;
        case XK_l:
-         Gamespeed = 10;
-         printf("gamespeed == %d\n", Gamespeed);
+         ScrollStepSize = TILEX;
+         printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
          break;
 
        case XK_Q:
        case XK_q:
          Dynamite = 1000;
          break;
-#endif
 
        case XK_x:
-         /*
+
          {
-           int i,j,k, num_steps = 4, step_size = TILEX / num_steps;
+           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<10;i++)
+           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;
-
-                 XCopyArea(display,backbuffer,window,gc,
-                           REAL_SX+xxx,REAL_SY,
-                           FULL_SXSIZE-xxx,FULL_SYSIZE,
-                           REAL_SX,REAL_SY);
-                 XCopyArea(display,backbuffer,window,gc,
-                           REAL_SX,REAL_SY,
-                           xxx,FULL_SYSIZE,
-                           REAL_SX+FULL_SXSIZE-xxx,REAL_SY);
-
-                 XFlush(display);
-                 XSync(display,FALSE);
+                 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(1000);
+                   }
+                 }
+  
+                 /*
+                 Delay(160000 / num_steps);
+                 */
+                 /*
                  Delay(120000 / 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(1000000);
+         }
+
          break;
+#endif
 
        default:
          break;
@@ -533,7 +588,7 @@ void HandleKey(KeySym key, int key_status)
 
 void HandleNoXEvent()
 {
-  if (button_status && game_status!=PLAYING)
+  if (button_status && game_status != PLAYING)
   {
     HandleButton(-1,-1,button_status);
     return;
@@ -666,9 +721,6 @@ void HandleJoystick()
          }
        }
       }
-
-      DrawPlayerField();
-
       break;
     }
     default: