rnd-19980915
authorHolger Schemel <info@artsoft.org>
Tue, 15 Sep 1998 01:00:03 +0000 (03:00 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:30:36 +0000 (10:30 +0200)
12 files changed:
src/cartoons.c
src/events.c
src/game.c
src/gif.c
src/gifload.c
src/init.c
src/main.c
src/main.h
src/misc.c
src/screens.c
src/tools.c
src/tools.h

index 2edb0e4e942932d859ffc02e106e8146f4ad37ca..1d5373142b4a6fa18a90b2402383f5884f2570a3 100644 (file)
@@ -125,7 +125,7 @@ void HandleAnimation(int mode)
       reset_delay = TRUE;
 
       /* Fill empty backbuffer for animation functions */
-      if (direct_draw_on && game_status==PLAYING)
+      if (direct_draw_on && game_status == PLAYING)
       {
        int xx,yy;
 
@@ -139,7 +139,7 @@ void HandleAnimation(int mode)
        SetDrawtoField(DRAW_DIRECT);
       }
 
-      if (soft_scrolling_on && game_status==PLAYING)
+      if (soft_scrolling_on && game_status == PLAYING)
       {
        int fx = FX, fy = FY;
 
index af4a4c5690f17aa8878fda42b2f556e10348567e..c669e5e7b5d24f189f297768a4c1c116515b31d8 100644 (file)
@@ -70,10 +70,13 @@ void EventLoop(void)
         has its own synchronization and is CPU friendly, too */
 
       if (game_status != PLAYING)
-       Delay(1000);
+      {
+       XSync(display, FALSE);
+       Delay(10000);
+      }
     }
 
-    if (game_status==EXITGAME)
+    if (game_status == EXITGAME)
       return;
   }
 }
@@ -173,10 +176,17 @@ void HandleExposeEvent(XExposeEvent *event)
     SetDrawtoField(DRAW_DIRECT);
   }
 
-  if (soft_scrolling_on && game_status==PLAYING)
+  if (soft_scrolling_on && game_status == PLAYING)
+  {
+    int fx = FX, fy = FY;
+
+    fx += (PlayerMovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0);
+    fy += (PlayerMovDir & (MV_UP|MV_DOWN)    ? ScreenMovPos : 0);
+
     XCopyArea(display,fieldbuffer,backbuffer,gc,
-             FX,FY, SXSIZE,SYSIZE,
+             fx,fy, SXSIZE,SYSIZE,
              SX,SY);
+  }
 
   XCopyArea(display,drawto,window,gc, x,y, width,height, x,y);
 
@@ -288,9 +298,6 @@ void HandleButton(int mx, int my, int button)
   }
 }
 
