rnd-19980812
authorHolger Schemel <info@artsoft.org>
Wed, 12 Aug 1998 21:19:20 +0000 (23:19 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:30:20 +0000 (10:30 +0200)
src/cartoons.c
src/events.c
src/game.c
src/init.c
src/main.c
src/main.h
src/tools.c
src/tools.h

index a295844ff733f9febfcf6fab182ea0c0b5e734b0..7cc59d1a05454557a136b2b6629c245993a87473 100644 (file)
@@ -129,14 +129,14 @@ void HandleAnimation(int mode)
       {
        int xx,yy;
 
-       drawto_field = backbuffer;
+       SetDrawtoField(DRAW_BACKBUFFER);
 
        for(xx=0;xx<SCR_FIELDX;xx++)
          for(yy=0;yy<SCR_FIELDY;yy++)
            DrawScreenField(xx,yy);
        DrawPlayerField();
 
-       drawto_field = window;
+       SetDrawtoField(DRAW_DIRECT);
       }
 
       return;
index 69b67685b87b95f7503fdd6a75843f12fc531076..ed43f4ec90d015436452eb51ec7fd486ad17c093 100644 (file)
@@ -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,7 +157,7 @@ void HandleExposeEvent(XExposeEvent *event)
          DrawScreenField(xx,yy);
     DrawPlayerField();
 
-    drawto_field = window;
+    SetDrawtoField(DRAW_DIRECT);
   }
 
   XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
@@ -263,8 +263,8 @@ void HandleButton(int mx, int my, int button)
 }
 
 int Gamespeed = 4;
-int Movemethod = 0;
-int Movespeed[2] = { 10, 3 };
+int Movemethod = 1;
+int Movespeed[2] = { 10, 4 };
 char *Movespeed_text[2] = { "asynchron", "syncron" };
 
 void HandleKey(KeySym key, int key_status)
@@ -361,6 +361,8 @@ void HandleKey(KeySym key, int key_status)
     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;
@@ -377,11 +379,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;
 
@@ -488,7 +490,7 @@ void HandleKey(KeySym key, int key_status)
          printf("gamespeed == %d\n", Gamespeed);
          break;
        case XK_l:
-         Gamespeed = 10;
+         Gamespeed = 50;
          printf("gamespeed == %d\n", Gamespeed);
          break;
 
@@ -496,7 +498,6 @@ void HandleKey(KeySym key, int key_status)
        case XK_q:
          Dynamite = 1000;
          break;
-#endif
 
        case XK_x:
 
@@ -520,11 +521,11 @@ void HandleKey(KeySym key, int key_status)
                  {
                    if (DelayReached(&scroll_delay, scroll_delay_value))
                    {
-                     XCopyArea(display,backbuffer,window,gc,
+                     XCopyArea(display,fieldbuffer,window,gc,
                                SX+xxx,SY,
                                SXSIZE-xxx,SYSIZE,
                                SX,SY);
-                     XCopyArea(display,backbuffer,window,gc,
+                     XCopyArea(display,fieldbuffer,window,gc,
                                SX,SY,
                                xxx,SYSIZE,
                                SX+SXSIZE-xxx,SY);
@@ -553,6 +554,22 @@ void HandleKey(KeySym key, int key_status)
 
          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;
       }
@@ -565,7 +582,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;
@@ -646,10 +663,15 @@ void HandleJoystick()
       }
 
 
-
+#if 0
       if (PlayerMovPos)
+      {
        ScrollFigure(0);
-
+       /*
+       BackToFront();
+       */
+      }
+#endif
 
 
       if (tape.pausing || PlayerGone)
@@ -706,7 +728,11 @@ void HandleJoystick()
        }
       }
 
+
+      /*
       DrawPlayerField();
+      */
+
 
       break;
     }
index 15c379531fc488fc94a14f84cc5b0c02b7d6cc5e..dbc5458281c82836719c2db85724588faebd3b11 100644 (file)
@@ -75,6 +75,7 @@ void InitGame()
   TimeFrames = 0;
   TimeLeft = level.time;
   PlayerMovDir = MV_NO_MOVING;
+  PlayerMovPos = 0;
   PlayerFrame = 0;
   PlayerPushing = FALSE;
   PlayerGone = LevelSolved = GameOver = SiebAktiv = FALSE;
@@ -2386,7 +2387,7 @@ void EdelsteinFunkeln(int x, int y)
       MovDelay[x][y]--;
 
       if (direct_draw_on && MovDelay[x][y])
-       drawto_field = backbuffer;
+       SetDrawtoField(DRAW_BUFFERED);
 
       DrawGraphic(SCROLLX(x),SCROLLY(y), el2gfx(Feld[x][y]));
 
@@ -2397,8 +2398,8 @@ void EdelsteinFunkeln(int x, int y)
 
        src_x  = SX+GFX_PER_LINE*TILEX;
        src_y  = SY+(phase > 2 ? 4-phase : phase)*TILEY;
