Use debug_timer on lights.
authorSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 18:49:06 +0000 (20:49 +0200)
committerSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 18:49:06 +0000 (20:49 +0200)
tabakrolletjie/lights.py

index 6f2c6e7a1082a5eba81d57e636fd9f1c42f34ff9..7620c480915c1e8b5bc2226ba1ec64028a7631f9 100644 (file)
@@ -1,13 +1,12 @@
 """ May it be a light for you in dark places, when all other lights go out.
 """
 
-import time
-
 import pymunk
 import pymunk.pygame_util
 import pygame.draw
 
-from .constants import SCREEN_SIZE, LIGHT_CATEGORY, DEBUG
+from .constants import SCREEN_SIZE, LIGHT_CATEGORY
+from .utils import debug_timer
 
 LIGHT_FILTER = pymunk.ShapeFilter(
     mask=pymunk.ShapeFilter.ALL_MASKS ^ LIGHT_CATEGORY,
@@ -32,8 +31,8 @@ def screen_rays(pos):
         yield pymunk.Vec2d(x, bottom)
 
 
+@debug_timer("lights.calculate_ray_polys")
 def calculate_ray_polys(space, body, position):
-    start_time = time.time()
     position = pymunk.Vec2d(position)
     vertices = [position]
     ray_polys = []
@@ -54,11 +53,6 @@ def calculate_ray_polys(space, body, position):
                 vertices = trial_poly.get_vertices() + [point]
     if len(vertices) > 2:
         ray_polys.append(pymunk.Poly(body, vertices))
-    end_time = time.time()
-    if DEBUG:
-        print(
-            "calculate_ray_polys: %d polys, %g seconds" %
-            (len(ray_polys), end_time - start_time))
     return ray_polys