-int GameSpeed = 2;
-int MoveSpeed = 8;
-
 void HandleKey(KeySym key, int key_status)
 {
   int joy = 0;
@@ -700,6 +707,7 @@ void HandleJoystick()
       break;
     case PLAYING:
     {
+      static int player_frame_reset_delay = 0;
       BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
 
       if (GameOver && newbutton)
@@ -715,6 +723,8 @@ void HandleJoystick()
 
       if (joy)
       {
+       player_frame_reset_delay = 0;
+
        if (button1)
          snapped = SnapField(dx,dy);
        else
@@ -737,7 +747,8 @@ void HandleJoystick()
       {
        DigField(0,0,0,0,DF_NO_PUSH);
        SnapField(0,0);
-       PlayerFrame = 0;
+       if (++player_frame_reset_delay > MoveSpeed)
+         PlayerFrame = 0;
       }
 
       if (tape.playing && !tape.pausing && !joy && tape.counter<tape.length)
index 1df5a24e7bcedc7316cc72dc0e4aca6abf037eac..f551a1fac7f0e3c1a9cd112ad31539a786304bba 100644 (file)
 #include "tape.h"
 #include "joystick.h"
 
-
-
-int tst = 0;
-int tst2 = 0;
-
-
-
-extern int GameSpeed;
-extern int MoveSpeed;
-
 void GetPlayerConfig()
 {
   int old_joystick_nr = joystick_nr;
@@ -2346,9 +2336,9 @@ void NussKnacken(int x, int y)
 
 void SiebAktivieren(int x, int y, int typ)
 {
-  if (SiebAktiv%2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
+  if (!(SiebAktiv % 4) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
     DrawGraphic(SCROLLX(x),SCROLLY(y),
-               (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%8)/2);
+               (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%16)/4);
 }
 
 void AusgangstuerPruefen(int x, int y)
@@ -2576,246 +2566,153 @@ void GameActions()
 {
   static long action_delay = 0;
   long action_delay_value;
+  int sieb_x = 0, sieb_y = 0;
+  int x, y, element;
 
   if (game_status != PLAYING)
     return;
 
-/*
-  action_delay_value =
-    (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY);
-*/
-
+#ifdef DEBUG
   action_delay_value =
     (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameSpeed);
-
-  /*
-  if (DelayReached(&action_delay, action_delay_value))
-  */
-
-
+#else
+  action_delay_value =
+    (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY);
+#endif
 
   if (PlayerMovPos)
     ScrollFigure(0);
 
-  DrawPlayerField();
-
-
-
-
-  tst++;
-
-  if (0)
-  {
-    static long last_Counter = 0;
-    long new_Counter = Counter();
-
-    printf("--> %ld / %ld [%d]\n",
-          new_Counter - last_Counter,
-          new_Counter,
-          FrameCounter);
-    last_Counter = new_Counter;
-  }
-
-
-
-
-  /*
-  if (!DelayReached(&action_delay, action_delay_value))
-    return;
-    */
-
-
   while(!DelayReached(&action_delay, action_delay_value))
-    Delay(1000);
-
-
-
-
-  /*
-  printf("-----------\n");
-  */
-
+    Delay(5000);
 
+  if (tape.pausing || (tape.playing && !TapePlayDelay()))
+    return;
+  else if (tape.recording)
+    TapeRecordDelay();
 
   FrameCounter++;
+  TimeFrames++;
 
-
-
-  /*
-  if (PlayerMovPos)
-    ScrollFigure(0);
-
-  DrawPlayerField();
-  */
-
-
-  tst2 = tst;
-  tst = 0;
-
-
-
-  if (0)
-  {
-    static long last_Counter = 0;
-    long new_Counter = Counter();
-
-    printf("--> %ld / %ld [%d]\n",
-          new_Counter - last_Counter,
-          new_Counter,
-          FrameCounter);
-    last_Counter = new_Counter;
-  }
-
-
-  /*
-  printf("--> %ld / ", Counter());
-  */
-
-
+  for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
   {
-    int x,y,element;
-    int sieb_x = 0, sieb_y = 0;
-
-    if (tape.pausing || (tape.playing && !TapePlayDelay()))
-      return;
-    else if (tape.recording)
-      TapeRecordDelay();
-
-
-    /*
-    FrameCounter++;
-    */
-
+    Stop[x][y] = FALSE;
+    if (JustHit[x][y]>0)
+      JustHit[x][y]--;
 
-    TimeFrames++;
-
-    for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
+#if DEBUG
+    if (IS_BLOCKED(x,y))
     {
-      Stop[x][y] = FALSE;
-      if (JustHit[x][y]>0)
-       JustHit[x][y]--;
+      int oldx,oldy;
 
-#if DEBUG
-      if (IS_BLOCKED(x,y))
+      Blocked2Moving(x,y,&oldx,&oldy);
+      if (!IS_MOVING(oldx,oldy))
       {
-       int oldx,oldy;
-
-       Blocked2Moving(x,y,&oldx,&oldy);
-       if (!IS_MOVING(oldx,oldy))
-       {
-         printf("GameActions(): (BLOCKED=>MOVING) context corrupted!\n");
-         printf("GameActions(): BLOCKED: x = %d, y = %d\n",x,y);
-         printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n",oldx,oldy);
-         printf("GameActions(): This should never happen!\n");
-       }
+       printf("GameActions(): (BLOCKED=>MOVING) context corrupted!\n");
+       printf("GameActions(): BLOCKED: x = %d, y = %d\n",x,y);
+       printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n",oldx,oldy);
+       printf("GameActions(): This should never happen!\n");
       }
+    }
 #endif
+  }
 
-    }
+  for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
+  {
+    element = Feld[x][y];
 
-    for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
-    {
-      element = Feld[x][y];
+    if (IS_INACTIVE(element))
+      continue;
 
-      if (IS_INACTIVE(element))
-       continue;
+    if (!IS_MOVING(x,y) && (CAN_FALL(element) || CAN_MOVE(element)))
+    {
+      StartMoving(x,y);
+
+      if (IS_GEM(element))
+       EdelsteinFunkeln(x,y);
+    }
+    else if (IS_MOVING(x,y))
+      ContinueMoving(x,y);
+    else if (element==EL_DYNAMIT || element==EL_DYNABOMB)
+      CheckDynamite(x,y);
+    else if (element==EL_EXPLODING)
+      Explode(x,y,Frame[x][y],EX_NORMAL);
+    else if (element==EL_AMOEBING)
+      AmoebeWaechst(x,y);
+    else if (IS_AMOEBALIVE(element))
+      AmoebeAbleger(x,y);
+    else if (element==EL_LIFE || element==EL_LIFE_ASYNC)
+      Life(x,y);
+    else if (element==EL_ABLENK_EIN)
+      Ablenk(x,y);
+    else if (element==EL_SALZSAEURE)
+      Blubber(x,y);
+    else if (element==EL_BLURB_LEFT || element==EL_BLURB_RIGHT)
+      Blurb(x,y);
+    else if (element==EL_CRACKINGNUT)
+      NussKnacken(x,y);
+    else if (element==EL_AUSGANG_ZU)
+      AusgangstuerPruefen(x,y);
+    else if (element==EL_AUSGANG_ACT)
+      AusgangstuerOeffnen(x,y);
+    else if (element==EL_AUSGANG_AUF)
+      AusgangstuerBlinken(x,y);
+    else if (element==EL_MAUERND)
+      MauerWaechst(x,y);
+    else if (element==EL_MAUER_LEBT)
+      MauerAbleger(x,y);
+    else if (element==EL_BURNING)
+      CheckForDragon(x,y);
 
-      if (!IS_MOVING(x,y) && (CAN_FALL(element) || CAN_MOVE(element)))
-      {
-       StartMoving(x,y);
+    if (SiebAktiv)
+    {
+      BOOL sieb = FALSE;
 
-       if (IS_GEM(element))
-         EdelsteinFunkeln(x,y);
+      if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL ||
+         Store[x][y]==EL_SIEB_LEER)
+      {
+       SiebAktivieren(x, y, 1);
+       sieb = TRUE;
       }
-      else if (IS_MOVING(x,y))
-       ContinueMoving(x,y);
-      else if (element==EL_DYNAMIT || element==EL_DYNABOMB)
-       CheckDynamite(x,y);
-      else if (element==EL_EXPLODING)
-       Explode(x,y,Frame[x][y],EX_NORMAL);
-      else if (element==EL_AMOEBING)
-       AmoebeWaechst(x,y);
-      else if (IS_AMOEBALIVE(element))
-       AmoebeAbleger(x,y);
-      else if (element==EL_LIFE || element==EL_LIFE_ASYNC)
-       Life(x,y);
-      else if (element==EL_ABLENK_EIN)
-       Ablenk(x,y);
-      else if (element==EL_SALZSAEURE)
-       Blubber(x,y);
-      else if (element==EL_BLURB_LEFT || element==EL_BLURB_RIGHT)
-       Blurb(x,y);
-      else if (element==EL_CRACKINGNUT)
-       NussKnacken(x,y);
-      else if (element==EL_AUSGANG_ZU)
-       AusgangstuerPruefen(x,y);
-      else if (element==EL_AUSGANG_ACT)
-       AusgangstuerOeffnen(x,y);
-      else if (element==EL_AUSGANG_AUF)
-       AusgangstuerBlinken(x,y);
-      else if (element==EL_MAUERND)
-       MauerWaechst(x,y);
-      else if (element==EL_MAUER_LEBT)
-       MauerAbleger(x,y);
-      else if (element==EL_BURNING)
-       CheckForDragon(x,y);
-
-      if (SiebAktiv)
+      else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL ||
+              Store[x][y]==EL_SIEB2_LEER)
       {
-       BOOL sieb = FALSE;
-
-       if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL ||
-           Store[x][y]==EL_SIEB_LEER)
-       {
-         SiebAktivieren(x, y, 1);
-         sieb = TRUE;
-       }
-       else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL ||
-                Store[x][y]==EL_SIEB2_LEER)
-       {
-         SiebAktivieren(x, y, 2);
-         sieb = TRUE;
-       }
+       SiebAktivieren(x, y, 2);
+       sieb = TRUE;
+      }
 
-       if (sieb && ABS(x-JX)+ABS(y-JY) < ABS(sieb_x-JX)+ABS(sieb_y-JY))
-       {
-         sieb_x = x;
-         sieb_y = y;
-       }
+      if (sieb && ABS(x-JX)+ABS(y-JY) < ABS(sieb_x-JX)+ABS(sieb_y-JY))
+      {
+       sieb_x = x;
+       sieb_y = y;
       }
     }
+  }
 
-    if (SiebAktiv)
+  if (SiebAktiv)
+  {
+    if (!(SiebAktiv%4))
+      PlaySoundLevel(sieb_x,sieb_y,SND_MIEP);
+    SiebAktiv--;
+    if (!SiebAktiv)
     {
-      if (!(SiebAktiv%4))
-       PlaySoundLevel(sieb_x,sieb_y,SND_MIEP);
-      SiebAktiv--;
-      if (!SiebAktiv)
+      for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
       {
-       for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
+       element = Feld[x][y];
+       if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL)
        {
-         element = Feld[x][y];
-         if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL)
-         {
-           Feld[x][y] = EL_SIEB_TOT;
-           DrawLevelField(x,y);
-         }
-         else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL)
-         {
-           Feld[x][y] = EL_SIEB2_TOT;
-           DrawLevelField(x,y);
-         }
+         Feld[x][y] = EL_SIEB_TOT;
+         DrawLevelField(x,y);
+       }
+       else if (element==EL_SIEB2_LEER || element==EL_SIEB2_VOLL)
+       {
+         Feld[x][y] = EL_SIEB2_TOT;
+         DrawLevelField(x,y);
        }
       }
     }
   }
 
