Esempio n. 1
0
 def _route(timeline):
     origin_location = sim.routing_location
     if path.status == routing.Path.PLANSTATUS_READY:
         if not FollowPath.should_follow_path(sim, path):
             if callback_fn is not None:
                 result = callback_fn(0)
                 if result == FollowPath.Action.CANCEL:
                     return False
             return True
         distance_left = path.length()
         if callback_fn is not None and distance_left < FollowPath.DISTANCE_TO_RECHECK_INUSE:
             route_action = callback_fn(distance_left)
             if route_action == FollowPath.Action.CANCEL:
                 return False
         if sim.position != origin_location.position:
             logger.error("Route-to-position has outdated starting location. Sim's position ({}) is {:0.2f}m from the original starting position ({})", sim.position, (sim.position - origin_location.position).magnitude(), origin_location.position)
         follow_element = FollowPath(sim, path, callback_fn=callback_fn)
         if path.is_route_fail():
             if handle_failure:
                 yield element_utils.run_child(timeline, follow_element)
             if lockout_target is not None:
                 sim.add_lockout(lockout_target, ReserveObjectHandler.LOCKOUT_TIME)
             return Result.ROUTE_FAILED
         critical_element = elements.WithFinallyElement(follow_element, lambda _: path.remove_from_quad_tree())
         result = yield element_utils.run_child(timeline, critical_element)
         return result
     if lockout_target is not None:
         sim.add_lockout(lockout_target, ReserveObjectHandler.LOCKOUT_TIME)
     return Result.ROUTE_PLAN_FAILED
Esempio n. 2
0
def _build_with_finally(sequence):
    (prefix, final) = _split_sequence(sequence)
    if not (final is not None and (inspect.isgeneratorfunction(final)
                                   or not inspect.isroutine(final))):
        raise ValueError('{} not a function in _build_element'.format(final))
    child = _build_from_iterable(prefix)
    if final is None:
        return child
    return elements.WithFinallyElement(child, final)
Esempio n. 3
0
    def save_using(self, save_generator, *args, **kwargs):

        def call_save_game_gen(timeline):
            result = yield save_generator(timeline, *args, **kwargs)
            return result

        self._create_save_timeline()
        element = elements.GeneratorElement(call_save_game_gen)
        element = elements.WithFinallyElement(element, self._destroy_save_timeline)
        element_handle = self.save_timeline.schedule(element)
        return element_handle