def _handle_content_removed(msg: ContentEntity):
    in_active_scene = msg.scene == get_active_scene()

    # select target context
    if in_active_scene:
        # active context
        cameras, context = _active_cameras, _active_context
    elif msg.scene in _context_cache:
        # not active but cached context
        cameras, context = _context_cache[msg.scene]
    else:
        # not in any relevant context
        return None

    # check if it is a camera
    if isinstance(msg, Camera):
        cameras.remove(msg)
        # todo other camera stuff

    # look for a component
    if msg in context:
        # update sorting if necessary
        if in_active_scene:
            _active_sorting.remove(context[msg])
        # remove component from context
        del context[msg]
def _handle_content_added(msg: ContentEntity):
    in_active_scene = msg.scene == get_active_scene()

    # select target context
    if in_active_scene:
        # active context
        cameras, context = _active_cameras, _active_context
    elif msg.scene in _context_cache:
        # not active but cached context
        cameras, context = _context_cache[msg.scene]
    else:
        # not in any relevant context
        return None

    # check if it is a camera
    if isinstance(msg, Camera):
        # todo hand over some rendering target
        _active_cameras.append(msg)

    # look for a component for content
    component = get_component(msg)
    if component:
        # add component to context
        context[msg] = component
        # update sorting if necessary
        if in_active_scene:
            _active_sorting.append(component)
            _active_sorting.sort(key=lambda s: s.sorting)
def _handle_content_removed(msg: ContentEntity):
    # remove from active core or cached context if core is cached
    if msg.scene == get_active_scene():
        context = _active_context
    elif msg.scene in _context_cache:
        context = _context_cache[msg.scene]
    else:
        return None

    if msg in context:
        del context[msg]
def _handle_content_added(msg: ContentEntity):
    instruction = get_instruction(msg)
    if instruction:
        # add to active core or cached context if core is cached
        if msg.scene == get_active_scene():
            # make instruction for msg and add instruction to context
            _active_context[msg] = instruction
        elif msg.scene in _context_cache:
            # update the cached context with msg
            instructions = _context_cache[msg.scene]
            instructions[msg] = instruction
def cache_active_context() -> None:
    # public
    scene = get_active_scene()
    _context_cache[scene] = _active_context
def cache_active_context() -> None:
    scene = get_active_scene()
    _context_cache[scene] = _active_cameras, _active_context