Skip to content

Commit

Permalink
docs: various docs improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Sep 12, 2023
1 parent b3f07af commit 4b8b323
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 136 deletions.
9 changes: 8 additions & 1 deletion Editor/API/Attributes/ExportsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

namespace nadena.dev.ndmf
{
/// <summary>
/// This attribute declares a plugin to be registered with NDMF.
///
/// <code>
/// [assembly: ExportsPlugin(typeof(MyPlugin))]
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
public class ExportsPlugin : Attribute
public sealed class ExportsPlugin : Attribute
{
public Type PluginType { get; }

Expand Down
15 changes: 8 additions & 7 deletions Editor/API/Fluent/Sequence/Constraints.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using nadena.dev.ndmf.model;

namespace nadena.dev.ndmf.fluent
Expand All @@ -17,7 +18,7 @@ private void OnNewPass(SolverPass pass)
_pendingDependencies.Clear();
}

public Sequence BeforePlugin(string QualifiedName, string sourceFile = "", int sourceLine = 0)
public Sequence BeforePlugin(string QualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -31,12 +32,12 @@ public Sequence BeforePlugin(string QualifiedName, string sourceFile = "", int s
return this;
}

public Sequence BeforePlugin<T>(T plugin, string sourceFile = "", int sourceLine = 0) where T : fluent.Plugin<T>, new()
public Sequence BeforePlugin<T>(T plugin, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Plugin<T>, new()
{
return BeforePlugin(plugin.QualifiedName, sourceFile, sourceLine);
}

public Sequence AfterPlugin(string qualifiedName, string sourceFile = "", int sourceLine = 0)
public Sequence AfterPlugin(string qualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -50,12 +51,12 @@ public Sequence AfterPlugin(string qualifiedName, string sourceFile = "", int so
return this;
}

public Sequence AfterPlugin<T>(T plugin, string sourceFile = "", int sourceLine = 0) where T : Plugin<T>, new()
public Sequence AfterPlugin<T>(T plugin, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : Plugin<T>, new()
{
return AfterPlugin(plugin.QualifiedName, sourceFile, sourceLine);
}

public Sequence WaitFor<T>(T pass, string sourceFile = "", int sourceLine = 0) where T : fluent.Pass<T>, new()
public Sequence WaitFor<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Pass<T>, new()
{
_pendingDependencies.Add(nextPass =>
{
Expand All @@ -72,7 +73,7 @@ public Sequence AfterPlugin(string qualifiedName, string sourceFile = "", int so
return this;
}

public Sequence AfterPass(string qualifiedName, string sourceFile = "", int sourceLine = 0)
public Sequence AfterPass(string qualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
{
_pendingDependencies.Add(nextPass =>
{
Expand All @@ -89,7 +90,7 @@ public Sequence AfterPass(string qualifiedName, string sourceFile = "", int sour
return this;
}

public Sequence AfterPass<T>(T pass, string sourceFile = "", int sourceLine = 0) where T : Pass<T>, new()
public Sequence AfterPass<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : Pass<T>, new()
{
return AfterPass(pass.QualifiedName, sourceFile, sourceLine);
}
Expand Down
75 changes: 74 additions & 1 deletion Editor/API/Fluent/Sequence/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public void Dispose()
}
}

/// <summary>
/// Declares that a group of passes are compatible with a given set of extensions - that is, they will not deactivate
/// the extensions if already active.
///
/// <code>
/// sequence.WithCompatibleExtensions(new[] {"foo.bar.MyExtension"}, s => {
/// s.Run(typeof(MyPass));
/// });
/// </code>
///
/// </summary>
/// <param name="extensions">The extensions to permit</param>
/// <param name="action">An action that will be invoked with the extensions marked compatible</param>
public void WithCompatibleExtensions(IEnumerable<string> extensions, Action<Sequence> action)
{
var prior = _compatibleExtensions;
Expand All @@ -40,21 +53,71 @@ public void WithCompatibleExtensions(IEnumerable<string> extensions, Action<Sequ
}
}

/// <summary>
/// Declares that a group of passes are compatible with given extensions - that is, they will not deactivate
/// the extensions if already active.
///
/// <code>
/// sequence.WithCompatibleExtensions(new[] {typeof(MyExtension)}, s => {
/// s.Run(typeof(MyPass));
/// });
/// </code>
///
/// </summary>
/// <param name="extensions">The extensions to permit</param>
/// <param name="action">An action that will be invoked with the extensions marked compatible</param>
public void WithCompatibleExtensions(IEnumerable<Type> extensions, Action<Sequence> action)
{
WithCompatibleExtensions(extensions.Select(t => t.FullName), action);
}

/// <summary>
/// Declares that a group of passes are compatible with a given extension - that is, they will not deactivate
/// the extension if it is already active.
///
/// <code>
/// sequence.WithCompatibleExtension("foo.bar.MyExtension", s => {
/// s.Run(typeof(MyPass));
/// });
/// </code>
///
/// </summary>
/// <param name="extension">The extension to permit</param>
/// <param name="action">An action that will be invoked with the extensions marked compatible</param>
public void WithCompatibleExtension(string extension, Action<Sequence> action)
{
WithCompatibleExtensions(new[] {extension}, action);
}

/// <summary>
/// Declares that a group of passes are compatible with a given extension - that is, they will not deactivate
/// the extension if it is already active.
///
/// <code>
/// sequence.WithCompatibleExtension(typeof(MyExtension), s => {
/// s.Run(typeof(MyPass));
/// });
/// </code>
///
/// </summary>
/// <param name="extension">The extension to permit</param>
/// <param name="action">An action that will be invoked with the extensions marked compatible</param>
public void WithCompatibleExtension(Type extension, Action<Sequence> action)
{
WithCompatibleExtension(extension.FullName, action);
}

/// <summary>
/// Declares that a group of passes require a given set of extensions - that is, they will activate the extensions
/// before executing.
///
/// <code>
/// sequence.WithRequiredExtensions(new[] {typeof(foo.bar.MyExtension)}, s => {
/// s.Run(typeof(MyPass));
/// });
/// </summary>
/// <param name="extension">The extension to request</param>
/// <param name="action">An action that will be invoked with the extensions marked required</param>
public void WithRequiredExtensions(IEnumerable<Type> extensions, Action<Sequence> action)
{
var prior = _requiredExtensions;
Expand All @@ -69,7 +132,17 @@ public void WithRequiredExtensions(IEnumerable<Type> extensions, Action<Sequence
_requiredExtensions = prior;
}
}

/// <summary>
/// Declares that a group of passes require a given extension - that is, they will activate the extension
/// before executing.
///
/// <code>
/// sequence.WithRequiredExtension(typeof(foo.bar.MyExtension), s => {
/// s.Run(typeof(MyPass));
/// });
/// </summary>
/// <param name="extension">The extension to request</param>
/// <param name="action">An action that will be invoked with the extensions marked required</param>
public void WithRequiredExtension(Type extension, Action<Sequence> action)
{
WithRequiredExtensions(new[] {extension}, action);
Expand Down
61 changes: 49 additions & 12 deletions Editor/API/Fluent/Sequence/Sequence.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using nadena.dev.ndmf;
using System.Runtime.CompilerServices;
using nadena.dev.ndmf.model;
using UnityEngine;

namespace nadena.dev.ndmf.fluent
{
/// <summary>
/// Callback invoked when an anonymous pass is executed.
/// </summary>
public delegate void InlinePass(BuildContext context);

/// <summary>
/// Fluent context type used to declare constraints on the execution order of passes.
///
/// <code>
/// sequence.Run(typeof(MyPass)) // returns DeclaringPass
/// .BeforePass(typeof(OtherPass)); // valid only on DeclaringPass
/// </code>
/// </summary>
public sealed class DeclaringPass
{
private readonly SolverContext _solverContext;
Expand All @@ -24,7 +29,12 @@ internal DeclaringPass(SolverPass pass, SolverContext solverContext, BuildPhase
_phase = phase;
}

public DeclaringPass BeforePlugin(string QualifiedName, string sourceFile = "", int sourceLine = 0)
/// <summary>
/// Declares that the pass you just declared must run before a particular other plugin.
/// </summary>
/// <param name="QualifiedName">The qualified name of the other plugin</param>
/// <returns>This DeclaringPass context</returns>
public DeclaringPass BeforePlugin(string QualifiedName, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -38,12 +48,18 @@ public DeclaringPass BeforePlugin(string QualifiedName, string sourceFile = "",
return this;
}

public DeclaringPass BeforePlugin<T>(T plugin, string sourceFile = "", int sourceLine = 0) where T : fluent.Plugin<T>, new()
/// <summary>
/// Declares that the pass you just declared must run before a particular other plugin.
/// </summary>
/// <param name="QualifiedName">The singleton of the other plugin</param>
/// <returns>This DeclaringPass context</returns>
public DeclaringPass BeforePlugin<T>(T plugin, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Plugin<T>, new()
{
return BeforePlugin(plugin.QualifiedName, sourceFile, sourceLine);
}

public DeclaringPass BeforePass(string qualifiedName, string sourceFile = "", int sourceLine = 0)

private DeclaringPass BeforePass(string qualifiedName, string sourceFile = "", int sourceLine = 0)
{
_solverContext.Constraints.Add(new Constraint()
{
Expand All @@ -57,12 +73,21 @@ public DeclaringPass BeforePass(string qualifiedName, string sourceFile = "", in
return this;
}

public DeclaringPass BeforePass<T>(T pass, string sourceFile = "", int sourceLine = 0) where T : Pass<T>, new()
/// <summary>
/// Declares that the pass you just declared must run before a particular other pass.
/// </summary>
/// <param name="QualifiedName">The singleton of the other plugin</param>
/// <returns>This DeclaringPass context</returns>
public DeclaringPass BeforePass<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : Pass<T>, new()
{
return BeforePass(pass.QualifiedName, sourceFile, sourceLine);
}
}

/// <summary>
/// Represents a sequence of passes that will execute in order (but not necessarily directly after one another),
/// and allows this sequence to be built up.
/// </summary>
public sealed partial class Sequence
{
private readonly IPlugin _plugin;
Expand All @@ -74,7 +99,6 @@ public sealed partial class Sequence
private SolverPass _priorPass = null;

private int inlinePassIndex = 0;


internal Sequence(BuildPhase phase, SolverContext solverContext, IPlugin plugin, string sequenceBaseName)
{
Expand Down Expand Up @@ -125,6 +149,12 @@ private SolverPass CreateSequencingPass(string displayName, InlinePass callback,
return pass;
}

/// <summary>
/// Registers a pass to run in this sequence.
/// </summary>
/// <param name="pass">The pass to run</param>
/// <typeparam name="T"></typeparam>
/// <returns>A DeclaringPass object that can be used to set BeforePass/BeforePlugin constraints</returns>
public DeclaringPass Run<T>(T pass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0) where T : fluent.Pass<T>, new()
{
return InternalRun(pass, sourceFile, sourceLine);
Expand Down Expand Up @@ -171,6 +201,13 @@ private DeclaringPass InternalRun(IPass pass, string sourceFile, int sourceLine)
return new DeclaringPass(solverPass, _solverContext, _phase);
}

/// <summary>
/// Declares a pass using an inline callback. This pass cannot be referenced by other plugins for the purpose
/// of setting BeforePass/AfterPass constraints.
/// </summary>
/// <param name="displayName">The name of the pass to show in debug output</param>
/// <param name="inlinePass">A callback to invoke when the pass is executed</param>
/// <returns></returns>
public DeclaringPass Run(string displayName, InlinePass inlinePass, [CallerFilePath] string sourceFile = "", [CallerLineNumber] int sourceLine = 0)
{
var anonPass = new AnonymousPass(_sequenceBaseName + "/anonymous#" + inlinePassIndex++, displayName, inlinePass);
Expand Down
10 changes: 10 additions & 0 deletions Editor/ExcludeFromDocs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace nadena.dev.ndmf
{
[System.AttributeUsage(AttributeTargets.All, Inherited = true, AllowMultiple = false)]
internal class ExcludeFromDocs : Attribute
{

}
}
3 changes: 3 additions & 0 deletions Editor/ExcludeFromDocs.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Editor/InternalPasses/RemoveEditorOnlyPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

namespace nadena.dev.ndmf.builtin
{
/// <summary>
/// This pass removes all objects tagged with "EditorOnly" from the avatar. It will be run early in the Resolving
/// phase; if you need to run before this, declare a BeforePass constraint on this type.
/// </summary>
[NDMFInternalEarlyPass]
public class RemoveEditorOnlyPass : Pass<RemoveEditorOnlyPass>
public sealed class RemoveEditorOnlyPass : Pass<RemoveEditorOnlyPass>
{
internal static RemoveEditorOnlyPass Instance = new RemoveEditorOnlyPass();
public override string QualifiedName => "nadena.dev.ndmf.system.RemoveEditorOnly";
public override string DisplayName => "Remove EditorOnly Objects";

[ExcludeFromDocs]
protected override void Execute(BuildContext context)
{
foreach (Transform t in context.AvatarRootTransform.GetComponentsInChildren<Transform>(true))
Expand Down
4 changes: 2 additions & 2 deletions Editor/UI/SolverUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace nadena.dev.ndmf.ui
{
public class SolverWindow : EditorWindow
internal class SolverWindow : EditorWindow
{
[MenuItem("Tools/NDM Framework/Debug Tools/Plugin sequence display", false, 100)]
public static void ShowWindow()
Expand Down Expand Up @@ -50,7 +50,7 @@ internal class SolverUIItem : TreeViewItem
public double? ExecutionTimeMS;
}

public class SolverUI : TreeView
internal class SolverUI : TreeView
{
private static PluginResolver Resolver = new PluginResolver();

Expand Down
2 changes: 1 addition & 1 deletion Editor/VRChat/CleanupTemporaryAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace nadena.dev.ndmf.VRChat
{
public class CleanupTemporaryAssets : IVRCSDKPostprocessAvatarCallback
internal class CleanupTemporaryAssets : IVRCSDKPostprocessAvatarCallback
{
public int callbackOrder => 0;

Expand Down
Loading

0 comments on commit 4b8b323

Please sign in to comment.