def test_SDL_GetTicks(self): ticks = timer.SDL_GetTicks() time.sleep(1) ticks2 = timer.SDL_GetTicks() time.sleep(1) ticks3 = timer.SDL_GetTicks() self.assertGreater(ticks3, ticks2) self.assertGreater(ticks2, ticks)
def test_SDL_GetTicks(self): ticks = timer.SDL_GetTicks() time.sleep(1) ticks2 = timer.SDL_GetTicks() time.sleep(1) ticks3 = timer.SDL_GetTicks() assert ticks3 > ticks2 assert ticks2 > ticks
def test_SDL_AddRemoveTimer(self): calls = [] def timerfunc(interval, param): calls.append(param) return interval callback = timer.SDL_TimerCallback(timerfunc) timerid = timer.SDL_AddTimer(100, callback, "Test") start = timer.SDL_GetTicks() end = long(start) while (end - start) < 1100: # One second wait end = timer.SDL_GetTicks() # check for <=11, since it can happen that a last call is still # executing self.assertLessEqual(len(calls), 11) timer.SDL_RemoveTimer(timerid) self.assertLessEqual(len(calls), 11) timer.SDL_RemoveTimer(timerid) # Wait a bit, so the last executing handlers can finish timer.SDL_Delay(10)
def loop(self): last_tick = timer.SDL_GetTicks() avg_time = 0 while True: start = timer.SDL_GetTicks() if self.events(): return self.player.tick() # self.world.tick() # optimize to be called on every frame self.focus_player() self.draw() self.window.refresh() now = timer.SDL_GetTicks() if now - last_tick > 1000: last_tick = now print(int(avg_time)) avg_time = 0.75 * avg_time + 0.25 * (now - start) timer.SDL_Delay(1000 // 60)