-       dest_x = SX+SCROLLX(x)*TILEX;
-       dest_y = SY+SCROLLY(y)*TILEY;
+       dest_x = FX+SCROLLX(x)*TILEX;
+       dest_y = FY+SCROLLY(y)*TILEY;
 
        XSetClipOrigin(display,clip_gc[PIX_BACK],dest_x-src_x,dest_y-src_y);
        XCopyArea(display,pix[PIX_BACK],drawto_field,clip_gc[PIX_BACK],
@@ -2406,9 +2407,9 @@ void EdelsteinFunkeln(int x, int y)
 
        if (direct_draw_on)
        {
-         XCopyArea(display,backbuffer,window,gc,
+         XCopyArea(display,drawto_field,window,gc,
                    dest_x,dest_y, TILEX,TILEY, dest_x,dest_y);
-         drawto_field = window;
+         SetDrawtoField(DRAW_DIRECT);
        }
       }
     }
@@ -2564,7 +2565,23 @@ void GameActions()
   action_delay_value =
     (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : Gamespeed);
 
+  /*
   if (DelayReached(&action_delay, action_delay_value))
+  */
+
+
+
+  if (PlayerMovPos)
+    ScrollFigure(0);
+
+  DrawPlayerField();
+
+
+
+
+  if (!DelayReached(&action_delay, action_delay_value))
+    return;
+
   {
     int x,y,element;
     int sieb_x = 0, sieb_y = 0;
@@ -2696,6 +2713,14 @@ void GameActions()
        }
       }
     }
+
+    /*
+    if (PlayerMovPos)
+      ScrollFigure(0);
+
+    DrawPlayerField();
+    */
+
   }
 
   if (TimeLeft>0 && TimeFrames>=25 && !tape.pausing)
@@ -2715,32 +2740,53 @@ void GameActions()
       KillHero();
   }
 
+  /*
+  if (PlayerMovPos)
+    ScrollFigure(0);
+    */
+
+
+  /*
+  DrawPlayerField();
+  */
+
+
   BackToFront();
 }
 
 void ScrollLevel(int dx, int dy)
 {
   int x,y;
+  int softscroll_offset = (FX == TILEX ? TILEX : 0);
+
+  if (soft_scrolling_on)
+  {
+    ScreenMovPos = PlayerMovPos;
+    redraw_mask |= REDRAW_FIELD;
+  }
 
   XCopyArea(display,drawto_field,drawto_field,gc,
-           SX+TILEX*(dx==-1),SY+TILEY*(dy==-1),
-           SXSIZE-TILEX*(dx!=0),SYSIZE-TILEY*(dy!=0),
-           SX+TILEX*(dx==1),SY+TILEY*(dy==1));
+           FX + TILEX*(dx==-1) - softscroll_offset,
+           FY + TILEY*(dy==-1) - softscroll_offset,
+           SXSIZE - TILEX*(dx!=0) + 2*softscroll_offset,
+           SYSIZE - TILEY*(dy!=0) + 2*softscroll_offset,
+           FX + TILEX*(dx==1) - softscroll_offset,
+           FY + TILEY*(dy==1) - softscroll_offset);
 
   if (dx)
   {
-    x = (dx==1 ? 0 : SCR_FIELDX-1);
-    for(y=0;y<SCR_FIELDY;y++)
+    x = (dx==1 ? BX1 : BX2);
+    for(y=BY1; y<=BY2; y++)
       DrawScreenField(x,y);
   }
   if (dy)
   {
-    y = (dy==1 ? 0 : SCR_FIELDY-1);
-    for(x=0;x<SCR_FIELDX;x++)
+    y = (dy==1 ? BY1 : BY2);
+    for(x=BX1; x<=BX2; x++)
       DrawScreenField(x,y);
   }
 
-  redraw_mask|=REDRAW_FIELD;
+  redraw_mask |= REDRAW_FIELD;
 }
 
 BOOL MoveFigureOneStep(int dx, int dy, int real_dx, int real_dy)
@@ -2802,7 +2848,6 @@ BOOL MoveFigureOneStep(int dx, int dy, int real_dx, int real_dy)
   JX2 = oldJX;
   JY2 = oldJY;
 
-  PlayerMovPos = TILEX/4;
   PlayerMovPos = (dx > 0 || dy > 0 ? -1 : 1) * 3*TILEX/4;
 
   ScrollFigure(-1);
@@ -2897,7 +2942,9 @@ BOOL MoveFigure(int dx, int dy)
 
   TestIfHeroHitsBadThing();
 
+  /*
   BackToFront();
+  */
 
   if (PlayerGone)
     RemoveHero();
