piku wrote:
What about putting my display code in a seperate thread? The physics code can then be locked to a specific speed and the display code can go and run off as fast as it can.
Except that both your renderer and your physics will be using the same shared data, so having two threads tinkering with it at the same time is going to cause no end of trouble. You'd have to have some kind of buffering scheme so they can run on their own set of data. And the usual headaches caused by non-deterministic threading are almost enough to avoid it completely.
Of couse no two people can ever agree on a timing/update/render scheme, so you might as well just pick one you like and stick with it.
the2bears wrote:
I'm a bit out of my league, not having done much in the way of 3D, but I do feel single-threaded is better. Excepting networking of course. I just tthink that complete determinism might be the way to go. I'd like to hear other thoughts though, those with more experience.
Yeah, it seems a bit daft having this supposed HyperThreading CPU in my laptop and not using it to its full potential.
The code doing the logic would still be deterministic, the rendering code would be the one in the separate thread and we've already established that changes update speed depending on your machine.
The popcap games framework is currently downloading. I'll take it apart and have a look tomorrow. Might even use it if it is better than the cruft I've invented...
I'm gonna agree with the 2bears. Resist the temptation to use multiple threads unless you absolutely have to... and if you absolutely have to, you're probably doing something wrong... I'm sort of kidding, but basically, it's true. You won't get the performance gains from your Hyperthreading that you might imagine, and the additional code required will probably induce nightmares and/or colon cancer. Avoid!
Read the FlipCode article I posted above. It's very enlightening. Pro developers taking about real life situations on consoles / PCs and they are suggesting deterministic logic updates and single threaded game loops.
Demo recording is a dead easy that way and leads to a simple networking model and ghosts modes too.
PaulCunningham wrote:Read the FlipCode article I posted above. It's very enlightening. Pro developers taking about real life situations on consoles / PCs and they are suggesting deterministic logic updates and single threaded game loops.
Demo recording is a dead easy that way and leads to a simple networking model and ghosts modes too.
Yeah the Popcap stuff is deterministic and single threaded (well they use a separate thread for loading resources at the start but the actual game is single threaded). Logic updates guaranteed 100 times/sec.
Istar wrote:Let's not forget VSYNC. It's not perfect, but it has its uses.
Bad coder. BAD.
Thats the reason most Japanese games end up with manky PAL conversions...
Ever tried porting a game locked to a 60Hz or 30Hz vsync? I've lost entire months of my life to it...
Anyway, the way it's done on most games I've worked on is to decouple the render from the game logic.
We process all the game logic once every x milliseconds (in BW2, its every 10). The renderer can go however fast it likes. The game logic is then nicely deterministic because it's always running at a fixed update rate. You do then have to use delta timing in your animation and movement, which you get around by having a logical (game side) position for the object, and an interpolated render side position.
Oh, I don't actually -use- VSYNC. It's just the first thing that springs to mind when looking for a simple (but dirty) way of smoothing-out timing discrepancies when getting that initial alpha release running.
As others pointed out... you have basically two and a half options...
If the minimum system requirements of your game are rather low, you can go with a fixed speed (say 60fps) and some throtteling code, which basically just caps the framerate. So, it cant go faster than 60fps and if the machine is too slow the game will slow down.
Basically it works like this... you check how much time elapsed and is you have some free leftover time, you twiddle your thumbs until its time to move on. (Usually you try to go with the vsync and use the throttle bit as backup.)
The most complex approach is delta timing. While calculating the fraction and multiplying some values with it is simple, the collision detection stuff gets pretty hairy quickly.
The last option is some kind of mix. The game runs at a fixed timestep (say 100fps) and the renderer interpolates between the last two frames or just renders the most recent one (if it wasnt rendered already).
I'm using the first one for the most part. Its the easiest way, my games are all 2d so far, the minimum system requirements are very low (500mhz and some geforce) and I also think that a tiny occassional slowdown is more acceptable than dropped frames (beeing warped to death is the worst).
As far as I am aware, and please correct me if I'm wrong, most games have an internal 'tick', usually about 20 or 30 Hz (probably depends on the type of game). The game world is updated on this tic. However the graphics can usually be updated as fast as possible, more fps is usually a good thing!
That's what one of my teacher's at uni told me, anyway. I've never written anything that's required anything like that so I'm just theorising really.