def __init__(self, vehicle_config, env, clip_rgb: bool, resolution=None, max_distance=50): self.resolution = resolution or self.RESOLUTION super(TopDownObservation, self).__init__(vehicle_config, env) self.rgb_clip = clip_rgb self.num_stacks = 3 # self.obs_shape = (64, 64) self.obs_shape = self.resolution self.pygame = import_pygame() self.onscreen = env.config["use_render"] main_window_position = (0, 0) self._center_pos = None # automatically change, don't set the value self._should_draw_map = True self._canvas_to_display_scaling = 0.0 self.max_distance = max_distance # scene self.road_network = None self.engine = None # initialize pygame.init() pygame.display.set_caption(EDITION + " (Top-down)") # main_window_position means the left upper location. os.environ['SDL_VIDEO_WINDOW_POS'] = '{},{}' \ .format(main_window_position[0] - self.resolution[0], main_window_position[1]) # Used for display only! self.screen = pygame.display.set_mode( (self.resolution[0] * 2, self.resolution[1] * 2)) if self.onscreen else None # canvas self.init_canvas() self.init_obs_window()
import copy import numpy as np from pgdrive.base_class.base_runnable import BaseRunnable from pgdrive.component.algorithm.BIG import BigGenerateMethod from pgdrive.component.blocks.first_block import FirstPGBlock from pgdrive.component.blocks.pg_block import PGBlock from pgdrive.component.road.road import Road from pgdrive.component.road.road_network import RoadNetwork from pgdrive.engine.engine_utils import get_engine, get_global_config from pgdrive.utils import Config, import_pygame pygame = import_pygame() def parse_map_config(easy_map_config, new_map_config, default_config): assert isinstance(new_map_config, Config) assert isinstance(default_config, Config) # Return the user specified config if overwritten if not default_config["map_config"].is_identical(new_map_config): new_map_config = default_config["map_config"].copy( unchangeable=False).update(new_map_config) assert default_config["map"] == easy_map_config return new_map_config if isinstance(easy_map_config, int): new_map_config[BaseMap.GENERATE_TYPE] = BigGenerateMethod.BLOCK_NUM elif isinstance(easy_map_config, str): new_map_config[ BaseMap.GENERATE_TYPE] = BigGenerateMethod.BLOCK_SEQUENCE