| Total Complexity | 4 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| 1 | import platform |
||
| 36 | class FpsCounter(Timer): |
||
| 37 | ''' Helper class for Frames per Second calculation ''' |
||
| 38 | def __init__(self): |
||
| 39 | |||
| 40 | super(FpsCounter, self).__init__() |
||
| 41 | |||
| 42 | self.frames = 0 |
||
| 43 | self.fpsTime = 0 |
||
| 44 | self.fps = 0 |
||
| 45 | |||
| 46 | def tick(self): |
||
| 47 | ''' |
||
| 48 | Calculate Time delta, and keep running total of frames since last |
||
| 49 | fps calculation. |
||
| 50 | Must be called once per rendered frame. |
||
| 51 | ''' |
||
| 52 | super(FpsCounter, self).tick() |
||
| 53 | |||
| 54 | self.fpsTime += self.tickDelta |
||
| 55 | self.frames += 1 |
||
| 56 | |||
| 57 | return self.tickDelta |
||
| 58 | |||
| 59 | def get_fps(self): |
||
| 60 | ''' Calculate and return the estimated Frames Per Second ''' |
||
| 61 | if self.fpsTime == 0: |
||
| 62 | self.fpsTime += 1 |
||
| 63 | |||
| 64 | self.fps = self.frames / (self.fpsTime / 1000.0) |
||
| 65 | |||
| 66 | self.fpsTime = 0 |
||
| 67 | self.frames = 0 |
||
| 68 | |||
| 69 | return self.fps |
||
| 70 |