(args)
| 577 | # ============================================================================== |
| 578 | |
| 579 | def game_loop(args): |
| 580 | pygame.init() |
| 581 | pygame.font.init() |
| 582 | world = None |
| 583 | |
| 584 | try: |
| 585 | client = carla.Client(args.host, args.port) |
| 586 | client.set_timeout(4.0) |
| 587 | |
| 588 | display = pygame.display.set_mode( |
| 589 | (args.width, args.height), |
| 590 | pygame.HWSURFACE | pygame.DOUBLEBUF) |
| 591 | |
| 592 | hud = HUD(args.width, args.height) |
| 593 | world = World(client.get_world(), hud, args.filter) |
| 594 | controller = KeyboardControl(world) |
| 595 | |
| 596 | if args.agent == "Roaming": |
| 597 | agent = RoamingAgent(world.player) |
| 598 | else: |
| 599 | agent = BasicAgent(world.player) |
| 600 | spawn_point = world.map.get_spawn_points()[0] |
| 601 | agent.set_destination((spawn_point.location.x, |
| 602 | spawn_point.location.y, |
| 603 | spawn_point.location.z)) |
| 604 | |
| 605 | clock = pygame.time.Clock() |
| 606 | while True: |
| 607 | if controller.parse_events(): |
| 608 | return |
| 609 | |
| 610 | # as soon as the server is ready continue! |
| 611 | world.world.wait_for_tick(10.0) |
| 612 | |
| 613 | world.tick(clock) |
| 614 | world.render(display) |
| 615 | pygame.display.flip() |
| 616 | control = agent.run_step() |
| 617 | control.manual_gear_shift = False |
| 618 | world.player.apply_control(control) |
| 619 | |
| 620 | finally: |
| 621 | if world is not None: |
| 622 | world.destroy() |
| 623 | |
| 624 | pygame.quit() |
| 625 | |
| 626 | |
| 627 | # ============================================================================== |
no test coverage detected