-
-  /*
-  printf("%ld\n", Counter());
-  */
-
-
   if (TimeLeft>0 && TimeFrames>=(100/GameSpeed) && !tape.pausing)
   {
     TimeFrames = 0;
@@ -2834,8 +2731,6 @@ void GameActions()
   }
 
   DrawPlayerField();
-
-  BackToFront();
 }
 
 void ScrollLevel(int dx, int dy)
@@ -2991,79 +2886,18 @@ BOOL MoveFigure(int dx, int dy)
 void ScrollFigure(int init)
 {
   static long actual_frame_counter = 0;
-  static int oldJX = -1, oldJY = -1;
 
   if (init)
   {
-
-
-
     PlayerGfxPos = ScrollStepSize * (PlayerMovPos / ScrollStepSize);
-
-
-
-    /*
-    ScreenMovPos = PlayerGfxPos;
-    redraw_mask |= REDRAW_FIELD;
-    */
-
-
-
-    if (0)
-    {
-      static long last_Counter = 0;
-      long new_Counter = Counter();
-
-      printf("--> %ld / %ld [%d, %d]\n",
-            new_Counter - last_Counter,
-            new_Counter,
-            FrameCounter,
-            tst2);
-      last_Counter = new_Counter;
-    }
-
-
-
-
-    if (oldJX != -1 && oldJY != -1)
-      DrawLevelElement(oldJX,oldJY, Feld[oldJX][oldJY]);
+    actual_frame_counter = FrameCounter;
 
     if (Feld[lastJX][lastJY] == EL_LEERRAUM &&
        IN_LEV_FIELD(lastJX,lastJY-1) &&
        CAN_FALL(Feld[lastJX][lastJY-1]))
       Feld[lastJX][lastJY] = EL_PLAYER_IS_LEAVING;
-    DrawLevelElement(lastJX,lastJY, Feld[lastJX][lastJY]);
-    DrawPlayerField();
-
-    oldJX = lastJX;
-    oldJY = lastJY;
-    actual_frame_counter = FrameCounter;
-
-    if (PlayerPushing)
-    {
-      int nextJX = JX + (JX - lastJX);
-      int nextJY = JY + (JY - lastJY);
-
-      if (Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL)
-       DrawLevelElement(nextJX,nextJY, EL_SOKOBAN_FELD_LEER);
-      else
-       DrawLevelElement(nextJX,nextJY, EL_LEERRAUM);
-    }
 
     DrawPlayerField();
-
-    if (Store[lastJX][lastJY])
-    {
-      DrawGraphic(SCROLLX(lastJX),SCROLLY(lastJY),
-                 el2gfx(Store[lastJX][lastJY]));
-      DrawGraphicThruMask(SCROLLX(lastJX),SCROLLY(lastJY),
-                         el2gfx(Feld[lastJX][lastJY]));
-    }
-    else if (Feld[lastJX][lastJY]==EL_DYNAMIT)
-      DrawDynamite(lastJX,lastJY);
-    else
-      DrawLevelField(lastJX,lastJY);
-
     return;
   }
   else if (!FrameReached(&actual_frame_counter,1))
@@ -3072,59 +2906,21 @@ void ScrollFigure(int init)
   PlayerMovPos += (PlayerMovPos > 0 ? -1 : 1) * TILEX/8;
   PlayerGfxPos = ScrollStepSize * (PlayerMovPos / ScrollStepSize);
 
-
-  /*
-  printf("PlayerGfxPos = %d\n", PlayerGfxPos);
-  */
-
-
   if (ScreenMovPos && ScreenMovPos != PlayerGfxPos)
   {
     ScreenMovPos = PlayerGfxPos;
     redraw_mask |= REDRAW_FIELD;
   }
 
-  if (Feld[oldJX][oldJY] == EL_PLAYER_IS_LEAVING)
-    Feld[oldJX][oldJY] = EL_LEERRAUM;
+  if (Feld[lastJX][lastJY] == EL_PLAYER_IS_LEAVING)
+    Feld[lastJX][lastJY] = EL_LEERRAUM;
 
-  DrawLevelElement(oldJX,oldJY, Feld[oldJX][oldJY]);
   DrawPlayerField();
 
-
-
-  if (Store[oldJX][oldJY])
-  {
-    DrawGraphic(SCROLLX(oldJX),SCROLLY(oldJY),el2gfx(Store[oldJX][oldJY]));
-    DrawGraphicThruMask(SCROLLX(oldJX),SCROLLY(oldJY),
-                       el2gfx(Feld[oldJX][oldJY]));
-  }
-  else if (Feld[oldJX][oldJY]==EL_DYNAMIT)
-    DrawDynamite(oldJX,oldJY);
-  else
-    DrawLevelField(oldJX,oldJY);
-
-  if (PlayerPushing)
-  {
-    int nextJX = JX + (JX - lastJX);
-    int nextJY = JY + (JY - lastJY);
-
-    if (PlayerGfxPos)
-    {
-      if (Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL)
-       DrawLevelElement(nextJX,nextJY, EL_SOKOBAN_FELD_LEER);
-      else
-       DrawLevelElement(nextJX,nextJY, EL_LEERRAUM);
-    }
-    else
-      DrawLevelElement(nextJX,nextJY, Feld[nextJX][nextJY]);
-  }
-
   if (!PlayerMovPos)
   {
     lastJX = JX;
     lastJY = JY;
-
-    oldJX = oldJY = -1;
   }
 }
 
