|
-
Jul 2nd, 2001, 10:22 PM
#1
Thread Starter
New Member
Frame Rate
I am building a game, and as most vb programs, there are a few event based aspects. But my engine is not. and I am trying to run my engine as fast as I can and for all of my events to happen. my first solution was to put it in a timer, but as you probably already know, a timer is not fast enough when it comes to redrawing the full screen in neccesary moments. I have implemented in my engine the following code:
dim events as boolean
...
events= false
do
DoEvents
if events = true then exit do
loop
...
'in every event I have implated the following
events = true
this work, as long as an event happens, but it does not give me a steady frame rate because it comes to a crwal when I'm doing nothing and when I move my mouse for example, it sky rockets... I want to know if there is a better way of knowing if the events have been completed??
any help would be greatly appreciated....
-
Jul 2nd, 2001, 10:28 PM
#2
Good Ol' Platypus
Well you could use the GetTickCount API declared in the Win32 API. Then to get the event-rate you want (not the framerate!), you do this:
VB Code:
Dim eFPS As Long
Dim A As Long
Dim B As Long
...
eFPS = 40
A = GetTickCount
Do
B = GetTickCount
DoEvents
If (B - A) >= (1000 / eFPS) Then
'Change Player Positions, etc.
End If
'Draw stuff, perform interpolation (make 3d animations smooth, etc.
A = GetTickCount
Loop
Okay. This code defines the events/second (40 event calls/second). Then it finds out the clock time. After doing this, it checks the clock time again to see if enough time has passed to make the events run at 40 events/second. If it has, then you get to do the events. Even if it hasn't you still draw the screen. Then it finds out the clock time again to compare.
I hope you understand
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Jul 3rd, 2001, 12:21 AM
#3
Be sure you separate game ticks from frames per second. Generally, a game loop looks like this:
Code:
While bRunning
If Update > GetTickCount Then
Start = GetTickCount + 30
'//Update game objects, etc
End If
'//Render Scene
DoEvents '//This will process all waiting windows messages,
'// Including any KeyDown Events, etc.
Wend
'//Cleanup
This way, everything runs at the same speed on any machine that can keep up, and renders the scene as fast as the machine can handle. Multiple frames can be rendered between game updates. DoEvents does exactly what it says =). When the program hits that, any KeyDowns, MouseMoves, etc get executed, and the game continues, so you dont need that "events = true" thing.
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|