Skip to main content
gamedev.net
🔒 Locked

Physics implementation questions

Started by SiS-Shadowman Apr 16, 2009 at 6:19 AM 2 replies 700+ views
Original Post
SiS-Shadowman
SiS-Shadowman
So I decided to start implementing my own simple physics system. I have a fair knowledge of dynamics in theory and I've already written a small application that simulates planets rotating around a sun (using newtons laws). I'm currently trying to figure out what I need to learn and consider when implementing dynamics, collision detection and -response. I don't care about springs and all those advanced techniques yet, because I won't need them, so I can concentrate on the above 3 points. My greatest concern is whether I should run the simulation in a separate thread or not. The biggest plus would be that the simulation can run independant of the main thread (which should lead to a performance boost on multicore systems, if I do it right). However I think I now understand why it is important that I still update my main thread in the same frequency as the simulation runs. It's not important if the main thread only queries the state of objects in the simulation, but it's important if the main thread modifies the simulation by applying forces / impulses to objects. If update is not called with the same frequency, then forces could be applied two or three times per simulation step (if the main thread runs very fast) or only every two or three simulation steps (if the main thread is very slow). What do you think. Is multithreading worth the additional code to keep both threads in sync or should I aim for just one thread? About what I want to do with the physics system: Simulate space combat using newtons laws (like Point defense system for Homeworld 2). I think there may be about 1000 or 2000 objects out there at once (most of them will be small & fast objects like projectiles and missiles), but this is just a very rough guess.
stonemetal
stonemetal
It depends why are you writing the physics engine? If it is to learn physics simulation as you suggest then make it single threaded so you can focus on what you are trying to learn no need to debug threading issues if you don't have to.
SiS-Shadowman
SiS-Shadowman
It's for learning purpose, but I plan on using it as well. I was using physx previously, but It does not have an x64 port available yet, and I've enjoyed porting a portion of my code base to x64 so I decided that I try to port the entire engine as well.

I think I'll write it single threaded only until I run into issues or decide otherwise. It shouldn't be too hard to write the physics system again using multi threading when I already have large portions of the code working.

Thanks :), though I'm still open to suggestions.
stonemetal
stonemetal
For threading I suggest a single threaded flow with work queues\thread pools to parallelize each task. That way you are actually getting speed up from your multithreading and not doing a lot of useless extra work like rendering 4 frames while waiting for the world update thread to update the world once.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.