index bbeb6aba3baf73f0ea10d8eb2f319c057e50d900..d2fdda81448b909c603b90f7640873e697442247 100644 (file)
--- a/src/gif.c
+++ b/src/gif.c
@@ -492,12 +492,18 @@ Image *gifLoad(char *fullname)
     return(NULL);
   }
 
+
+
+  /*
   printf("%s:\n   %dx%d %s%s image with %d colors at depth %d\n",
         fullname, gifin_img_width, gifin_img_height,
         (gifin_interlace_flag ? "interlaced " : ""),
         gif_version_name[gifin_version],
         (gifin_l_cmap_flag ? gifin_l_ncolors : gifin_g_ncolors),
         (gifin_l_cmap_flag ? gifin_l_pixel_bits : gifin_g_pixel_bits));
+        */
+
+
 
   image = newRGBImage(gifin_img_width, gifin_img_height, (gifin_l_cmap_flag ?
                                                          gifin_l_pixel_bits :
index fc2fc28af8602ee4cb20a2efede6ba6223576cfb..215d32a0cc988f69ea8f1da10de8c0bf4b57aa7a 100644 (file)
@@ -18,7 +18,9 @@
 #include "xli.h"
 
 #ifdef DEBUG
+/*
 #define DEBUG_TIMING
+*/
 #endif
 
 
index 0262c37ea1e887ca48655f17e33f03f0b66f4797..61055359839d2aa0bcb82835e30d98995ac60c07 100644 (file)
@@ -25,7 +25,9 @@
 #include <signal.h>
 
 #ifdef DEBUG
+/*
 #define DEBUG_TIMING
+*/
 #endif
 
 struct PictureFileInfo
index 9028fb6bfd6ce40980ed4c0034aa3e872c95492a..302b5418e8d7e87878eb8c1948dd8e9de23d5742 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "main.h"
 #include "init.h"
+#include "game.h"
 #include "events.h"
 #include "sound.h"
 #include "joystick.h"
@@ -88,6 +89,7 @@ int           level_nr, leveldir_nr, num_leveldirs;
 int            lev_fieldx,lev_fieldy, scroll_x,scroll_y;
 
 int            FX = SX, FY = SY, ScreenMovPos = 0, ScrollStepSize = TILEX/8;
+int            GameSpeed = GAME_FRAME_DELAY, MoveSpeed = 8;
 int            BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
 int            JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
 int            PlayerMovDir, PlayerMovPos, PlayerPushing;
index be08fcdbb205d9baa2a1fe9a7ff8ea28c082efde..37131fef9f8460bec5828fee51731761b706732f 100644 (file)
@@ -328,6 +328,7 @@ extern int          level_nr, leveldir_nr, num_leveldirs;
 extern int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
 
 extern int             FX,FY, ScreenMovPos, ScrollStepSize;
+extern int             GameSpeed, MoveSpeed;
 extern int             BX1,BY1, BX2,BY2;
 extern int             JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
 extern int             PlayerMovDir, PlayerMovPos, PlayerPushing;
index 14007b7e3d20868f510911e8a4150e93060c864f..657bc164f495b6f61e09fcbfcf9e4d6d53e6d99d 100644 (file)
 
 void microsleep(unsigned long usec)
 {
-  struct timeval delay;
+  if (usec < 5000)
+  {
+    /* we want to wait less than 5 ms -- if we assume that we have a
+       kernel timer resolution of 10 ms, we would wait far to long;
+       therefore it's better to do a short interval of busy waiting
+       to get our sleeping time more accurate */
 
-  delay.tv_sec  = usec / 1000000;
-  delay.tv_usec = usec % 1000000;
+    long base_counter = Counter2(), actual_counter = Counter2();
+    long delay = usec/1000;
 
-  if (select(0,NULL,NULL,NULL,&delay)!=0)
-    fprintf(stderr,"%s: in function microsleep: select failed!\n",
-           progname);
+    while (actual_counter < base_counter+delay &&
+          actual_counter >= base_counter)
+      actual_counter = Counter2();
+  }
+  else
+  {
+    struct timeval delay;
+
+    delay.tv_sec  = usec / 1000000;
+    delay.tv_usec = usec % 1000000;
+
+    if (select(0,NULL,NULL,NULL,&delay) != 0)
+      fprintf(stderr,"%s: in function microsleep: select failed!\n",
+             progname);
+  }
 }
 
 long mainCounter(int mode)
index 37c8128c9c79187eed99716cc833487e6f6611a9..e4f8f8a157e45872c9365ee880775663b92958b8 100644 (file)
@@ -1312,6 +1312,8 @@ void HandleGameActions()
     TapeStop();
 
   GameActions();
+
+  BackToFront();
 }
 
 void HandleVideoButtons(int mx, int my, int button)
index 499469d696a4972e429ac92e9185ab8161725c36..f611f5cd7344c54a6b6940f8562ce4d1ea8bfdf3 100644 (file)
@@ -339,7 +339,6 @@ void DrawPlayerField()
 
   int element = Feld[x][y];
   int graphic, phase;
-  BOOL draw_thru_mask = FALSE;
 
   if (PlayerGone)
     return;
@@ -360,39 +359,43 @@ void DrawPlayerField()
   if (direct_draw_on)
     SetDrawtoField(DRAW_BUFFERED);
 
-  /* draw things behind the player (EL_PFORTE* || mole/penguin/pig/dragon) */
-
-
+  /* draw things in the field the player is leaving, if needed */
 
+  if (lastJX != JX || lastJY != JY)
+  {
+    if (Store[lastJX][lastJY])
+    {
+      DrawLevelElement(lastJX,lastJY, Store[lastJX][lastJY]);
+      DrawLevelElementThruMask(lastJX,lastJY, Feld[lastJX][lastJY]);
+    }
+    else if (Feld[lastJX][lastJY] == EL_DYNAMIT)
+      DrawDynamite(lastJX,lastJY);
+    else
+      DrawLevelField(lastJX,lastJY);
 
-  DrawLevelField(x,y);
+    if (PlayerPushing)
+    {
+      int nextJX = JX + (JX - lastJX);
+      int nextJY = JY + (JY - lastJY);
 
+      if (PlayerGfxPos)
+      {
+       if (Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL)
+         DrawLevelElement(nextJX,nextJY, EL_SOKOBAN_FELD_LEER);
+       else
+         DrawLevelElement(nextJX,nextJY, EL_LEERRAUM);
+      }
+      else
+       DrawLevelField(nextJX,nextJY);
+    }
+  }
 
+  /* draw things behind the player, if needed */
 
   if (Store[x][y])
-  {
-    DrawGraphic(sx,sy, el2gfx(Store[x][y]));
-    draw_thru_mask = TRUE;
-  }
-  else if (element!=EL_DYNAMIT && element!=EL_DYNABOMB)
-  {
-    DrawLevelField(x,y);
-    draw_thru_mask = TRUE;
-  }
-
-  /*
-  else if (element!=EL_LEERRAUM && element!=EL_DYNAMIT && element!=EL_DYNABOMB)
-  {
+    DrawLevelElement(x,y, Store[x][y]);
+  else if (element != EL_DYNAMIT && element != EL_DYNABOMB)
     DrawLevelField(x,y);
-    draw_thru_mask = TRUE;
-  }
-  */
-
-
-  draw_thru_mask = TRUE;
-
-
-
 
   /* draw player himself */
 
@@ -407,7 +410,6 @@ void DrawPlayerField()
 
   graphic += PlayerFrame;
 
-
   if (PlayerGfxPos)
   {
     if (PlayerMovDir == MV_LEFT || PlayerMovDir == MV_RIGHT)
@@ -416,31 +418,10 @@ void DrawPlayerField()
       syy = PlayerGfxPos;
   }
 
-
   if (!soft_scrolling_on && ScreenMovPos)
     sxx = syy = 0;
 
-
-
-
-
-
-  if (draw_thru_mask)
-    DrawGraphicShiftedThruMask(sx,sy,sxx,syy,graphic,CUT_NO_CUTTING);
-    /*
-    DrawGraphicThruMask(sx, sy, graphic);
-    */
-  else
-    DrawGraphicShifted(sx,sy,sxx,syy,graphic,CUT_NO_CUTTING);
-  /*
-    DrawGraphic(sx, sy, graphic);
-    */
-
-
-
-  MarkTileDirty(sx,sy);
-
-
+  DrawGraphicShiftedThruMask(sx,sy, sxx,syy, graphic, NO_CUTTING);
 
   if (PlayerPushing && PlayerGfxPos)
   {
@@ -450,9 +431,7 @@ void DrawPlayerField()
 
     if (Feld[JX][JY] == EL_SOKOBAN_FELD_LEER ||
        Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL)
-      DrawGraphicShiftedThruMask(px,py,sxx,syy,
-                                GFX_SOKOBAN_OBJEKT,
-                                CUT_NO_CUTTING);
+      DrawGraphicShiftedThruMask(px,py,sxx,syy, GFX_SOKOBAN_OBJEKT,NO_CUTTING);
     else
     {
       int element = Feld[nextJX][nextJY];
@@ -466,21 +445,12 @@ void DrawPlayerField()
          graphic += phase;
        else
          graphic += (phase+4)%4;
-
-
-       /*
-       printf("----> (%d, %d, %d)\n",
-              PlayerGfxPos, phase, graphic);
-              */
-
       }
 
-      DrawGraphicShifted(px,py, sxx,syy, graphic, CUT_NO_CUTTING);
+      DrawGraphicShifted(px,py, sxx,syy, graphic, NO_CUTTING, NO_MASKING);
     }
   }
 
