Skip to content

Commit

Permalink
Added ECS stuff back
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Jan 1, 2024
1 parent 8e93ba6 commit 39a60f3
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 27 deletions.
13 changes: 13 additions & 0 deletions FinalEngine.ECS/Attributes/EntitySystemProcessAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <copyright file="EntitySystemProcessAttribute.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS.Attributes;

using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class EntitySystemProcessAttribute : Attribute
{
public GameLoopType ExecutionType { get; init; }
}
18 changes: 0 additions & 18 deletions FinalEngine.ECS/Components/Core/VelocityComponent.cs

This file was deleted.

23 changes: 23 additions & 0 deletions FinalEngine.ECS/EntityWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace FinalEngine.ECS;

using System;
using System.Collections.Generic;
using System.Reflection;
using FinalEngine.ECS.Attributes;
using FinalEngine.ECS.Exceptions;

public class EntityWorld : IEntityWorld
Expand Down Expand Up @@ -59,6 +61,27 @@ public void AddSystem(EntitySystemBase system)
this.systems.Add(system);
}

public void ProcessAll(GameLoopType type)
{
foreach (var system in this.systems)
{
var loopType = GameLoopType.Update;
var attribute = system.GetType().GetCustomAttribute<EntitySystemProcessAttribute>();

if (attribute != null)
{
loopType = attribute.ExecutionType;
}

if (loopType != type)
{
continue;
}

system.Process();
}
}

public void RemoveEntity(Entity entity)
{
ArgumentNullException.ThrowIfNull(entity, nameof(entity));
Expand Down
8 changes: 0 additions & 8 deletions FinalEngine.ECS/FinalEngine.ECS.xml

This file was deleted.

12 changes: 12 additions & 0 deletions FinalEngine.ECS/GameLoopType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <copyright file="GameLoopType.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS;

public enum GameLoopType
{
Update,

Render,
}
10 changes: 10 additions & 0 deletions FinalEngine.ECS/IEntitySystemsProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// <copyright file="IEntitySystemsProcessor.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.ECS;

public interface IEntitySystemsProcessor
{
void ProcessAll(GameLoopType type);
}
2 changes: 1 addition & 1 deletion FinalEngine.ECS/IEntityWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace FinalEngine.ECS;

using System;

public interface IEntityWorld
public interface IEntityWorld : IEntitySystemsProcessor
{
void AddEntity(Entity entity);

Expand Down

0 comments on commit 39a60f3

Please sign in to comment.