-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Scene View Document (#190)
- Loading branch information
1 parent
80d907c
commit cba77b1
Showing
34 changed files
with
1,478 additions
and
34 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
FinalEngine.Editor.Common/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// <copyright file="ServiceCollectionExtensions.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FinalEngine.Editor.Common.Extensions; | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using FinalEngine.Editor.Common.Services.Factories; | ||
using FinalEngine.Editor.Common.Services.Rendering; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Provides extension methods for an <see cref="IServiceCollection"/>. | ||
/// </summary> | ||
[ExcludeFromCodeCoverage(Justification = "Extension Methods")] | ||
public static class ServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds all common services to specified <paramref name="services"/> collection. | ||
/// </summary> | ||
/// <param name="services"> | ||
/// The services collection. | ||
/// </param> | ||
/// <returns> | ||
/// The <paramref name="services"/> collection. | ||
/// </returns> | ||
/// <exception cref="ArgumentNullException"> | ||
/// The specified <paramref name="services"/> parameter cannot be null. | ||
/// </exception> | ||
public static IServiceCollection AddCommon(this IServiceCollection services) | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
services.AddSingleton<ISceneRenderer, SceneRenderer>(); | ||
|
||
return services; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a factory that creates an instance of type <typeparamref name="TViewModel"/> to the specified <paramref name="services"/> collection. | ||
/// </summary> | ||
/// <typeparam name="TViewModel"> | ||
/// The type of instance to create. | ||
/// </typeparam> | ||
/// <param name="services"> | ||
/// The services collection. | ||
/// </param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// The specified <paramref name="services"/> parameter cannot be null. | ||
/// </exception> | ||
public static void AddFactory<TViewModel>(this IServiceCollection services) | ||
where TViewModel : class | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
services.AddTransient<TViewModel>(); | ||
services.AddSingleton<Func<TViewModel>>(x => | ||
{ | ||
return () => | ||
{ | ||
return x.GetRequiredService<TViewModel>(); | ||
}; | ||
}); | ||
|
||
services.AddSingleton<IFactory<TViewModel>, Factory<TViewModel>>(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
FinalEngine.Editor.Common/FinalEngine.Editor.Common.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<LangVersion>11.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<AnalysisMode>All</AnalysisMode> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<Platforms>x64</Platforms> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<NoWarn>CA1848;CA2254</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="..\Styling\StyleCop\Other\stylecop.json" Link="stylecop.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FinalEngine.Rendering\FinalEngine.Rendering.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// <copyright file="AssemblyInfo.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: CLSCompliant(true)] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyTitle("FinalEngine.Editor.Common")] | ||
[assembly: AssemblyDescription("A common services library for the Final Engine editor.")] | ||
[assembly: Guid("D8E94A1E-3718-429D-A3F7-40ADAADA636D")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// <copyright file="Factory.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FinalEngine.Editor.Common.Services.Factories; | ||
|
||
using System; | ||
|
||
/// <summary> | ||
/// Provides a standard implementation of an <see cref="IFactory{T}"/>. | ||
/// </summary> | ||
/// <typeparam name="T"> | ||
/// The type of instance to create. | ||
/// </typeparam> | ||
/// <seealso cref="IFactory{T}"/> | ||
public sealed class Factory<T> : IFactory<T> | ||
{ | ||
/// <summary> | ||
/// The function used to create the instance. | ||
/// </summary> | ||
private readonly Func<T> factory; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Factory{T}"/> class. | ||
/// </summary> | ||
/// <param name="factory"> | ||
/// The function used to create the instance. | ||
/// </param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// The specified <paramref name="factory"/> parameter cannot be null. | ||
/// </exception> | ||
public Factory(Func<T> factory) | ||
{ | ||
this.factory = factory ?? throw new ArgumentNullException(nameof(factory)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public T Create() | ||
{ | ||
return this.factory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// <copyright file="IFactory.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FinalEngine.Editor.Common.Services.Factories; | ||
|
||
/// <summary> | ||
/// Defines an interface that provides a method to create an instance of type <typeparamref name="T"/>. | ||
/// </summary> | ||
/// <typeparam name="T"> | ||
/// The type of instance to create. | ||
/// </typeparam> | ||
public interface IFactory<out T> | ||
{ | ||
/// <summary> | ||
/// Creates an instance of type <typeparamref name="T"/>. | ||
/// </summary> | ||
/// <returns> | ||
/// The newly created instance of type <typeparamref name="T"/>. | ||
/// </returns> | ||
T Create(); | ||
} |
27 changes: 27 additions & 0 deletions
27
FinalEngine.Editor.Common/Services/Rendering/ISceneRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// <copyright file="ISceneRenderer.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FinalEngine.Editor.Common.Services.Rendering; | ||
|
||
/// <summary> | ||
/// Defines an interface that represents a scene renderer. | ||
/// </summary> | ||
public interface ISceneRenderer | ||
{ | ||
/// <summary> | ||
/// Changes the current scene projection the specified <paramref name="projectionWidth"/> and <paramref name="projectionHeight"/>. | ||
/// </summary> | ||
/// <param name="projectionWidth"> | ||
/// The width of the projection. | ||
/// </param> | ||
/// <param name="projectionHeight"> | ||
/// The height of the projection. | ||
/// </param> | ||
void ChangeProjection(int projectionWidth, int projectionHeight); | ||
|
||
/// <summary> | ||
/// Renders the currently active scene. | ||
/// </summary> | ||
void Render(); | ||
} |
61 changes: 61 additions & 0 deletions
61
FinalEngine.Editor.Common/Services/Rendering/SceneRenderer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// <copyright file="SceneRenderer.cs" company="Software Antics"> | ||
// Copyright (c) Software Antics. All rights reserved. | ||
// </copyright> | ||
|
||
namespace FinalEngine.Editor.Common.Services.Rendering; | ||
|
||
using System; | ||
using System.Drawing; | ||
using System.Numerics; | ||
using FinalEngine.Rendering; | ||
using Microsoft.Extensions.Logging; | ||
|
||
/// <summary> | ||
/// Provides a standard implementation of an <see cref="ISceneRenderer"/>. | ||
/// </summary> | ||
/// <seealso cref="ISceneRenderer" /> | ||
public sealed class SceneRenderer : ISceneRenderer | ||
{ | ||
/// <summary> | ||
/// The logger. | ||
/// </summary> | ||
private readonly ILogger<SceneRenderer> logger; | ||
|
||
/// <summary> | ||
/// The render device. | ||
/// </summary> | ||
private readonly IRenderDevice renderDevice; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="SceneRenderer"/> class. | ||
/// </summary> | ||
/// <param name="logger"> | ||
/// The logger. | ||
/// </param> | ||
/// <param name="renderDevice"> | ||
/// The render device. | ||
/// </param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// The specified <paramref name="logger"/> or <paramref name="renderDevice"/> parameter cannot be null. | ||
/// </exception> | ||
public SceneRenderer(ILogger<SceneRenderer> logger, IRenderDevice renderDevice) | ||
{ | ||
this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
this.renderDevice = renderDevice ?? throw new ArgumentNullException(nameof(renderDevice)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void ChangeProjection(int projectionWidth, int projectionHeight) | ||
{ | ||
this.logger.LogDebug($"Changing projection to: ({projectionWidth}, {projectionHeight})."); | ||
|
||
this.renderDevice.Pipeline.SetUniform("u_projection", Matrix4x4.CreateOrthographicOffCenter(0, projectionWidth, 0, projectionHeight, -1, 1)); | ||
this.renderDevice.Rasterizer.SetViewport(new Rectangle(0, 0, projectionWidth, projectionHeight)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Render() | ||
{ | ||
this.renderDevice.Clear(Color.FromArgb(255, 30, 30, 30)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.