-
-
   /* draw things in front of player (EL_DYNAMIT || EL_DYNABOMB) */
 
   if (element == EL_DYNAMIT || element == EL_DYNABOMB)
@@ -520,6 +490,8 @@ void DrawPlayerField()
              dest_x,dest_y, x_size,y_size, dest_x,dest_y);
     SetDrawtoField(DRAW_DIRECT);
   }
+
+  MarkTileDirty(sx,sy);
 }
 
 static int getGraphicAnimationPhase(int frames, int delay, int mode)
@@ -648,11 +620,17 @@ void DrawGraphicThruMask(int x, int y, int graphic)
   MarkTileDirty(x,y);
 }
 
-void DrawElementThruMask(int x, int y, int element)
+void DrawScreenElementThruMask(int x, int y, int element)
 {
   DrawGraphicThruMask(x,y,el2gfx(element));
 }
 
+void DrawLevelElementThruMask(int x, int y, int element)
+{
+  if (IN_LEV_FIELD(x,y) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
+    DrawScreenElementThruMask(SCROLLX(x),SCROLLY(y),element);
+}
+
 void DrawMiniGraphic(int x, int y, int graphic)
 {
   DrawMiniGraphicExt(drawto, gc, x, y, graphic);
@@ -687,10 +665,12 @@ void DrawMiniGraphicExtHiRes(Drawable d, GC gc, int x, int y, int graphic)
     XFillRectangle(display,d,gc, x,y, MINI_TILEX,MINI_TILEY);
 }
 
-void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
+void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic,
+                       int cut_mode, int mask_mode)
 {
   int width = TILEX, height = TILEY;
   int cx = 0, cy = 0;
+  int src_x,src_y, dest_x,dest_y;
 
   if (graphic < 0)
   {
@@ -765,18 +745,38 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
   {
     graphic -= GFX_START_ROCKSSCREEN;
-    XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
-             SX+(graphic % GFX_PER_LINE)*TILEX+cx,
-             SY+(graphic / GFX_PER_LINE)*TILEY+cy,
-             width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
+    src_x  = SX+(graphic % GFX_PER_LINE)*TILEX+cx;
+    src_y  = SY+(graphic / GFX_PER_LINE)*TILEY+cy;
+    dest_x = FX+x*TILEX+dx;
+    dest_y = FY+y*TILEY+dy;
+
+    if (mask_mode == USE_MASKING)
+    {
+      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],
+               src_x,src_y, width,height, dest_x,dest_y);
+    }
+    else
+      XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
+               src_x,src_y, width,height, dest_x,dest_y);
   }
   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
   {
     graphic -= GFX_START_ROCKSHEROES;
-    XCopyArea(display,pix[PIX_HEROES],drawto_field,gc,
-             (graphic % HEROES_PER_LINE)*TILEX+cx,
-             (graphic / HEROES_PER_LINE)*TILEY+cy,
-             width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
+    src_x  = (graphic % HEROES_PER_LINE)*TILEX+cx;
+    src_y  = (graphic / HEROES_PER_LINE)*TILEY+cy;
+    dest_x = FX+x*TILEX+dx;
+    dest_y = FY+y*TILEY+dy;
+
+    if (mask_mode == USE_MASKING)
+    {
+      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],
+               src_x,src_y, width,height, dest_x,dest_y);
+    }
+    else
+      XCopyArea(display,pix[PIX_HEROES],drawto_field,gc,
+               src_x,src_y, width,height, dest_x,dest_y);
   }
 
 #if DEBUG
