Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is anyone interested in clearing up some questions about a game loop and timing?  (Read 3237 times)

0 Members and 1 Guest are viewing this topic.

metroplex

  • Newbie
  • *
  • Posts: 2
    • View Profile
This will start as a general question, but I'm in the dotnet section of the forums, because if I add some questions, they will need to be dotnet code related.

I wanted to get a clear understanding of game loops. I read lot's of posts and articles on the internet, and have a decent general understanding. Except, I have some trouble with frame independent movement (both fixed and variable timestep.

Ok, let me start with my first question.

The simplest loop is a Do while loop with a condition such as bQuit which is initially set to False and then to true when exiting the loop. Simple enough to understand. The most important point being, that if I put anything inside that loop, it will try to run at the fastest possible speed the computer can handle. Which is why we need to use frame independent movement to slow things down.

My biggest problem with understanding this is because of some utility functions and or procedures. I will need
a -

DoInput
DoUpdate
DoRender

...at the least. When looking up information on frame independent movement, I found out about delta. In most examples the delta is passed into the DoUpdate function. but I'm not sure where it is used inside the function. Also in the loop itself, the delta is used. Can someone start to put together a basic game loop in this thread, so we can slowly step by step make a clear explanation of how it works or how it should work?

C# would be fine for me. I have some experience with C/C++ C# and visual basic.

*Note* Please do NOT refer me to gaffer on games. It's not at all easy to understand. I spent 2 or 3 days trying to decipher that. No luck.

No code yet - hopefully someone can start this

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
C# would be fine for me. I have some experience with C/C++ C# and visual basic.
I'm not sure if this means that you would understand c++ code if it was used to demonstrate points.
So, with that said, I'll avoid actual code as it would be c++ and use only pseudo code.

...at the least. When looking up information on frame independent movement, I found out about delta. In most examples the delta is passed into the DoUpdate function. but I'm not sure where it is used inside the function. Also in the loop itself, the delta is used
The delta time (dt) is used only in the update - as you rightly already stated - and is used to update things by the amount of time that has passed rather than a fixed amount. For example, if you moved a position by 1 pixel per frame, it would be reliant on frame time but if you moved a position by a speed * dt pixels (assuming that dt is in seconds), it would move by speed pixels per second.

*Note* Please do NOT refer me to gaffer on games. It's not at all easy to understand. I spent 2 or 3 days trying to decipher that. No luck.
It's a shame that the article on time steps didn't help you. It can be confusing (especially the last part about interpolation) but that part isn't necessary to get a basic timestep set up. Basically, the second piece of code (variable delta time) is what we have just said: each frame you multiple the movements/modifications by delta time - the amount of time passed since the previous frame.
If you have any particular problem with the article, it might be easier to help you understand it than explain it again from scratch without using the same sorts of terminology etc..
One thing I should clarify is that 'integrate' means (in this case) update.

so, pseudo code:
loop = true
do until loop is false
{
  input
  dt = amount of time since previous frame
  update (multiplying modifications by dt)
  render
}
« Last Edit: June 05, 2015, 05:48:31 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

metroplex

  • Newbie
  • *
  • Posts: 2
    • View Profile
Awesome, thanks - I'm able to start putting together a simple working example. In the meantime I was searching more and studying up on this. You were right, the Integrate explanation confused me on gaffer, but I am not giving up. So maybe 2 or 3 more times I will better understand it. It's still recommended everywhere.

I also found this article which is helpful and I'm reading it right now. http://archive.is/qMyq5

 

anything