Code: Select all
t = timer: Do: Loop while t > timer
Any help is appreciated.
Code: Select all
t = timer: Do: Loop while t > timer
Code: Select all
sleep n
Code: Select all
for x = 1 to num_of_ms
sleep 1
next x
This is at least approximately correct for the timer used by the FB Sleep function, which AFAIK uses the “system timer” under Windows, but not for the high-resolution performance counter that is used by the FB Timer function under Windows on most recent systems. Per Microsoft, the system timer has a period of approximately 55ms under Windows 95/98/Me, and approximately 10ms under the later versions. Assuming the high-resolution performance counter is available, this code should return the resolution of the Sleep function, essentially 10ms on my Windows 2000 system.Timer resolution isn't 1 millisecond. It can vary anywhere between 5-50ms.
Code: Select all
dim as integer i
dim as double t,tot
for i = 1 to 1000
t = timer
sleep 1
tot += timer - t
next
print using "sleep resolution = ##.###ms";tot
sleep
Code: Select all
'' How many Frames Per Second we want
Dim as integer FPS = 60
'' Holds how long a frame is
Dim as Double SingleFrame = ( 1 / FPS )
'' Holds the time of the last frame
Dim as Double LastTime = Timer
'' Main Loop
Do
'' Loop until one frame has passed by
Do
'' Save CPU while waiting for the frame to pass
Sleep 1, 1
Loop until ( Timer - LastTime ) >= SingleFrame
'' Print our estimated fps ( 1 / Amountoftimeframetook )
locate 1, 1
Print "Estimated FPS: " & ( 1 / ( Timer - LastTime ) )
'' Save the new time in our variable for comparison
LastTime = Timer
Loop until Multikey(&h01)
I could argue that the FB Sleep function is calling the API, but instead…Since no one is answering the API question I assume no one cares.
Code: Select all
#include "windows.bi"
'' In winbase.bi the Windows Sleep function has been
'' renamed to to Sleep_, I assume to avoid a name
'' conflict with the FB Sleep function.
dim as integer i
dim as double t,tot
for i = 1 to 1000
t = timer
Sleep_ 1
tot += timer - t
next
print using "Sleep_ resolution = ##.###ms";tot
sleep
Code: Select all
t = Timer + 2: Do: Loop While t > Timer
Code: Select all
t = Timer + 2: Do: Sleep 1: Loop While t > Timer