@@ -791,7 +791,14 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
   MarkTileDirty(x,y);
 }
 
-void DrawElementShifted(int x, int y, int dx, int dy, int element,int cut_mode)
+void DrawGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic,
+                               int cut_mode)
+{
+  DrawGraphicShifted(x,y, dx,dy, graphic, cut_mode, USE_MASKING);
+}
+
+void DrawScreenElementShifted(int x, int y, int dx, int dy, int element,
+                             int cut_mode)
 {
   int ux = UNSCROLLX(x), uy = UNSCROLLY(y);
   int graphic = el2gfx(element);
@@ -872,124 +879,16 @@ void DrawElementShifted(int x, int y, int dx, int dy, int element,int cut_mode)
   }
 
   if (dx || dy)
-    DrawGraphicShifted(x,y, dx,dy, graphic, cut_mode);
+    DrawGraphicShifted(x,y, dx,dy, graphic, cut_mode, NO_MASKING);
   else
     DrawGraphic(x,y, graphic);
 }
 
-void DrawGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic,
-                               int cut_mode)
+void DrawLevelElementShifted(int x, int y, int dx, int dy, int element,
+                            int cut_mode)
 {
-  int width = TILEX, height = TILEY;
-  int cx = 0, cy = 0;
-  int src_x,src_y, dest_x,dest_y;
-
-  if (graphic < 0)
-  {
-    DrawGraphic(x,y,graphic);
-    return;
-  }
-
-  if (dx || dy)                        /* Verschiebung der Grafik? */
-  {
-    if (x < BX1)               /* Element kommt von links ins Bild */
-    {
-      x = BX1;
-      width = dx;
-      cx = TILEX - dx;
-      dx = 0;
-    }
-    else if (x > BX2)          /* Element kommt von rechts ins Bild */
-    {
-      x = BX2;
-      width = -dx;
-      dx = TILEX + dx;
-    }
-    else if (x==BX1 && dx<0)   /* Element verläßt links das Bild */
-    {
-      width += dx;
-      cx = -dx;
-      dx = 0;
-    }
-    else if (x==BX2 && dx>0)   /* Element verläßt rechts das Bild */
-      width -= dx;
-    else if (dx)               /* allg. Bewegung in x-Richtung */
-      MarkTileDirty(x + SIGN(dx), y);
-
-    if (y < BY1)               /* Element kommt von oben ins Bild */
-    {
-      if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */
-       return;
-
-      y = BY1;
-      height = dy;
-      cy = TILEY - dy;
-      dy = 0;
-    }
-    else if (y > BY2)          /* Element kommt von unten ins Bild */
-    {
-      y = BY2;
-      height = -dy;
-      dy = TILEY + dy;
-    }
-    else if (y==BY1 && dy<0)   /* Element verläßt oben das Bild */
-    {
-      height += dy;
-      cy = -dy;
-      dy = 0;
-    }
-    else if (dy > 0 && cut_mode==CUT_ABOVE)
-    {
-      if (y == BY2)            /* Element unterhalb des Bildes */
-       return;
-
-      height = dy;
-      cy = TILEY-dy;
-      dy = TILEY;
-      MarkTileDirty(x, y + 1);
-    }                          /* Element verläßt unten das Bild */
-    else if (dy > 0 && (y == BY2 || cut_mode==CUT_BELOW))
-      height -= dy;
-    else if (dy)               /* allg. Bewegung in y-Richtung */
-      MarkTileDirty(x, y + SIGN(dy));
-  }
-
-  if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
-  {
-    graphic -= GFX_START_ROCKSSCREEN;
-    src_x  = SX+(graphic % GFX_PER_LINE)*TILEX+cx;
-    src_y  = SY+(graphic / GFX_PER_LINE)*TILEY+cy;
-    dest_x = FX+x*TILEX+dx;
-    dest_y = FY+y*TILEY+dy;
-
-    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],
-              src_x,src_y, width,height, dest_x,dest_y);
-  }
-  else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
-  {
-    graphic -= GFX_START_ROCKSHEROES;
-    src_x  = (graphic % HEROES_PER_LINE)*TILEX+cx;
-    src_y  = (graphic / HEROES_PER_LINE)*TILEY+cy;
-    dest_x = FX+x*TILEX+dx;
-    dest_y = FY+y*TILEY+dy;
-
-    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],
-              src_x,src_y, width,height, dest_x,dest_y);
-  }
-
-#if DEBUG
-  if (!IN_SCR_FIELD(x,y))
-  {
-    printf("DrawGraphicShiftedThruMask(): x = %d, y = %d, graphic = %d\n",
-          x,y,graphic);
-    printf("DrawGraphicShifted(): This should never happen!\n");
-    return;
-  }
-#endif
-
-  MarkTileDirty(x,y);
+  if (IN_LEV_FIELD(x,y) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
+    DrawScreenElementShifted(SCROLLX(x),SCROLLY(y), dx,dy, element, cut_mode);
 }
 
 void ErdreichAnbroeckeln(int x, int y)
