Skip to content
Snippets Groups Projects
Commit ff6e4842 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Round rotation angles and sizes for caching

parent ff6d5d8a
No related branches found
No related tags found
2 merge requests!110V1.2.0 changes,!104Resolve "Faster Drawing"
Pipeline #58980 failed
......@@ -358,10 +358,15 @@ class Visualizer:
pos: The position of the center of the image, given in pixels.
rot_angle: Optional angle to rotate the image around.
"""
size = int(np.round(size))
rot_angle = int(np.round(rot_angle))
cache_entry = f"{img_path}-{size}-{rot_angle}" + ("-burnt" if burnt else "")
if cache_entry in self.image_cache_dict:
image = self.image_cache_dict[cache_entry]
else:
image = pygame.image.load(
ROOT_DIR / "pygame_2d_vis" / img_path
).convert_alpha()
......@@ -371,9 +376,9 @@ class Visualizer:
# TODO: smoothscale or not???
# image = pygame.transform.smoothscale(image, (size, size))
image = pygame.transform.scale(image, (size, size))
if rot_angle != 0:
image = pygame.transform.rotate(image, rot_angle)
self.image_cache_dict[cache_entry] = image
rect = image.get_rect()
......
......@@ -46,10 +46,10 @@ def run_benchmark(GRID_SIZE, ITERS, OPTIMIZATIONS):
json_dict = env.get_state(player_id=PLAYER)
time_start = time.perf_counter()
observation = visualizer.get_state_image(state=json_dict)
observation = visualizer.get_state_image(state=json_dict, cache_flags=OPTIMIZATIONS["cache_counters"])
img = observation.astype(np.uint8).transpose((1, 0, 2))
img = cv2.resize(img, (640, 640), interpolation=cv2.INTER_NEAREST)
img = cv2.resize(img, (400, 400), interpolation=cv2.INTER_NEAREST)
cv2.imshow("env", img[:, :, ::-1])
cv2.waitKey(1)
durations.append(time.perf_counter() - time_start)
......@@ -75,10 +75,8 @@ if __name__ == "__main__":
with open(ROOT_DIR / "pygame_2d_vis" / "visualization.yaml", "r") as file:
visualization_config = yaml.safe_load(file)
GRID_SIZE = 24
# GRID_SIZE = 12.8
ITERS = 4000
GRID_SIZE = 100
ITERS = 1000
# for array3d in [False, True]:
OPTIMIZATIONS = {"use_array3d": True, "cache_counters": CacheFlags.NONE}
OPTIMIZATIONS = {"use_array3d": True, "cache_counters": CacheFlags.BACKGROUND | CacheFlags.COUNTERS}
run_benchmark(GRID_SIZE, ITERS, OPTIMIZATIONS)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment