Skip to content

Commit

Permalink
Change to only compute has_updater status as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Mar 7, 2024
1 parent fd35433 commit 70b839e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manimlib/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def begin(self) -> None:
self.target_copy = self.target_mobject.copy()
self.mobject.align_data_and_family(self.target_copy)
super().begin()
if not self.mobject.has_updaters:
if not self.mobject.has_updaters():
self.mobject.lock_matching_data(
self.starting_mobject,
self.target_copy,
Expand Down
50 changes: 30 additions & 20 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def init_updaters(self):
self.updating_suspended: bool = False

def update(self, dt: float = 0, recurse: bool = True) -> Self:
if not self.has_updaters or self.updating_suspended:
if not self.has_updaters() or self.updating_suspended:
return self
if recurse:
for submob in self.submobjects:
Expand All @@ -862,31 +862,33 @@ def get_family_updaters(self) -> list[Updater]:

def add_updater(
self,
update_function: Updater,
index: int | None = None,
update_func: Updater,
call_updater: bool = True
) -> Self:
if "dt" in get_parameters(update_function):
updater_list = self.time_based_updaters
if "dt" in get_parameters(update_func):
self.time_based_updaters.append(update_func)
else:
updater_list = self.non_time_updaters
self.non_time_updaters.append(update_func)

if index is None:
updater_list.append(update_function)
if call_updater:
self.update(dt=0)

self.refresh_has_updater_status()
return self

def insert_updater(self, update_func: Updater, index=0):
if "dt" in get_parameters(update_func):
self.time_based_updaters.insert(index, update_func)
else:
updater_list.insert(index, update_function)
self.non_time_updaters.insert(index, update_func)

self.refresh_has_updater_status()
for parent in self.parents:
parent.has_updaters = True
if call_updater:
self.update(dt=0)
return self

def remove_updater(self, update_function: Updater) -> Self:
def remove_updater(self, update_func: Updater) -> Self:
for updater_list in [self.time_based_updaters, self.non_time_updaters]:
while update_function in updater_list:
updater_list.remove(update_function)
while update_func in updater_list:
updater_list.remove(update_func)
self.refresh_has_updater_status()
return self

Expand Down Expand Up @@ -923,14 +925,22 @@ def resume_updating(self, recurse: bool = True, call_updater: bool = True) -> Se
self.update(dt=0, recurse=recurse)
return self

def has_updaters(self) -> bool:
if self._has_updaters_in_family is None:
# Recompute and save
res = bool(self.time_based_updaters or self.non_time_updaters)
self._has_updaters_in_family = res or any(sm.has_updaters() for sm in self.submobjects)
return self._has_updaters_in_family

def refresh_has_updater_status(self) -> Self:
self.has_updaters = any(mob.get_updaters() for mob in self.get_family())
for mob in (self, *self.parents):
mob._has_updaters_in_family = None
return self

# Check if mark as static or not for camera

def is_changing(self) -> bool:
return self._is_animating or self.has_updaters
return self._is_animating or self.has_updaters()

def set_animating_status(self, is_animating: bool, recurse: bool = True) -> Self:
for mob in (*self.get_family(recurse), *self.get_ancestors()):
Expand Down Expand Up @@ -1865,13 +1875,13 @@ def lock_data(self, keys: Iterable[str]) -> Self:
interpolate can skip this, and so that it's not
read into the shader_wrapper objects needlessly
"""
if self.has_updaters:
if self.has_updaters():
return self
self.locked_data_keys = set(keys)
return self

def lock_uniforms(self, keys: Iterable[str]) -> Self:
if self.has_updaters:
if self.has_updaters():
return self
self.locked_uniform_keys = set(keys)
return self
Expand Down

0 comments on commit 70b839e

Please sign in to comment.