Hertz and Flip

BlitzMax Forums/BlitzMax Beginners Area/Hertz and Flip

Grey Alien(Posted 2006) [#1]
Sorry if this has been asked before...

To me it seems great that I can make a full-screen action game and fix it to 60Hz and thus not bother with delta timing due to different PCs having different refresh rates. This also means I can have totally smooth scrolling and movement. Is setting at 60Hz not recommended though? How reliable is it on a wide range of PCs? Any known issues?

I realise that if I made a game with a windowed mode, that windowed mode would run at whatever frequency the desktop wsa set to, and thus delta timing is required.

OK, Flip, seems there are 3 options and the default is -1, so a standard graphics window with flip at 60Hz then? What are the advantages of 0 and 1, why would I want to use them? Which is best on most hardware and doesn't cause any tearing or weird artifacts?

Also, whilst I'm at it, can someone explain the difference between GLGraphicsDriver, GLMax2DDriver and D3D7Max2DDriver to a noob? Thanks in advance! :-)


Gabriel(Posted 2006) [#2]
I don't see how you *can* "not bother with delta timing". If I disable VSync in my drivers ( as some people do ) then there's nothing you can do to make the game play at 60hz on my machine, is there?


Robert Cummings(Posted 2006) [#3]
I don't bother with delta timing. I use fixed rate logic. It works on slow and fast pcs.


xlsior(Posted 2006) [#4]
Sorry if this has been asked before...

To me it seems great that I can make a full-screen action game and fix it to 60Hz and thus not bother with delta timing due to different PCs having different refresh rates. This also means I can have totally smooth scrolling and movement. Is setting at 60Hz not recommended though? How reliable is it on a wide range of PCs? Any known issues?


On my previous PC I had all my refreshrates fixed at 100Hz -- since my old trinitron worked great at 100 and 120Hz, but made a really high-pitched whining noise at any refreshrate lower than that. The rest of the family couldn't hear it, but I could tell hear it squeal from the other side of the house myself. Extremely annoying.
Anyway, to address that issue, I installed a monitor driver that told my system that the only refreshrate supported in any video mode was 100Hz -- other video modes simply weren't available.

Maybe a bit unique of a setup, but it does go to show that you can't count on 60Hz being universally available.

Now, before artificially locking it to 100Hz, 60Hz technically worked, but due to those squealing noises it made it unbearable to actually play anything in that mode.


Grey Alien(Posted 2006) [#5]
I thought I read *somewhere* that Max attempts to keep the Vsync to the Hz specified in Graphics (by using timing methods), even if the machine has Vsync Disabled or is running at a different refresh rate. Anyone else hear this?

One Eyed Jack: What's Fixed rate timing? Is it like the "retro 64" method which I currently used?

xlsior: so you are saying that even if you specify 60Hz in Max, your fresh rate is still 100Hz? Have you tried setting it to 60Hz with graphics and then using flip -1 and then measuring the FPS. Would it be 100 or 60 I wonder?


Dreamora(Posted 2006) [#6]
FPS and refresh rate are independent!

flip -1 says the grahpics card not to wait for the LCD/TFT to finish updating. In that case, you will get the maximum fps your card can generate.

If you do flip true then it will run on the screens maximum.

I don't use herzt on my system at all as it is not really able to get the herzt of 60hz notebook displays at all.

Beside that: This is completely useless to make stuff on the same speed anywhere. The graphic card defines the fps in the ned, not the TFT. The TFT only says how many different pictures you can get in maximum


Grey Alien(Posted 2006) [#7]
hmm, I'm not sure I got that. The manual says
If sync is -1 and the current graphics object was created with the Graphics command, then flips will occur at the graphics object's refresh rate - regardless of whether or not the graphics hardware supports such a refresh rate.
so I don't see how this would result in the "maximum". Maybe flip 0 would.


Yan(Posted 2006) [#8]
I believe the new Flip works like so...

Flip -1 = SOFTSYNC
Flip 1 = HARDSYNC
Flip 0 = NOSYNC


Grey Alien(Posted 2006) [#9]
yeah I get that thanks. What I originally asked was:

What are the advantages of 0 and 1, why would I want to use them? Which is best on most hardware and doesn't cause any tearing or weird artifacts?

Although I assume -1 is the best otherwise it wouldn't be default right? Speaking of defaults, the graphics command has a default of 60Hz too, if this was so bad, why is it the default? I'm just wondering if it's viable to make a 60Hz full-screen arcade game that will run on almost all systems fine.

this thread seems to just be opening up more questions than it closes!


Yan(Posted 2006) [#10]
yeah I get that thanks.
You clearly don't. ;o)

so you are saying that even if you specify 60Hz in Max, your fresh rate is still 100Hz? Have you tried setting it to 60Hz with graphics and then using flip -1 and then measuring the FPS. Would it be 100 or 60 I wonder?
It should be 60...

Strict

Graphics 800, 600, 32, 15

Local x#, y#
Local xv# = Rnd(-4, 4), yv# = Rnd(-4, 4)
Local flipVar = -1
Local refreshRate = GetDeviceCaps(GetDC(PrimaryDevice.hWnd), VREFRESH)

Repeat
	x# :+ xv#
	If (x# < 0) Or (x# > 799)
		xv# = -xv#
		x# :+ xv#
	EndIf 
	
	y# :+ yv#
	If (y# < 0) Or (y# > 599)
		yv# = -yv#
		y# :+ yv#
	EndIf
	
	If KeyHit(KEY_SPACE)
		flipVar :+ 1
		If flipVar > 1 Then flipVar = -1
	EndIf
	
	Cls
	DrawOval x# - 15, y# - 15, 30, 30
	
	DrawText "Flip = " + flipVar, 12, 12
	DrawText "Screen Refresh = " + refreshRate, 12, 24
	
	Flip flipVar
Until KeyHit(KEY_ESCAPE)

End



Grey Alien(Posted 2006) [#11]
Ian: yeah sorry that question was Aimed at Xlsior who said he had his monitor fixed at 100Hz. However you demo does show me something. With Flipvar -1, the animation is clearly at 15Hz and my refresh is 85. With 0, it's at full speed, and with 1, it's very smooth thus must be at 85.

So basically if you call graphics at 60Hz and use Flip -1, if the user's refresh rate is 60, they'll get a nice smooth game, and if it's different from 60, BlitzMax will still keep the Flips occuring every 60 so the gameplay will be the same speed, just not "smooth" looking due to the discrepancy between refresh rate and the 60Hz flipping that Blitz is trying to do for you independant of the refresh rate. Does this sound correct now?


Yan(Posted 2006) [#12]
Aye!...Hence, Softsync...I probably should have made that clearer in my previous post. :o)

I used 15Hz in the demo to guarantee that it wouldn't be available and to make the difference between softsync and hardsync obvious.

The situation should be exactly the same for xlsior. He would see a 60Hz/FPS update with a 100Hz screen refresh.


Grey Alien(Posted 2006) [#13]
That's great thanks ian. Clears that one up at least. Now for the other questions ...


Yan(Posted 2006) [#14]
I'm by no means an expert on this stuff but from previous threads on this, I understand that:

The smoothest method is to use a hertz value of -1 (should be default refresh at that screen res) and use a fixed logic loop, as you've been doing, with flip 1.

Delta timing with flip 0 will give you the most control over the widest range of hardware but can look a bit juddery on occasions and can suffer from tearing.

Relying on a 60hz softsync can lead to screen flicker or juddery graphics too.

So, I'd suggest you search the forums and make your own mind up as to which method to use.



AFAIK, GlGraphics and DXGraphics handle the low level screen and window set up for the relative API.

GLMax2dDriver and D3D7Max2DDriver handle all the high level Max2D graphics stuff, Drawtext, DrawImage, etc.


Grey Alien(Posted 2006) [#15]
Hmm, so just call Graphics 800,600,32,-1 so it runs at the native Hz for that monitor and then Flip 1 means it VSync's with the refreshrate(Hz). Then a fixed logic loop to control the game speed. Means scrolling and animation won't be perfectly smooth, but pretty good. Oh well, I was just trying to figure out if I could reach my holy grail of choosing a 60Hz display and syncing the gamplay to it for perfectly smooth scrolling/animation like the old Amiga days. I bet this would for *most* people, just not everyone sigh ...

Thanks for the info Ian.


xlsior(Posted 2006) [#16]
so you are saying that even if you specify 60Hz in Max, your fresh rate is still 100Hz? Have you tried setting it to 60Hz with graphics and then using flip -1 and then measuring the FPS. Would it be 100 or 60 I wonder?


Not sure, don't have that graphics card & monitor anymore, so don't have those drivers set up.

It would stay at a 100Hz sync all the time, the OSD display would confirm that refresh rate... I got an LCD before I had BMax, so that issue kind of went away before I started playing with its screen updates.

I would assume that it simply wouldn't list any <100Hz mode under GetGraphicsModes...


BlackSp1der(Posted 2006) [#17]
Grey, can you explain how the retro64 method works?


Grey Alien(Posted 2006) [#18]
This thread and article describes it well.

http://www.blitzbasic.com/Community/posts.php?topic=57977

here's mine from Easter Bonus (Blitz Plus):

	;timing vars
	Global LastTime%
	Global NumTicks#
	Global LastNumTicks#

Function InitTimingVars()
	;set a first value for LastTime (it will be used in the main loop)
	LastTime = MilliSecs()/MS
	NumTicks = 0
	LastNumTicks = 1	
End Function

	InitTimingVars()
	
	Repeat
		If DoVWait Then
			;for our purposes, a tick is based on FRAMERATE
			;get in the time and make sure at least 1 tick expired
			Repeat
				TmpMS = MilliSecs()/MS
		
				;little sanity check here in case the timer flips back to 0 :)
				If TmpMS < LastTime Then LastTime = TmpMS - LastNumTicks
		
				NumTicks = TmpMS - LastTime
			Until NumTicks > 0
			LastTime = TmpMS
			;account for when the user alt-tabs :)
			;If NumTicks > 500 Then NumTicks = LastNumTicks
			If NumTicks > 50 Then NumTicks = 50 ;LastNumTicks ;Laptop runs at 7 in windowed mode
			LastNumTicks = NumTicks		
			If NumTicks > MaxTicks Then MaxTicks = NumTicks
		EndIf
		
		;now we do the logic loop ... from 1 not 0!
		;don't do ticks as it @#!*s things up
		For i = 1 To NumTicks

                     ;logic
                Next

                DrawStuff()
                Flip
	Until LoopExit <> 0