So many different timing methods; which to use?

BlitzMax Forums/BlitzMax Programming/So many different timing methods; which to use?

Amon(Posted 2010) [#1]
There's so many timing methods which all look different I have no idea which one to use.

For startes can anybody make a module with the best one that can be used easily? I'm useless at this timing stuff probably because I've never bothered to look in to it and I don't have time to learn about it all.

So are there any takers on making one a module?


okee(Posted 2010) [#2]
i'd like to +1 that


H&K(Posted 2010) [#3]
GAs framework has one. Not sure if its part of the shareware bit or the commercial bit tho


Czar Flavius(Posted 2010) [#4]
TimelineFX is a particle effects module but also comes with a Tweening module that the guy created too. You can download it and just use the Tweening module for your timing - thought you could use both, as the effects are pretty cool tool.

http://www.rigzsoft.co.uk/index.php?option=com_content&view=article&id=44&Itemid=25


EOF(Posted 2010) [#5]
I use this method although I am not sure where I got it from now. It's nothing too fancy making it easy enough to follow. The Update() function contains its own variables which makes dropping it into other projects a doddle




popcade(Posted 2010) [#6]
Frame limiting is the easiest method, which should work on most fast-enough PCs.

However if you have to do network-related programming, it'll cause lots of issues, maybe try delta-timing or others instead.


Grey Alien(Posted 2010) [#7]
Here's another simple method I used for my last 2 minigames:

Local gameTimer:TTimer = CreateTimer(60)

While Not (KeyHit(KEY_X) And (KeyDown(KEY_LCONTROL) Or KeyDown(KEY_RCONTROL)))	 
	If game.Logic() Then Finish()
	game.Draw()
	WaitTimer (gameTimer)
	Flip 0
	Delay(1) 'Give system time to catch up on things.
Wend
Finish()

Function Finish()
        'Perform any clean up here.
	End 'Exit the program
End Function


This will run a game at 60FPS, one logic per draw (so you can move things by 1 pixel a frame for example). It doesn't work that well with Flip 1 (vsync) though because there no guarantee the timer will stay in sync with the vsync. There's no delta timing so if the code got too slow it would just drop frames.


Grey Alien(Posted 2010) [#8]
@Jim Brown: What does the main loop look like that calls your two functions? Does it just call update then draw? If so, and Flip 1 (vysnc) was used instead of Flip (default is -1), then the Rate param won't make much difference as the game will be locked to 60FPS. Same problem exists for mine if I use Flip 1 no matter what rate I set the timer at. The trick to getting faster or slower Updates than 60FPS with VSync on is to loop the updates until they are all done and then call draw only once - that's the Fixed Rate Logic approach. Of course Fixed Rate Logic falls down if the code becomes too slow, it can never keep up with what it supposed to be doing, and that's where Delta Time comes into it's own.

Last edited 2010


EOF(Posted 2010) [#9]
Jake,

The main game loop is a simple:
Repeat
    Update ; Render
Until somestate

Flip is done in the Render() function (using default parameter)

I am not sure if what I am using is good implementation but I went for the easiest and least complex solution at the time. I can set the 'Rate' in the Update() function which changes how fast the games 'action' takes place


GW(Posted 2010) [#10]
I use a slightly modified version of this:
Here
It's always worked well for me.
Remember to always cap the tween value though.


Tibit(Posted 2010) [#11]
I'm just curious, but what you specifically mean by "timing stuff"? Intended use cases?

Do you mean stuff like: Stopwatch, CountDown timer, cooldown remaining timer, Date Comparison, FPS counter, Tweening, get timestamps, get timeSince timestamp, Delta time, slowmotion effect, profiling timer or perhaps a windows-based precision-timer in micro/nanosec?


Gabriel(Posted 2010) [#12]
I'm just curious, but what you specifically mean by "timing stuff"?

He means making your game run at the same speed on all machines as consistently and nicely as possible, with all the associated factors.


Kryzon(Posted 2010) [#13]
Why use only one? you have to deal with the fact that some machines will try to run the game faster than it's meant to run, whilst others will run it slower.

We have frame-limitting for the former case.
We have frame-skipping*, tweening or delta-timing for the latter.

*I'm not absolutely sure about what this is, but I remember some game emulators having this feature. I guess it's a somewhat crude way to make the game run faster, by disregarding some frames (using a Continue to skip to the next logic iteration).

Last edited 2010


Grey Alien(Posted 2010) [#14]
@Kryzon: A simple timing system is just to get your game running the same on most computers (an includes frame-limiting), a better one would take into account both the cases you mentioned, although frame-skipping is only really needed for CPU/GPU heavy games - many games simply won't need it unless.


dmaz(Posted 2010) [#15]
here's mine with example... (I have it as a mod as well) I used this in Rocks, invaders from space and others...



Last edited 2010

Last edited 2010

Last edited 2010


siread(Posted 2010) [#16]
This is my tipple...
http://blitzbasic.com/codearcs/codearcs.php?code=2039


Amon(Posted 2010) [#17]
@dmaz

Is the mod available? If not may I have it, please?


dmaz(Posted 2010) [#18]
sure, I'll get it up in a couple hours...

Last edited 2010


dmaz(Posted 2010) [#19]
here's the mod, fully documented with an example in help.
http://www.ooeyug.com/files/dmaz.mod.zip

make sure you rebuild documentation.


Amon(Posted 2010) [#20]
Nice one man, thanks! :)

Last edited 2010

Last edited 2010


Amon(Posted 2010) [#21]
I have tried modifying the template TObject but I'm getting problems. First I got a StackOverflow then it complained about the Drawimage command in the Draw Method!

Can someone help fix this so I can see how all this will fit together nicely?

Oh I've added comments etc to each in the hope I'd understand it better.

[EDIT] ISSUE FIXED. I was doing something majorly wrong with TLinks.

Last edited 2010