Hi;
I must say that the trick explained is technically perfect for any Hz rate.
I mean, that this trick allows to liberate CPU from those rendering-task surplus millisecs used and bad-wasted by FlipBuffers() command and by DX7 Vsync functions.
What that this trick do while Vsync time is to ensure rendering time is not cutted while ensures rendering surplus time is not CPU badwasted (of course, ensuring
tearing effect free too)
Perhaps you have inserted it in a bad way.
1) You must insert this
before you open the graphics screen in your code:
Code: Select all
Global t1.LARGE_INTEGER,t2.LARGE_INTEGER,SysFreq.LARGE_INTEGER,MustDelay.f,DispFreq.l
#ENUM_CURRENT_SETTINGS = -1
If QueryPerformanceFrequency_(@SysFreq.LARGE_INTEGER)=0
MessageRequester("Sorry","No High-res timer allowed"):End
EndIf
QueryPerformanceCounter_(@t1.LARGE_INTEGER);<- checkpoint1
!macro myFlipBuffers{
QueryPerformanceCounter_(@t2.LARGE_INTEGER);<- checkpoint2
!fld1
!fidiv dword[v_DispFreq];<-now in st0 is seconds amount per screen frame
!fild qword[v_t2];<-now in st0 is checkpoint2. In st1 is seconds amount per screen frame
!fild qword[v_t1];<-now in st0 is checkpoint1. in st1 is checkpoint2. In st2 is seconds amount per screen frame
!fsubp;<-now in st0 is checkpoint2-checkpoint1. In st1 is seconds amount per screen frame
!fild qword[v_SysFreq];<-now in st0 is SysFreq. In st1 is checkpoint2-checkpoint1. In st2 seconds amount per screen frame
!fdivp ;<-now in st0 is (checkpoint2-checkpoint1)/SysFreq. In st1 is seconds amount per screen frame
!fsubp ;<-now in st0 is 1/DispFreq-(checkpoint2-checkpoint1)/SysFreq.
!fstp dword[v_MustDelay];<- MustDelay.f=1/DispFreq-(checkpoint2-checkpoint1)/SysFreq.
MustDelay.f*1000
If MustDelay.f>1
Sleep_(Int(MustDelay.f))
EndIf
FlipBuffers()
QueryPerformanceCounter_(@t1.LARGE_INTEGER);<- checkpoint1
!}
2) You must insert this
after open the graphics screen in your code:
Code: Select all
; ----------------------------------------------------------------------------------------------------
;NOTE next line must be executed after screen is open:
EnumDisplaySettings_(#NULL,#ENUM_CURRENT_SETTINGS,@dm.DEVMODE):DispFreq.l=dm\dmDisplayFrequency
3) You must replace FlipBuffers() command in the MAIN program section by !myFlipBuffers
That's all
And Well; even technically perfect, this trick is not efficiently perfect: since current PCs system time resolution is 1 millisec for the Sleep_() or Delay() functions, there are a portion time less than 1 millisec which is badwasted by FlipBuffers() function existing in my routine, but always less than 1 millisec/frame will be badwasted.
On the other hand there is another different solution for your games, etc. which consists in adding static delay time just after FlipBuffers(); a Delay(16), Delay(15), or less values if machine is slow, or if rendering task are too hard (the higher delay value, the less time badwasted, but faster machine is required). This method allows graphics movements to go smooth on fastest computers, but jerky on slower machines. Try values from Int(1000/Refresh Rate) down to 1 by 1, and watch how smooth is going.