Created
February 22, 2012 00:42
-
-
Save RyanHope/1880225 to your computer and use it in GitHub Desktop.
Integrate PyGame with twisted.internet's mainloop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
def _update( callback, fps, reactor, clock ): | |
if not callback(): | |
reactor.stop() | |
else: | |
delay = 1.0 / fps - ( clock.tick() / 1000.0 - ( 20.0 / fps ) / fps ) | |
if delay < 0: | |
reactor.callLater( 0 , _update, callback, fps, reactor, clock ) | |
else: | |
reactor.callLater( delay , _update, callback, fps, reactor, clock ) | |
print clock.get_fps() | |
def install( callback, fps = 30, reactor = None ): | |
if reactor is None: | |
from twisted.internet import reactor | |
if callback: | |
_update( callback, fps, reactor, pygame.time.Clock() ) | |
__all__ = ["install"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from twisted.internet import reactor | |
from random import random | |
import pygamesupport | |
import time | |
def doWork(): | |
time.sleep( random() / 50 ) | |
return True | |
if __name__ == '__main__': | |
pygamesupport.install( doWork, fps = 30 ) | |
reactor.run() |
I actually have a much better solution using twisted.internet.task.LoopingCall
On Wed, Jul 4, 2012 at 3:54 AM, Drvanon ***@***.*** wrote:
So, where would we put the factory here?
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1880225
##
Ryan Hope, M.S.
CogWorks Lab
Cognitive Science Department
Rensselaer Polytechnic Institute
Here is what I am using now: https://gist.github.com/3708020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, where would we put the factory here?