diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8be34273f..3ad5bd6e1 100755 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D2X-Rebirth Changelog +20070826 +-------- +main/game.c, main/multi.c: Improved CPU cycles sleeping for -nicefps - moved out of main frame calc loop and taking care of 10ms timer inaccuracy + 20070824 -------- main/game.c, main/gamecntl.c, main/gamerend.c: allow framerate indicator to be toggled in-game again diff --git a/arch/sdl/mixdigi.c b/arch/sdl/mixdigi.c index 6f0f76fad..ca7b81361 100644 --- a/arch/sdl/mixdigi.c +++ b/arch/sdl/mixdigi.c @@ -143,7 +143,7 @@ int digi_start_sound(short soundnum, fix volume, int pan, int looping, int loop_ int mix_loop = looping * -1; if (MIX_DIGI_DEBUG) printf("digi_start_sound %d, volume %d, pan %d (start=%d, end=%d)\n", soundnum, mix_vol, mix_pan, loop_start, loop_end); -printf("%i, %i\n",(SoundChunks[soundnum]), mix_loop); + int channel = Mix_PlayChannel(-1, &(SoundChunks[soundnum]), mix_loop); Mix_SetPanning(channel, 255-mix_pan, mix_pan); Mix_SetDistance(channel, 255-mix_vol); diff --git a/main/game.c b/main/game.c index 7559022d9..96883a81d 100755 --- a/main/game.c +++ b/main/game.c @@ -154,12 +154,6 @@ int Speedtest_count=0; // number of times to do the debug test. static fix last_timer_value=0; fix ThisLevelTime=0; -#if defined(TIMER_TEST) && !defined(NDEBUG) -fix _timer_value,actual_last_timer_value,_last_frametime; -int stop_count,start_count; -int time_stopped,time_started; -#endif - ubyte VR_screen_flags = 0; //see values in screens.h fix VR_eye_width = F1_0; int VR_render_mode = VR_NONE; @@ -557,20 +551,10 @@ void stop_time() time = timer_get_fixed_seconds(); last_timer_value = time - last_timer_value; if (last_timer_value < 0) { - #if defined(TIMER_TEST) && !defined(NDEBUG) - Int3(); //get Matt!!!! - #endif last_timer_value = 0; } - #if defined(TIMER_TEST) && !defined(NDEBUG) - time_stopped = time; - #endif } timer_paused++; - - #if defined(TIMER_TEST) && !defined(NDEBUG) - stop_count++; - #endif } void start_time() @@ -580,19 +564,8 @@ void start_time() if (timer_paused==0) { fix time; time = timer_get_fixed_seconds(); - #if defined(TIMER_TEST) && !defined(NDEBUG) - if (last_timer_value < 0) - Int3(); //get Matt!!!! - #endif last_timer_value = time - last_timer_value; - #if defined(TIMER_TEST) && !defined(NDEBUG) - time_started = time; - #endif } - - #if defined(TIMER_TEST) && !defined(NDEBUG) - start_count++; - #endif } void game_flush_inputs() @@ -623,39 +596,39 @@ void calc_frame_time() { fix timer_value,last_frametime = FrameTime; - #if defined(TIMER_TEST) && !defined(NDEBUG) - _last_frametime = last_frametime; - #endif - timer_value = timer_get_fixed_seconds(); FrameTime = timer_value - last_timer_value; + // sleep for one frame to free CPU cycles if GameArg.SysUseNiceFPS is active. + if (GameArg.SysUseNiceFPS) + { + // Timer which sleeps for the time between frames but substracts 10ms timer inaccuracy. + // CPU usage not optimized, but more reliable to get desired FPS and smooth gameplay. + // Should probably replaced by a better solution. + int FrameDelay = (1000/GameArg.SysMaxFPS) // ms to pause between frames for desired FPS rate + - FrameTime/(F1_0/1000) // Substract the time the game needs to do it's operations + - 10; // Substract 10ms inaccuracy due to OS scheduling + + if (FrameDelay > 0) + SDL_Delay(FrameDelay); + } + while (FrameTime < f1_0 / GameArg.SysMaxFPS) { - if (GameArg.SysUseNiceFPS) - timer_delay(f1_0 / GameArg.SysMaxFPS - FrameTime); +// if (GameArg.SysUseNiceFPS) +// timer_delay(f1_0 / GameArg.SysMaxFPS - FrameTime); timer_value = timer_get_fixed_seconds(); FrameTime = timer_value - last_timer_value; } - #if defined(TIMER_TEST) && !defined(NDEBUG) - _timer_value = timer_value; - #endif - #ifndef NDEBUG if (!(((FrameTime > 0) && (FrameTime <= F1_0)) || (Function_mode == FMODE_EDITOR) || (Newdemo_state == ND_STATE_PLAYBACK))) { mprintf((1,"Bad FrameTime - value = %x\n",FrameTime)); if (FrameTime == 0) Int3(); // Call Mike or Matt or John! Your interrupts are probably trashed! -// if ( !dpmi_virtual_memory ) -// Int3(); //Get MATT if hit this! } #endif - #if defined(TIMER_TEST) && !defined(NDEBUG) - actual_last_timer_value = last_timer_value; - #endif - if ( Game_turbo_mode ) FrameTime *= 2; @@ -687,10 +660,6 @@ void calc_frame_time() #if Arcade_mode FrameTime /= 2; #endif - - #if defined(TIMER_TEST) && !defined(NDEBUG) - stop_count = start_count = 0; - #endif } //--unused-- int Auto_flythrough=0; //if set, start flythough automatically diff --git a/main/multi.c b/main/multi.c index a9c6c8f66..916eeaa18 100755 --- a/main/multi.c +++ b/main/multi.c @@ -1020,8 +1020,6 @@ multi_menu_poll(void) multi_in_menu--; - timer_delay(f0_1); // delay 100 milliseconds - if (Endlevel_sequence || (Control_center_destroyed && !was_fuelcen_alive) || (Player_is_dead != player_was_dead) || (Players[Player_num].shields < old_shields)) { multi_leave_menu = 1;