Skip to content

Commit 7286453

Browse files
committed
Pass scene argument to play and wait
1 parent e7a38a9 commit 7286453

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

manim/renderer/cairo_renderer.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
from ..camera.camera import Camera
1010

1111

12-
def manage_scene_reference(func):
12+
def pass_scene_reference(func):
1313
def wrapper(self, scene, *args, **kwargs):
14-
setattr(self, "scene", scene)
15-
func(self, *args, **kwargs)
16-
delattr(self, "scene")
14+
func(self, scene, *args, **kwargs)
1715

1816
return wrapper
1917

@@ -39,10 +37,10 @@ def handle_play_like_call(func):
3937
to the video file stream.
4038
"""
4139

42-
def wrapper(self, *args, **kwargs):
40+
def wrapper(self, scene, *args, **kwargs):
4341
allow_write = not file_writer_config["skip_animations"]
4442
self.file_writer.begin_animation(allow_write)
45-
func(self, *args, **kwargs)
43+
func(self, scene, *args, **kwargs)
4644
self.file_writer.end_animation(allow_write)
4745
self.num_plays += 1
4846

@@ -88,17 +86,17 @@ def init(self, scene):
8886
**file_writer_config,
8987
)
9088

91-
@manage_scene_reference
89+
@pass_scene_reference
9290
@handle_caching_play
9391
@handle_play_like_call
94-
def play(self, *args, **kwargs):
95-
self.scene.play_internal(*args, **kwargs)
92+
def play(self, scene, *args, **kwargs):
93+
scene.play_internal(*args, **kwargs)
9694

97-
@manage_scene_reference
95+
@pass_scene_reference
9896
@handle_caching_wait
9997
@handle_play_like_call
100-
def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
101-
self.scene.wait_internal(duration=duration, stop_condition=stop_condition)
98+
def wait(self, scene, duration=DEFAULT_WAIT_TIME, stop_condition=None):
99+
scene.wait_internal(duration=duration, stop_condition=stop_condition)
102100

103101
def update_frame( # TODO Description in Docstring
104102
self,

manim/utils/caching.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ def handle_caching_play(func):
1515
The play like function that has to be written to the video file stream. Take the same parameters as `scene.play`.
1616
"""
1717

18-
def wrapper(self, *args, **kwargs):
18+
def wrapper(self, scene, *args, **kwargs):
1919
self.revert_to_original_skipping_status()
2020
self.update_skipping_status()
21-
animations = self.scene.compile_play_args_to_animation_list(*args, **kwargs)
22-
self.scene.add_mobjects_from_animations(animations)
21+
animations = scene.compile_play_args_to_animation_list(*args, **kwargs)
22+
scene.add_mobjects_from_animations(animations)
2323
if file_writer_config["skip_animations"]:
2424
logger.debug(f"Skipping animation {self.num_plays}")
25-
func(self, *args, **kwargs)
25+
func(self, scene, *args, **kwargs)
2626
# If the animation is skipped, we mark its hash as None.
2727
# When sceneFileWriter will start combining partial movie files, it won't take into account None hashes.
2828
self.animations_hashes.append(None)
2929
self.file_writer.add_partial_movie_file(None)
3030
return
3131
if not file_writer_config["disable_caching"]:
32-
mobjects_on_scene = self.scene.get_mobjects()
32+
mobjects_on_scene = scene.get_mobjects()
3333
hash_play = get_hash_from_play_call(
3434
self, self.camera, animations, mobjects_on_scene
3535
)
@@ -47,7 +47,7 @@ def wrapper(self, *args, **kwargs):
4747
"List of the first few animation hashes of the scene: %(h)s",
4848
{"h": str(self.animations_hashes[:5])},
4949
)
50-
func(self, *args, **kwargs)
50+
func(self, scene, *args, **kwargs)
5151

5252
return wrapper
5353

@@ -64,20 +64,20 @@ def handle_caching_wait(func):
6464
The wait like function that has to be written to the video file stream. Take the same parameters as `scene.wait`.
6565
"""
6666

67-
def wrapper(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
67+
def wrapper(self, scene, duration=DEFAULT_WAIT_TIME, stop_condition=None):
6868
self.revert_to_original_skipping_status()
6969
self.update_skipping_status()
7070
if file_writer_config["skip_animations"]:
7171
logger.debug(f"Skipping wait {self.num_plays}")
72-
func(self, duration, stop_condition)
72+
func(self, scene, duration, stop_condition)
7373
# If the animation is skipped, we mark its hash as None.
7474
# When sceneFileWriter will start combining partial movie files, it won't take into account None hashes.
7575
self.animations_hashes.append(None)
7676
self.file_writer.add_partial_movie_file(None)
7777
return
7878
if not file_writer_config["disable_caching"]:
7979
hash_wait = get_hash_from_wait_call(
80-
self, self.camera, duration, stop_condition, self.scene.get_mobjects()
80+
self, self.camera, duration, stop_condition, scene.get_mobjects()
8181
)
8282
if self.file_writer.is_already_cached(hash_wait):
8383
logger.info(
@@ -92,6 +92,6 @@ def wrapper(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
9292
"Animations hashes list of the scene : (concatened to 5) %(h)s",
9393
{"h": str(self.animations_hashes[:5])},
9494
)
95-
func(self, duration, stop_condition)
95+
func(self, scene, duration, stop_condition)
9696

9797
return wrapper

0 commit comments

Comments
 (0)