Unable to avoid the networking issue any longer, I have made a couple of forays into how to add networking to “Pitcher’s Duel”. One way or another, Twisted will be involved, as they have a very reputable code base, and using the standard lib modules does not seem to have any relative merits. They all have the same major limitations.
The principle limitation is that the network ‘library/engine/framework’ wants to own the main loop. That is fine for a server, it is a PITA for other sorts of software. I wrote a post on the pygame mailing list this morning summarizing the approaches to networking that I have identified, and may copy that post into the blog.
For now, I wish to describe one architecture for accomodating Twisted’s ownership of the main loop. Since the reactor, once started, never returns, the game logic has to be managed via callbacks from the reactor. Game state must be maintained in class variables, object instance variables, global variables, or generator local variables. Generators provide a relatively graceful way to code the ‘main’ function, where game state for the whole game is maintained in locals.
(more…)
