add timer wrapper & tests
This commit is contained in:
parent
cc16beb8b0
commit
180328231d
24
photon/tests/test_timer.py
Normal file
24
photon/tests/test_timer.py
Normal 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
17
photon/timer.py
Normal 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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user