Beispiel #1
0
 def snek(hueRotation=0.0, saturationBoost=0.0):
     animationIndex = random.randint(0, 4)
     if pygame.key.get_mods() & pygame.locals.KMOD_LSHIFT:
         hueRotation = random.random()
         saturationBoost = random.random() * 0.2
     images = spriteRow(16 + (32 * animationIndex), hueRotation,
                        saturationBoost)
     sprite = Sprite(images, random.randint(0, 400), random.randint(0, 400))
     moveSpeed = random.randint(50, 100)
     animateSpeed = random.randint(5, 35)
     animator = LoopingCall.withCount(sprite.animate)
     animator.start(1.0 / animateSpeed)
     mover = LoopingCall.withCount(Mover(sprite).move)
     mover.start(1.0 / moveSpeed)
     engine.drawables.append(sprite)
     sneks.append((animator, mover, sprite))
Beispiel #2
0
 def start(self):
   """
   Start the simulated advancement of time.
   """
   self._call = LoopingCall.withCount(self._update)
   self._call.clock = self.platformClock
   self._call.start(1.0 / self.granularity, now=False)
Beispiel #3
0
    def start(self):
        screen = pygame.display.set_mode(self.screen_size, vsync=1)

        def handle_events():
            if self.game_state.state == locals.GAME_PLAY:
                if self.player.is_touching(self.goal):
                    print("Touching!")
                    self.game_state.state = locals.GAME_WIN
            for event in pygame.event.get():
                if event.type == pygame.locals.KEYDOWN:
                    handler = self.keydown_handlers.get(event.key)
                    if handler:
                        handler()
                elif event.type == pygame.locals.KEYUP:
                    handler = self.keyup_handlers.get(event.key)
                    if handler:
                        handler()

        def draw_screen():
            screen.fill(self.game_state.background_color)
            for drawable in self.drawables:
                drawable.draw(screen)
            pygame.display.flip()

        player_mover = LoopingCall.withCount(self.player.move)
        player_mover.start(1 / 60.0)
        LoopingCall(draw_screen).start(1.0 / 60.0)
        LoopingCall(handle_events).start(1.0 / 120.0)
Beispiel #4
0
 def __init__(self, *args, **kwargs):
     self.dead = False
     self.type = None
     self.secure = False
     self.data = 0
     self.data_checker = LoopingCall(self.checkData)
     self.pinger = LoopingCall.withCount(self.ping)
Beispiel #5
0
    def __init__(
        self, reactor, request, request_rate=10,
        sample_size=DEFAULT_SAMPLE_SIZE, timeout=45,
        tolerance_percentage=0.2
    ):
        """
        ``RequestLoadScenario`` constructor.

        :param tolerance_percentage: error percentage in the rate that is
            considered valid. For example, if we request a ``request_rate``
            of 20, and we give a tolerance_percentage of 0.2 (20%), anything
            in [16,20] will be a valid rate.
        """
        self.reactor = reactor
        self.request = request
        self.request_rate = request_rate
        self.timeout = timeout
        self._maintained = Deferred()
        self.rate_measurer = RateMeasurer(sample_size)
        self.max_outstanding = 10 * request_rate
        self.tolerated_errors = 5 * request_rate
        # Send requests per second
        self.loop = LoopingCall.withCount(self._request_and_measure)
        self.loop.clock = self.reactor
        # Monitor the status of the scenario
        self.monitor_loop = LoopingCall(self.check_rate)
        self.monitor_loop.clock = self.reactor
        self.is_started = False
        self.rate_tolerated = (
            float(request_rate) - (request_rate*tolerance_percentage)
        )
Beispiel #6
0
 def start(self):
     """
     Start the simulated advancement of time.
     """
     self._call = LoopingCall.withCount(self._update)
     self._call.clock = reactor
     self._call.start(1.0 / self.framerate, now=False)
     self._running = True
Beispiel #7
0
 def start(self):
     """
     Start the simulated advancement of time.
     """
     self._call = LoopingCall.withCount(self._update)
     self._call.clock = reactor
     self._call.start(1.0 / self.framerate, now=False)
     self._running = True
 def start(self):
     """
     Start the simulated advancement of time.
     """
     print "Simulation Time Starting"
     self._call = LoopingCall.withCount(self._update)
     self._call.clock = self.platformClock
     self._call.start(1.0 / self.granularity, now=False)
