I once read a quote that goes something like:
[quote]Begining programmers think programming is hard.
Average programmers think programming is easy.
Good programers know programming is hard.
[/quote]
I think I saw it in the book Code Complete but I couldn’t find it to make sure I got it right.
Anyway, the point is that as we pass though different stages of understanding of something we have different views of the subject. To a beginier, programming may well be greek, he doesn’t understand it. An average programer can make his program do what he wants and works in the situations he can think of to test it in. An expert understands the process and can see the possible problems that he himself may never experience.
I’m not a thread expert but I think there is a lot of oversimplification of threads going on in this discussion thread. If you don’t have a complete understanding of all the nuances of threads, someday they will lead to obsure problems.
EgonOlsen: To at least somewhat answer your question, the collection of input, be it from the player or the network, need to be done with threads. The thing is these “input threads” should never directly touch the state of you game. The “main game loop” asks each of these input threads via a queue if they have new input at the start of a iteration. This way everything is consistant when you render a frame or calculate a npc’s next move.
[quote]you simply can’t jump out of the recursion of the AI calculations just to render half the image and then return.
[/quote]
(the bold is my edit)
This is why AIs tend to be written so they execute iterativly. Have you ever looked at the A-Star and asked “why does it only consider the spaces around the unit? Why not just figure out to my destination and be smarter about pathing?” The reason is in a game we need these cheap little steps that won’t interupt the flow of game play as the computer does the number crunching.
Now you could use threads and wait() and notifyAll() at the right points and let many things run in parellel but it’s very easy to make mistakes.