diff --git a/SConstruct b/SConstruct index 4d2161ffd..3e43123a4 100755 --- a/SConstruct +++ b/SConstruct @@ -77,6 +77,7 @@ common_sources = [ 'arch/sdl/joydefs.c', 'arch/sdl/key.c', 'arch/sdl/mouse.c', +'arch/sdl/timer.c', 'cfile/cfile.c', 'iff/iff.c', 'main/ai.c', @@ -171,7 +172,6 @@ common_sources = [ 'mem/mem.c', 'misc/compare.c', 'misc/d_glob.c', -'misc/d_delay.c', 'misc/d_io.c', 'misc/d_slash.c', 'misc/dl_list.c', @@ -253,7 +253,6 @@ arch_linux_sources = [ 'arch/linux/linuxnet.c', 'arch/linux/mono.c', 'arch/linux/serial.c', -'arch/linux/timer.c', 'arch/linux/ukali.c', 'arch/sdl/clipboard.c' ] @@ -278,7 +277,6 @@ arch_win32_sources = [ 'arch/win32/midi.c', 'arch/win32/mono.c', 'arch/win32/serial.c', -'arch/win32/timer.c', 'arch/win32/winnet.c', 'arch/sdl/digi.c' ] diff --git a/arch/linux/init.c b/arch/linux/init.c index 9ef087cdb..65468cbe8 100755 --- a/arch/linux/init.c +++ b/arch/linux/init.c @@ -12,7 +12,6 @@ extern void arch_sdl_init(); extern void arch_svgalib_init(); extern void key_init(); extern int com_init(); -extern void timer_init(); void arch_init_start() { @@ -42,6 +41,5 @@ void arch_init() //added 06/09/99 Matt Mueller - fix nonetwork compile #endif //end addition -MM - timer_init(); key_init(); } diff --git a/arch/linux/timer.c b/arch/linux/timer.c deleted file mode 100755 index 34b8007be..000000000 --- a/arch/linux/timer.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include "maths.h" - -static struct timeval tv_old; - -fix timer_get_fixed_seconds(void) -{ - fix x; - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - x=i2f(tv_now.tv_sec - tv_old.tv_sec) + fixdiv(i2f((tv_now.tv_usec - tv_old.tv_usec)/1000), i2f(1000)); - return x; -} - -void timer_init(void) -{ - gettimeofday(&tv_old, NULL); -} diff --git a/arch/sdl/key.c b/arch/sdl/key.c index 9433c9705..836f618df 100755 --- a/arch/sdl/key.c +++ b/arch/sdl/key.c @@ -19,7 +19,6 @@ #include "error.h" #include "key.h" #include "timer.h" -#include "d_delay.h" #define KEY_BUFFER_SIZE 16 @@ -525,7 +524,7 @@ int key_inkey() key_data.keyhead = add_one(key_data.keyhead); } //added 9/3/98 by Matt Mueller to free cpu time instead of hogging during menus and such - else d_delay(1); + else timer_delay(1); //end addition - Matt Mueller return key; diff --git a/arch/sdl/timer.c b/arch/sdl/timer.c index c6d06393f..5808dd43b 100755 --- a/arch/sdl/timer.c +++ b/arch/sdl/timer.c @@ -1,12 +1,34 @@ -// SDL library timer functions +/* $Id: timer.c,v 1.1.1.1 2006/03/17 19:53:40 zicodxx Exp $ */ +/* + * + * SDL library timer functions + * + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include -#include #include "maths.h" +#include "timer.h" -fix timer_get_fixed_seconds(void) { - fix x; - unsigned long tv_now = SDL_GetTicks(); - x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000)); - return x; +fix timer_get_approx_seconds(void) +{ + return approx_msec_to_fsec(SDL_GetTicks()); } +fix timer_get_fixed_seconds(void) +{ + fix x; + unsigned long tv_now = SDL_GetTicks(); + x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000)); + return x; +} + +void timer_delay(fix seconds) +{ + SDL_Delay(f2i(fixmul(seconds, i2f(1000)))); +} diff --git a/arch/win32/init.c b/arch/win32/init.c index 7286b491c..21275d057 100755 --- a/arch/win32/init.c +++ b/arch/win32/init.c @@ -21,7 +21,6 @@ extern void arch_sdl_init(); extern void key_init(); extern int com_init(); -extern void timer_init(); void arch_init_start() { diff --git a/arch/win32/timer.c b/arch/win32/timer.c deleted file mode 100755 index 4b59a88df..000000000 --- a/arch/win32/timer.c +++ /dev/null @@ -1,71 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -// File nearly completely rewritten by dph-man - -#include -#include // DPH: We use timeGetTime from here... - -#include "types.h" -#include "maths.h" -#include "timer.h" - -static int Installed = 0; - -static unsigned long old_tv; - -fix timer_get_fixed_seconds() -{ - fix x; - - //Ye good olde unix: - //Ye bad olde Windows DPH:-) -/* DPH: Using timeGetTime will fail approximately 47 days after Windows was - started as the timer wraps around to 0. Ever had Windows not crash for 47 - consecutive days? Thought not. */ - - unsigned long tv_now=timeGetTime()-old_tv; - x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000)); - return x; -} - -void delay(int d_time) -{ - fix t, total; - - total = (F1_0 * d_time) / 1000; - t = timer_get_fixed_seconds(); - while (timer_get_fixed_seconds() - t < total) ; -} - -void timer_close() -{ - Installed = 0; -} - -void timer_init() -{ - - if (Installed) - return; - Installed = 1; - -/* DPH: Using timeGetTime will fail approximately 47 days after Windows was - started as the timer wraps around to 0. Ever had Windows not crash for 47 - consecutive days? Thought not. */ - old_tv=timeGetTime(); - -} - -// NOTE: This C file has been "neutered" by dph-man. If someone wants to work -// on this, feel free. I don't use joystick :-) diff --git a/include/d_delay.h b/include/d_delay.h deleted file mode 100755 index fc1556e94..000000000 --- a/include/d_delay.h +++ /dev/null @@ -1,17 +0,0 @@ -//added on 9/2/98 by Matt Mueller - -#ifndef _D_DELAY -#define _D_DELAY - -#if (defined(__LINUX__) || defined(__WINDOWS__)) -#define SUPPORTS_NICEFPS -#endif - -//#ifdef __LINUX__ - void d_delay (int ms); -/*#else -#include -#define d_delay delay -#endif - */ -#endif diff --git a/include/timer.h b/include/timer.h index 8febaf41b..4afb800c4 100755 --- a/include/timer.h +++ b/include/timer.h @@ -1,3 +1,4 @@ +/* $Id: timer.h,v 1.1.1.1 2006/03/17 20:01:31 zicodxx Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -7,55 +8,14 @@ IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ + /* - * $Source: /cvsroot/dxx-rebirth/d1x-rebirth/include/timer.h,v $ - * $Revision: 1.1.1.1 $ - * $Author: zicodxx $ - * $Date: 2006/03/17 19:46:29 $ * * Header for timer functions * - * $Log: timer.h,v $ - * Revision 1.1.1.1 2006/03/17 19:46:29 zicodxx - * initial import - * - * Revision 1.1.1.1 1999/06/14 22:02:21 donut - * Import of d1x 1.37 source. - * - * Revision 1.8 1994/12/10 12:27:23 john - * Added timer_get_approx_seconds. - * - * Revision 1.7 1994/12/10 12:10:25 john - * Added types.h. - * - * - * - * - * Revision 1.6 1994/12/10 12:07:06 john - * Added tick counter variable. - * - * Revision 1.5 1994/11/15 12:04:15 john - * Cleaned up timer code a bit... took out unused functions - * like timer_get_milliseconds, etc. - * - * Revision 1.4 1994/04/28 23:50:08 john - * Changed calling for init_timer. Made the function that the - * timer calls be a far function. All of this was done to make - * our timer system compatible with the HMI sound stuff. - * - * Revision 1.3 1994/02/17 15:57:12 john - * Changed key libary to C. - * - * Revision 1.2 1994/01/18 10:58:34 john - * Added timer_get_fixed_seconds - * - * Revision 1.1 1993/07/10 13:10:41 matt - * Initial revision - * - * */ @@ -74,11 +34,9 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. // interrupt rate. #define TIMER_FREQUENCY 1193180 -#if !defined (__MSDOS__) || defined(__GNUC__) #define _far #define __far #define __interrupt -#endif extern void timer_init(); extern void timer_close(); @@ -94,13 +52,14 @@ extern void timer_set_function( void _far * function ); // 1 hr, respectively. extern fix timer_get_fixed_seconds(); // Rolls about every 9 hours... -#ifdef __MSDOS__ +#ifdef __DJGPP__ extern fix timer_get_fixed_secondsX(); // Assume interrupts already disabled extern fix timer_get_approx_seconds(); // Returns time since program started... accurate to 1/120th of a second extern void timer_set_joyhandler( void (*joy_handler)() ); #else #define timer_get_fixed_secondsX timer_get_fixed_seconds -#define timer_get_approx_seconds timer_get_fixed_seconds +//#define timer_get_approx_seconds timer_get_fixed_seconds +extern fix timer_get_approx_seconds(); #endif //NOT_USED extern unsigned int timer_get_microseconds(); @@ -109,13 +68,15 @@ extern void timer_set_joyhandler( void (*joy_handler)() ); //NOT_USED extern unsigned int timer_get_milliseconds(); //NOT_USED extern unsigned int timer_get_millisecondsX(); // Assume interrupts disabled +void timer_delay(fix seconds); + //========================================================================== // Use to access the BIOS ticker... ie... i = TICKER -#ifdef __LINUX__ +#ifndef __DJGPP__ #define TICKER (timer_get_fixed_seconds()) #endif -#ifdef __MSDOS__ +#ifdef __DJGPP__ #ifndef __GNUC__ #define TICKER (*(volatile int *)0x46C) @@ -127,4 +88,10 @@ extern void timer_set_joyhandler( void (*joy_handler)() ); #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames) #endif + +#define approx_usec_to_fsec(usec) ((usec) >> 4) +#define approx_fsec_to_usec(fsec) ((fsec) << 4) +#define approx_msec_to_fsec(msec) ((msec) << 6) +#define approx_fsec_to_msec(fsec) ((fsec) >> 6) + #endif diff --git a/main/automap.c b/main/automap.c index cbaf7e9d7..4e9be8fd2 100755 --- a/main/automap.c +++ b/main/automap.c @@ -69,7 +69,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "network.h" #include "newmenu.h" #include "cntrlcen.h" -#include "d_delay.h" +#include "timer.h" #include "automap.h" #define EF_USED 1 // This edge is used @@ -648,7 +648,7 @@ void do_automap( int key_code ) { while (t2 - t1 < F1_0 / 100) // ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :) { if (nice_automap) - d_delay(1); + timer_delay(1); t2 = timer_get_fixed_seconds(); } diff --git a/main/game.c b/main/game.c index 68364085b..100e805ad 100755 --- a/main/game.c +++ b/main/game.c @@ -102,7 +102,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "gr.h" #include "reorder.h" #include "hudmsg.h" -#include "d_delay.h" +#include "timer.h" #include "cdplay.h" #include "hudlog.h" #ifdef NETWORK @@ -995,12 +995,15 @@ void calc_frame_time() _last_frametime = last_frametime; #endif - do { + timer_value = timer_get_fixed_seconds(); + FrameTime = timer_value - last_timer_value; + + while (FrameTime < f1_0 / maxfps) + { + timer_delay(f1_0 / maxfps - FrameTime); timer_value = timer_get_fixed_seconds(); FrameTime = timer_value - last_timer_value; - if (use_nice_fps && FrameTime - -void d_delay (int ms) { - Sleep(ms); -} - -#else - -#include -#include -#include -#include - -void d_delay (int ms) { -#if 0 - struct timeval tv; - tv.tv_sec=ms/1000; -//edited 02/06/99 Matt Mueller - microseconds, not milliseconds - tv.tv_usec=(ms%1000)*1000; -//end edit -MM - select(0,NULL,NULL,NULL,&tv); -#elif 0 - struct timespec tv; - tv.tv_sec=ms/1000; - tv.tv_nsec=(ms%1000)*1000000;//nanoseconds - nanosleep(&tv,NULL); -#else - usleep(ms*1000); -#endif -} - -#endif -#endif