So here's the problem:
We all want to write games in REALbasic, but what do we use for our
game loop?
Timer's suck - they can't seem to get much above 30fps.
Tight loops suck because the app freezes and looks like it's crashed.
Threads suck because the new threads have considerably degraded
performance.
Tight loops with DoEvents called in them quite possibly suck more than
any of the above since they are the slowest.
Well I though I'd try something (on the grounds that it couldn't
possibly work otherwise someone else would have though of it). And
guess what? It works! (OS X only I'm afraid - might work on classic if
you change the declare lib, but I doubt it)
Put the following in the action event of a button. You'll need a
statictext in the window too:
Declare function WaitNextEvent lib "CarbonLib" (eventMask as short,
theEvent as ptr, sleep as integer, mouseRgn as integer) as boolean
dim t as double
dim evnt as MemoryBlock = newMemoryblock(16)
do
StaticText1.text = "FPS: " + str(1000000/(microseconds-t))
t = Microseconds
Refresh
call WaitNextEvent(-1, evnt, 0, 0)
loop
And here we have a tight loop running at about 100fps (on my machine
anyway), yet the window can still be moved and closed, and the app can
be quit!
Granted there are a few bugs such as crash-on quit's, but that's
probably easy to fix. Menus don't work at all either btw, but they
aren't much needed in games anyway.
Nick
_______________________________________________
Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|