Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having a multithreading problem with Nvidia PhysX. the SDK requires that you call Simulate() (starts computing new physics positions within a new thread) and FetchResults() (waits 'till the physics computations are done). Inbetween Simulate() and FetchResults() you may not "compute new physics".

It is proposed (in a sample) that we create a game loop as such:

  1. Logic (you may calculate physics here and other stuff)
  2. Render + Simulate() at start of Render call and FetchResults at end of Render() call

However, this has given me various little errors that stack up: since you actually render the scene that was computed in the previous iteration in the game loop.

Does anyone have a solution to this?

share|improve this question
    
As long as your having 60fps the delay is only 17ms, human reaction time is longer than this so its unlikely to cause any great problems. The other option would be to do the simulation in the logic part and stall waiting for the results before rendering. You would lower your framerates but it would give you something to compare the results with, see if the problem really is with the delay or not. –  Daniel Carlsson Apr 7 '12 at 14:21
    
The problem escalates with the number of threads you have that are dependent on the physics, you might end up with one thread(for example AI) to use the physics from 7 frames ago in it's calculations, and that is a serious problem. The other option you propose is impossible since inbetween a simulate and fetchresults call you can't compute new physics –  xcrypt Apr 7 '12 at 14:47
1  
To alleviate that you should create several sync bounds. If you have multiple threads they should all finish at the end of each frame for example. For a really good example see: altdevblogaday.com/2011/07/03/threading-and-your-game-loop –  Roy T. Apr 7 '12 at 16:42
    
@RoyT. I can't seem to open the page you linked to :( –  xcrypt Apr 9 '12 at 14:03
    
@xcrypt, how weird, does this tinyurl link work: tinyurl.com/cybzwb5 ? Else try to find the article "Threading and Your Game Loop" on altdevblogaday.com –  Roy T. Apr 9 '12 at 21:16
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.