Timing

Blitz3D Forums/Blitz3D Beginners Area/Timing

thalamus(Posted 2004) [#1]
Ok, I'm trying to get my head around timing and keeping an even framerate, and I'm more than a little confused.

The way I see it, you create a timer with CreateTimer(x), where X is the FPS you require.

Then, you can either use WaitEvent or WaitTimer to check the timer. If you use Waitevent, your program can still receive events until the end of the frame. If you use WaitTimer, all activities cease until the next frame.

But, as the docs say: "You should never use the WaitTimer AND WaitEvent methods of controlling speed at the same time, as you will 'lose' ticks."

So which is the best system? Presumably, WaitTimer is best for games and WaitEvent best for GUI stuff?

So where does Vwait come into things? Is Vwait purely to stop your graphics being updated mid-screen?


soja(Posted 2004) [#2]
In BlitzPlus (WaitEvent doesn't apply to Blitz3D), I use WaitEvent exclusively. The only reason I can see not using it is for backwards compatibility with Blitz2D.

You are correct in your other assumptions.

I usually start with a loop like this:
CreateTimer(60)
InitGui()
InitGame()

Repeat
	Select WaitEvent()
		Case $803 : End
		; other cases here (input, etc)
		Case $4001
			Logic()
			Update()
			Render()
	End Select
Forever


You can even enclose the Select WaitEvent() block in a Select GameState block, along with more Select WaitEvent() blocks for other states.


thalamus(Posted 2004) [#3]
Well, that sort of answers my next question: the Editor I'm writing started off as a full-screen app, then moved to a window, then I added GUI functionality (basically it progressed like this as I was learning Blitz+).

At the moment I have a "Code" section which clears the canvases, updates the map, checks the controls, and updates the cursor. This is followed by a WaitEvent loop, which contains the GUI checks. At the bottom, if Escape hasn't been pressed, it goes back to the Code section and so forth.

Am I right in my assumption that everything should be done within the WaitEvent loop? I have a control routine, for instance, that checks keypresses and initiates the relevant drawing tool - this should be done using Event checks?

(Thanks for your help, by the way soja - immensely useful :) )


soja(Posted 2004) [#4]
Am I right in my assumption that everything should be done within the WaitEvent loop? I have a control routine, for instance, that checks keypresses and initiates the relevant drawing tool - this should be done using Event checks?

In BlitzPlus, ideally, yes. I would recommend using an event system exclusively or not at all. If not at all, then it's more like a legacy Blitz2D style. It's easiest not to mix them.

Thanks for your help, by the way soja - immensely useful :)

You're welcome =)