• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Kurasu1415

Physics Engine Timing Suggestions?

12 posts in this topic

So, I am working on my own physics engine for a game that requires precise controls. The physics is handled in it's own thread separate from the rendering. My issue is making sure that my simulations run at the same speed on all systems. I have looked around and found a few posts relating to this, but as they use Box2D, some things aren't explained. I am particularly interested in the Semi-fixed timestep.

Related Posts :
[url="http://gafferongames.com/game-physics/fix-your-timestep/"]http://gafferongames.com/game-physics/fix-your-timestep/[/url]
[url="http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-10-fixed-time-step/"]http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-10-fixed-time-step/[/url]

Now, my system essentially works this way as of current. This is a pretty simplified explanation, but I have a list of Physical Objects, and a Queue of Pairs(or tuples) that have an objectID and a Vector (The mathematical vector). Each Pair represents a force. Then I have my collision handling code. (As I said, horribly oversimplified)

How have you guys solved this problem? Could you offer any clarification on what is explained in these posts?
0

Share this post


Link to post
Share on other sites
I don’t know what you mean by “semi-fixed”, because those articles are related to a purely fixed time-step, and a purely fixed time-step is necessary for a stable physics simulation.

My article on the subject might clarify some things: http://lspiroengine.com/?p=378

You basically have to divide your loop into 2 halves. One does logic and one does rendering. Although they are handled inside the same function, they operate at different intervals. My post explains how it works.


L. Spiro
1

Share this post


Link to post
Share on other sites
@L. Spiro Thanks for the links. I read through your post and I am still a bit confused. The interpolation part is where I get a little thrown off. How do we ensure that physics will update every 33.3 ms? From what I understand, looking at your graph we SHOULD be at 48.0 seconds, but we actually interpolate in between 0.0 and 33.3 in order to get our position at an exact 33.3 seconds of lag. If that is correct, then my only question is, how do we know that physics will run every 33.3 seconds? Also, when it comes time to render, who does the interpolation, the renderer, or the physics engine? I ask because my system is multi-threaded.
0

Share this post


Link to post
Share on other sites
In Spirou example you chop time at 33.333 ms, but your update goes not exactly at this time , intervals can be
28 36 33 34 29 38 ... but average will be = 33.333 ms and usualy there is no need to pass parameter to update function Update( 33333ULL ) if its your own engine;
To render smoothly you need calc interpolation variable alpha=0.0..1.0 to know how far you are to next update.
So engine gives alpha, renderer draws according to this alpha. Edited by serumas
0

Share this post


Link to post
Share on other sites
I don't understand how that could work though. I thought the point of this was to make sure that physics ticks at an exact interval.
0

Share this post


Link to post
Share on other sites
The gaffer article is quite good and not locked to a particular physics solution. Which part are you having trouble understanding?
0

Share this post


Link to post
Share on other sites
[quote name='Kurasu1415' timestamp='1349380398' post='4986858']
I don't understand how that could work though. I thought the point of this was to make sure that physics ticks at an exact interval.
[/quote]
It is not possible to fix something to an exact interval.

You are misunderstanding that the updates have to be spaced at every 33.33 actual real-life milliseconds.
In fact, inside the simulation, if you made 2 updates of 33.33 milliseconds each, but in 1 case they are done immediately back-to-back, 0.00001 milliseconds apart, and in another case they are done closer to real-world time at exactly 33.33 milliseconds apart, the simulation result is the same.
In either case, you just told the simulation to update 2 times, at 33.33 milliseconds each. How much actual time was between those updates does not matter to the simulation.


With that understood, that means you now understand that you can update any number of times within a single game loop. Meaning if the simulation falls behind real-world time you can catch it up by updating multiple times instead of just updating once by a longer amount of time.
Likewise, if too little time has passed since the last update (as in, fewer than 33.33 milliseconds) then you can update 0 times. Just move on.


