Skip to content

Commit

Permalink
chore: add MarkBehaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 25, 2023
1 parent 7bc727c commit ee281cb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
14 changes: 14 additions & 0 deletions API-Editor/ComponentInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ internal ComponentDependencyCollector()
[PublicAPI]
public abstract void MarkEntrypoint();

/// <summary>
/// Marks this component as Behaviour component, which means has some effects to components in the avatars.
/// When you mark some components Behaviour component, Avatar Optimizer will generate animation that disables
/// the component when entrypoint is not active / enabled.
///
/// If your component is not marked as Behaviour, enable-ness / activeness will not changed by Avatar Optimizer.
/// If your component have some runtime load and can be skipped if your component is not needed by all
/// EntryPoint components, you should mark your component as Behaviour for runtime-load optimization.
///
/// For example, VRCPhysBone and Constraints are marked as Behaviour.
/// </summary>
[PublicAPI]
public abstract void MarkBehaviour();

/// <summary>
/// Adds <see cref="dependency"/> as dependencies of <see cref="dependant"/>.
/// The dependency will be assumed as the dependant will have dependency if dependant is enabled and
Expand Down
5 changes: 5 additions & 0 deletions Editor/APIInternal/ComponentInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ protected override void CollectDependency(T component, ComponentDependencyCollec
.EvenIfDependantDisabled();
for (var i = 0; i < component.sourceCount; i++)
collector.AddDependency(component.GetSource(i).sourceTransform);
collector.MarkBehaviour();
}
}

Expand Down Expand Up @@ -484,6 +485,8 @@ void CollectTransforms(Transform bone)
foreach (var physBoneCollider in component.colliders)
collector.AddDependency(physBoneCollider).OnlyIfTargetCanBeEnable();

collector.MarkBehaviour();

// If parameter is not empty, the PB can be required for Animator Parameter so it's Entrypoint Component
// https://github.com/anatawa12/AvatarOptimizer/issues/450
if (!string.IsNullOrEmpty(component.parameter))
Expand Down Expand Up @@ -572,6 +575,8 @@ internal class DynamicBoneInformation : ComponentInformation<Component>
{
protected override void CollectDependency(Component component, ComponentDependencyCollector collector)
{
collector.MarkBehaviour();

foreach (var transform in GetAffectedTransforms(component))
{
collector.AddDependency(transform, component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public MeshInfo2 GetMeshInfoFor(SkinnedMeshRenderer renderer) =>

public override void MarkEntrypoint() => _info.EntrypointComponent = true;

public override void MarkBehaviour() => _info.BehaviourComponent = true;

private API.ComponentDependencyInfo AddDependencyInternal(
[NotNull] GCComponentInfo info,
[CanBeNull] Component dependency,
Expand Down
7 changes: 6 additions & 1 deletion Editor/Processors/TraceAndOptimize/GCComponentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ public GCComponentInfo TryGetInfo(Component dependent) =>
internal class GCComponentInfo
{
/// <summary>
/// True if this component has Active Meaning on the Avatar.
/// True if this component has Active side-effect Meaning on the Avatar.
/// </summary>
public bool EntrypointComponent = false;

/// <summary>
/// True if activeness of this component has meaning and inactive is lighter
/// </summary>
public bool BehaviourComponent = false;

/// <summary>
/// Dependencies of this component
Expand Down

0 comments on commit ee281cb

Please sign in to comment.