@@ -1029,10 +928,6 @@ void ErdreichAnbroeckeln(int x, int y)
       else
        element = Feld[uxx][uyy];
 
-/*
-      if (element==EL_ERDREICH || IS_SOLID(element))
-       continue;
-*/
       if (element==EL_ERDREICH)
        continue;
 
@@ -1071,11 +966,6 @@ void ErdreichAnbroeckeln(int x, int y)
       yy = y+xy[i][1];
       uxx = ux+xy[i][0];
       uyy = uy+xy[i][1];
-/*
-      if (!IN_LEV_FIELD(uxx,uyy) || Feld[uxx][uyy]!=EL_ERDREICH ||
-         !IN_SCR_FIELD(xx,yy) || IS_SOLID(element))
-       continue;
-*/
 
       if (!IN_LEV_FIELD(uxx,uyy) || Feld[uxx][uyy]!=EL_ERDREICH ||
          !IN_SCR_FIELD(xx,yy))
@@ -1108,7 +998,7 @@ void ErdreichAnbroeckeln(int x, int y)
 
 void DrawScreenElement(int x, int y, int element)
 {
-  DrawElementShifted(x,y,0,0,element,CUT_NO_CUTTING);
+  DrawScreenElementShifted(x,y, 0,0, element, NO_CUTTING);
   ErdreichAnbroeckeln(x,y);
 }
 
