From: Holger Schemel Date: Thu, 31 Aug 2000 18:31:57 +0000 (+0200) Subject: rnd-20000831-1-src X-Git-Tag: 2.0.0^2~46 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=8eee8a56a5aae567522998ccddf929e38aed6872 rnd-20000831-1-src --- diff --git a/src/game.c b/src/game.c index 4e716e3e..5561d17c 100644 --- a/src/game.c +++ b/src/game.c @@ -4563,6 +4563,25 @@ void GameActions() } DrawAllPlayers(); + + if (options.debug) /* calculate frames per second */ + { + static unsigned long fps_counter = 0; + static int fps_frames = 0; + unsigned long fps_delay_ms = Counter() - fps_counter; + + fps_frames++; + + if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */ + { + global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms; + + fps_frames = 0; + fps_counter = Counter(); + } + + redraw_mask |= REDRAW_FPS; + } } static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y) diff --git a/src/main.h b/src/main.h index 568e5c0e..dfec496c 100644 --- a/src/main.h +++ b/src/main.h @@ -247,6 +247,7 @@ struct OptionInfo boolean serveronly; boolean network; boolean verbose; + boolean debug; }; struct SetupJoystickInfo @@ -443,7 +444,7 @@ struct GameInfo struct GlobalInfo { - int dummy; + float frames_per_second; }; extern Display *display; @@ -1701,6 +1702,7 @@ extern char *element_info[]; #define REDRAW_MAIN (REDRAW_FIELD | \ REDRAW_TILES | \ REDRAW_MICROLEVEL) +#define REDRAW_FPS (1 << 10) #define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2) /* areas in bitmap PIX_DOOR */ diff --git a/src/misc.c b/src/misc.c index 8b86b89c..90bbe16a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -464,6 +464,10 @@ void GetOptions(char *argv[]) options.serveronly = FALSE; options.network = FALSE; options.verbose = FALSE; + options.debug = FALSE; + + /* initialize some more global variables */ + global.frames_per_second = 0; while (*options_left) { @@ -505,7 +509,7 @@ void GetOptions(char *argv[]) "Options:\n" " -d, --display machine:0 X server display\n" " -b, --basepath directory alternative base directory\n" - " -l, --level directory alternative level directory\n" + " -l, --level directory alternative level directory\n" " -s, --serveronly only start network server\n" " -n, --network network multiplayer game\n" " -v, --verbose verbose mode\n", @@ -557,6 +561,10 @@ void GetOptions(char *argv[]) { options.verbose = TRUE; } + else if (strncmp(option, "-debug", option_len) == 0) + { + options.debug = TRUE; + } else if (*option == '-') { Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str); diff --git a/src/tools.c b/src/tools.c index 685323c8..d4e42abb 100644 --- a/src/tools.c +++ b/src/tools.c @@ -99,6 +99,49 @@ void BackToFront() if (!redraw_mask) return; + + + if (1 && game_status == PLAYING) + { + static boolean last_frame_skipped = 0; + int fps_slowdown_factor = 2; + boolean skip_even_when_not_scrolling = 1; + boolean just_scrolling = (ScreenMovDir != 0); + boolean p = 0; + + /* + printf("ScreenMovDir = %d\n", ScreenMovDir); + */ + + /* + printf("ScreenGfxPos = %d\n", ScreenGfxPos); + */ + + if (fps_slowdown_factor > 1 && + (FrameCounter % fps_slowdown_factor) && + (just_scrolling || skip_even_when_not_scrolling)) + { + redraw_mask &= ~REDRAW_MAIN; + + if (p) + printf("FRAME SKIPPED\n"); + + last_frame_skipped = 1; + } + else + { + if (last_frame_skipped) + redraw_mask |= REDRAW_FIELD; + + last_frame_skipped = 0; + + if (p) + printf("frame not skipped\n"); + } + } + + + /* synchronize X11 graphics at this point; if we would synchronize the display immediately after the buffer switching (after the XFlush), this could mean that we have to wait for the graphics to complete, @@ -151,6 +194,7 @@ void BackToFront() #endif } } + redraw_mask &= ~REDRAW_MAIN; } @@ -207,6 +251,14 @@ void BackToFront() SX + x * TILEX, SY + y * TILEY); } + if (redraw_mask & REDRAW_FPS) /* display frames per second */ + { + char text[100]; + + sprintf(text, "%.1f fps", global.frames_per_second); + DrawTextExt(window, gc, SX, SY, text, FS_SMALL, FC_YELLOW); + } + FlushDisplay(); for(x=0; x