Flecs.NET is a high-level wrapper for flecs. Low-level bindings to the C api are included and generated with Bindgen.NET. Native libraries are cross-compiled with Vezel-Dev's Zig Toolsets.
// Copy, paste, and run in a .NET project!
using Flecs.NET.Core;
using World world = World.Create();
Entity entity = world.Entity()
.Set(new Position(10, 20))
.Set(new Velocity(1, 2));
world.Each(static (ref Position p, ref Velocity v) =>
{
p.X += v.X;
p.Y += v.Y;
});
public record struct Position(float X, float Y);
public record struct Velocity(float X, float Y);Flecs.NET - High-level C# port of the C++ wrapper
- Modern .NET 9
- Near feature parity with the C++ API
- Struct-based API with minimal GC interaction
- Supports both unmanaged and managed types as components
- Implicitly registers components on-the-fly
Flecs.NET.Bindings - Low-level bindings of the C API
- Build your own wrapper to suite your personal needs
- Auto-generated bindings for the entire flecs API
- Fully blittable interface with no runtime marshalling
Flecs.NET.Native - Precompiled native libraries
- Provides both shared and static libraries for Windows, MacOS, Linux, iOS, and WASM
- Packaged with Zig for dependency free cross-compilation everywhere
You can use the latest builds from NuGet:
<ItemGroup>
<PackageReference Include="Deathbeam.Flecs.NET.Debug" Version="*-build.*" Condition="'$(Configuration)' == 'Debug'" />
<PackageReference Include="Deathbeam.Flecs.NET.Release" Version="*-build.*" Condition="'$(Configuration)' == 'Release'" />
</ItemGroup>Or from GitHub Packages (replace YOUR_GITHUB_USERNAME and YOUR_GITHUB_TOKEN with your GitHub username and classic personal access token with read:packages scope):
dotnet nuget add source --name "deathbeam" --username "YOUR_GITHUB_USERNAME" --password "YOUR_GITHUB_TOKEN" --store-password-in-clear-text "https://nuget.pkg.github.com/deathbeam/index.json"To run any of the example programs, use dotnet run and set the "Example" property to the example's path relative to the Flecs.NET.Examples project. Each level of the path must be separated by an underscore.
Example:
dotnet run --project src/Flecs.NET.Examples --property:Example=Entities_BasicsClone the repo and it's submodules.
git clone --recursive https://github.com/deathbeam/Flecs.NET.git
cd Flecs.NETRun the following command on the solution to restore all project dependencies.
dotnet restoreCompile the wrapper and native libraries. The zig compiler will automatically be downloaded and cached in your local nuget package folder. Native libraries will be cross-compiled for linux, macos, and windows.
dotnet buildReference the project and import the native libraries. You should now be able to use Flecs.NET from your project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="PATH/Flecs.NET/src/Flecs.NET/Flecs.NET.csproj" />
</ItemGroup>
</Project>Low-level bindings to the flecs C API are pre-generated and included in the Flecs.NET.Bindings project by default. If needed, you can run the following command to regenerate the bindings file.
dotnet run --project src/Flecs.NET.Bindgen
Flecs.NET relies on code generation to avoid manual code duplication. If any changes are made to the Flecs.NET.Codegen project, you can run the following command to rerun the code generators. The generated files will be output to this folder.
dotnet run --project src/Flecs.NET.CodegenFeel free to open an issue or pull request. All contributions are welcome!
Ways to contribute:
- Bug Fixes/Reports
- Feature Requests
- Documentation
- Examples/Snippets
- Demos
- Typo Corrections
