# Debug
DEBUG = os.environ.get("TABAK_DEBUG", "").lower() in ("1", "y", "yes")
+DRAW_FPS = os.environ.get("TABAK_DRAW_FPS", "").lower() in ("1", "y", "yes")
+# Intervals to average fps over
+FPS_FRAMES = 50
# 704 is 768 minus space for window decorations :)
SCREEN_SIZE = (1024, 704)
LIGHT_CATEGORY = 1 << 1
MOULD_CATEGORY = 1 << 2
FITTINGS_CATEGORY = 1 << 3
+
+# Font definitions
+FONTS = {
+ 'sans': 'DejaVuSans.ttf',
+}
import pygame.locals as pgl
-from .constants import FPS
+from .constants import FPS, DRAW_FPS, FONTS, FPS_FRAMES
+from .loader import loader
from .events import QuitEvent, SceneChangeEvent
def run(self):
clock = pygame.time.Clock()
+ fpses = [FPS] * FPS_FRAMES
+ frame = 0
+ font = loader.load_font(FONTS['sans'], size=16)
while True:
events = pygame.event.get()
# Time is assumed to flow perfectly, so no dt parameter for now
self._scene.tick(self._gamestate)
self._scene.render(self._screen, self._gamestate)
+ if DRAW_FPS:
+ fps = sum(fpses) / FPS_FRAMES
+ text = font.render("FPS: %.2f" % fps, True, (255, 255, 255))
+ self._screen.blit(text, (10, 10), None)
pygame.display.flip()
- clock.tick(FPS)
+ fpses[frame] = 1000.0 / clock.tick(FPS)
+ frame += 1
+ if frame >= FPS_FRAMES:
+ frame = 0