X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/346a9b8e1fcfe30629f0d1ee4675e9e8f89890cf..4c4732c6ed8cb0aaa70fb2d4c6e5a958868c5349:/src/pgu/timer.py?ds=sidebyside diff --git a/src/pgu/timer.py b/src/pgu/timer.py deleted file mode 100644 index 1201b7a..0000000 --- a/src/pgu/timer.py +++ /dev/null @@ -1,68 +0,0 @@ -"""A timer for games with set-rate FPS. -""" - -import pygame - -class Timer: - """A timer for games with set-rate FPS. - -
Timer(fps)- """ - - def __init__(self,fps): - if fps == 0: - self.tick = self._blank - return - self.wait = 1000/fps - self.nt = pygame.time.get_ticks() - pygame.time.wait(0) - - def _blank(self): - pass - - def tick(self): - """Wait correct amount of time each frame. Call this once per frame. - -
Timer.tick()- """ - self.ct = pygame.time.get_ticks() - if self.ct < self.nt: - pygame.time.wait(self.nt-self.ct) - self.nt+=self.wait - else: - self.nt = pygame.time.get_ticks()+self.wait - - -class Speedometer: - """A timer replacement that returns out FPS once a second. -
Speedometer()- - Attributes -
Speedometer.tick()- """ - r = None - self.frames += 1 - self.ct = pygame.time.get_ticks() - if (self.ct - self.st) >= 1000: - r = self.fps = self.frames - #print "%s: %d fps"%(self.__class__.__name__,self.fps) - self.frames = 0 - self.st += 1000 - pygame.time.wait(0) #NOTE: not sure why, but you gotta call this now and again - return r - - - -# vim: set filetype=python sts=4 sw=4 noet si :