realbasic-games
[Top] [All Lists]

A possible answer to performance woes?

To: REALbasic Games <REALbasic-Games at lists dot realsoftware dot com>
Subject: A possible answer to performance woes?
From: Nick Lockwood <nick at charcoaldesign dot co dot uk>
Date: Thu, 27 May 2004 03:51:59 +0100
Cc:
Delivered-to: REALbasic-Games at lists dot realsoftware dot com
List-help: <mailto:realbasic-games-request@lists.realsoftware.com?subject=help>
List-id: REALbasic Games <realbasic-games.lists.realsoftware.com>
List-post: <mailto:realbasic-games@lists.realsoftware.com>
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>

<Prev in Thread] Current Thread [Next in Thread>