Пример #1
0
def test_next_tick_time_on_schedule():
    # Best case - 0 delay between current tick and current time
    current_tt = time.time()
    ntt, delta = engine.calc_next_tick_time(current_tt, current_time=current_tt)
    assert ntt == current_tt + utils.frames_to_secs(1)
    assert round(delta, 5) == utils.frames_to_secs(1)


    # Test what happens if we actually do some work during a frame
    ntt, delta = engine.calc_next_tick_time(current_tt, current_time=(current_tt + utils.frames_to_secs(1)/2))
    assert ntt == current_tt + utils.frames_to_secs(1)
    assert round(delta, 5) == utils.frames_to_secs(1)/2
Пример #2
0
def calc_next_tick_time(current_tick, current_time=None):  # current_time parameter used for unit testing
    if current_time is None:
        t = time.time()
    else:
        t = current_time
    expected_next_tick = current_tick + utils.frames_to_secs(1)
    next_tick = max(expected_next_tick, t)
    delta = max(0, next_tick - t)  # Time delta to next tick. If we take < 1 frame's time to render a frame, sleep until the next frame tick. If we're taking longer than 1 frame's time to render each frame, don't sleep. 
    if delta == 0:
        logger.warn("Frame ran too long by %f secs", t - expected_next_tick)

    return (
        next_tick,
        delta
    )
Пример #3
0
def test_next_tick_time_behind_schedule():
    current_time = time.time()
    current_tick = current_time - utils.frames_to_secs(4)
    ntt, delta = engine.calc_next_tick_time(current_tick, current_time=current_time)
    assert round(ntt, 5) == round(current_time, 5)
    assert delta == 0
Пример #4
0
def test_frames_to_secs():
    fts = utils.frames_to_secs(1)
    assert 0 < round(fts, 5) < 1