removed d_delay, now using timer_delay as wrapper for SDL_Delay

This commit is contained in:
zicodxx 2007-03-25 21:00:14 +00:00
parent 91d32b1a9d
commit 6b84e27046
20 changed files with 83 additions and 260 deletions

View file

@ -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'
]

View file

@ -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();
}

View file

@ -1,19 +0,0 @@
#include <sys/time.h>
#include <stdio.h>
#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);
}

View file

@ -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;

View file

@ -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 <conf.h>
#endif
#include <SDL.h>
#include <SDL/SDL.h>
#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))));
}

View file

@ -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()
{

View file

@ -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 <windows.h>
#include <mmsystem.h> // 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 :-)

View file

@ -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 <dos.h>
#define d_delay delay
#endif
*/
#endif

View file

@ -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

View file

@ -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();
}

View file

@ -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<F1_0/maxfps)
d_delay(1);
} while (FrameTime<F1_0/maxfps);
}
#if defined(TIMER_TEST) && !defined(NDEBUG)
_timer_value = timer_value;
@ -1775,7 +1778,7 @@ int do_game_pause(int allow_menu)
SDL_WM_GrabInput(SDL_GRAB_OFF);
while (paused) {
d_delay(1);
timer_delay(1);
#ifdef OGL
show_boxed_message(TXT_PAUSE);
#endif

View file

@ -133,7 +133,6 @@ static char *__reference[2]={copyright,(char *)__reference};
#include "strutil.h"
#include "altsound.h"
#include "../texmap/scanline.h" //for select_tmap -MM
#include "d_delay.h"
#include "vers_id.h"
#include "collide.h"

View file

@ -62,10 +62,8 @@ static char rcsid[] = "$Id: kconfig.c,v 1.1.1.1 2006/03/17 19:44:27 zicodxx Exp
#include "key.h"
#include "gr.h"
#include "reorder.h"
#include "d_delay.h"
#include "physics.h"
#include "vlcnfire.h"
#include "d_delay.h"
#ifdef OGL
#include "ogl_init.h"
@ -644,7 +642,7 @@ void kconfig_sub(kc_item * items,int nitems, char * title)
while(1)
{
d_delay(5);
timer_delay(5);
gr_set_current_canvas(NULL);
#ifdef OGL
@ -1121,7 +1119,7 @@ void kc_change_key( kc_item * item )
// GameLoop( 0, 0 ); // Continue
k = key_inkey();
//added/changed on 9/2/98 by Matt Mueller
d_delay(10);
timer_delay(f0_1/10);
//end change -MM
kc_drawquestion( item );
@ -1179,7 +1177,7 @@ void kc_change_joybutton( kc_item * item )
// GameLoop( 0, 0 ); // Continue
k = key_inkey();
//added/changed on 9/2/98 by Matt Mueller
d_delay(10);
timer_delay(f0_1/10);
//end change -MM
if (k == KEY_PRINT_SCREEN)
@ -1255,7 +1253,7 @@ void kc_change_mousebutton( kc_item * item )
// GameLoop( 0, 0 ); // Continue
k = key_inkey();
//added/changed on 9/2/98 by Matt Mueller
d_delay(10);
timer_delay(f0_1/10);
//end change -MM
if (k == KEY_PRINT_SCREEN)
@ -1354,7 +1352,7 @@ void kc_change_joyaxis( kc_item * item )
// if ( Game_mode & GM_MULTI )
// GameLoop( 0, 0 ); // Continue
k = key_inkey();
d_delay(10);
timer_delay(f0_1/10);
if (k == KEY_PRINT_SCREEN)
save_screen_shot(0);
@ -1429,7 +1427,7 @@ void kc_change_mouseaxis( kc_item * item )
// GameLoop( 0, 0 ); // Continue
k = key_inkey();
//added/changed on 9/2/98 by Matt Mueller
d_delay(10);
timer_delay(f0_1/10);
//end change -MM
if (k == KEY_PRINT_SCREEN)

View file

@ -141,7 +141,6 @@ static char rcsid[] = "$Id: kmatrix.c,v 1.1.1.1 2006/03/17 19:44:38 zicodxx Exp
#include "pcx.h"
#include "network.h"
#include "hudlog.h"
#include "d_delay.h"
#ifdef OGL
#include "ogl_init.h"
@ -313,7 +312,7 @@ void kmatrix_view(int network)
done = 0;
while(!done) {
d_delay(5);
timer_delay(5);
kmatrix_redraw();
for (i=0; i<4; i++ )

View file

@ -79,21 +79,10 @@ static char rcsid[] = "$Id: menu.c,v 1.1.1.1 2006/03/17 19:43:27 zicodxx Exp $";
#include "config.h"
#include "reorder.h"
#include "d_glob.h"
#include "cfile.h"
//added on 9/20/98 by Victor Rachels in attempt to add screnres changing
#include "gauges.h"
//end this section addition - Victor Rachels
//add on 2/2/99 by Victor Rachels
#include "ban.h"
//end this section addition
#include "hudmsg.h" //for HUD_max_num_disp
#include "d_delay.h" //for SUPPORTS_NICEFPS
#include "ipx.h"

View file

@ -1118,16 +1118,17 @@ multi_menu_poll(void)
multi_in_menu--;
// t1 = timer_get_fixed_seconds();
// while (timer_get_fixed_seconds() < t1+F1_0/20)
// ;
// only allow faster framerates if exploded to prevent
// possible cheating using the higher framerate -- adb
//added/changed by ADB for getting rid of TICKER
t1 = timer_get_fixed_seconds() + F1_0/20;
while (timer_get_fixed_seconds() < t1 && (!Player_exploded || !key_checkch()))
;
//end change - ADB
// // t1 = timer_get_fixed_seconds();
// // while (timer_get_fixed_seconds() < t1+F1_0/20)
// // ;
// // only allow faster framerates if exploded to prevent
// // possible cheating using the higher framerate -- adb
// //added/changed by ADB for getting rid of TICKER
// t1 = timer_get_fixed_seconds() + F1_0/20;
// while (timer_get_fixed_seconds() < t1 && (!Player_exploded || !key_checkch()))
// ;
// //end change - ADB
timer_delay(f0_1); // 100 ms
if (Endlevel_sequence || (Fuelcen_control_center_destroyed && !was_fuelcen_alive) || (Player_is_dead && !Player_exploded) || (Players[Player_num].shields < old_shields))
{

View file

@ -56,7 +56,6 @@ static char rcsid[] = "$Id: newmenu.c,v 1.1.1.1 2006/03/17 19:44:42 zicodxx Exp
#include "d_io.h"
#include "timer.h"
#include "vers_id.h"
#include "d_delay.h"
#ifdef OGL
#include "ogl_init.h"
@ -801,7 +800,7 @@ int newmenu_do3_real( char * title, char * subtitle, int nitems, newmenu_item *
#endif
while(!done) {
d_delay(5);
timer_delay(5);
#ifdef OGL
gr_flip();
@ -1642,7 +1641,7 @@ ReadFileNames:
#endif
while(!done) {
d_delay(5);
timer_delay(5);
ocitem = citem;
ofirst_item = first_item;
gr_update();
@ -2042,7 +2041,7 @@ int newmenu_listbox1( char * title, int nitems, char * items[], int allow_abort_
#endif
while(!done) {
d_delay(5);
timer_delay(5);
#ifdef OGL
gr_flip();
nm_draw_background1(NULL);

View file

@ -272,7 +272,6 @@ static char rcsid[] = "$Id: scores.c,v 1.1.1.1 2006/03/17 19:42:39 zicodxx Exp $
#include "timer.h"
#include "text.h"
#include "d_io.h"
#include "d_delay.h"
#ifdef OGL
#include "ogl_init.h"
@ -604,7 +603,7 @@ ReshowScores:
looper = 0;
while(!done) {
d_delay(5);
timer_delay(5);
gr_set_current_canvas(NULL);
#ifdef OGL
gr_flip();

View file

@ -47,7 +47,7 @@ static char rcsid[] = "$Id: titles.c,v 1.2 2006/03/18 23:08:13 michaelstather Ex
#include "newmenu.h"
#include "state.h"
#include "gameseq.h"
#include "d_delay.h"
#ifdef OGL
#include "ogl_init.h"
#endif
@ -782,7 +782,7 @@ int show_briefing_message(int screen_num, char *message)
}
while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
;
d_delay(5);
timer_delay(5);
#ifdef OGL
gr_flip();
gr_clear_canvas(255);
@ -917,7 +917,7 @@ int show_briefing_message(int screen_num, char *message)
}
while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
;
d_delay(5);
timer_delay(5);
#ifdef OGL
gr_flip();
gr_clear_canvas(255);

View file

@ -1,40 +0,0 @@
//added on 9/2/98 by Matt Mueller
#include "d_delay.h"
#ifndef d_delay
#ifdef __WINDOWS__
#include <windows.h>
void d_delay (int ms) {
Sleep(ms);
}
#else
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
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