Repository: ManimCommunity/manim
File: manim/scene/scene.py (Python)

Code before:
    # Related to updating

    def _update_mobjects(self, dt: float) -> None:
        for mobject in self.mobjects:
            mobject.update(dt)

    def should_update_mobjects(self) -> bool:
        """
        This is called to check if a wait frame should be frozen

        Returns
        -------
            bool: does it have to be rerendered or is it static
        """
        # always rerender by returning True
        # TODO: Apply caching here
        return self.always_update_mobjects or any(
            mob.has_updaters for mob in self.mobjects
        )

    def is_current_animation_frozen_frame(self) -> bool:
        if not self.animations:
            return False

        current = self.animations[0]
        return getattr(current, "is_static_wait", False)

    def has_time_based_updaters(self) -> bool:
        return any(
            sm.has_time_based_updater()
            for mob in self.mobjects
            for sm in mob.get_family()
        )

    # Related to internal mobject organization

    def add(self, *new_mobjects: OpenGLMobject) -> Self:
        """
        Mobjects will be displayed, from background to
        foreground in the order with which they are added.
        """
        self.remove(*new_mobjects)
        self.mobjects += new_mobjects
        return self

    def remove(self, *mobjects_to_remove: OpenGLMobject) -> Self:
        """
        Removes anything in mobjects from scenes mobject list, but in the event that one
        of the items to be removed is a member of the family of an item in mobject_list,
        the other family members are added back into the list.


Review comment (suggestion):
This method should probably just take in a sequence of animations instead of using `self.animations`

Code after:
    # Only these methods should touch the camera
    # Related to updating

    def _update_mobjects(self, dt: float) -> None:
        for mobject in self.mobjects:
            mobject.update(dt)

    def should_update_mobjects(self) -> bool:
        """
        This is called to check if a wait frame should be frozen

        Returns
        -------
            bool: does it have to be rerendered or is it static
        """
        # always rerender by returning True
        # TODO: Apply caching here
        return self.always_update_mobjects or any(
            mob.has_updaters for mob in self.mobjects
        )

    def is_current_animation_frozen_frame(
        self, animations: Sequence[AnimationProtocol]
    ) -> bool:
        if len(animations) == 0:
            return False
        return all(getattr(anim, "is_static_wait", False) for anim in animations)

    def has_time_based_updaters(self) -> bool:
        return any(
            sm.has_time_based_updater()
            for mob in self.mobjects
            for sm in mob.get_family()
        )

    # Related to internal mobject organization

    def add(self, *new_mobjects: OpenGLMobject) -> Self:
        """
        Mobjects will be displayed, from background to
        foreground in the order with which they are added.
        """
        self.remove(*new_mobjects)
        self.mobjects += new_mobjects
        return self

    def remove(self, *mobjects_to_remove: OpenGLMobject) -> Self:
        """
        Removes anything in mobjects from scenes mobject list, but in the event that one
        of the items to be removed is a member of the family of an item in mobject_list,
        the other family members are added back into the list.