Esempio n. 1
0
def game_loop(worldstate, current_tick_time, ttl=None):
    logger.debug("New tick: %d", worldstate.ticks)

    events_ = itertools.chain(
        ai.dot_ai(worldstate),
        events.process_browser_events(worldstate)
    )
    worldstate = events.handle_events(worldstate, events_)  # TODO: New variable name, because FP

    new_worldstate = attr_update(
        worldstate,
        ticks=_+1,  # Elapsed ticks in game
    )

    next_tick_time, delta = calc_next_tick_time(current_tick_time)  # Get times for next frame
    logger.debug("Sleeping for %s (%s%%)", delta, round(delta * 1000, 2))
    time.sleep(delta)

    # TTL stuff is in place to let us unit test this function, which we can't do if it runs forever
    if ttl is None:
        new_ttl = ttl
    else:
        new_ttl = ttl - 1
    if ttl == 0:
        continue_ = False
    else:
        continue_ = True

    return continue_, (new_worldstate, next_tick_time, new_ttl)
Esempio n. 2
0
    def _predicate(f):
        @functools.wraps(f)
        def func(*args, **kwargs):
            return f(*args, **kwargs)

        if not hasattr(event, "events"):
            event.events = {}
        event.events[e] = func
        logger.debug("event %s: %s", e, f)

        return func