[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Network game programming with python




On Sunday, Apr 13, 2003, at 16:03 America/New_York, RPGnMets@aol.com wrote:

"Well, if you're going to write a game, you're almost certainly going
to do it in a mostly event-driven fashion "

Why?  What is wrong with a mainloop that goes something like

while (not over):
   handle_input()
   update_game_entities()
   draw_frame()
wrt your pb comment, you almost definitely want to use pb, because it will make it much easier to write a secure and stable gaming framework in the shortest amount of time.. a mostly C/C++ game won't be affected by the fact that your networking layer is in mostly python.

From what I've heard from Glyph (who attended the most recent GDC), every game developer using Twisted _has not_ found it to be a performance bottleneck in their games, even though the majority of Twisted is pure python at the moment. I've also seen benchmarks where psyco can considerably boost speed for Twisted, at least in the case of conch (the SSH client/server). In fact, conch running w/ psyco hints has been shown to have BETTER performance than OpenSSH (which is all C)!

In regard to your mainloop, what's wrong with registering those events with the reactor? That's the Twisted way of doing things. Here's an oversimplified example:

FRAMEDELAY = 1.0 / 30.0
def oneFrame():
handle_input()
update_game_entities()
draw_frame()
if not over:
# call oneFrame after a short delay
reactor.callLater(FRAMEDELAY, oneFrame)

if __name__ == '__main__':
from twisted.internet import reactor
gameSetup()
# call oneFrame at the next reactor iteration
reactor.callLater(0.0, oneFrame)
reactor.run()
gameShutdown()