Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=crlf
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ jobs:
dotnet-version: |
6.0.x
7.0.x
8.0.x
# workaround for actions/setup-dotnet#155
- name: Clear package cache
run: dotnet clean Arch.Extended.sln && dotnet nuget locals all --clear
- name: Restore packages
run: dotnet restore Arch.Extended.sln
- name: Build
run: dotnet build Arch.Extended.sln -c ${{ matrix.config }} --no-restore
run: dotnet build Arch.Extended.sln -c ${{ matrix.config }} --no-restore -warnaserror
- name: Test
run: dotnet test Arch.Extended.sln -c ${{ matrix.config }} -l "console;verbosity=detailed"
2 changes: 2 additions & 0 deletions Arch.AOT.SourceGenerator/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace Arch.AOT.SourceGenerator
public sealed class ComponentAttribute : Attribute { }
}
""";

/// <inheritdoc cref="IIncrementalGenerator.Initialize"/>
public void Initialize(IncrementalGeneratorInitializationContext context)
{
// Register the attribute.
Expand Down
7 changes: 5 additions & 2 deletions Arch.EventBus/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public struct ReceivingMethod
public int Order;
}

/// <summary>
/// EventBusExtensions
/// </summary>
public static class EventBusExtensions
{

Expand All @@ -86,7 +89,7 @@ public static string RefKindToString(RefKind refKind)
case RefKind.Out:
return "out";
}
return null;
return null!;
}

/// <summary>
Expand All @@ -108,7 +111,7 @@ public static StringBuilder AppendEventMethods(this StringBuilder sb, IList<Meth
/// Appends all methods redirecting events.
/// </summary>
/// <param name="sb">The <see cref="StringBuilder"/>.</param>
/// <param name="callMethods">The <see cref="IList{T}"/> containing the <see cref="Method"/>s redirecting the event and calling the methods. </param>
/// <param name="callMethod">The <see cref="IList{T}"/> containing the <see cref="Method"/>s redirecting the event and calling the methods. </param>
/// <returns></returns>
public static StringBuilder AppendEventMethod(this StringBuilder sb, Method callMethod)
{
Expand Down
21 changes: 20 additions & 1 deletion Arch.EventBus/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@

namespace Arch.Bus;

/// <summary>
/// Hooks.
/// </summary>
public struct Hooks
{
/// <summary>
/// Instances.
/// </summary>
public List<ClassHooks> Instances;
}

/// <summary>
/// Class hooks.
/// </summary>
public struct ClassHooks
{
/// <summary>
/// Partial class.
/// </summary>
public ITypeSymbol PartialClass;

/// <summary>
/// Event hooks.
/// </summary>
public IList<EventHook> EventHooks;
}

Expand All @@ -32,7 +48,10 @@ public struct EventHook
public IMethodSymbol MethodSymbol;
}

public static class Hookersxtensions
/// <summary>
/// Hook extensions.
/// </summary>
public static class HookExtensions
{

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Arch.Bus;

public static class IMethodSymbolExtensions
/// <summary>
/// Method symbol extensions.
/// </summary>
public static class MethodSymbolExtensions
{

/// <summary>
Expand All @@ -16,12 +19,12 @@ public static AttributeData GetAttributeData(this IMethodSymbol ms, string name)
foreach (var attribute in ms.GetAttributes())
{
var classSymbol = attribute.AttributeClass;
if(!classSymbol.Name.Contains(name)) continue;
if(!classSymbol!.Name.Contains(name)) continue;

return attribute;
}

return default;
return default!;
}

/// <summary>
Expand All @@ -30,17 +33,17 @@ public static AttributeData GetAttributeData(this IMethodSymbol ms, string name)
/// </summary>
/// <param name="data">The <see cref="AttributeData"/>.</param>
/// <param name="array">The <see cref="List{T}"/> where the found <see cref="ITypeSymbol"/>s are added to.</param>
public static void GetAttributeTypes(this AttributeData data, List<ITypeSymbol> array)
public static void GetAttributeTypes(this AttributeData? data, List<ITypeSymbol> array)
{
if (data is not null && data.AttributeClass.IsGenericType)
if (data is not null && data.AttributeClass!.IsGenericType)
{
array.AddRange(data.AttributeClass.TypeArguments);
}
else if (data is not null && !data.AttributeClass.IsGenericType)
else if (data is not null && !data.AttributeClass!.IsGenericType)
{
var constructorArguments = data.ConstructorArguments[0].Values;
var constructorArgumentsTypes = constructorArguments.Select(constant => constant.Value as ITypeSymbol).ToList();
array.AddRange(constructorArgumentsTypes);
array.AddRange(constructorArgumentsTypes!);
}
}
}
20 changes: 12 additions & 8 deletions Arch.EventBus/SourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

namespace Arch.Bus;

/// <summary>
/// Query generator.
/// </summary>
[Generator]
public class QueryGenerator : IIncrementalGenerator
{
private static EventBus _eventBus;
private static Hooks _hooks;

private static Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)> _eventTypeToReceivingMethods;
private static Dictionary<ITypeSymbol, IList<EventHook>> _containingTypeToReceivingMethods;
private static Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)> _eventTypeToReceivingMethods = null!;
private static Dictionary<ITypeSymbol, IList<EventHook>> _containingTypeToReceivingMethods = null!;

/// <inheritdoc cref="IIncrementalGenerator.Initialize"/>
public void Initialize(IncrementalGeneratorInitializationContext context)
{
//if (!Debugger.IsAttached) Debugger.Launch();
Expand Down Expand Up @@ -59,7 +63,7 @@ public EventAttribute(int order = 0)


/// <summary>
/// Returns a <see cref="MethodDeclarationSyntax"/> if its annocated with a attribute of <see cref="name"/>.
/// Returns a <see cref="MethodDeclarationSyntax"/> if its annotated with an attribute of <paramref name="name"/>.
/// </summary>
/// <param name="context">Its <see cref="GeneratorSyntaxContext"/>.</param>
/// <param name="name">The attributes name.</param>
Expand Down Expand Up @@ -97,7 +101,7 @@ private static void MapMethodToEventType(IMethodSymbol methodSymbol)
{
var eventType = methodSymbol.Parameters[0];
var param = methodSymbol.GetAttributes()[0].ConstructorArguments[0];
var receivingMethod = new ReceivingMethod{ Static = methodSymbol.IsStatic, MethodSymbol = methodSymbol, Order = (int)param.Value };
var receivingMethod = new ReceivingMethod{ Static = methodSymbol.IsStatic, MethodSymbol = methodSymbol, Order = (int)param.Value! };

// Either append or create a new receiving method with a new list.
if (_eventTypeToReceivingMethods.TryGetValue(eventType.Type, out var tuple))
Expand Down Expand Up @@ -189,19 +193,19 @@ private static void Generate(Compilation compilation, ImmutableArray<MethodDecla
// Init
_eventBus.Namespace = "Arch.Bus";
_eventBus.Methods = new List<Method>(512);
_eventTypeToReceivingMethods = new Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)>(512);
_eventTypeToReceivingMethods = new Dictionary<ITypeSymbol, (RefKind, IList<ReceivingMethod>)>(512, SymbolEqualityComparer.Default);

_hooks.Instances = new List<ClassHooks>(512);
_containingTypeToReceivingMethods = new Dictionary<ITypeSymbol, IList<EventHook>>(512);
_containingTypeToReceivingMethods = new Dictionary<ITypeSymbol, IList<EventHook>>(512, SymbolEqualityComparer.Default);

// Generate Query methods and map them to their classes
foreach (var methodSyntax in methods)
{
var semanticModel = compilation.GetSemanticModel(methodSyntax.SyntaxTree);
var methodSymbol = ModelExtensions.GetDeclaredSymbol(semanticModel, methodSyntax) as IMethodSymbol;

MapMethodToEventType(methodSymbol);
MapMethodToContainingType(methodSymbol);
MapMethodToEventType(methodSymbol!);
MapMethodToContainingType(methodSymbol!);
}

PrepareEventBus();
Expand Down
2 changes: 1 addition & 1 deletion Arch.Extended.Sample/Arch.Extended.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arch" Version="2.0.0" />
<PackageReference Include="Arch" Version="2.1.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
Expand Down
14 changes: 7 additions & 7 deletions Arch.Extended.Sample/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ namespace Arch.Extended;
public class Game : Microsoft.Xna.Framework.Game
{
// The world and a job scheduler for multithreading
private World _world;
private JobScheduler _jobScheduler;
private World _world = null!;
private JobScheduler _jobScheduler = null!;

// Our systems processing entities
private System.Group<GameTime> _systems;
private DrawSystem _drawSystem;
private System.Group<GameTime> _systems = null!;
private DrawSystem _drawSystem = null!;

// Monogame stuff
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Texture2D _texture2D;
private Random _random;
private SpriteBatch _spriteBatch = null!;
private Texture2D _texture2D = null!;
private Random _random = null!;

public Game()
{
Expand Down
4 changes: 2 additions & 2 deletions Arch.Extended.Sample/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class SpriteSerializer : IJsonFormatter<Sprite>, IMessagePackFormatter<Sp
/// <summary>
/// The <see cref="GraphicsDevice"/> to create <see cref="Texture2D"/>s from.
/// </summary>
public GraphicsDevice GraphicsDevice { get; set; }
public GraphicsDevice GraphicsDevice { get; set; } = null!;

public void Serialize(ref JsonWriter writer, Sprite value, IJsonFormatterResolver formatterResolver)
{
writer.WriteBeginObject();
Expand Down
1 change: 0 additions & 1 deletion Arch.Extended.Sample/Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Arch.Core.Extensions;
using Arch.LowLevel;
using Arch.System;
using Arch.System.SourceGenerator;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
Expand Down
12 changes: 12 additions & 0 deletions Arch.Extended.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arch.System.SourceGenerator
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Arch.System.SourceGenerator.Tests", "Arch.System.SourceGenerator.Tests\Arch.System.SourceGenerator.Tests.csproj", "{FDDA22B1-43DF-48E6-82CE-BC528C8349B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arch.AOT.SourceGenerator", "Arch.AOT.SourceGenerator\Arch.AOT.SourceGenerator.csproj", "{454AC3E0-A46A-4620-A377-3A360B8D11A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Arch.Persistence.Tests", "Arch.Persistence.Tests\Arch.Persistence.Tests.csproj", "{15E851C2-ACD6-4626-A7E4-46AA4CCD3BD5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -75,6 +79,14 @@ Global
{FDDA22B1-43DF-48E6-82CE-BC528C8349B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDDA22B1-43DF-48E6-82CE-BC528C8349B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDDA22B1-43DF-48E6-82CE-BC528C8349B9}.Release|Any CPU.Build.0 = Release|Any CPU
{454AC3E0-A46A-4620-A377-3A360B8D11A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{454AC3E0-A46A-4620-A377-3A360B8D11A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{454AC3E0-A46A-4620-A377-3A360B8D11A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{454AC3E0-A46A-4620-A377-3A360B8D11A3}.Release|Any CPU.Build.0 = Release|Any CPU
{15E851C2-ACD6-4626-A7E4-46AA4CCD3BD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15E851C2-ACD6-4626-A7E4-46AA4CCD3BD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15E851C2-ACD6-4626-A7E4-46AA4CCD3BD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15E851C2-ACD6-4626-A7E4-46AA4CCD3BD5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions Arch.LowLevel.Tests/UnsafeArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void UnsafeArrayFill()
var array = new UnsafeArray<int>(35);
using (array)
{
#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement
UnsafeArray.Fill(ref array, 8);
#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement

for (var i = 0; i < array.Length; i++)
That(array[i], Is.EqualTo(8));
Expand All @@ -72,8 +74,10 @@ public void UnsafeArrayCopy()
for (var i = 0; i < src.Length; i++)
src[i] = i;

#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement
UnsafeArray.Fill(ref dst);
UnsafeArray.Copy(ref src, 4, ref dst, 1, 4);
#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement

Multiple(() =>
{
Expand Down
7 changes: 5 additions & 2 deletions Arch.LowLevel/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public override string ToString()
}


/// <summary>
/// Array.
/// </summary>
public unsafe struct Array
{

Expand Down Expand Up @@ -221,13 +224,13 @@ public static void Copy<T>(ref Array<T> source, int index, ref Array<T> destinat
/// <param name="source">The <see cref="UnsafeArray{T}"/> instance.</param>
/// <param name="value">The value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Fill<T>(ref Array<T> source, in T value = default)
public static void Fill<T>(ref Array<T> source, in T value = default!)
{
source.AsSpan().Fill(value);
}

/// <summary>
/// Resizes an <see cref="UnsafeArray{T}"/> to a new <see cref="newCapacity"/>.
/// Resizes an <see cref="UnsafeArray{T}"/> to a new <paramref name="newCapacity"/>.
/// </summary>
/// <param name="source">The <see cref="UnsafeArray{T}"/>.</param>
/// <param name="newCapacity">The new capacity.</param>
Expand Down
4 changes: 4 additions & 0 deletions Arch.LowLevel/Enumerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public unsafe struct UnsafeIEnumerator<T> : IEnumerator<T> where T : unmanaged
/// Creates an instance of the <see cref="UnsafeIEnumerator{T}"/>.
/// </summary>
/// <param name="list">The <see cref="UnsafeList{T}"/>.</param>
/// <param name="count">Count.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal UnsafeIEnumerator(T* list, int count)
{
Expand Down Expand Up @@ -117,6 +118,7 @@ public void Reset()
/// Creates an instance of the <see cref="UnsafeIEnumerator{T}"/>.
/// </summary>
/// <param name="list">The <see cref="UnsafeList{T}"/>.</param>
/// <param name="count">Count.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal UnsafeEnumerator(T* list, int count)
{
Expand Down Expand Up @@ -162,6 +164,7 @@ public unsafe struct ReverseIEnumerator<T> : IEnumerator<T> where T : unmanaged
/// Creates an instance of the <see cref="UnsafeIEnumerator{T}"/>.
/// </summary>
/// <param name="list">The <see cref="UnsafeList{T}"/>.</param>
/// <param name="count">Count.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ReverseIEnumerator(T* list, int count)
{
Expand Down Expand Up @@ -216,6 +219,7 @@ public void Reset()
/// Creates an instance of the <see cref="UnsafeIEnumerator{T}"/>.
/// </summary>
/// <param name="list">The <see cref="UnsafeList{T}"/>.</param>
/// <param name="count">Count.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal UnsafeReverseEnumerator(T* list, int count)
{
Expand Down
Loading