mirror of
https://github.com/3b1b/manim.git
synced 2025-08-21 05:44:04 +00:00
Replace handle_play_like_call with pre_play and post_play method
This commit is contained in:
parent
24fd6d890e
commit
38db5ca9b9
1 changed files with 26 additions and 28 deletions
|
@ -511,39 +511,35 @@ class Scene(object):
|
||||||
kw["override_skip_animations"] = True
|
kw["override_skip_animations"] = True
|
||||||
return self.get_time_progression(duration, **kw)
|
return self.get_time_progression(duration, **kw)
|
||||||
|
|
||||||
@staticmethod
|
def pre_play(self):
|
||||||
def handle_play_like_call(func: Callable):
|
if self.inside_embed:
|
||||||
@wraps(func)
|
self.save_state()
|
||||||
def wrapper(self, *args, **kwargs):
|
if self.presenter_mode and self.num_plays == 0:
|
||||||
if self.inside_embed:
|
self.hold_loop()
|
||||||
self.save_state()
|
|
||||||
if self.presenter_mode and self.num_plays == 0:
|
|
||||||
self.hold_loop()
|
|
||||||
|
|
||||||
self.update_skipping_status()
|
self.update_skipping_status()
|
||||||
should_write = not self.skip_animations
|
|
||||||
if should_write:
|
|
||||||
self.file_writer.begin_animation()
|
|
||||||
|
|
||||||
if self.window:
|
if not self.skip_animations:
|
||||||
self.real_animation_start_time = time.time()
|
self.file_writer.begin_animation()
|
||||||
self.virtual_animation_start_time = self.time
|
|
||||||
|
|
||||||
self.refresh_static_mobjects()
|
if self.window:
|
||||||
func(self, *args, **kwargs)
|
self.real_animation_start_time = time.time()
|
||||||
|
self.virtual_animation_start_time = self.time
|
||||||
|
|
||||||
if should_write:
|
self.refresh_static_mobjects()
|
||||||
self.file_writer.end_animation()
|
|
||||||
|
|
||||||
if self.inside_embed:
|
def post_play(self):
|
||||||
self.save_state()
|
if not self.skip_animations:
|
||||||
|
self.file_writer.end_animation()
|
||||||
|
|
||||||
if self.skip_animations and self.window is not None:
|
if self.inside_embed:
|
||||||
# Show some quick frames along the way
|
self.save_state()
|
||||||
self.update_frame(dt=0, ignore_skipping=True)
|
|
||||||
|
|
||||||
self.num_plays += 1
|
if self.skip_animations and self.window is not None:
|
||||||
return wrapper
|
# Show some quick frames along the way
|
||||||
|
self.update_frame(dt=0, ignore_skipping=True)
|
||||||
|
|
||||||
|
self.num_plays += 1
|
||||||
|
|
||||||
def refresh_static_mobjects(self) -> None:
|
def refresh_static_mobjects(self) -> None:
|
||||||
self.camera.refresh_static_mobjects()
|
self.camera.refresh_static_mobjects()
|
||||||
|
@ -580,7 +576,6 @@ class Scene(object):
|
||||||
else:
|
else:
|
||||||
self.update_mobjects(0)
|
self.update_mobjects(0)
|
||||||
|
|
||||||
@handle_play_like_call
|
|
||||||
def play(
|
def play(
|
||||||
self,
|
self,
|
||||||
*proto_animations: Animation | _AnimationBuilder,
|
*proto_animations: Animation | _AnimationBuilder,
|
||||||
|
@ -594,11 +589,12 @@ class Scene(object):
|
||||||
animations = list(map(prepare_animation, proto_animations))
|
animations = list(map(prepare_animation, proto_animations))
|
||||||
for anim in animations:
|
for anim in animations:
|
||||||
anim.update_rate_info(run_time, rate_func, lag_ratio)
|
anim.update_rate_info(run_time, rate_func, lag_ratio)
|
||||||
|
self.pre_play()
|
||||||
self.begin_animations(animations)
|
self.begin_animations(animations)
|
||||||
self.progress_through_animations(animations)
|
self.progress_through_animations(animations)
|
||||||
self.finish_animations(animations)
|
self.finish_animations(animations)
|
||||||
|
self.post_play()
|
||||||
|
|
||||||
@handle_play_like_call
|
|
||||||
def wait(
|
def wait(
|
||||||
self,
|
self,
|
||||||
duration: float = DEFAULT_WAIT_TIME,
|
duration: float = DEFAULT_WAIT_TIME,
|
||||||
|
@ -606,6 +602,7 @@ class Scene(object):
|
||||||
note: str = None,
|
note: str = None,
|
||||||
ignore_presenter_mode: bool = False
|
ignore_presenter_mode: bool = False
|
||||||
):
|
):
|
||||||
|
self.pre_play()
|
||||||
self.update_mobjects(dt=0) # Any problems with this?
|
self.update_mobjects(dt=0) # Any problems with this?
|
||||||
if self.presenter_mode and not self.skip_animations and not ignore_presenter_mode:
|
if self.presenter_mode and not self.skip_animations and not ignore_presenter_mode:
|
||||||
if note:
|
if note:
|
||||||
|
@ -622,6 +619,7 @@ class Scene(object):
|
||||||
if stop_condition is not None and stop_condition():
|
if stop_condition is not None and stop_condition():
|
||||||
break
|
break
|
||||||
self.refresh_static_mobjects()
|
self.refresh_static_mobjects()
|
||||||
|
self.post_play()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def hold_loop(self):
|
def hold_loop(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue