From: Holger Schemel Date: Mon, 21 Sep 1998 09:07:48 +0000 (+0200) Subject: rnd-19980920 X-Git-Tag: 1.2.0^2~80 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=01a14ec659822082594be0304cc701f816043ad9;p=rocksndiamonds.git rnd-19980920 --- diff --git a/src/events.c b/src/events.c index 02a13795..238aa066 100644 --- a/src/events.c +++ b/src/events.c @@ -516,10 +516,11 @@ void HandleKey(KeySym key, int key_status) case XK_8: case XK_9: if (key == XK_0) - GameSpeed = 500; + GameFrameDelay = 500; else - GameSpeed = (key - XK_0) * 10; - printf("GameSpeed == %d\n", GameSpeed); + GameFrameDelay = (key - XK_0) * 10; + printf("Game speed == %d%% (%d ms delay between two frames)\n", + GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay); break; case XK_a: diff --git a/src/game.c b/src/game.c index 384d7431..0a7bbd4d 100644 --- a/src/game.c +++ b/src/game.c @@ -2588,7 +2588,7 @@ void GameActions() #ifdef DEBUG action_delay_value = - (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameSpeed); + (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameFrameDelay); #else action_delay_value = (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY); @@ -2727,7 +2727,7 @@ void GameActions() } } - if (TimeLeft>0 && TimeFrames>=(1000/GameSpeed) && !tape.pausing) + if (TimeLeft>0 && TimeFrames>=(1000/GameFrameDelay) && !tape.pausing) { TimeFrames = 0; TimeLeft--; diff --git a/src/game.h b/src/game.h index 18a9010d..dabcb1af 100644 --- a/src/game.h +++ b/src/game.h @@ -32,7 +32,7 @@ /* fundamental game speed */ #define GAME_FRAME_DELAY 20 /* frame delay in milliseconds */ -#define FFWD_FRAME_DELAY 1 +#define FFWD_FRAME_DELAY 10 /* 200% speed for fast forward */ #define FRAMES_PER_SECOND (1000 / GAME_FRAME_DELAY) void GetPlayerConfig(void); diff --git a/src/main.c b/src/main.c index aa4d14bd..443a4336 100644 --- a/src/main.c +++ b/src/main.c @@ -64,7 +64,6 @@ 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; @@ -89,7 +88,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 GameFrameDelay = 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; diff --git a/src/main.h b/src/main.h index d34fbb96..bf9fbfec 100644 --- a/src/main.h +++ b/src/main.h @@ -302,7 +302,6 @@ 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; @@ -327,7 +326,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 GameFrameDelay, MoveSpeed; extern int BX1,BY1, BX2,BY2; extern int JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY; extern int PlayerMovDir, PlayerMovPos, PlayerPushing; diff --git a/src/misc.c b/src/misc.c index 944458f5..8a17d8c3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -53,9 +53,9 @@ unsigned long Counter() /* get milliseconds since last call of InitCounter() */ static void sleep_milliseconds(unsigned long milliseconds_delay) { - if (milliseconds_delay < 5 || !cpu_friendly) + if (milliseconds_delay < 5) { - /* we want to wait less than 5 ms -- if we assume that we have a + /* we want to wait only a few 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 */ @@ -110,10 +110,18 @@ BOOL DelayReached(unsigned long *counter_var, unsigned long delay) void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay) { - unsigned long actual_counter = Counter(); + unsigned long actual_counter; + + while(1) + { + actual_counter = Counter(); - if (actual_counter < *counter_var + delay && actual_counter >= *counter_var) - sleep_milliseconds(*counter_var + delay - actual_counter); + if (actual_counter < *counter_var + delay && + actual_counter >= *counter_var) + sleep_milliseconds((*counter_var + delay - actual_counter) / 2); + else + break; + } *counter_var = actual_counter; }