import pygame.locals as pgl
import pymunk
-import time
from .base import BaseScene
from ..lights import BaseLight
from ..obstacles import BaseObstacle
from ..events import SceneChangeEvent
-
-from ..constants import DEBUG
+from ..utils import debug_timer
class DayScene(BaseScene):
for light in self._lights:
light.add(self._space)
+ @debug_timer("day.render")
def render(self, surface, gamestate):
- start_time = time.time()
surface.fill((0, 0, 155))
for light in self._lights:
light.render_light(surface)
for light in self._lights:
light.render_fittings(surface)
- end_time = time.time()
- if DEBUG:
- print "Day Render", end_time - start_time
-
def event(self, ev, gamestate):
if ev.type == pgl.KEYDOWN:
if ev.key in (pgl.K_q, pgl.K_ESCAPE):
for light in self._lights:
light.toggle()
+ @debug_timer("day.tick")
def tick(self, gamestate):
- start_time = time.time()
- end_time = time.time()
- if DEBUG:
- print "Day Tick", end_time - start_time
+ pass
--- /dev/null
+""" Tabakutilities. """
+
+import functools
+import time
+
+from .constants import DEBUG
+
+
+def debug_timer(label):
+ """ A decorator for printing how long a function took if debug is true.
+ """
+ def debug_inner(f):
+ @functools.wraps(f)
+ def wrapper(*args, **kw):
+ start_time = time.time()
+ try:
+ return f(*args, **kw)
+ finally:
+ duration = time.time() - start_time
+ if DEBUG:
+ print "%s [%g seconds]" % (label, duration)
+ return wrapper
+ return debug_inner