Skip to content

Commit

Permalink
And simple setup for basic game class woot
Browse files Browse the repository at this point in the history
  • Loading branch information
Software Antics committed Apr 21, 2024
1 parent 883c6bf commit 7150015
Show file tree
Hide file tree
Showing 86 changed files with 516 additions and 2,345 deletions.
15 changes: 13 additions & 2 deletions FinalEngine.ECS/EntityWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ namespace FinalEngine.ECS;
using System.Reflection;
using FinalEngine.ECS.Attributes;
using FinalEngine.ECS.Exceptions;
using FinalEngine.ECS.Resolving;

public class EntityWorld : IEntityWorld
internal sealed class EntityWorld : IEntityWorld
{
private readonly List<Entity> entities;

private readonly IEntitySystemResolver resolver;

private readonly List<EntitySystemBase> systems;

public EntityWorld()
public EntityWorld(IEntitySystemResolver resolver)
{
this.resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));

this.entities = [];
this.systems = [];
}
Expand Down Expand Up @@ -61,6 +66,12 @@ public void AddSystem(EntitySystemBase system)
this.systems.Add(system);
}

public void AddSystem<TSystem>()
where TSystem : EntitySystemBase
{
this.AddSystem(this.resolver.GetEntitySystem<TSystem>());
}

public void ProcessAll(GameLoopType type)
{
foreach (var system in this.systems)
Expand Down
22 changes: 22 additions & 0 deletions FinalEngine.ECS/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="ServiceCollectionExtensions.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS.Extensions;

using System;
using FinalEngine.ECS.Resolving;
using Microsoft.Extensions.DependencyInjection;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddECS(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services, nameof(services));

services.AddTransient<IEntityWorld, EntityWorld>();
services.AddSingleton<IEntitySystemResolver, EntitySystemResolver>();

return services;
}
}
1 change: 1 addition & 0 deletions FinalEngine.ECS/FinalEngine.ECS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
3 changes: 3 additions & 0 deletions FinalEngine.ECS/IEntityWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public interface IEntityWorld
{
void AddEntity(Entity entity);

void AddSystem<TSystem>()
where TSystem : EntitySystemBase;

void AddSystem(EntitySystemBase system);

void ProcessAll(GameLoopType type);
Expand Down
24 changes: 24 additions & 0 deletions FinalEngine.ECS/Resolving/EntitySystemResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// <copyright file="EntitySystemResolver.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS.Resolving;

using System;
using Microsoft.Extensions.DependencyInjection;

internal sealed class EntitySystemResolver : IEntitySystemResolver
{
private readonly IServiceProvider serviceProvider;

public EntitySystemResolver(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}

public TSystem GetEntitySystem<TSystem>()
where TSystem : EntitySystemBase
{
return this.serviceProvider.GetRequiredService<TSystem>();
}
}
11 changes: 11 additions & 0 deletions FinalEngine.ECS/Resolving/IEntitySystemResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <copyright file="IEntitySystemResolver.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS.Resolving;

internal interface IEntitySystemResolver
{
TSystem GetEntitySystem<TSystem>()
where TSystem : EntitySystemBase;
}
6 changes: 6 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/IScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public interface IScene

void AddEntity(string tag, Guid uniqueID);

void AddSystem<TSystem>()
where TSystem : EntitySystemBase;

void RemoveEntity(Guid uniqueIdentifier);

void RemoveSystem<TSystem>()
where TSystem : EntitySystemBase;

void Render();
}
12 changes: 12 additions & 0 deletions FinalEngine.Editor.Common/Models/Scenes/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public void AddEntity(string tag, Guid uniqueID)
this.logger.LogInformation($"Added {nameof(Entity)} to {nameof(Scene)} with ID: '{uniqueID}'.");
}

public void AddSystem<TSystem>()
where TSystem : EntitySystemBase
{
this.world.AddSystem<TSystem>();
}

public void RemoveEntity(Guid uniqueIdentifier)
{
this.logger.LogInformation($"Removing {nameof(Entity)} from {nameof(Scene)} with ID: '{uniqueIdentifier}'.");
Expand All @@ -76,6 +82,12 @@ public void RemoveEntity(Guid uniqueIdentifier)
this.logger.LogInformation($"Removed {nameof(Entity)} from {nameof(Scene)} with ID: '{uniqueIdentifier}'.");
}

public void RemoveSystem<TSystem>()
where TSystem : EntitySystemBase
{
this.world.RemoveSystem(typeof(TSystem));
}

public void Render()
{
this.world.ProcessAll(GameLoopType.Render);
Expand Down
145 changes: 0 additions & 145 deletions FinalEngine.Editor.Common/Services/Scenes/Cameras/EditorCamera.cs

This file was deleted.

2 changes: 2 additions & 0 deletions FinalEngine.Editor.Common/Services/Scenes/ISceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ namespace FinalEngine.Editor.Common.Services.Scenes;
public interface ISceneManager
{
IScene ActiveScene { get; }

void Initialize();
}
12 changes: 0 additions & 12 deletions FinalEngine.Editor.Common/Services/Scenes/ISceneViewRenderer.cs

This file was deleted.

17 changes: 16 additions & 1 deletion FinalEngine.Editor.Common/Services/Scenes/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ namespace FinalEngine.Editor.Common.Services.Scenes;

using System;
using FinalEngine.Editor.Common.Models.Scenes;
using FinalEngine.Rendering;

public sealed class SceneManager : ISceneManager
{
public SceneManager(IScene scene)
private static bool isInitialized;

private readonly IRenderPipeline renderPipeline;

public SceneManager(IScene scene, IRenderPipeline renderPipeline)
{
this.renderPipeline = renderPipeline ?? throw new ArgumentNullException(nameof(renderPipeline));
this.ActiveScene = scene ?? throw new ArgumentNullException(nameof(scene));
}

public IScene ActiveScene { get; }

public void Initialize()
{
if (!isInitialized)
{
this.renderPipeline.Initialize();
isInitialized = true;
}
}
}
Loading

0 comments on commit 7150015

Please sign in to comment.