Dual Core Game Programming

Started by
17 comments, last by I_Smell_Tuna 18 years, 2 months ago
Quote:Does each graphical entity have its own thread?


No, you really don't want each object to have a thread. Personally, that would drive me insane.

When multithreading, I just look for situations where it doesn't matter if things are done at the same time or not. It doesn't matter if you render an object where it is or where is was 0.016 seconds ago does it? So you should have 1 thread that updates game state and scene graph, and another that renders it. Sure, sometimes you'll render while it's halfway through updating, but it'll look fine. An added bonus is that if the game is minimized or the window is being moved the game still updates, just the rendering thread is stopped. And pausing the game is simple too. The gameplay thread just waits for another pause click and doesn't update till it gets one.

You can do similar (but more difficult) things for physics, animation (if you're not doing it on the gpu anyway) probably other things...

EDIT: Another benifit of multiple threads is you can claim insanely high framerates on machines with fast gpus by limiting the rate the game state thread updates at. No need to tell anyone most of those frames are identical...
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Advertisement
Your right with the idea of specialist parallel tasks.

The main advantage of parallel processing as far as games are concerned is going to be that graphics dont have to be the "main" focus of resources.

With sequential processing, per frame ( so at a nice usable speed 0.017 seconds ) you have to perform all the graphics calculations, the network, the user interface, some A.I. and physics, and be ready for the next frame.

With two parallel processes you can now shove the graphics on to one process, and have a hole second process for just the network, UI, A.I. and physics :D

Im sure we all know how much CPU time (even tho its running mainly through the GPU) the graphics takes up, but now it can almost all be devoted to machine learning A.I. for example. Or complicated realworld physics.
Okay. Stumped.

The A.I. and Graphics are going to share a critical section (the entities themselves). Correct? 'Cuz I think I misread your post as the two threads being completely separate from each other.

Beginner in Game Development?  Read here. And read here.

 

Quote:Original post by Alpha_ProgDes
The A.I. and Graphics are going to share a critical section (the entities themselves). Correct?

Yes, but it doesn't really matter. The graphics thread only has to lock the entity for as long as it takes to read the entity's current configuration; actually drawing the entity takes the lion's share of the time and doesn't require any entity data to be locked. Likewise, the AI thread can generally get away with only locking the entity for a short period of time.
What about doing a sort of double buffering with entity data? Could the AI/physics/game logic systems write the new state of the objects into a second buffer and then swap some pointers when the new entity information is ready?
The downside to that, apart from taking twice the memory, is that the threads have to be sort of synchronised. They'll end up waiting for each other. The graphics thread has to wait till the buffers are swapped, or the gameplay thread has to wait until the graphics one finishes.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Well get used to these issues.

Intel has 8 core CPUs on the road map for 2007.
Quad cores end of this year.

http://www.tomshardware.com/2005/12/04/top_secret_intel_processor_plans_uncovered/
Quote:Original post by RAZORUNREAL
The downside to that, apart from taking twice the memory, is that the threads have to be sort of synchronised. They'll end up waiting for each other. The graphics thread has to wait till the buffers are swapped, or the gameplay thread has to wait until the graphics one finishes.


Which is why you infact triple buffer the data, with the simulation running a step ahead.
Yes, there is a slight increase in latency but its not that bad and as long as the gfx stay smooth it shouldnt be a problem.

So, you'd have two pointers to last and current frame of data and one to the next frame which is the next update step.

The memory overhead, while larger, isnt as large as you might think as only certain things have to be stored; for example position and direction of travel.

Oh, and this it the perfect time to introduce a fixed time step system, so your world updates every 20ms or so and your renderer just throws polys out as fast as it can and interpolates between two frames of world data.

Sync is a slight problem, I've not looked into it heavily, at worse you'll be waiting for some pointer swaps to occur, infact if arranged correctly this should become a series of atomic operations.
I second what phantom said. The data for the entities isn't that large. It's not like your storing copies of textures and audio that the entities use. I plan on implementing a triple buffer in my threading architecture to create a 'non-blocking' design. Higher performance at the cost of a little memory.

This topic is closed to new replies.

Advertisement