Skip to content

Commit

Permalink
v1.5.5-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
baetz-daniel committed Mar 19, 2021
1 parent 8958dc4 commit cca333e
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 444 deletions.
26 changes: 8 additions & 18 deletions src/Exomia.ECS/Attributes/EntityComponentConfigurationAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License

// Copyright (c) 2018-2020, exomia
// Copyright (c) 2018-2021, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
Expand All @@ -12,33 +12,23 @@

namespace Exomia.ECS.Attributes
{
/// <summary>
/// Attribute for entity component configuration. This class cannot be inherited.
/// </summary>
/// <summary> Attribute for entity component configuration. This class cannot be inherited. </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class EntityComponentConfigurationAttribute : Attribute
{
/// <summary>
/// True to use pooling.
/// </summary>
internal bool _usePooling;
internal bool UsePooling;

/// <summary>
/// Gets or sets the pool size.
/// </summary>
/// <value>
/// The size of the pool.
/// </value>
/// <summary> Gets or sets the pool size. </summary>
/// <value> The size of the pool. </value>
public int PoolSize { get; set; } = EntityManager.INITIAL_ARRAY_SIZE;

/// <summary>
/// Initializes a new instance of the <see cref="EntityComponentConfigurationAttribute" />
/// class.
/// Initializes a new instance of the <see cref="EntityComponentConfigurationAttribute" /> class.
/// </summary>
/// <param name="usePooling"> True to use pooling. </param>
/// <param name="usePooling"> (Optional) True to use pooling. </param>
public EntityComponentConfigurationAttribute(bool usePooling = true)
{
_usePooling = usePooling;
UsePooling = usePooling;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License

// Copyright (c) 2018-2020, exomia
// Copyright (c) 2018-2021, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
Expand All @@ -17,9 +17,6 @@ namespace Exomia.ECS.Attributes
[AttributeUsage(AttributeTargets.Class)]
public sealed class EntitySystemConfigurationAttribute : Attribute
{
/// <summary>
/// The name.
/// </summary>
internal readonly string Name;

/// <summary> Gets or sets the list of system names which has to be executed after this one. </summary>
Expand Down
66 changes: 12 additions & 54 deletions src/Exomia.ECS/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License

// Copyright (c) 2018-2020, exomia
// Copyright (c) 2018-2021, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
Expand All @@ -13,63 +13,33 @@

namespace Exomia.ECS
{
/// <summary>
/// An entity. This class cannot be inherited.
/// </summary>
/// <summary> An entity. This class cannot be inherited. </summary>
public sealed class Entity
{
/// <summary>
/// Initial size of the components.
/// </summary>
private const int INITIAL_COMPONENTS_SIZE = 8;

/// <summary>
/// True if this object is initialized.
/// </summary>
internal bool _isInitialized = false;

/// <summary>
/// The group flags.
/// </summary>
internal uint _systemFlags = 0u;

/// <summary>
/// The components.
/// </summary>
internal bool IsInitialized = false;
internal uint SystemFlags = 0u;
private readonly Dictionary<Type, object> _components;

/// <summary>
/// Unique identifier.
/// </summary>
/// <summary> Unique identifier. </summary>
/// <value> The identifier of the unique. </value>
public Guid Guid { get; internal set; }

/// <summary>
/// Gets the components.
/// </summary>
/// <value>
/// The components.
/// </value>
internal IEnumerable<object> Components
{
get { return _components.Values; }
}

/// <summary>
/// Initializes a new instance of the <see cref="Entity" /> class.
/// </summary>
internal Entity()
{
_components = new Dictionary<Type, object>(INITIAL_COMPONENTS_SIZE);
}

/// <summary>
/// Gets a bool using the given component.
/// </summary>
/// <summary> Gets a bool using the given component. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="component"> [out] The component. </param>
/// <returns>
/// True if it succeeds, false if it fails.
/// </returns>
/// <returns> True if it succeeds, false if it fails. </returns>
public bool Get<T>(out T component)
where T : class
{
Expand All @@ -78,30 +48,25 @@ public bool Get<T>(out T component)
return res;
}

/// <inheritdoc />
/// <inheritdoc/>
public override bool Equals(object obj)
{
return obj is Entity other && Guid.Equals(other.Guid);
}

/// <inheritdoc />
/// <inheritdoc/>
public override int GetHashCode()
{
// ReSharper disable once NonReadonlyMemberInGetHashCode
return Guid.GetHashCode();
}

/// <inheritdoc />
/// <inheritdoc/>
public override string ToString()
{
return $"[{Guid}]";
return $"[{Guid.ToString()}]";
}

/// <summary>
/// Adds component.
/// </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="component"> The component. </param>
internal void Add<T>(T component)
where T : class
{
Expand All @@ -111,13 +76,6 @@ internal void Add<T>(T component)
_components.Add(typeof(T), component!);
}

/// <summary>
/// Removes this object.
/// </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <returns>
/// True if it succeeds, false if it fails.
/// </returns>
internal bool Remove<T>()
where T : class
{
Expand Down
26 changes: 5 additions & 21 deletions src/Exomia.ECS/EntityComponentPool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License

// Copyright (c) 2018-2020, exomia
// Copyright (c) 2018-2021, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
Expand All @@ -15,49 +15,33 @@
using Exomia.ECS.Attributes;

// ReSharper disable StaticMemberInGenericType

namespace Exomia.ECS
{
/// <summary>
/// An entity component pool.
/// </summary>
static class EntityComponentPool
internal static class EntityComponentPool
{
/// <summary>
/// Releases the given component.
/// </summary>
/// <typeparam name="TComponent"> Type of the component. </typeparam>
/// <param name="component"> The component. </param>
public static void Release<TComponent>(TComponent component)
where TComponent : class
{
EntityComponentPool<TComponent>.Release(component);
}
}

/// <summary>
/// An entity component pool.
/// </summary>
/// <typeparam name="TComponent"> Type of the component. </typeparam>
static class EntityComponentPool<TComponent>
internal static class EntityComponentPool<TComponent>
where TComponent : class
{
private static readonly bool s_usePooling;
private static readonly Stack<TComponent> s_free = null!;
private static readonly Func<TComponent> s_getInstance;

/// <summary>
/// Initializes static members of the <see cref="EntityComponentPool{TComponent}" /> class.
/// </summary>
static EntityComponentPool()
{
s_getInstance = Expression.Lambda<Func<TComponent>>(Expression.New(typeof(TComponent))).Compile();

EntityComponentConfigurationAttribute cfg =
typeof(TComponent).GetCustomAttribute<EntityComponentConfigurationAttribute>(false)
?? new EntityComponentConfigurationAttribute();
?? new EntityComponentConfigurationAttribute();

s_usePooling = cfg._usePooling;
s_usePooling = cfg.UsePooling;
if (!s_usePooling) { return; }

s_free = new Stack<TComponent>(cfg.PoolSize);
Expand Down
15 changes: 8 additions & 7 deletions src/Exomia.ECS/EntityManager.DrawableComponent.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region License

// Copyright (c) 2018-2020, exomia
// Copyright (c) 2018-2021, exomia
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
Expand All @@ -15,12 +15,13 @@

namespace Exomia.ECS
{
/// <content> Manager for entities. This class cannot be inherited. </content>
public sealed partial class EntityManager : DrawableComponent
{
private readonly Entity[] _currentlyToChanged = new Entity[INITIAL_ARRAY_SIZE];
private readonly Entity[] _currentlyToRemove = new Entity[INITIAL_ARRAY_SIZE];

/// <inheritdoc />
/// <inheritdoc/>
public override void Update(GameTime gameTime)
{
int currentlyToRemoveCount;
Expand All @@ -39,7 +40,7 @@ public override void Update(GameTime gameTime)
for (int si = _entitySystemsCount - 1; si >= 0; si--)
{
EntitySystemBase system = _entitySystems[si];
if (entity._systemFlags == 0 || (entity._systemFlags & system.SystemMask) == system.SystemMask)
if (entity.SystemFlags == 0 || (entity.SystemFlags & system.SystemMask) == system.SystemMask)
{
system.Remove(entity);
}
Expand All @@ -62,7 +63,7 @@ public override void Update(GameTime gameTime)
for (int si = _entitySystemsCount - 1; si >= 0; si--)
{
EntitySystemBase system = _entitySystems[si];
if (entity._systemFlags == 0 || (entity._systemFlags & system.SystemMask) == system.SystemMask)
if (entity.SystemFlags == 0 || (entity.SystemFlags & system.SystemMask) == system.SystemMask)
{
system.Changed(entity);
}
Expand All @@ -79,7 +80,7 @@ public override void Update(GameTime gameTime)
}
}

/// <inheritdoc />
/// <inheritdoc/>
public override void Draw(GameTime gameTime)
{
for (int i = 0; i < _entityDrawableSystemsCount; i++)
Expand All @@ -93,7 +94,7 @@ public override void Draw(GameTime gameTime)
}
}

/// <inheritdoc />
/// <inheritdoc/>
protected override void OnInitialize(IServiceRegistry registry)
{
for (int si = _entitySystemsCount - 1; si >= 0; si--)
Expand All @@ -104,7 +105,7 @@ protected override void OnInitialize(IServiceRegistry registry)

#region IDisposable Support

/// <inheritdoc />
/// <inheritdoc/>
protected override void OnDispose(bool disposing)
{
if (disposing)
Expand Down
Loading

0 comments on commit cca333e

Please sign in to comment.