add timer wrapper & tests

This commit is contained in:
James Turk 2011-05-10 01:20:32 -04:00
parent cc16beb8b0
commit 180328231d
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,24 @@
from .. import init, InitFlags, timer
import time
def init_timer():
init(InitFlags.TIMER)
def test_performance_counter():
init_timer()
first = timer.get_performance_counter()
time.sleep(1.1)
second = timer.get_performance_counter()
freq = timer.get_performance_frequency()
assert second > first
assert second/freq > first/freq
def test_get_ticks():
init_timer()
first = timer.get_ticks()
time.sleep(0.1)
second = timer.get_ticks()
assert second > first
# delay should safely put it in this range
assert 50 < second - first < 500

17
photon/timer.py Normal file
View File

@ -0,0 +1,17 @@
import ctypes
from .internal import _SDL
_SDL.SDL_GetPerformanceCounter.restype = ctypes.c_uint64
_SDL.SDL_GetPerformanceFrequency.restype = ctypes.c_uint64
_SDL.SDL_GetTicks.restype = ctypes.c_uint32
def get_performance_counter():
return _SDL.SDL_GetPerformanceCounter()
def get_performance_frequency():
return _SDL.SDL_GetPerformanceFrequency()
def get_ticks():
return _SDL.SDL_GetTicks()