Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Use as existing project + enforce StyleCop
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast committed Jul 11, 2023
1 parent 27f743d commit 807d2c4
Show file tree
Hide file tree
Showing 36 changed files with 290 additions and 290 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Automatically updated C# bindings for https://github.com/SanderMertens/flecs wit
1. Download and install [.NET 7](https://dotnet.microsoft.com/download).
2. Fork the repository using GitHub or clone the repository manually with submodules: `git clone --recurse-submodules https://github.com/flecs-hub/flecs-cs`.
3. Build the native library by running `library.sh`. To execute `.sh` scripts on Windows, use Git Bash which can be installed with Git itself: https://git-scm.com/download/win. The `library.sh` script requires that CMake is installed and in your path and that [`C2CS`](https://github.com/bottlenoselabs/c2cs) is installed.
4. To setup everything you need: Either (1), add the `src/cs/production/Flecs/Flecs.csproj` C# project to your solution as an existing project and reference it within your own solution, or (2) import the MSBuild `flecs.props` file which is located in the root of this directory to your `.csproj` file. See the [flecs.csproj](https://github.com/flecs-hub/flecs-cs/blob/main/src/cs/production/Flecs/Flecs.csproj) file for how to import the `flecs.props` directly.
4. Add the `src/cs/production/Flecs/Flecs.csproj` C# project to your solution as an existing project and thenreference it within your own solution.

## Developers: Documentation

Expand Down
46 changes: 0 additions & 46 deletions flecs.props
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
<Project>

<PropertyGroup>
<_LibraryName>flecs</_LibraryName>
<_GitDirectoryPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), .gitignore))/</_GitDirectoryPath>
<_LibraryDirectoryPath>$(_GitDirectoryPath)/lib</_LibraryDirectoryPath>
<_SourceCodeDirectoryPath>$(_GitDirectoryPath)/src/cs/production/$(_LibraryName)/</_SourceCodeDirectoryPath>
<_LinkDirectoryPath>$(_LibraryName)/</_LinkDirectoryPath>
<_IsEnabledSourceCode Condition=" '$(_IsEnabledSourceCode)' == '' ">true</_IsEnabledSourceCode>
</PropertyGroup>

<!-- C# source code-->
<ItemGroup Condition=" '$(_IsEnabledSourceCode)' == 'true' ">
<Compile Include="$(_SourceCodeDirectoryPath)/**/*.cs" >
<Pack>false</Pack>
<Link>$(_LinkDirectoryPath)/%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
<Compile Remove="$(_SourceCodeDirectoryPath)/obj/**/*.cs" />
<Compile Remove="$(_SourceCodeDirectoryPath)/bin/**/*.cs" />
</ItemGroup>

<!-- Implicit global usings-->
<ItemGroup Condition=" '$(ImplicitUsings)' == 'true' ">
<Using Include="System.Runtime.InteropServices" />
<Using Include="flecs_hub" />
<Using Include="flecs_hub.flecs" Static="true" />
<Using Include="flecs_hub.flecs.Runtime" Static="true" />
</ItemGroup>