@@ -1134,7 +1024,7 @@ void DrawScreenField(int x, int y)
   if (IS_MOVING(ux,uy))
   {
     int horiz_move = (MovDir[ux][uy]==MV_LEFT || MovDir[ux][uy]==MV_RIGHT);
-    BOOL cut_mode = CUT_NO_CUTTING;
+    BOOL cut_mode = NO_CUTTING;
 
     if (Store[ux][uy]==EL_MORAST_LEER ||
        Store[ux][uy]==EL_SIEB_LEER ||
@@ -1148,21 +1038,21 @@ void DrawScreenField(int x, int y)
       cut_mode = CUT_BELOW;
 
     if (cut_mode==CUT_ABOVE)
-      DrawElementShifted(x,y,0,0,Store[ux][uy],CUT_NO_CUTTING);
+      DrawScreenElementShifted(x,y, 0,0, Store[ux][uy], NO_CUTTING);
     else
       DrawScreenElement(x,y,EL_LEERRAUM);
 
     if (horiz_move)
-      DrawElementShifted(x,y,MovPos[ux][uy],0,element,CUT_NO_CUTTING);
+      DrawScreenElementShifted(x,y, MovPos[ux][uy],0, element, NO_CUTTING);
     else
-      DrawElementShifted(x,y,0,MovPos[ux][uy],element,cut_mode);
+      DrawScreenElementShifted(x,y, 0,MovPos[ux][uy], element, cut_mode);
   }
   else if (IS_BLOCKED(ux,uy))
   {
     int oldx,oldy;
     int sx, sy;
     int horiz_move;
-    BOOL cut_mode = CUT_NO_CUTTING;
+    BOOL cut_mode = NO_CUTTING;
 
     Blocked2Moving(ux,uy,&oldx,&oldy);
     sx = SCROLLX(oldx);
@@ -1179,9 +1069,9 @@ void DrawScreenField(int x, int y)
     element = Feld[oldx][oldy];
 
     if (horiz_move)
-      DrawElementShifted(sx,sy,MovPos[oldx][oldy],0,element,CUT_NO_CUTTING);
+      DrawScreenElementShifted(sx,sy, MovPos[oldx][oldy],0,element,NO_CUTTING);
     else
-      DrawElementShifted(sx,sy,0,MovPos[oldx][oldy],element,cut_mode);
+      DrawScreenElementShifted(sx,sy, 0,MovPos[oldx][oldy],element,cut_mode);
   }
   else if (IS_DRAWABLE(element))
     DrawScreenElement(x,y,element);
@@ -1666,7 +1556,7 @@ unsigned int MoveDoor(unsigned int door_state)
 
       BackToFront();
 
-      if (game_status==MAINMENU)
+      if (game_status == MAINMENU)
        DoAnimation();
     }
   }
index 2d31f211ff5a6026c43b2da824c1ac2c206d73f1..459011a13212ef4559899c80a419e6e5b4221c34 100644 (file)
 
 #include <sys/time.h>
 
-/* für SetDrawtoField */
+/* for SetDrawtoField */
 #define DRAW_DIRECT    0
 #define DRAW_BUFFERED  1
 #define DRAW_BACKBUFFER        2
 
-/* für DrawElementShifted */
-#define CUT_NO_CUTTING 0
+/* for DrawElementShifted */
+#define NO_CUTTING     0
 #define CUT_ABOVE      1
 #define CUT_BELOW      2
 #define CUT_LEFT       4
 #define CUT_RIGHT      8
 
-/* für MoveDoor */
+/* for masking functions */
+#define NO_MASKING     0
+#define USE_MASKING    1
+/* for MoveDoor */
 #define DOOR_OPEN_1    1
 #define DOOR_OPEN_2    2
 #define DOOR_CLOSE_1   4
@@ -45,7 +49,7 @@
 #define DOOR_NO_DELAY  32
 #define DOOR_GET_STATE 64
 
-/* für AreYouSure */
+/* for AreYouSure */
 #define AYS_ASK                1
 #define AYS_OPEN       2
 #define AYS_CLOSE      4
@@ -65,13 +69,15 @@ void DrawGraphic(int, int, int);
 void DrawGraphicExt(Drawable, GC, int, int, int);
 void DrawGraphicExtHiRes(Drawable, GC, int, int, int);
 void DrawGraphicThruMask(int, int, int);
-void DrawElementThruMask(int, int, int);
+void DrawScreenElementThruMask(int, int, int);
+void DrawLevelElementThruMask(int, int, int);
 void DrawMiniGraphic(int, int, int);
 void DrawMiniGraphicExt(Drawable, GC, int, int, int);
 void DrawMiniGraphicExtHiRes(Drawable, GC, int, int, int);
-void DrawGraphicShifted(int, int, int, int, int, int);
-void DrawElementShifted(int, int, int, int, int, int);
+void DrawGraphicShifted(int, int, int, int, int, int, int);
 void DrawGraphicShiftedThruMask(int, int, int, int, int, int);
+void DrawScreenElementShifted(int, int, int, int, int, int);
+void DrawLevelElementShifted(int, int, int, int, int, int);
 void ErdreichAnbroeckeln(int, int);
 void DrawScreenElement(int, int, int);
 void DrawLevelElement(int, int, int);