The concept should become simple. Updates are always done at a fixed amount of time, and then in order to keep the simulation as close to real-time as possible, each frame you check to see how many times you should perform an update. If you are running at 60 FPS, the every second frame will update 0 times, and every other frame will update 1 time.
If you suddenly drop to 10 FPS, every frame you will update 3 times. This catches the simulation up to the current real-world time without allowing it to go beyond the current real-world time.


[quote name='Kurasu1415' timestamp='1349375914' post='4986834']
Also, when it comes time to render, who does the interpolation, the renderer, or the physics engine? I ask because my system is multi-threaded.
[/quote]
The renderer. Physics won’t updated at an interval fast enough to provide interpolations meant for the renderer. Since they are only meant for the renderer, they should be updated by the renderer.


L. Spiro Edited by L. Spiro
0

Share this post


Link to post
Share on other sites
Ok, I see what you are saying. So basically I set each Physical step to simulate a fixed amount of in-game time, which in this case is 33.3 ms. and I run as many of them per frame that is necessary to make sure it is caught up to current time. Then I take the difference between real-time and the next step-time, and use that difference to interpolate between the last 2 simulated times, to get the final rendered time? Does that make sense?
0

Share this post


Link to post
Share on other sites
What the renderer needs is not a time but a fractional amount from 0 to 1 representing the amount of interpolation to be applied between the object’s last and current transformations.

Also, if you are running these on different threads just for the sake of keeping them on different threads, you should put them back on the same thread. You will encounter both synchronization issues and performance issues otherwise.
This isn’t how multi-threaded rendering is supposed to work; this is a different type of decoupling.


L. Spiro
0

Share this post


Link to post
Share on other sites
Alright, taking it out of the thread is no problem. It really shouldn't be necessary anyway considering this is a 2D game using Shaders for all of my rendering, so rendering should be quick. So, I could essentially multiply my change in X by the percentage, and my change in Y by the percentage and that should be the translation that I actually apply to my geometry.
0

Share this post


Link to post
Share on other sites
I have one last simple question, and I believe I know the answer. I assume the safest way to handle passing the data from Physics to Rendering would be all at once in a structure. For example, have a PhysicsFrame class that holds the ObjectID, its transformation, and the Matrix of every changed object in the physics frame. Then pass that to the Renderer, and have it apply the percentage of interpolation between the new matrix and the old matrix per object. Does that make sense?

Thanks again for all the effort you guys have put into helping me.
0

Share this post


Link to post
Share on other sites
That would be superfluous.

The physics engine has nothing to do with rendering and should not prepare any information for the renderer. Any information passed between physics and rendering is intermediate. In other words the fact that there is a current and previous transform for interpolation is only because a layer was injected into the system specifically to bind physics and rendering together. Otherwise they would and should be entirely completely unrelated systems.


The physics system prepares only date related to physics, which in this case means the current transform of each object.
An intermediate layer stores the current transform into to the “lastTransform” for an object on each physical update.
And finally the renderer is run each frame using the above transforms with a time value to interpolate between them. The time value and the interpolation process are repeated for each frame. No information from the physics is prepared except for what the physics itself does: The current transform.


L. Spiro
0

Share this post


Link to post
Share on other sites
[quote name='Kurasu1415' timestamp='1349556891' post='4987503']
I have one last simple question, and I believe I know the answer. I assume the safest way to handle passing the data from Physics to Rendering would be all at once in a structure. For example, have a PhysicsFrame class that holds the ObjectID, its transformation, and the Matrix of every changed object in the physics frame. Then pass that to the Renderer, and have it apply the percentage of interpolation between the new matrix and the old matrix per object. Does that make sense?[/quote]I'm afraid not.
First, [font=courier new,courier,monospace]objectID [/font]or ids in general are typically unnecessary. We have far better tools which are pointers. Personally, I'm against most uses of IDs.
For Bullet, object transform is just poured out to the external code by using a proper [url="http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates"]interface[/url]. That is, if it's good enough for Bullet, I guess it will be good enough for you as well. Edited by Krohm
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0