Latest Uploads
Extraterre ... .0.1 (zip)

dantheman363

Monty Teas ... Screenie 1

steve_ancell

Santa Clau ... ed his bag

waroffice

manic_platdude.png

spinal

Tetris Clone

steve_ancell

Super blues bros.

spinal

Forum Home

Maintaining the same timing on different systems

UserMessage
Posted : Thursday, 19 April 2012, 20:49 | Permalink | Mark Here
dna



ST=MilliSecs():ET=MilliSecs()
I=0
While Not KeyDown(1)
If ET+1000> MilliSecs()
I=I+1
Else
Exit
EndIf
Wend
Print I
WaitKey():I=0:ST=MilliSecs():ET=MilliSecs()


-----
DNA
Posted : Thursday, 19 April 2012, 21:24 | Permalink | Mark Here
9572AD


I've never been one for trying to count cycles to figure out how many frames the system will do per loop then forcing the game to update according to that.

I generally express motion as a vector and use the actual number of cycles taken by the loop to determine how far something moved.

Makes more sense to me, but most of the industry seems to do it the former way and I've never really finished a project so I can't claim superiority.
(One thing with my way is variations in the number of cycles per loop will cause un-smoothness in the motion visually, while the other way would cause slight slow-down instead. But that's why I use an average of the last several loops instead of the actual cycle count to smooth it out.)

-----
All the raw, animal magnetism of a rutabaga.
Posted : Thursday, 19 April 2012, 21:26 | Permalink | Mark Here
9572AD


Of course, whatever you do will depend on the machines' timers being precise or there will be differences in speed between machines.

-----
All the raw, animal magnetism of a rutabaga.
Posted : Friday, 20 April 2012, 01:50 | Permalink | Mark Here
shroom_monk


WW Entries : 8
Basing your timing on clock cycles can be quite tricky. What exactly do you want to do with this? There might be an alternative way of doing it.

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Friday, 20 April 2012, 11:32 | Permalink | Mark Here
dna


I was trying to measure the number of loops made in the same timed cycle.
Let's say we use a 5 second interval, counting the number of loops in that interval on a particular machine.
But on a different machine, faster or slower, the same number of cycles counted in that 5 second interval would be different.

I used the variable I for checking the algorithm.


-----
DNA
Posted : Friday, 20 April 2012, 11:40 | Permalink | Mark Here
shroom_monk


WW Entries : 8
OK, but what do you actually want to do with this code? What do you want to use it for once you have the number of loops?

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Friday, 20 April 2012, 11:55 | Permalink | Mark Here
dna


I just need it to work in the fashion that I mentioned using the variable I, thereafter I will reuse the code for something else, in something else.

I was worried about the syntax being correct.

-----
DNA
Posted : Friday, 20 April 2012, 15:14 | Permalink | Mark Here
dna


I get different values each time I run the program.

This time I got

17272844

Does this have to do with the so called machine cycles that poll the system every so often?

What I wanted was for the timing interval to be exactly the same and so the value of the variable I should not change in that instance.

-----
DNA
Posted : Friday, 20 April 2012, 16:13 | Permalink | Mark Here
shroom_monk


WW Entries : 8
You will get a different value each time because the number of clock cycles or whatever that your loop takes for one iteration will be dependant on other background processes, a certain degree of randomosity, and the alignment of the stars. This isn't a value you can really measure with any degree of accuracy, I don't think.

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Friday, 20 April 2012, 16:37 | Permalink | Mark Here
dna


So how do the big game programmers keep time measurement for events in an interval the same for their games on any speed machine and platform?

At least they claim to keep the same time. Different language?

-----
DNA
Posted : Saturday, 21 April 2012, 03:19 | Permalink | Mark Here
shroom_monk


WW Entries : 8
Like I said, you want to use a completely different method.

A good way is to use a time delta. You measure the amount of time that passed since the last tick, and use that to control how much things change.

For instance, say you have a player character who should be walking at a speed of 64 pixels per second. If the time that passed since the last frame was 0.01 seconds, then you would move the character 64 * 0.01 = 0.64 pixels in that next tick. That method is relatively accurate at not that difficult to implement.

(The only caveat is with collision checks if you need them, because if the computer freezes for a moment then 2 seconds might pass, meaning in this example you would move 128 pixels, causing you to phase through a wall, so you may wish to do collision checks in smaller steps.)

-----
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Posted : Saturday, 21 April 2012, 06:08 | Permalink | Mark Here
JL235


WW Entries : 7
Shroom is right, about using delta time, although I believe I use a different approach.

In an ideal and perfect world, my game would run at 60fps. So the time for 1 ideal frame would be 1/60 (1 second divided by 60 frames).

You then get the actual amount of time between now and the last frame. Dividing that time by your 'ideal' frame time gives you 'delta time'. delta is just a multiplier you use in calculation, like speed or acceleration.

What values would you expect? Well if the game really is running at 60fps, then the last frame divided by the ideal frame will just give you 1. This means it should run at 1 times the speed. If your game is running at 30fps, then the previous frame time takes twice as long, and dividing it by the ideal frame gives you 2. Your game should run twice as fast, to compensate for the halved frame rate.

You then multiply movement by this delta value, and your done. i.e.

-->

An alternative method, which I'm finding myself using more and more, is to use timers. This is very useful for when you know where you are moving to, and how long it should take. You can then just work out what location you are on each frame as you move from point a to point b.

Timers have a number of small advantages, such as being able to easily tell you when you reach point b, and being able to ensure you don't go past point b. That is useful for fade-ins, swipes, switching between frames in an animation, and other effects that have a specific time frame to run.

-----
PlayMyCode.com - build and play in your browser, Blog, Twitter.
Posted : Saturday, 28 April 2012, 10:56 | Permalink | Mark Here
dna


I've decided to simplify the original code problem

-----
DNA
Latest Posts
Progress / Location Bars
dna Mon 07:58
Noel's Graduation
rockford Mon 07:37
Screen Burn of the Mind
rockford Mon 07:33
RoadRash!
waroffice Mon 03:08
Development via GUI
waroffice Mon 02:48
Audio Rant
steve_ancell Sat 19:16
Wrong Partition!!!!?
spinal Sat 11:24
eBay Lies
spinal Fri 23:44
Shoutbox Topic - 968
dna Fri 19:42
Meh
Afr0 Fri 04:13
More

Latest Items
News : Newsletter #176
Jayenkai Sat 04:49
News : Newsletter #175
Dabz Tue 09:38
Blog : Snow: More Material Junk
Cower Sat 23:17
Dev-Diary : Mutant Monty: Amstrad CPC to Windows conversion
rockford Fri 13:14
Techy : AppleTV
Jayenkai Thu 09:40
Blog : Graphviz
steve_ancell Sat 14:17
Pets : Top-Down Shadow Hack
Jayenkai Tue 05:52
Snippet : JNKrunch v1.0
Jayenkai Sat 07:20
News : Newsletter #173
waroffice Fri 04:47
Blog : Material Loading
Cower Fri 02:08
Pets : I Done Won A Thing
shroom_monk Sun 11:31
Pets : Repurposing A Lexer
Cower Mon 22:06
Bah : Feeling a Little Angry
spinal Mon 11:26
News : Newsletter #170
Dabz Sat 00:34
Showcase : sbfgen
Cower Sat 16:57
More

Who's Online
shroom_monk
Mon, at 08:10
Cower
Mon, at 08:09
Jayenkai
Mon, at 08:03
Hotshot
Mon, at 08:03
dna
Mon, at 07:59
rockford
Mon, at 07:45
spinal
Mon, at 07:13
9572AD
Mon, at 06:20
HoboBen
Mon, at 06:09
steve_ancell
Mon, at 06:06
Link to this page
Site : Jayenkai 2006-Infinity |
MudChat's origins, BBCode's former life, Image Scaler.