@@ -2908,10 +2955,29 @@ BOOL MoveFigure(int dx, int dy)
 void ScrollFigure(int init)
 {
   static long actual_frame_counter;
+  static int oldX = -1, oldY = -1;
 
   if (init)
   {
+    if (PlayerMovPos && oldX != -1 && oldY != -1)
+    {
+      DrawLevelElement(oldX,oldY, Feld[oldX][oldY]);
+      DrawPlayerField();
+    }
+
+    oldX = JX2;
+    oldY = JY2;
     actual_frame_counter = FrameCounter;
+
+    redraw[redraw_x1 + oldX][redraw_y1 + oldY] = 1;
+    redraw_tiles++;
+
+    /*
+    DrawLevelElement(oldX,oldY, Feld[oldX][oldY]);
+    */
+
+    DrawPlayerField();
+
     return;
   }
   else if (!FrameReached(&actual_frame_counter,1))
@@ -2919,8 +2985,20 @@ void ScrollFigure(int init)
 
   PlayerMovPos += (PlayerMovPos > 0 ? -1 : 1) * TILEX/4;
 
-  DrawLevelElement(JX2,JY2, Feld[JX2][JY2]);
+  if (ScreenMovPos)
+  {
+    ScreenMovPos = PlayerMovPos;
+    redraw_mask |= REDRAW_FIELD;
+  }
+
+  DrawLevelElement(oldX,oldY, Feld[oldX][oldY]);
   DrawPlayerField();
+
+  if (!PlayerMovPos)
+  {
+    JX2 = JX;
+    JY2 = JY;
+  }
 }
 
 void TestIfGoodThingHitsBadThing(int goodx, int goody)
@@ -3493,7 +3571,6 @@ void RaiseScore(int value)
 {
   Score += value;
   DrawText(DX_SCORE,DY_SCORE,int2str(Score,5),FS_SMALL,FC_YELLOW);
-  BackToFront();
 }
 
 void RaiseScoreElement(int element)
index 0f0bd65234873a2ea12c2877b54c65b68c810924..134cf74aeadfee1f092b95fb9496cb1adc9b2b09 100644 (file)
@@ -362,7 +362,7 @@ void InitGfx()
                                   3*DXSIZE,DYSIZE+VYSIZE,
                                   XDefaultDepth(display,screen));
   pix[PIX_DB_FIELD] = XCreatePixmap(display, window,
-                                   SXSIZE+2*TILEX,SYSIZE+2*TILEY,
+                                   FXSIZE,FYSIZE,
                                    XDefaultDepth(display,screen));
 
   if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
@@ -386,8 +386,9 @@ void InitGfx()
     }
   }
 
-  drawto = drawto_field = backbuffer = pix[PIX_DB_BACK];
+  drawto = backbuffer = pix[PIX_DB_BACK];
   fieldbuffer = pix[PIX_DB_FIELD];
