rnd-19980918
authorHolger Schemel <info@artsoft.org>
Fri, 18 Sep 1998 14:48:43 +0000 (16:48 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:30:39 +0000 (10:30 +0200)
src/Makefile
src/cartoons.c
src/editor.c
src/events.c
src/game.c
src/main.c
src/main.h
src/misc.c
src/misc.h
src/screens.c
src/tools.c

index cd1c80e947bc52b75f60f7d8c28b080c2669fca5..3bba1da00e7e18b07faef790f1768657cfe303f8 100644 (file)
@@ -97,7 +97,7 @@ clean:
        $(RM) $(OBJS)
 
 BACKUP_DIR = /home/aeglos/BACKUP/rnd
-BACKUP_DATE = `date +%y%m%d`
+BACKUP_DATE = `date +%Y%m%d`
 BACKUP_FILE = $(BACKUP_DIR)/rnd-$(BACKUP_DATE).tgz
 
 backup:
index b1b31921c03f0f1cc01131a9160a9fe4a77f447d..b8efebf3b9a2c4358a91709d016433b5daac5089 100644 (file)
@@ -181,7 +181,7 @@ void HandleAnimation(int mode)
 
   if (anim_restart)
   {
-    if (!DelayReached(&animstart_delay,animstart_delay_value))
+    if (!DelayReached(&animstart_delay, animstart_delay_value))
       return;
 
     toon_nr = SimpleRND(NUM_TOONS);
@@ -232,7 +232,7 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
       JUMPER_FPS,
       JUMPER_STEPSIZE,
       ANIM_NORMAL,
-      ANIMDIR_LEFT,
+      ANIMDIR_RIGHT,
       ANIMPOS_DOWN
     },
     {
@@ -461,7 +461,7 @@ BOOL AnimateToon(int toon_nr, BOOL restart)
       pos_y >=  FULL_SYSIZE  + anim->stepsize)
     return(TRUE);
 
-  if (!DelayReached(&anim_delay,anim_delay_value))
+  if (!DelayReached(&anim_delay, anim_delay_value))
   {
     if (game_status==HELPSCREEN && !restart)
       DrawAnim(anim_pixmap,anim_clip_gc,
index 17677e8dec42d4520c39a2d481f87a50c5f0f030..fef23e2b5d3ba6fb172af8e1205a82aa10320606 100644 (file)
@@ -19,6 +19,8 @@
 #include "buttons.h"
 #include "files.h"
 
+#define CHOICE_DELAY_VALUE     100
+
 static int level_xpos,level_ypos;
 static BOOL edit_mode;
 static BOOL name_typing;
@@ -676,7 +678,7 @@ void LevelEd(int mx, int my, int button)
     if (((choice == ED_BUTTON_EUP && element_shift>0) ||
         (choice == ED_BUTTON_EDOWN &&
          element_shift<elements_in_list-MAX_ELEM_X*MAX_ELEM_Y)) &&
-       DelayReached(&choice_delay,10))
+       DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
     {
       int i, step;
 
@@ -746,7 +748,7 @@ void LevelEd(int mx, int my, int button)
        case ED_BUTTON_LEFT:
          if (level_xpos>=0)
          {
-           if (!DelayReached(&choice_delay,10))
+           if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
              break;
            if (lev_fieldx<2*SCR_FIELDX-2)
              break;
@@ -763,7 +765,7 @@ void LevelEd(int mx, int my, int button)
        case ED_BUTTON_RIGHT:
          if (level_xpos<=lev_fieldx-2*SCR_FIELDX)
          {
-           if (!DelayReached(&choice_delay,10))
+           if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
              break;
            if (lev_fieldx<2*SCR_FIELDX-2)
              break;
@@ -780,7 +782,7 @@ void LevelEd(int mx, int my, int button)
        case ED_BUTTON_UP:
          if (level_ypos>=0)
          {
-           if (!DelayReached(&choice_delay,10))
+           if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
              break;
            if (lev_fieldy<2*SCR_FIELDY-2)
              break;
@@ -797,7 +799,7 @@ void LevelEd(int mx, int my, int button)
        case ED_BUTTON_DOWN:
          if (level_ypos<=lev_fieldy-2*SCR_FIELDY)
          {
-           if (!DelayReached(&choice_delay,10))
+           if (!DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
              break;
            if (lev_fieldy<2*SCR_FIELDY-2)
              break;
@@ -864,7 +866,8 @@ void LevelEd(int mx, int my, int button)
       int choice = CheckCountButtons(mx,my,button);
       int step = (button==1 ? 1 : button==2 ? 5 : button==3 ? 10 : 0);
 
-      if (choice>=0 && choice<36 && DelayReached(&choice_delay,10))
+      if (choice >= 0 && choice < 36 &&
+         DelayReached(&choice_delay, CHOICE_DELAY_VALUE))
       {
        if (!(choice % 2))
          step = -step;
index 73d681d72efa38f7f274741b390aade98a81c311..02a13795d1573693e8dd55b6a7c89f1ad2267215 100644 (file)
@@ -516,9 +516,9 @@ void HandleKey(KeySym key, int key_status)
        case XK_8:
        case XK_9:
          if (key == XK_0)
-           GameSpeed = 50;
+           GameSpeed = 500;
          else
-           GameSpeed = key - XK_0;
+           GameSpeed = (key - XK_0) * 10;
          printf("GameSpeed == %d\n", GameSpeed);
          break;
 
index 0561c22c2afbc7d07601ec8378a241641b99f11e..384d7431d4b14e611113d302da44945d288b0089 100644 (file)
@@ -2041,7 +2041,7 @@ void AmoebeWaechst(int x, int y)
   {
     MovDelay[x][y] = 7;
 
-    if (DelayReached(&sound_delay,sound_delay_value))
+    if (DelayReached(&sound_delay, sound_delay_value))
     {
       PlaySoundLevel(x,y,SND_AMOEBE);
       sound_delay_value = 30;
@@ -2597,8 +2597,8 @@ void GameActions()
   if (PlayerMovPos)
     ScrollFigure(0);
 
-  while(!DelayReached(&action_delay, action_delay_value))
-    Delay(5);
+  /* main game synchronization point */
+  WaitUntilDelayReached(&action_delay, action_delay_value);
 
   if (tape.pausing || (tape.playing && !TapePlayDelay()))
     return;
@@ -2727,7 +2727,7 @@ void GameActions()
     }
   }
 
-  if (TimeLeft>0 && TimeFrames>=(100/GameSpeed) && !tape.pausing)
+  if (TimeLeft>0 && TimeFrames>=(1000/GameSpeed) && !tape.pausing)
   {
     TimeFrames = 0;
     TimeLeft--;
index fd9804cc03ee729a778705edee6389c1e470256a..aa4d14bd74124685ac61702223f0ce6411672eda 100644 (file)
@@ -64,6 +64,7 @@ int           fading_on = FALSE;
 int            autorecord_on = FALSE;
 int            joystick_nr = 0;
 int            quick_doors = FALSE;
+int            cpu_friendly = TRUE;
 
 BOOL           redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
 int            redraw_x1 = 0, redraw_y1 = 0;
index 3d8267d5f1c48dd75107506d73c6346cd8d02c6d..d34fbb96085bbae64644fcad02f29afde17b0bd2 100644 (file)
@@ -302,6 +302,7 @@ extern int          fading_on;
 extern int             autorecord_on;
 extern int             joystick_nr;
 extern int             quick_doors;
+extern int             cpu_friendly;
 
 extern BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
 extern int             redraw_x1, redraw_y1;
index 28d04a6d1b3844eb59994f17142859aa4905a3ff..944458f5669d0bd63d486123b3978d773c5aa8cc 100644 (file)
 #include <sys/param.h>
 #include <sys/types.h>
 
-void microsleep(unsigned long usec)
+static unsigned long mainCounter(int mode)
 {
-  if (usec < 5000)
+  static struct timeval base_time = { 0, 0 };
+  struct timeval current_time;
+  unsigned long counter_ms;
+
+  gettimeofday(&current_time, NULL);
+
+  if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
+    base_time = current_time;
+
+  counter_ms = (current_time.tv_sec  - base_time.tv_sec)  * 1000
+             + (current_time.tv_usec - base_time.tv_usec) / 1000;
+
+  return counter_ms;           /* return milliseconds since last init */
+}
+
+void InitCounter()             /* set counter back to zero */
+{
+  mainCounter(INIT_COUNTER);
+}
+
+unsigned long Counter()        /* get milliseconds since last call of InitCounter() */
+{
+  return(mainCounter(READ_COUNTER));
+}
+
+static void sleep_milliseconds(unsigned long milliseconds_delay)
+{
+  if (milliseconds_delay < 5 || !cpu_friendly)
   {
     /* 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 */
 
-    long base_counter = Counter(), actual_counter = Counter();
-    long delay = usec/1000;
+    unsigned long base_counter = Counter(), actual_counter = Counter();
 
-    while (actual_counter < base_counter+delay &&
+    while (actual_counter < base_counter + milliseconds_delay &&
           actual_counter >= base_counter)
       actual_counter = Counter();
   }
@@ -44,79 +70,52 @@ void microsleep(unsigned long usec)
   {
     struct timeval delay;
 
-    delay.tv_sec  = usec / 1000000;
-    delay.tv_usec = usec % 1000000;
+    delay.tv_sec  = milliseconds_delay / 1000;
+    delay.tv_usec = 1000 * (milliseconds_delay % 1000);
 
-    if (select(0,NULL,NULL,NULL,&delay) != 0)
-      fprintf(stderr,"%s: in function microsleep: select failed!\n",
+    if (select(0, NULL, NULL, NULL, &delay) != 0)
+      fprintf(stderr,"%s: in function sleep_milliseconds: select() failed!\n",
              progname);
   }
 }
 
-long mainCounter(int mode)
+void Delay(unsigned long delay)        /* Sleep specified number of milliseconds */
 {
-  static struct timeval base_time = { 0, 0 };
-  struct timeval current_time;
-  long counter_ms;
-
-  gettimeofday(&current_time,NULL);
-  if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
-    base_time = current_time;
-
-  counter_ms = (current_time.tv_sec - base_time.tv_sec)*1000
-             + (current_time.tv_usec - base_time.tv_usec)/1000;
-
-  return counter_ms;           /* return milliseconds since last init */
-}
-
-void InitCounter() /* set counter back to zero */
-{
-  mainCounter(INIT_COUNTER);
-}
-
-long Counter() /* get milliseconds since last call of InitCounter() */
-{
-  return(mainCounter(READ_COUNTER));
+  sleep_milliseconds(delay);
 }
 
-void WaitCounter(long value)   /* wait for counter to reach value */
+BOOL FrameReached(unsigned long *frame_counter_var, unsigned long frame_delay)
 {
-  long wait;
+  unsigned long actual_frame_counter = FrameCounter;
 
-  while((wait=value-Counter())>0)
-    microsleep(wait * 1000);
-}
+  if (actual_frame_counter < *frame_counter_var+frame_delay &&
+      actual_frame_counter >= *frame_counter_var)
+    return(FALSE);
 
-void Delay(long value)         /* Delay 'value' milliseconds */
-{
-  microsleep(value * 1000);
+  *frame_counter_var = actual_frame_counter;
+  return(TRUE);
 }
 
-BOOL DelayReached(long *counter_var, int delay)
+BOOL DelayReached(unsigned long *counter_var, unsigned long delay)
 {
-  long actual_counter = Counter();
+  unsigned long actual_counter = Counter();
 
-  if (actual_counter >= *counter_var+delay || actual_counter < *counter_var)
-  {
-    *counter_var = actual_counter;
-    return(TRUE);
-  }
-  else
+  if (actual_counter < *counter_var + delay &&
+      actual_counter >= *counter_var)
     return(FALSE);
+
+  *counter_var = actual_counter;
+  return(TRUE);
 }
 
-BOOL FrameReached(long *frame_counter_var, int frame_delay)
+void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
 {
-  long actual_frame_counter = FrameCounter;
+  unsigned long actual_counter = Counter();
 
-  if (actual_frame_counter >= *frame_counter_var+frame_delay ||
-      actual_frame_counter < *frame_counter_var)
-  {
-    *frame_counter_var = actual_frame_counter;
-    return(TRUE);
-  }
-  else
-    return(FALSE);
+  if (actual_counter < *counter_var + delay && actual_counter >= *counter_var)
+    sleep_milliseconds(*counter_var + delay - actual_counter);
+
+  *counter_var = actual_counter;
 }
 
 char *int2str(int ct, int nr)
index 9641265fc28c607f81b6b01894f093b0f16cf5a7..a6a8fb01df4731a37860e954d2c36220f88e18c8 100644 (file)
 
 #define NEW_RANDOMIZE          -1
 
-void microsleep(unsigned long);
-long mainCounter(int);
 void InitCounter(void);
-long Counter(void);
-void WaitCounter(long);
-void Delay(long);
-BOOL DelayReached(long *, int);
-BOOL FrameReached(long *, int);
+unsigned long Counter(void);
+void Delay(unsigned long);
+BOOL FrameReached(unsigned long *, unsigned long);
+BOOL DelayReached(unsigned long *, unsigned long);
+void WaitUntilDelayReached(unsigned long *, unsigned long);
 char *int2str(int, int);
 unsigned int SimpleRND(unsigned int);
 unsigned int RND(unsigned int);
index 907878bf6dac80c1bddbc9e2836f24d68705fa7f..9cc9235e6f780899c90c35ea63e232a1a25234dc 100644 (file)
@@ -146,7 +146,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
     if (new_level_nr>leveldir[leveldir_nr].levels-1)
       new_level_nr = leveldir[leveldir_nr].levels-1;
 
-    if (old_level_nr==new_level_nr || !DelayReached(&level_delay,15))
+    if (old_level_nr==new_level_nr || !DelayReached(&level_delay,150))
       goto out;
 
     level_nr = new_level_nr;
index efcba4dbc2ba57b619a2291a2ac4477977a558e5..08c6dc68d3a63e814933be8b4a285e60dbc89549 100644 (file)
@@ -1538,8 +1538,7 @@ unsigned int MoveDoor(unsigned int door_state)
 
     for(x=start; x<=DXSIZE; x+=stepsize)
     {
-      while(!DelayReached(&door_delay, door_delay_value/10))
-       Delay(1);
+      WaitUntilDelayReached(&door_delay, door_delay_value);
 
       if (door_state & DOOR_ACTION_1)
       {