Beispiel #9
0
 def __init__(self, ip):
     self.dead = False
     self.type = None
     self.secure = False
     self.data = 0
     self.data_checker = LoopingCall(self.checkData)
     self.pinger = LoopingCall.withCount(self.ping)
     self.connection_expire = reactor.callLater(15, self.connectionLost, None)
     self.ip = ip
Beispiel #10
0
 def configure(self, config):
     room = self.original
     self._loop = LoopingCall.withCount(self.update)
     self._interval = 0.1
     self.map, self.walk = gen_map()
     self.tick = 0
     self.enemies = []
     self.towers = []
     self.spawned = 0
     self.stats = defaultdict(int)
Beispiel #11
0
 def configure(self, config):
     room = self.original
     self._loop = LoopingCall.withCount(self.update)
     self._interval = 0.1
     self.map, self.walk = gen_map()
     self.tick = 0
     self.enemies = []
     self.towers = []
     self.spawned = 0
     self.stats = defaultdict(int)
Beispiel #12
0
    def _start_audio_processing_loop(self, interval):
        looping_call = LoopingCall.withCount(self.process_audio_frame)

        d = looping_call.start(interval)

        def on_stop(data):
            print("The audio processing loop was stopped")
            
        def on_error(data):
            print("ERROR: An error occurred during the audio processing loop:", data)
            raise Exception("An error occurred during the audio processing loop:" + str(data))

        d.addCallback(on_stop)
        d.addErrback(on_error)

        return d
 def __init__(
     self, reactor, cluster, request_rate=10,
     sample_size=DEFAULT_SAMPLE_SIZE, timeout=45
 ):
     self._maintained = Deferred()
     self.reactor = reactor
     self.control_service = cluster.get_control_service(reactor)
     self.request_rate = request_rate
     self.timeout = timeout
     self.rate_measurer = RateMeasurer(sample_size)
     self.max_outstanding = 10 * request_rate
     # Send requests per second
     self.loop = LoopingCall.withCount(self._request_and_measure)
     self.loop.clock = self.reactor
     self.monitor_loop = LoopingCall(self.check_rate)
     self.monitor_loop.clock = self.reactor
 def __init__(self,
              reactor,
              cluster,
              request_rate=10,
              sample_size=DEFAULT_SAMPLE_SIZE,
              timeout=45):
     self._maintained = Deferred()
     self.reactor = reactor
     self.control_service = cluster.get_control_service(reactor)
     self.request_rate = request_rate
     self.timeout = timeout
     self.rate_measurer = RateMeasurer(sample_size)
     self.max_outstanding = 10 * request_rate
     # Send requests per second
     self.loop = LoopingCall.withCount(self._request_and_measure)
     self.loop.clock = self.reactor
     self.monitor_loop = LoopingCall(self.check_rate)
     self.monitor_loop.clock = self.reactor
 def __init__(
     self, reactor, cluster, request_rate=10,
     sample_size=DEFAULT_SAMPLE_SIZE, timeout=45
 ):
     self._maintained = Deferred()
     self.reactor = reactor
     self.control_service = cluster.get_control_service(reactor)
     self.request_rate = request_rate
     self.timeout = timeout
     self.rate_measurer = RateMeasurer(sample_size)
     self.max_outstanding = 10 * request_rate
     self._dataset_id = ""
     # Send requests per second
     self.loop = LoopingCall.withCount(self._request_and_measure)
     self.loop.clock = self.reactor
     # Once the expected rate is reached, we will start monitoring
     # the scenario inside this loop
     self.monitor_loop = LoopingCall(self.check_rate)
     self.monitor_loop.clock = self.reactor