<!-- Dynamic link libraries -->
<ItemGroup>
<Content Include="$(_LibraryDirectoryPath)/*.dll">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(_LibraryDirectoryPath)/*.dylib">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(_LibraryDirectoryPath)/*.so">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/cs/.globalconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# NOTE: Requires .NET 5 SDK (VS2019 16.8 or later)
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig
is_global = true

dotnet_diagnostic.CA1815.severity = none

# StyleCop Rules
## Description: StyleCop code analysis rules for C# projects.
dotnet_diagnostic.SA1401.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1649.severity = none
61 changes: 53 additions & 8 deletions src/cs/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
<Project>

<!-- MSBuild settings -->
<PropertyGroup>
<NoWarn>$(NoWarn);CA1303;CA1707</NoWarn>
<BaseOutputPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), .gitignore))/bin/$(MSBuildProjectName)</BaseOutputPath>
<BaseIntermediateOutputPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), .gitignore))/obj/$(MSBuildProjectName)/$(Configuration)</BaseIntermediateOutputPath>
<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath>
</PropertyGroup>

<!-- Implicit global usings-->
<ItemGroup Condition=" '$(ImplicitUsings)' == 'true' ">
<Using Include="System.Runtime.InteropServices" />
<Using Include="flecs_hub" />
<Using Include="flecs_hub.flecs" Static="true" />
<Using Include="bottlenoselabs.C2CS" />
</ItemGroup>

<!-- .NET8: Use artifacts path for bin/obj output folders -->
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
<ArtifactsPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), .gitignore))/artifacts</ArtifactsPath>
</PropertyGroup>

<!-- NuGet package references -->
<ItemGroup>
<PackageReference Include="bottlenoselabs.Common.Tools" Version="*">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Dynamic link libraries -->
<PropertyGroup>
<LibraryName>flecs</LibraryName>
<LibraryDirectoryPath>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),.gitignore))/lib</LibraryDirectoryPath>
</PropertyGroup>
<ItemGroup>
<Content Include="$(LibraryDirectoryPath)/*.dll">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(LibraryDirectoryPath)/*.dylib">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(LibraryDirectoryPath)/*.so">
<Link>%(Filename)%(Extension)</Link>
<Pack>false</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<!-- bottlenose.Common.Tools project settings -->
<PropertyGroup>
<StyleCopSettingsFilePath>$(MSBuildThisFileDirectory)StyleCop.json</StyleCopSettingsFilePath>
</PropertyGroup>

</Project>
File renamed without changes.
2 changes: 1 addition & 1 deletion src/cs/examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>

<Import Project="$(MSBuildThisFileDirectory)/../Directory.Build.props" />
<Import Project="../Directory.Build.props" />

</Project>
2 changes: 1 addition & 1 deletion src/cs/examples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>

<Import Project="$(MSBuildThisFileDirectory)/../Directory.Build.targets" />
<Import Project="../Directory.Build.targets" />

</Project>
8 changes: 4 additions & 4 deletions src/cs/examples/Flecs.Examples.HelloWorld/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static void Move(Iterator iterator)
var tableString = iterator.Table().String();
Console.WriteLine("Move entities with table: " + tableString);

// Iterate entities for the current group
// Iterate entities for the current group
for (var i = 0; i < iterator.Count; i++)
{
ref var position = ref p[i];
Expand All @@ -56,7 +56,7 @@ private static int Main(string[] args)
{
// Create the world
var world = new World(args);

world.RegisterComponent<Position>();
world.RegisterComponent<Velocity>();
world.RegisterTag<Eats>();
Expand All @@ -75,11 +75,11 @@ private static int Main(string[] args)
// Run systems twice. Usually this function is called once per frame
world.Progress(0);
world.Progress(0);

// See if Bob has moved (he has)
var p = bob.GetComponent<Position>();
Console.WriteLine("Bob's position is {" + p.X + ", " + p.Y + "}");

return world.Fini();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public struct Walking : ITag

internal static class Program
{
static int Main(string[] args)
private static int Main(string[] args)
{
var world = new World(args);

world.RegisterComponent<Position>();
world.RegisterTag<Walking>();

Expand All @@ -28,7 +28,7 @@ static int Main(string[] args)

var position = bob.GetComponent<Position>();
Console.WriteLine("Bob's initial position: {" + position.X + ", " + position.Y + "}");

// Print all the components the entity has. This will output:
// Position, Walking, (Identifier,Name)
Console.WriteLine("Bob's type: " + bob.Type().String());
Expand All @@ -48,10 +48,10 @@ static int Main(string[] args)

// Iterate all entities with Position
var it = world.EntityIterator<Position>();
while (it.HasNext())
while (it.HasNext())
{
var p = it.Field<Position>(1);
for (var i = 0; i < it.Count; i ++)
for (var i = 0; i < it.Count; i++)
{
var entity = it.Entity(i);
var entityName = entity.Name();
Expand All @@ -62,4 +62,4 @@ static int Main(string[] args)

return world.Fini();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public struct Position : IComponent
public struct Star : ITag
{
}

public struct Planet : ITag
{
}

public struct Moon : ITag
{
}
Expand All @@ -26,7 +26,7 @@ internal static class Program
private static int Main(string[] args)
{
var world = new World(args);

world.RegisterComponent<Position>();
world.RegisterTag<Star>();
world.RegisterTag<Planet>();
Expand All @@ -39,27 +39,27 @@ private static int Main(string[] args)
var sun = world.CreateEntity("Sun");
sun.Add<Star>();
sun.Set(new Position { X = 1, Y = 1 });

var mercury = world.CreateEntity("Mercury");
mercury.AddParent(sun);
mercury.Add<Planet>();
mercury.Set(new Position { X = 1, Y = 1 });

var venus = world.CreateEntity("Venus");
venus.AddParent(sun);
venus.Add<Planet>();
venus.Set(new Position { X = 2, Y = 2 });

var earth = world.CreateEntity("Earth");
earth.AddParent(sun);
earth.Add<Planet>();
earth.Set(new Position { X = 3, Y = 3 });

var moon = world.CreateEntity("Moon");
moon.AddParent(earth);
moon.Add<Moon>();
moon.Set(new Position { X = 0.1f, Y = 0.1f });

// Is the Moon a child of Earth?
Console.WriteLine("Is Moon a child entity of Earth?: " + moon.IsChildOf(earth));
Console.WriteLine("Is Earth a child entity of Moon?: " + earth.IsChildOf(moon));
Expand Down Expand Up @@ -94,4 +94,4 @@ private static void IterateTree(World world, Entity entity, Position parentPosit
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct Tag : ITag

internal static class Program
{
static int Main(string[] args)
private static int Main(string[] args)
{
var world = new World(args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public struct Velocity : IComponent
public struct Human : ITag
{
}

public struct Eats : ITag
{
}

public struct Apples : ITag
{
}
Expand All @@ -47,7 +47,7 @@ private static int Main(string[] args)

// Create an entity which all of the above
var bob = world.CreateEntity("bob");

bob.Set(new Position { X = 10, Y = 20 });
bob.Set(new Velocity { X = 1, Y = 1 });
bob.Add<Human>();
Expand Down Expand Up @@ -115,7 +115,7 @@ private static void IterateComponents(Entity entity)
Console.WriteLine();
i++;
}

Console.WriteLine();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public struct FreightCapacity : IComponent

[StructLayout(LayoutKind.Sequential)]
public struct ImpulseSpeed : IComponent
{
{
public double Value;
}

[StructLayout(LayoutKind.Sequential)]
public struct Position : IComponent
{
{
public double X;
public double Y;
}
Expand Down Expand Up @@ -65,7 +65,7 @@ private static int Main(string[] args)
var spaceShip = world.CreatePrefab("SpaceShip");
spaceShip.Set(new ImpulseSpeed { Value = 50 });
spaceShip.Set(new Defense { Value = 50 });
//setting as overridable, every ship instance can be damaged individually
// setting as overridable, every ship instance can be damaged individually
spaceShip.SetOverride(hull, new Amount() { Max = 200, Current = 200});
spaceShip.SetOverride(shield, new Amount() { Max = 200, Current = 200 });

Expand Down Expand Up @@ -105,7 +105,7 @@ private static int Main(string[] args)
// Position,(Identifier,Name),(IsA,MammothFreighter)
var instanceTypeString = freighter1.Type().String();
Console.WriteLine("Instance type: " + instanceTypeString);

// Even though the instance doesn't have a private copy of ImpulseSpeed, we
// can still get it using the regular API (outputs 50)
var impulseSpeed = freighter1.GetComponent<ImpulseSpeed>();
Expand All @@ -119,4 +119,4 @@ private static int Main(string[] args)

return world.Fini();
}
}
}
Loading

0 comments on commit 807d2c4

Please sign in to comment.