Change how play/wait timing works with the window

This commit is contained in:
Grant Sanderson 2020-02-18 22:30:43 -08:00
parent 26a872be94
commit 9f3551f43b

View file

@ -5,10 +5,8 @@ import platform
from tqdm import tqdm as ProgressDisplay from tqdm import tqdm as ProgressDisplay
import numpy as np import numpy as np
import itertools as it
import time import time
from IPython.terminal.embed import InteractiveShellEmbed from IPython.terminal.embed import InteractiveShellEmbed
from traitlets.config.loader import Config
from manimlib.animation.animation import Animation from manimlib.animation.animation import Animation
from manimlib.animation.transform import MoveToTarget from manimlib.animation.transform import MoveToTarget
@ -43,6 +41,8 @@ class Scene(Container):
if self.preview: if self.preview:
self.window = Window(self, **self.window_config) self.window = Window(self, **self.window_config)
self.camera_config["ctx"] = self.window.ctx self.camera_config["ctx"] = self.window.ctx
self.virtual_animation_start_time = 0
self.real_animation_start_time = time.time()
else: else:
self.window = None self.window = None
@ -98,7 +98,6 @@ class Scene(Container):
# the hood calling the pyglet event loop # the hood calling the pyglet event loop
self.quit_interaction = False self.quit_interaction = False
while not self.window.is_closing and not self.quit_interaction: while not self.window.is_closing and not self.quit_interaction:
self.time = self.window.timer.time
self.update_frame() self.update_frame()
if self.window.is_closing: if self.window.is_closing:
self.window.destroy() self.window.destroy()
@ -155,12 +154,12 @@ class Scene(Container):
if self.window: if self.window:
self.window.swap_buffers() self.window.swap_buffers()
win_time, win_dt = self.window.timer.next_frame() # win_time, win_dt = self.window.timer.next_frame()
while (self.time - self.skip_time - win_time) > 0: # while (self.time - self.skip_time - win_time) > 0:
self.window.clear() vt = self.time - self.virtual_animation_start_time
self.camera.capture(*self.mobjects) rt = time.time() - self.real_animation_start_time
self.window.swap_buffers() if rt < vt:
win_time, win_dt = self.window.timer.next_frame() self.update_frame(0)
def emit_frame(self): def emit_frame(self):
if not self.skip_animations: if not self.skip_animations:
@ -374,12 +373,19 @@ class Scene(Container):
def handle_play_like_call(func): def handle_play_like_call(func):
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
self.update_skipping_status() self.update_skipping_status()
if not self.skip_animations: should_write = not self.skip_animations
if should_write:
self.file_writer.begin_animation() self.file_writer.begin_animation()
if self.window:
self.real_animation_start_time = time.time()
self.virtual_animation_start_time = self.time
func(self, *args, **kwargs) func(self, *args, **kwargs)
if should_write:
self.file_writer.end_animation() self.file_writer.end_animation()
else:
func(self, *args, **kwargs)
self.num_plays += 1 self.num_plays += 1
return wrapper return wrapper