Beispiel #16
0
    def __init__(self,
                 reactor,
                 scenario_setup_instance,
                 request_rate=10,
                 sample_size=DEFAULT_SAMPLE_SIZE,
                 timeout=45,
                 tolerance_percentage=0.2):
        """
        ``RequestLoadScenario`` constructor.

        :param reactor: Reactor to use.
        :param scenario_setup_instance: provider of the
            ``IRequestScenarioSetup`` interface.
        :param request_rate: target number of request per second.
        :param sample_size: number of samples to collect when measuring
            the rate.
        :param tolerance_percentage: error percentage in the rate that is
            considered valid. For example, if we request a ``request_rate``
            of 20, and we give a tolerance_percentage of 0.2 (20%), anything
            in [16,20] will be a valid rate.
        """
        self.reactor = reactor
        self.scenario_setup = scenario_setup_instance
        self.request_rate = request_rate
        self.timeout = timeout
        self._maintained = Deferred()
        self.rate_measurer = RateMeasurer(sample_size)
        self.max_outstanding = 10 * request_rate
        # Send requests per second
        self.loop = LoopingCall.withCount(self._request_and_measure)
        self.loop.clock = self.reactor
        # Monitor the status of the scenario
        self.monitor_loop = LoopingCall(self.check_rate)
        self.monitor_loop.clock = self.reactor
        self.is_started = False
        self.rate_tolerated = (float(request_rate) -
                               (request_rate * tolerance_percentage))
Beispiel #17
0
    def __init__(
        self, reactor, scenario_setup_instance, request_rate=10,
        sample_size=DEFAULT_SAMPLE_SIZE, timeout=45,
        tolerance_percentage=0.2
    ):
        """
        ``RequestLoadScenario`` constructor.

        :param reactor: Reactor to use.
        :param scenario_setup_instance: provider of the
            ``IRequestScenarioSetup`` interface.
        :param request_rate: target number of request per second.
        :param sample_size: number of samples to collect when measuring
            the rate.
        :param tolerance_percentage: error percentage in the rate that is
            considered valid. For example, if we request a ``request_rate``
            of 20, and we give a tolerance_percentage of 0.2 (20%), anything
            in [16,20] will be a valid rate.
        """
        self.reactor = reactor
        self.scenario_setup = scenario_setup_instance
        self.request_rate = request_rate
        self.timeout = timeout
        self._maintained = Deferred()
        self.rate_measurer = RateMeasurer(sample_size)
        self.max_outstanding = 10 * request_rate
        # Send requests per second
        self.loop = LoopingCall.withCount(self._request_and_measure)
        self.loop.clock = self.reactor
        # Monitor the status of the scenario
        self.monitor_loop = LoopingCall(self.check_rate)
        self.monitor_loop.clock = self.reactor
        self.is_started = False
        self.rate_tolerated = (
            float(request_rate) - (request_rate*tolerance_percentage)
        )
Beispiel #18
0
 def configure(self, config):
     self._loop = LoopingCall.withCount(self.update)
     self._interval = 1
     self.points = 0
Beispiel #19
0
 def __init__(self, logger):
     self._logger = logger
     self._tasks = []
     self._impl = LoopingCall.withCount(self._update)
Beispiel #20
0
 def start(self):
     self._call = LoopingCall.withCount(self._update)
     self._call.clock = self.platformClock
     self._call.start(1.0 / self.granularity, now=False)
     print 'start clock'
Beispiel #21
0
    def __init__(self, *args, **kwargs):
        super(Furnace, self).__init__(*args, **kwargs)

        self.inventory = FurnaceStorage()
        self.burning = LoopingCall.withCount(self.burn)
Beispiel #22
0
    def __init__(self, *args, **kwargs):
        super(Furnace, self).__init__(*args, **kwargs)

        self.inventory = FurnaceStorage()
        self.burning = LoopingCall.withCount(self.burn)
Beispiel #23
0
 def __init__(self):
     # Mapping of user commands to handlers
     self.command_handlers = {
         Commands.CONNECTION_PASSWORD: self.on_connection_password,
     }
     self.info_collector = LoopingCall.withCount(self.collect_info)
Beispiel #24
0
 def __init__(self, delay=0.01):
     self.delay = delay
     self.loop_call = LoopingCall.withCount(self.watch)
     self.blocked = 0
     self.checks = []
     self.d = None
Beispiel #25
0
 def configure(self, config):
     self._loop = LoopingCall.withCount(self.update)
     self._interval = 1
     self.points = 0
Beispiel #26
0
 def __init__(self, tile, coords):
     self.tile = tile
     self.coords = coords
     self.running = False
     self.burning = LoopingCall.withCount(self.burn)