[Twisted-Python] jfi: twisted pygame :)
took me longer to write this mail, than to convert a simple pygame based scrolling game to twisted + pygame. works great: without fps limits i lose about 3-5 fps compared to the Clock.tick(n) based loop. if the game engine takes care of events and updates with a single call per frame, all you need to do is get rid of pygame.time.Clock calls, and do scheduled updates with reactor.callLater. paul
Paul Boehm <typo@soniq.net> writes:
took me longer to write this mail, than to convert a simple pygame based scrolling game to twisted + pygame.
Cool! Could I persuade you to post a simple example of how you integrated the event loops? I'm just starting to get into pygame; it would make multiplayer stuff a lot easier if I could use twisted at the same time. thanks, -Brian
On Wed, Oct 09, 2002 at 05:36:42PM -0700, Brian Warner wrote:
Cool! Could I persuade you to post a simple example of how you integrated the event loops? I'm just starting to get into pygame; it would make multiplayer stuff a lot easier if I could use twisted at the same time.
sure, while it still needs lot of refining, this is a start: # MyGame embedded in Twisted from pygame import time from twisted.internet import reactor import mygame class PygameTimer: def __init__(self, game): self.clock = time.Clock() self.game = game self.update() def update(self): self.clock.tick() self.ms = self.clock.get_rawtime() framespeed = (1.0/100.0) * 1000 lastspeed = self.ms next = framespeed - lastspeed print "framespeed", framespeed, "ms", self.ms, "next", next, "fps", self.clock.get_fps() self.game.iterate() if self.game.want_quit: self.game.cleanup() reactor.stop() else: reactor.callLater(next/1000.0*2.0, self.update) if __name__ == "__main__": pt = PygameTimer(mygame.Game()) reactor.run()
On Thu, 10 Oct 2002 03:48:41 +0200 Paul Boehm <typo@soniq.net> wrote:
Cool! Could I persuade you to post a simple example of how you integrated the event loops? I'm just starting to get into pygame; it would make multiplayer stuff a lot easier if I could use twisted at the same time.
sure, while it still needs lot of refining, this is a start:
Do the refining and we can add it to twisted.internet. -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python, Twisted, Zope and Java consulting
participants (3)
-
Brian Warner
-
Itamar Shtull-Trauring
-
Paul Boehm