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

Cache rotated and resized images

parent 421f22dc
No related branches found
No related tags found
2 merge requests!110V1.2.0 changes,!104Resolve "Faster Drawing"
Pipeline #58978 failed
......@@ -358,33 +358,26 @@ class Visualizer:
pos: The position of the center of the image, given in pixels.
rot_angle: Optional angle to rotate the image around.
"""
cache_entry = f"{img_path}"
if cache_entry + ("-burnt" if burnt else "") in self.image_cache_dict:
image = self.image_cache_dict[cache_entry + ("-burnt" if burnt else "")]
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()
if burnt:
if cache_entry in self.image_cache_dict:
normal_image = self.image_cache_dict[cache_entry]
else:
normal_image = pygame.image.load(
ROOT_DIR / "pygame_2d_vis" / img_path
).convert_alpha()
self.image_cache_dict[cache_entry] = normal_image
image = grayscale(normal_image)
self.image_cache_dict[cache_entry + "-burnt"] = image
else:
image = pygame.image.load(
ROOT_DIR / "pygame_2d_vis" / img_path
).convert_alpha()
self.image_cache_dict[cache_entry] = image
# TODO: smoothscale or not???
# image = pygame.transform.smoothscale(image, (size, size))
image = pygame.transform.scale(image, (size, size))
# TODO cache rotation
if rot_angle != 0:
image = pygame.transform.rotate(image, rot_angle)
image = grayscale(image)
# 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()
rect.center = np.floor(pos)
rect.center = np.round(pos)
screen.blit(image, rect)
def draw_cook(
......@@ -805,17 +798,17 @@ class Visualizer:
counter_type = counter["type"]
if counter_type.endswith("Dispenser") and "Plate" not in counter_type:
# if "item_offset" in self.config["Dispenser"].keys():
# offset_vec = pygame.math.Vector2(
# self.config["Dispenser"]["item_offset"]
# )
# offset_vec.rotate_ip(
# offset_vec.angle_to(
# pygame.math.Vector2(counter["orientation"])
# )
# + 180
# )
# item_pos += offset_vec
if "item_offset" in self.config["Dispenser"].keys():
offset_vec = pygame.math.Vector2(
self.config["Dispenser"]["item_offset"]
)
offset_vec.rotate_ip(
offset_vec.angle_to(
pygame.math.Vector2(counter["orientation"])
)
+ 180
)
item_pos += offset_vec
if "item_scale" in self.config["Dispenser"].keys():
item_scale = self.config["Dispenser"]["item_scale"]
......
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