+  SetDrawtoField(DRAW_BACKBUFFER);
 
   XCopyArea(display,pix[PIX_BACK],backbuffer,gc,
            0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
@@ -396,11 +397,11 @@ void InitGfx()
   XFillRectangle(display,pix[PIX_DB_DOOR],gc,
                 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
 
-  for(i=0;i<SCR_FIELDX;i++)
-    for(j=0;j<SCR_FIELDY;j++)
-      redraw[i][j]=0;
-  redraw_tiles=0;
-  redraw_mask=REDRAW_ALL;
+  for(i=0; i<MAX_BUF_XSIZE; i++)
+    for(j=0; j<MAX_BUF_YSIZE; j++)
+      redraw[i][j] = 0;
+  redraw_tiles = 0;
+  redraw_mask = REDRAW_ALL;
 }
 
 void LoadGfx(int pos, struct PictureFileInfo *pic)
index 9918892c00c6b7c814775755132fc82d0ec4a0cf..f8077436a2e6bd71f61af6bd2fc566e482a3e651 100644 (file)
@@ -54,12 +54,14 @@ int         sound_simple_on = FALSE;
 int            toons_on = TRUE;
 int            direct_draw_on = FALSE;
 int            scroll_delay_on = FALSE;
+int            soft_scrolling_on = TRUE;
 int            fading_on = FALSE;
 int            autorecord_on = FALSE;
 int            joystick_nr = 0;
 int            quick_doors = FALSE;
 
-BOOL           redraw[SCR_FIELDX][SCR_FIELDY];
+BOOL           redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
+int            redraw_x1 = 0, redraw_y1 = 0;
 int            redraw_mask;
 int            redraw_tiles;
 
@@ -80,6 +82,8 @@ long          Elementeigenschaften[MAX_ELEMENTS];
 int            level_nr, leveldir_nr, num_leveldirs;
 int            lev_fieldx,lev_fieldy, scroll_x,scroll_y;
 
+int            FX = SX, FY = SY, ScreenMovPos = 0;
+int            BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
 int            JX,JY, JX2,JY2, ZX,ZY, ExitX,ExitY;
 int            PlayerMovDir, PlayerMovPos, PlayerFrame, PlayerPushing;
 int            PlayerGone,LevelSolved,GameOver;
index 6023c372f332b454e04b7d5a3cf58f9aaa39e87b..4bdf70f1f85a64c4134e9d6f3817e80ce0e7b427 100644 (file)
@@ -46,6 +46,8 @@ typedef int BOOL;
 #define WIN_YSIZE      560
 #define SCR_FIELDX     17
 #define SCR_FIELDY     17
+#define MAX_BUF_XSIZE  (SCR_FIELDX + 2)
+#define MAX_BUF_YSIZE  (SCR_FIELDY + 2)
 
 #define MIN_LEV_FIELDX (SCR_FIELDX-2)
 #define MIN_LEV_FIELDY (SCR_FIELDY-2)
@@ -62,7 +64,7 @@ typedef int BOOL;
 #define SCROLLY(a)     ((a)-scroll_y)
 #define UNSCROLLX(a)   ((a)+scroll_x)
 #define UNSCROLLY(a)   ((a)+scroll_y)
-#define IN_SCR_FIELD(x,y) ((x)>=0 && (x)<SCR_FIELDX && (y)>=0 &&(y)<SCR_FIELDY)
+#define IN_SCR_FIELD(x,y) ((x)>=BX1 && (x)<=BX2 && (y)>=BY1 &&(y)<=BY2)
 #define IN_LEV_FIELD(x,y) ((x)>=0 && (x)<lev_fieldx && (y)>=0 &&(y)<lev_fieldy)
 
 /*
@@ -275,12 +277,14 @@ extern int                sound_simple_on;
 extern int             toons_on;
 extern int             direct_draw_on;
 extern int             scroll_delay_on;
+extern int             soft_scrolling_on;
 extern int             fading_on;
 extern int             autorecord_on;
 extern int             joystick_nr;
 extern int             quick_doors;
 
-extern BOOL            redraw[SCR_FIELDX][SCR_FIELDY];
+extern BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
+extern int             redraw_x1, redraw_y1;
 extern int             redraw_mask;
 extern int             redraw_tiles;
 
@@ -301,6 +305,8 @@ extern long         Elementeigenschaften[MAX_ELEMENTS];
 extern int             level_nr, leveldir_nr, num_leveldirs;
 extern int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
 
+extern int             FX,FY, ScreenMovPos;
+extern int             BX1,BY1, BX2,BY2;
 extern int             JX,JY, JX2,JY2, ZX,ZY, ExitX,ExitY;
 extern int             PlayerMovDir, PlayerMovPos, PlayerFrame, PlayerPushing;
 extern int             PlayerGone,LevelSolved,GameOver;
@@ -344,6 +350,8 @@ extern char         *progname;
 #define MIDPOSY                        (SCR_FIELDY/2)
 #define SXSIZE                 (SCR_FIELDX*TILEX)
 #define SYSIZE                 (SCR_FIELDY*TILEY)
+#define FXSIZE                 ((SCR_FIELDX+2)*TILEX)
+#define FYSIZE                 ((SCR_FIELDY+2)*TILEY)
 #define DXSIZE                 100
 #define DYSIZE                 280
 #define VXSIZE                 DXSIZE
@@ -991,7 +999,7 @@ extern char         *progname;
 #define REDRAW_DOOR_2  (REDRAW_VIDEO_1 | REDRAW_VIDEO_2 | REDRAW_VIDEO_3)
 #define REDRAW_DOORS   (REDRAW_DOOR_1 | REDRAW_DOOR_2)
 #define REDRAW_MAIN    (REDRAW_FIELD | REDRAW_TILES | REDRAW_MICROLEV)
-#define REDRAWTILES_TH         SCR_FIELDX*SCR_FIELDY/2
+#define REDRAWTILES_THRESHOLD  SCR_FIELDX*SCR_FIELDY/2
 
 /* positions in the game control window */
 #define XX_LEVEL               37
index 2bbf09019da7a375d0d175bd7bc6e203b7c14e83..e020340b43dc2ac4c404d2826dc431ad20abc36d 100644 (file)
 
 #include <math.h>
 
+void SetDrawtoField(int mode)
+{
+  if (mode == DRAW_BUFFERED && soft_scrolling_on)
+  {
+    FX = TILEX;
+    FY = TILEY;
+    BX1 = -1;
+    BY1 = -1;
+    BX2 = SCR_FIELDX;
+    BY2 = SCR_FIELDY;
+    redraw_x1 = 1;
+    redraw_y1 = 1;
+
+    drawto_field = fieldbuffer;
+  }
+  else /* DRAW_DIRECT, DRAW_BACKBUFFER */
+  {
+    FX = SX;
+    FY = SY;
+    BX1 = 0;
+    BY1 = 0;
+    BX2 = SCR_FIELDX - 1;
+    BY2 = SCR_FIELDY - 1;
+    redraw_x1 = 0;
+    redraw_y1 = 0;
+
+    drawto_field = (mode == DRAW_DIRECT ? window :  backbuffer);
+  }
+}
+
 void BackToFront()
 {
   int x,y;
+  Drawable buffer = (drawto_field != window ? drawto_field : backbuffer);
 
-  if (direct_draw_on && game_status==PLAYING)
+  if (direct_draw_on && game_status == PLAYING)
     redraw_mask &= ~REDRAW_MAIN;
 
+
+
+  /*
+  if (ScreenMovPos && redraw_mask & REDRAW_FIELD)
+  {
+    redraw_mask |= REDRAW_FIELD;
+
+    printf("FULL SCREEN REDRAW FORCED by ScreenMovPos == %d\n", ScreenMovPos);
+  }
+  */
+
+
+
+  /*
+  if (ScreenMovPos && redraw_mask & REDRAW_TILES)
+  {
+    redraw_mask |= REDRAW_FIELD;
+
+    printf("FULL SCREEN REDRAW FORCED by ScreenMovPos == %d\n", ScreenMovPos);
+  }
+  */
+
+
+  /*
+  if (ScreenMovPos && !(redraw_mask & REDRAW_FIELD))
+  {
+    printf("OOPS!\n");
+
+    *((int *)NULL) = 0;
+  }
+  */
+
+  /*
+  if (IN_SCR_FIELD(JX2,JY2))
+    redraw[redraw_x1 + JX2][redraw_y1 + JY2] = 0;
+    */
+
+
+  if (redraw_mask & REDRAW_TILES && redraw_tiles > REDRAWTILES_THRESHOLD)
+    redraw_mask |= REDRAW_FIELD;
+
+  if (redraw_mask & REDRAW_FIELD)
+    redraw_mask &= ~REDRAW_TILES;
+
+  /*
+  {
+    static int lastFrame = 0;
+
+    printf("FrameCounter: %d\n", FrameCounter);
+
+    if (FrameCounter != lastFrame + 1)
+    {
+      printf("SYNC LOST! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
+
+      if (FrameCounter > 100)
+       *((int *)NULL) = 0;
+    }
+
+    lastFrame = FrameCounter;
+  }
+  */
+
   if (!redraw_mask)
     return;
 
-  if (redraw_mask & REDRAW_ALL ||
-      (redraw_mask & REDRAW_FIELD && redraw_mask & REDRAW_DOORS))
+  if (redraw_mask & REDRAW_ALL)
   {
     XCopyArea(display,backbuffer,window,gc,
              0,0, WIN_XSIZE,WIN_YSIZE,
              0,0);
     redraw_mask = 0;
   }
-  else if (redraw_mask & REDRAW_FIELD)
+
+  if (redraw_mask & REDRAW_FIELD)
   {
-    XCopyArea(display,backbuffer,window,gc,
-             REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE,
-             REAL_SX,REAL_SY);
+    int fx = FX + (PlayerMovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0);
+    int fy = FY + (PlayerMovDir & (MV_UP|MV_DOWN)    ? ScreenMovPos : 0);
+
+    if (game_status == PLAYING)
+    {
+      XCopyArea(display,buffer,window,gc,
+               fx,fy, SXSIZE,SYSIZE,
+               SX,SY);
+
+      /*
+      printf("FULL SCREEN REDRAW / ScreenMovPos == %d\n", ScreenMovPos);
+      */
+
+    }
+    else
+      XCopyArea(display,backbuffer,window,gc,
+               REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE,
+               REAL_SX,REAL_SY);
     redraw_mask &= ~REDRAW_MAIN;
   }
-  else if (redraw_mask & REDRAW_DOORS)
+
+  if (redraw_mask & REDRAW_DOORS)
   {
     if (redraw_mask & REDRAW_DOOR_1)
       XCopyArea(display,backbuffer,window,gc,
-               DX,DY, DXSIZE,DYSIZE, DX,DY);
+               DX,DY, DXSIZE,DYSIZE,
+               DX,DY);
     if (redraw_mask & REDRAW_DOOR_2)
     {
       if ((redraw_mask & REDRAW_DOOR_2) == REDRAW_DOOR_2)
        XCopyArea(display,backbuffer,window,gc,
-                 VX,VY, VXSIZE,VYSIZE, VX,VY);
+                 VX,VY, VXSIZE,VYSIZE,
+                 VX,VY);
       else
       {
        if (redraw_mask & REDRAW_VIDEO_1)
@@ -97,23 +208,21 @@ void BackToFront()
 
   if (redraw_mask & REDRAW_TILES)
   {
-    if (redraw_tiles>REDRAWTILES_TH)
-      XCopyArea(display,backbuffer,window,gc,SX,SY,SXSIZE,SYSIZE,SX,SY);
-    else
-      for(x=0;x<SCR_FIELDX;x++)
-       for(y=0;y<SCR_FIELDY;y++)
-         if (redraw[x][y])
-           XCopyArea(display,backbuffer,window,gc,
-                     SX+x*TILEX,SY+y*TILEY,TILEX,TILEY,SX+x*TILEX,SY+y*TILEY);
+    for(x=0; x<SCR_FIELDX; x++)
+      for(y=0; y<SCR_FIELDY; y++)
+       if (redraw[redraw_x1 + x][redraw_y1 + y])
+         XCopyArea(display,buffer,window,gc,
+                   FX+x*TILEX,FX+y*TILEY, TILEX,TILEY,
+                   SX+x*TILEX,SY+y*TILEY);
   }
 
   XFlush(display);
 
-  for(x=0;x<SCR_FIELDX;x++)
-    for(y=0;y<SCR_FIELDY;y++)
-      redraw[x][y]=0;
-  redraw_tiles=0;
-  redraw_mask=0;
+  for(x=0; x<MAX_BUF_XSIZE; x++)
+    for(y=0; y<MAX_BUF_YSIZE; y++)
+      redraw[x][y] = 0;
+  redraw_tiles = 0;
+  redraw_mask = 0;
 }
 
 void FadeToFront()
@@ -187,26 +296,35 @@ void FadeToFront()
 
 void ClearWindow()
 {
-  drawto_field = backbuffer;
-  XFillRectangle(display,drawto_field,gc,
-                REAL_SX,REAL_SY,FULL_SXSIZE,FULL_SYSIZE);
-  redraw_mask|=REDRAW_FIELD;
+  XFillRectangle(display,backbuffer,gc,
+                REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
+
+  if (soft_scrolling_on && game_status==PLAYING)
+  {
+    XFillRectangle(display,fieldbuffer,gc,
+                  0,0, FXSIZE,FYSIZE);
+    SetDrawtoField(DRAW_BUFFERED);
+  }
+  else
+    SetDrawtoField(DRAW_BACKBUFFER);
 
   if (direct_draw_on && game_status==PLAYING)
   {
-    drawto_field = window;
-    XFillRectangle(display,drawto_field,gc,
-                  REAL_SX,REAL_SY,FULL_SXSIZE,FULL_SYSIZE);
+    XFillRectangle(display,window,gc,
+                  REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
+    SetDrawtoField(DRAW_DIRECT);
   }
+
+  redraw_mask |= REDRAW_FIELD;
 }
 
 void DrawText(int x, int y, char *text, int font, int col)
 {
   DrawTextExt(drawto, gc, x, y, text, font, col);
-  if (x<DX)
-    redraw_mask|=REDRAW_FIELD;
-  else if (y<VY)
-    redraw_mask|=REDRAW_DOOR_1;
+  if (x < DX)
+    redraw_mask |= REDRAW_FIELD;
+  else if (y < VY)
+    redraw_mask |= REDRAW_DOOR_1;
 }
 
 void DrawTextExt(Drawable d, GC gc, int x, int y,
@@ -281,7 +399,7 @@ void DrawPlayerField()
     return;
 
   if (direct_draw_on)
-    drawto_field = backbuffer;
+    SetDrawtoField(DRAW_BUFFERED);
 
   /* draw things behind the player (EL_PFORTE* || mole/penguin/pig/dragon) */
 
@@ -320,7 +438,7 @@ void DrawPlayerField()
 
 
   if (draw_thru_mask)
-    DrawGraphicThruMask(sx + sxx, sy + syy, graphic);
+    DrawGraphicThruMask(sx, sy, graphic);
   else
     DrawGraphicShifted(sx,sy,sxx,syy,graphic,CUT_NO_CUTTING);
   /*
@@ -353,9 +471,9 @@ void DrawPlayerField()
     int dest_x = SX+SCROLLX(x)*TILEX;
     int dest_y = SY+SCROLLY(y)*TILEY;
 
-    XCopyArea(display,backbuffer,window,gc,
+    XCopyArea(display,drawto_field,window,gc,
              dest_x,dest_y, TILEX,TILEY, dest_x,dest_y);
-    drawto_field = window;
+    SetDrawtoField(DRAW_DIRECT);
   }
 }
 
@@ -411,13 +529,13 @@ void DrawGraphic(int x, int y, int graphic)
 
   DrawGraphicExt(drawto_field, gc, x, y, graphic);
   redraw_tiles++;
-  redraw[x][y] = TRUE;
+  redraw[redraw_x1 + x][redraw_y1 + y] = TRUE;
   redraw_mask |= REDRAW_TILES;
 }
 
 void DrawGraphicExt(Drawable d, GC gc, int x, int y, int graphic)
 {
-  DrawGraphicExtHiRes(d, gc, SX+x*TILEX, SY+y*TILEY, graphic);
+  DrawGraphicExtHiRes(d, gc, FX+x*TILEX, FY+y*TILEY, graphic);
 }
 
 void DrawGraphicExtHiRes(Drawable d, GC gc, int x, int y, int graphic)
@@ -469,8 +587,8 @@ void DrawGraphicThruMask(int x, int y, int graphic)
     graphic -= GFX_START_ROCKSSCREEN;
     src_x  = SX+(graphic % GFX_PER_LINE)*TILEX;
     src_y  = SY+(graphic / GFX_PER_LINE)*TILEY;
-    dest_x = SX+x*TILEX;
-    dest_y = SY+y*TILEY;
+    dest_x = FX+x*TILEX;
+    dest_y = FY+y*TILEY;
 
     XSetClipOrigin(display,clip_gc[PIX_BACK],dest_x-src_x,dest_y-src_y);
     XCopyArea(display,pix[PIX_BACK],drawto_field,clip_gc[PIX_BACK],
@@ -481,8 +599,8 @@ void DrawGraphicThruMask(int x, int y, int graphic)
     graphic -= GFX_START_ROCKSHEROES;
     src_x  = (graphic % HEROES_PER_LINE)*TILEX;
     src_y  = (graphic / HEROES_PER_LINE)*TILEY;
-    dest_x = SX+x*TILEX;
-    dest_y = SY+y*TILEY;
+    dest_x = FX+x*TILEX;
+    dest_y = FY+y*TILEY;
 
     XSetClipOrigin(display,clip_gc[PIX_HEROES],dest_x-src_x,dest_y-src_y);
     XCopyArea(display,pix[PIX_HEROES],drawto_field,clip_gc[PIX_HEROES],
@@ -495,7 +613,7 @@ void DrawGraphicThruMask(int x, int y, int graphic)
   }
 
   redraw_tiles++;
-  redraw[x][y]=TRUE;
+  redraw[redraw_x1 + x][redraw_y1 + y]=TRUE;
   redraw_mask|=REDRAW_TILES;
 }
 
@@ -545,7 +663,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
   int width = TILEX, height = TILEY;
   int cx = 0, cy = 0;
 
-  if (graphic<0)
+  if (graphic < 0)
   {
     DrawGraphic(x,y,graphic);
     return;
@@ -553,66 +671,66 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
 
   if (dx || dy)                        /* Verschiebung der Grafik? */
   {
-    if (x<0)                   /* Element kommt von links ins Bild */
+    if (x < BX1)               /* Element kommt von links ins Bild */
     {
-      x=0;
-      width=dx;
-      cx=TILEX-dx;
-      dx=0;
+      x = BX1;
+      width = dx;
+      cx = TILEX - dx;
+      dx = 0;
     }
-    else if (x==SCR_FIELDX)    /* Element kommt von rechts ins Bild */
+    else if (x > BX2)          /* Element kommt von rechts ins Bild */
     {
-      x=SCR_FIELDX-1;
-      width=-dx;
-      dx=TILEX+dx;
+      x = BX2;
+      width = -dx;
+      dx = TILEX + dx;
     }
-    else if (x==0 && dx<0)     /* Element verläßt links das Bild */
+    else if (x==BX1 && dx<0)   /* Element verläßt links das Bild */
     {
-      width+=dx;
-      cx=-dx;
-      dx=0;
+      width += dx;
+      cx = -dx;
+      dx = 0;
     }
-    else if (x==SCR_FIELDX-1 && dx>0)  /* El. verläßt rechts das Bild */
-      width-=dx;
+    else if (x==BX2 && dx>0)   /* Element verläßt rechts das Bild */
+      width -= dx;
     else if (dx)               /* allg. Bewegung in x-Richtung */
-      redraw[x+SIGN(dx)][y]=TRUE;
+      redraw[redraw_x1 + x + SIGN(dx)][redraw_y1 + y] = TRUE;
 
-    if (y<0)                   /* Element kommt von oben ins Bild */
+    if (y < BY1)               /* Element kommt von oben ins Bild */
     {
       if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */
        return;
 
-      y=0;
-      height=dy;
-      cy=TILEY-dy;
-      dy=0;
+      y = BY1;
+      height = dy;
+      cy = TILEY - dy;
+      dy = 0;
     }
-    else if (y==SCR_FIELDY)    /* Element kommt von unten ins Bild */
+    else if (y > BY2)          /* Element kommt von unten ins Bild */
     {
-      y=SCR_FIELDY-1;
-      height=-dy;
-      dy=TILEY+dy;
+      y = BY2;
+      height = -dy;
+      dy = TILEY + dy;
     }
-    else if (y==0 && dy<0)     /* Element verläßt oben das Bild */
+    else if (y==BY1 && dy<0)   /* Element verläßt oben das Bild */
     {
-      height+=dy;
-      cy=-dy;
-      dy=0;
+      height += dy;
+      cy = -dy;
+      dy = 0;
     }
-    else if (dy>0 && cut_mode==CUT_ABOVE)
+    else if (dy > 0 && cut_mode==CUT_ABOVE)
     {
-      if (y==SCR_FIELDY-1)     /* Element unterhalb des Bildes */
+      if (y == BY2)            /* Element unterhalb des Bildes */
        return;
 
-      height=dy;
-      cy=TILEY-dy;
-      dy=TILEY;
-      redraw[x][y+1]=TRUE;
+      height = dy;
+      cy = TILEY-dy;
+      dy = TILEY;
+      redraw[redraw_x1 + x][redraw_y1 + y + 1] = TRUE;
     }                          /* Element verläßt unten das Bild */
-    else if (dy>0 && (y==SCR_FIELDY-1 || cut_mode==CUT_BELOW))
-      height-=dy;
+    else if (dy > 0 && (y == BY2 || cut_mode==CUT_BELOW))
+      height -= dy;
     else if (dy)               /* allg. Bewegung in y-Richtung */
-      redraw[x][y+SIGN(dy)]=TRUE;
+      redraw[redraw_x1 + x][redraw_y1 + y + SIGN(dy)] = TRUE;
   }
 
   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
@@ -621,7 +739,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
     XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
              SX+(graphic % GFX_PER_LINE)*TILEX+cx,
              SY+(graphic / GFX_PER_LINE)*TILEY+cy,
-             width,height, SX+x*TILEX+dx,SY+y*TILEY+dy);
+             width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
   }
   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
   {
@@ -629,7 +747,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
     XCopyArea(display,pix[PIX_HEROES],drawto_field,gc,
              (graphic % HEROES_PER_LINE)*TILEX+cx,
              (graphic / HEROES_PER_LINE)*TILEY+cy,
-             width,height, SX+x*TILEX+dx,SY+y*TILEY+dy);
+             width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
   }
 
 #if DEBUG
@@ -642,8 +760,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
 #endif
 
   redraw_tiles++;
-  redraw[x][y]=TRUE;
-  redraw_mask|=REDRAW_TILES;
+  redraw[redraw_x1 + x][redraw_y1 + y] = TRUE;
+  redraw_mask |= REDRAW_TILES;
 }
 
 void DrawElementShifted(int x, int y, int dx, int dy, int element,int cut_mode)
@@ -658,11 +776,11 @@ void DrawElementShifted(int x, int y, int dx, int dy, int element,int cut_mode)
   {
     graphic += 4*!phase;
 
-    if (dir==MV_UP)
+    if (dir == MV_UP)
       graphic += 1;
-    else if (dir==MV_LEFT)
+    else if (dir == MV_LEFT)
       graphic += 2;
-    else if (dir==MV_DOWN)
+    else if (dir == MV_DOWN)
       graphic += 3;
   }
   else if (element==EL_MAULWURF || element==EL_PINGUIN ||
@@ -794,11 +912,11 @@ void ErdreichAnbroeckeln(int x, int y)
       XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
                SX+(graphic % GFX_PER_LINE)*TILEX+cx,
                SY+(graphic / GFX_PER_LINE)*TILEY+cy,
-               width,height, SX+x*TILEX+cx,SY+y*TILEY+cy);
+               width,height, FX+x*TILEX+cx,FY+y*TILEY+cy);
     }
 
     redraw_tiles++;
-    redraw[x][y]=TRUE;
+    redraw[redraw_x1 + x][redraw_y1 + y] = TRUE;
   }
   else
   {
@@ -840,10 +958,10 @@ void ErdreichAnbroeckeln(int x, int y)
       XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
                SX+(graphic % GFX_PER_LINE)*TILEX+cx,
                SY+(graphic / GFX_PER_LINE)*TILEY+cy,
-               width,height, SX+xx*TILEX+cx,SY+yy*TILEY+cy);
+               width,height, FX+xx*TILEX+cx,FY+yy*TILEY+cy);
 
       redraw_tiles++;
-      redraw[xx][yy]=TRUE;
+      redraw[redraw_x1 + xx][redraw_y1 + yy] = TRUE;
     }
   }
 }
@@ -1004,8 +1122,8 @@ void DrawLevel()
 
   ClearWindow();
 
-  for(x=0;x<SCR_FIELDX;x++)
-    for(y=0;y<SCR_FIELDY;y++)
+  for(x=BX1; x<=BX2; x++)
+    for(y=BY1; y<=BY2; y++)
       DrawScreenField(x,y);
 
   redraw_mask |= REDRAW_FIELD;
index 43dcf1e0737bdf8d8bb948e8a57f31be85b8efed..10dcaaefb07a5a3f1f70b2c44608b08e95680b83 100644 (file)
 
 #include <sys/time.h>
 
+/* für SetDrawtoField */
+#define DRAW_DIRECT    0
+#define DRAW_BUFFERED  1
+#define DRAW_BACKBUFFER        2
+
 /* für DrawElementShifted */
 #define CUT_NO_CUTTING 0
 #define CUT_ABOVE      1
@@ -48,6 +53,7 @@
 #define AYS_STAY_CLOSED        16
 #define AYS_STAY_OPEN  32
 
+void SetDrawtoField(int);
 void BackToFront();
 void FadeToFront();
 void ClearWindow();