Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Elliott Lee Newsgroups: scee.yaroze.beginners Subject: Re: Questions about VSync. Date: Tue, 12 May 1998 13:24:59 -0700 Organization: Cisco Systems Lines: 69 Message-ID: <3558B01B.A01C8CF3@netmagic.net> References: <354C8851.709D2E83@chowfam.demon.co.uk> <6ij6jd$jpr18@chuka.playstation.co.uk> <354D8AA7.17CA37C6@chowfam.demon.co.uk> <354E298F.2865CC25@netmagic.net> <354E4EA8.A92F3D10@chowfam.demon.co.uk> <3557BAFE.CD170013@ndirect.co.uk> Reply-To: tenchi@cisco.com NNTP-Posting-Host: dhcp-e-39-237.cisco.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; U) Heya, There's a better way than to just slap random digits on the end and it's ACCURATE! (I just implemented this for a real-time clock so I know it works.) Cut and paste this code snippet into the appropriate places: // put in your constants definitions /* #define VIDEO_REFRESH 60 */ #define VIDEO_REFRESH 50 // put in your variable declarations char TimerBuf[8+1]; long RunningClock=0; // this is your main program loop while( ...whatever... ) { // to calculate the minutes, seconds, and hundredths: RunningClock++; sprintf( TimerBuf,"%0.2d:%0.2d.%0.2d", (RunningClock/VIDEO_REFRESH)/60, // mins (RunningClock/VIDEO_REFRESH)%60, // secs ((RunningClock*100)/VIDEO_REFRESH)%100 // 100ths ) // now print out the TimerBuf somehow... } // end of the while... Of course, you could increase the TimerBuf's storage space to 10+1 and change the 100ths to 1000ths or 10000ths, but that's your option. This is pretty accurate as long as you don't miss a video frame. And, if you do, say, 25 FPS, then just change the VIDEO_REFRESH to 25. etc. etc. etc... ^_^ Alex Herbert wrote: > > James Chow wrote: > > > I know it's not a good way to do timing, but are there any other > > suggestions of how to get a finer resolution than 1/50th sec > > or 1/60th sec? But not too fine, eg. using the root counter, which > > flies past like f*** and has probably "gone round" a few > > times before you've checked again. > > > > Games like Ridge Racer have timers going down to 1/1000th sec > > resolution. Now how to do they manage that? > > Personally I find using vsync(-1) + rand()/RAND_MAX > > a bit too tacky. > > > > Cheers. > > -- > > jc > > All games (with only a few exceptions) are clocked to 50 or 60Hz (PAL or > NTSC). There is no point it having a higher resolution timer. Ridge Racer is > only clocked at 25Hz ('cos it updates every other frame). It's just an > illusion. Clock your game at 50Hz with vsync() and slap some random digits > on the end. No one will notice! > > Herbs -- - e! tenchi@netmagic.net http://www.netmagic.net/~tenchi/yaroze/