Path: chuka.playstation.co.uk!news From: Alex Herbert Newsgroups: scee.yaroze.beginners Subject: Re: Questions about VSync. Date: Wed, 13 May 1998 00:38:58 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 70 Message-ID: <3558DD92.8524211E@ndirect.co.uk> 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> <3558B01B.A01C8CF3@netmagic.net> Reply-To: aherbert@ndirect.co.uk NNTP-Posting-Host: dialin0-14.ndirect.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) To: tenchi@cisco.com Elliott Lee wrote: > 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... > Hello again. Two things. 1. What is the point in actually clocking at a higher rate than your frame rate? The person playing the game is responding to what was drawn 2 frames ago, and the game situation and display only change once per frame. How much accuracy can a game under these conditions need? 2. In your example code you use RunningClock which is incremented once per frame. So, your counter is clocked at the same rate as your frame rate. Therefore it is not any more acurate. With a video refresh of 50Hz and a frame rate of 50Hz, your hundredths will always be even numbers. If you extend it to thousandths of a second, then they will always be multiples of 20. If you extend it further to 10,000ths, then multiples of 200 - the last 2 digits will always be 0! Is that more accurate? Futhermore, if you reduce your frame rate to 25fps, then the accuracy is halved. Your timer's accuracy is always restricted to the frame rate. You are simply adjusting the scale of your frame counter, not increasing the accuracy. Remember, creating a game is about creating illusion. If you want to give the illusion that your timer is more accurate than your frame rate, then my original suggestion is the easiest way. Herbs PS. Sorry if that sounds rude or big headed - not my intention. :)