refactor(app): define ordered composition contract
This commit is contained in:
parent
1d04b94da2
commit
adb204560d
6 changed files with 927 additions and 0 deletions
119
src/AcDream.App/Composition/GameWindowCompositionPipeline.cs
Normal file
119
src/AcDream.App/Composition/GameWindowCompositionPipeline.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
namespace AcDream.App.Composition;
|
||||
|
||||
internal interface IHostInputCameraCompositionPhase<in TPlatform, out TResult>
|
||||
{
|
||||
TResult Compose(TPlatform platform);
|
||||
}
|
||||
|
||||
internal interface IContentEffectsAudioCompositionPhase<in TPlatform, in THost, out TResult>
|
||||
{
|
||||
TResult Compose(TPlatform platform, THost host);
|
||||
}
|
||||
|
||||
internal interface ISettingsDevToolsCompositionPhase<in TPlatform, in THost, in TContent, out TResult>
|
||||
{
|
||||
TResult Compose(TPlatform platform, THost host, TContent content);
|
||||
}
|
||||
|
||||
internal interface IWorldRenderCompositionPhase<in TPlatform, in TContent, in TSettings, out TResult>
|
||||
{
|
||||
TResult Compose(TPlatform platform, TContent content, TSettings settings);
|
||||
}
|
||||
|
||||
internal interface IInteractionUiCompositionPhase<in THost, in TContent, in TSettings, in TWorld, out TResult>
|
||||
{
|
||||
TResult Compose(THost host, TContent content, TSettings settings, TWorld world);
|
||||
}
|
||||
|
||||
internal interface ILivePresentationCompositionPhase<in THost, in TContent, in TWorld, in TInteraction, out TResult>
|
||||
{
|
||||
TResult Compose(THost host, TContent content, TWorld world, TInteraction interaction);
|
||||
}
|
||||
|
||||
internal interface ISessionPlayerCompositionPhase<in THost, in TContent, in TWorld, in TInteraction, in TLive, out TResult>
|
||||
{
|
||||
TResult Compose(
|
||||
THost host,
|
||||
TContent content,
|
||||
TWorld world,
|
||||
TInteraction interaction,
|
||||
TLive live);
|
||||
}
|
||||
|
||||
internal interface IFrameRootCompositionPhase<in THost, in TSettings, in TWorld, in TInteraction, in TLive, in TSession, out TResult>
|
||||
{
|
||||
TResult Compose(
|
||||
THost host,
|
||||
TSettings settings,
|
||||
TWorld world,
|
||||
TInteraction interaction,
|
||||
TLive live,
|
||||
TSession session);
|
||||
}
|
||||
|
||||
internal interface ISessionStartCompositionPhase<in TFrame>
|
||||
{
|
||||
void Start(TFrame frame);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fixed startup topology. It intentionally retains no cumulative context or
|
||||
/// final runtime graph; immutable phase results exist only as locals during
|
||||
/// one composition run.
|
||||
/// </summary>
|
||||
internal sealed class GameWindowCompositionPipeline<
|
||||
TPlatform,
|
||||
THost,
|
||||
TContent,
|
||||
TSettings,
|
||||
TWorld,
|
||||
TInteraction,
|
||||
TLive,
|
||||
TSession,
|
||||
TFrame>
|
||||
{
|
||||
private readonly IHostInputCameraCompositionPhase<TPlatform, THost> _host;
|
||||
private readonly IContentEffectsAudioCompositionPhase<TPlatform, THost, TContent> _content;
|
||||
private readonly ISettingsDevToolsCompositionPhase<TPlatform, THost, TContent, TSettings> _settings;
|
||||
private readonly IWorldRenderCompositionPhase<TPlatform, TContent, TSettings, TWorld> _world;
|
||||
private readonly IInteractionUiCompositionPhase<THost, TContent, TSettings, TWorld, TInteraction> _interaction;
|
||||
private readonly ILivePresentationCompositionPhase<THost, TContent, TWorld, TInteraction, TLive> _live;
|
||||
private readonly ISessionPlayerCompositionPhase<THost, TContent, TWorld, TInteraction, TLive, TSession> _session;
|
||||
private readonly IFrameRootCompositionPhase<THost, TSettings, TWorld, TInteraction, TLive, TSession, TFrame> _frame;
|
||||
private readonly ISessionStartCompositionPhase<TFrame> _start;
|
||||
|
||||
public GameWindowCompositionPipeline(
|
||||
IHostInputCameraCompositionPhase<TPlatform, THost> host,
|
||||
IContentEffectsAudioCompositionPhase<TPlatform, THost, TContent> content,
|
||||
ISettingsDevToolsCompositionPhase<TPlatform, THost, TContent, TSettings> settings,
|
||||
IWorldRenderCompositionPhase<TPlatform, TContent, TSettings, TWorld> world,
|
||||
IInteractionUiCompositionPhase<THost, TContent, TSettings, TWorld, TInteraction> interaction,
|
||||
ILivePresentationCompositionPhase<THost, TContent, TWorld, TInteraction, TLive> live,
|
||||
ISessionPlayerCompositionPhase<THost, TContent, TWorld, TInteraction, TLive, TSession> session,
|
||||
IFrameRootCompositionPhase<THost, TSettings, TWorld, TInteraction, TLive, TSession, TFrame> frame,
|
||||
ISessionStartCompositionPhase<TFrame> start)
|
||||
{
|
||||
_host = host ?? throw new ArgumentNullException(nameof(host));
|
||||
_content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_world = world ?? throw new ArgumentNullException(nameof(world));
|
||||
_interaction = interaction ?? throw new ArgumentNullException(nameof(interaction));
|
||||
_live = live ?? throw new ArgumentNullException(nameof(live));
|
||||
_session = session ?? throw new ArgumentNullException(nameof(session));
|
||||
_frame = frame ?? throw new ArgumentNullException(nameof(frame));
|
||||
_start = start ?? throw new ArgumentNullException(nameof(start));
|
||||
}
|
||||
|
||||
public void Run(TPlatform platform)
|
||||
{
|
||||
THost host = _host.Compose(platform);
|
||||
TContent content = _content.Compose(platform, host);
|
||||
TSettings settings = _settings.Compose(platform, host, content);
|
||||
TWorld world = _world.Compose(platform, content, settings);
|
||||
TInteraction interaction = _interaction.Compose(host, content, settings, world);
|
||||
TLive live = _live.Compose(host, content, world, interaction);
|
||||
TSession session = _session.Compose(host, content, world, interaction, live);
|
||||
TFrame frame = _frame.Compose(host, settings, world, interaction, live, session);
|
||||
_start.Start(frame);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue