|
5 | 5 | from ..utils.hashing import get_hash_from_play_call, get_hash_from_wait_call
|
6 | 6 | from ..constants import DEFAULT_WAIT_TIME
|
7 | 7 | from ..scene.scene_file_writer import SceneFileWriter
|
8 |
| - |
9 |
| - |
10 |
| -def handle_caching_play(func): |
11 |
| - """ |
12 |
| - Decorator that returns a wrapped version of func that will compute the hash of the play invocation. |
13 |
| -
|
14 |
| - The returned function will act according to the computed hash: either skip the animation because it's already cached, or let the invoked function play normally. |
15 |
| -
|
16 |
| - Parameters |
17 |
| - ---------- |
18 |
| - func : Callable[[...], None] |
19 |
| - The play like function that has to be written to the video file stream. Take the same parameters as `scene.play`. |
20 |
| - """ |
21 |
| - |
22 |
| - def wrapper(self, *args, **kwargs): |
23 |
| - self.revert_to_original_skipping_status() |
24 |
| - self.update_skipping_status() |
25 |
| - animations = self.scene.compile_play_args_to_animation_list(*args, **kwargs) |
26 |
| - self.scene.add_mobjects_from_animations(animations) |
27 |
| - if file_writer_config["skip_animations"]: |
28 |
| - logger.debug(f"Skipping animation {self.num_plays}") |
29 |
| - func(self, *args, **kwargs) |
30 |
| - # If the animation is skipped, we mark its hash as None. |
31 |
| - # When sceneFileWriter will start combining partial movie files, it won't take into account None hashes. |
32 |
| - self.animations_hashes.append(None) |
33 |
| - self.file_writer.add_partial_movie_file(None) |
34 |
| - return |
35 |
| - if not file_writer_config["disable_caching"]: |
36 |
| - mobjects_on_scene = self.scene.get_mobjects() |
37 |
| - hash_play = get_hash_from_play_call( |
38 |
| - self, self.camera, animations, mobjects_on_scene |
39 |
| - ) |
40 |
| - if self.file_writer.is_already_cached(hash_play): |
41 |
| - logger.info( |
42 |
| - f"Animation {self.num_plays} : Using cached data (hash : %(hash_play)s)", |
43 |
| - {"hash_play": hash_play}, |
44 |
| - ) |
45 |
| - file_writer_config["skip_animations"] = True |
46 |
| - else: |
47 |
| - hash_play = "uncached_{:05}".format(self.num_plays) |
48 |
| - self.animations_hashes.append(hash_play) |
49 |
| - self.file_writer.add_partial_movie_file(hash_play) |
50 |
| - logger.debug( |
51 |
| - "List of the first few animation hashes of the scene: %(h)s", |
52 |
| - {"h": str(self.animations_hashes[:5])}, |
53 |
| - ) |
54 |
| - func(self, *args, **kwargs) |
55 |
| - |
56 |
| - return wrapper |
57 |
| - |
58 |
| - |
59 |
| -def handle_caching_wait(func): |
60 |
| - """ |
61 |
| - Decorator that returns a wrapped version of func that will compute the hash of the wait invocation. |
62 |
| -
|
63 |
| - The returned function will act according to the computed hash: either skip the animation because it's already cached, or let the invoked function play normally. |
64 |
| -
|
65 |
| - Parameters |
66 |
| - ---------- |
67 |
| - func : Callable[[...], None] |
68 |
| - The wait like function that has to be written to the video file stream. Take the same parameters as `scene.wait`. |
69 |
| - """ |
70 |
| - |
71 |
| - def wrapper(self, duration=DEFAULT_WAIT_TIME, stop_condition=None): |
72 |
| - self.revert_to_original_skipping_status() |
73 |
| - self.update_skipping_status() |
74 |
| - if file_writer_config["skip_animations"]: |
75 |
| - logger.debug(f"Skipping wait {self.num_plays}") |
76 |
| - func(self, duration, stop_condition) |
77 |
| - # If the animation is skipped, we mark its hash as None. |
78 |
| - # When sceneFileWriter will start combining partial movie files, it won't take into account None hashes. |
79 |
| - self.animations_hashes.append(None) |
80 |
| - self.file_writer.add_partial_movie_file(None) |
81 |
| - return |
82 |
| - if not file_writer_config["disable_caching"]: |
83 |
| - hash_wait = get_hash_from_wait_call( |
84 |
| - self, self.camera, duration, stop_condition, self.scene.get_mobjects() |
85 |
| - ) |
86 |
| - if self.file_writer.is_already_cached(hash_wait): |
87 |
| - logger.info( |
88 |
| - f"Wait {self.num_plays} : Using cached data (hash : {hash_wait})" |
89 |
| - ) |
90 |
| - file_writer_config["skip_animations"] = True |
91 |
| - else: |
92 |
| - hash_wait = "uncached_{:05}".format(self.num_plays) |
93 |
| - self.animations_hashes.append(hash_wait) |
94 |
| - self.file_writer.add_partial_movie_file(hash_wait) |
95 |
| - logger.debug( |
96 |
| - "Animations hashes list of the scene : (concatened to 5) %(h)s", |
97 |
| - {"h": str(self.animations_hashes[:5])}, |
98 |
| - ) |
99 |
| - func(self, duration, stop_condition) |
100 |
| - |
101 |
| - return wrapper |
| 8 | +from ..utils.caching import handle_caching_play, handle_caching_wait |
102 | 9 |
|
103 | 10 |
|
104 | 11 | def handle_play_like_call(func):
|
|
0 commit comments