Simplify pyglet.clock.Clock by removing unnecessary base classes.
@@ -110,26 +110,11 @@ Multiple and derived clocks potentially allow you to separate "game-time" and
"wall-time", or to synchronise your clock to an audio or video stream instead
of the system clock.
"""
-import sys
import time
-import ctypes
from operator import attrgetter
from heapq import heappush, heappop, heappushpop
from collections import deque
-import pyglet.lib
-from pyglet import compat_platform
-
-
-class _ClockBase(object):
-
- @staticmethod
- def sleep(microseconds):
- time.sleep(microseconds * 1e-6)
-
-
-_default_time_function = time.perf_counter
-
class _ScheduledItem(object):
__slots__ = ['func', 'args', 'kwargs']
@@ -158,26 +143,11 @@ class _ScheduledIntervalItem(object):
return self.next_ts < other
-class Clock(_ClockBase):
+class Clock:
"""Class for calculating and limiting framerate.
It is also used for calling scheduled functions.
"""
-
- #: The minimum amount of time in seconds this clock will attempt to sleep
- #: for when framerate limiting. Higher values will increase the
- #: accuracy of the limiting but also increase CPU usage while
- #: busy-waiting. Lower values mean the process sleeps more often, but is
- #: prone to over-sleep and run at a potentially lower or uneven framerate
- #: than desired.
- #: On Windows, MIN_SLEEP is larger because the default timer resolution
- #: is set by default to 15 .6 ms.
- MIN_SLEEP = 0.008 if compat_platform in ('win32', 'cygwin') else 0.005
-
- #: The amount of time in seconds this clock subtracts from sleep values
- #: to compensate for lazy operating systems.
- SLEEP_UNDERSHOOT = MIN_SLEEP - 0.001
-
# List of functions to call every tick.
_schedule_items = None
@@ -187,7 +157,7 @@ class Clock(_ClockBase):
# If True, a sleep(0) is inserted on every tick.
_force_sleep = False
- def __init__(self, time_function=_default_time_function):
+ def __init__(self, time_function=time.perf_counter):
"""Initialise a Clock, with optional custom time function.
:Parameters:
@@ -354,7 +324,8 @@ class Clock(_ClockBase):
self.call_scheduled_functions(delta_t)
return delta_t
- def sleep(self, microseconds):
+ @staticmethod
+ def sleep(microseconds):
time.sleep(microseconds * 1e-6)
def get_sleep_time(self, sleep_idle):
