https://github.com/simulation-tree/simulation
For containerizing program code
https://github.com/simulation-tree/simulation
csharp dotnet ecs nativeaot
Last synced: 5 months ago
JSON representation
For containerizing program code
- Host: GitHub
- URL: https://github.com/simulation-tree/simulation
- Owner: simulation-tree
- License: mit
- Created: 2024-11-28T17:42:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-24T03:03:14.000Z (9 months ago)
- Last Synced: 2025-10-29T11:46:58.183Z (8 months ago)
- Topics: csharp, dotnet, ecs, nativeaot
- Language: C#
- Homepage:
- Size: 208 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Simulation
[](https://github.com/simulation-tree/simulation/actions/workflows/test.yml)
Library providing a way to broadcast messages to added listeners.
### Running simulators
Simulators contain and update systems:
```cs
public static void Main()
{
using Simulator simulator = new();
simulator.Add(new ProgramSystems());
// do work
simulator.Remove();
}
public class ProgramSystems : IDisposable
{
public ProgramSystems()
{
//before addition
}
public void Dispose()
{
//after removal
}
}
```
### Receiving messages
A system that is partial, and implementing the `IListener` interface will
allow it to receive messages broadcast by the simulator:
```cs
simulator.Broadcast(32f);
simulator.Broadcast(32f);
simulator.Broadcast(32f);
public partial class ListenerSystem : IListener
{
void IListener.Receive(ref float message)
{
}
}
```
Messages can also be broadcast by reference, allowing systems to modify them,
and use it to communicate between different projects:
```cs
LoadRequest request = new();
simulator.Broadcast(ref request);
Assert.That(request.loaded, Is.True);
public partial class LoadSystem : IListener
{
void IListener.Receive(ref LoadRequest message)
{
message.loaded = true;
}
}
public struct LoadRequest
{
public bool loaded;
}
```
### Global simulator
Another way to have listeners and broadcasting setup, is using the included `GlobalSimulator` type.
This approach is slimmer than with the `Simulator`, at the cost of the listeners being global to the entire
runtime.
```cs
public class Program
{
public static void Main()
{
GlobalSimulatorLoader.Load();
GlobalSimulator.Broadcast(32f);
GlobalSimulator.Broadcast(32f);
GlobalSimulator.Broadcast(32f);
}
}
public static class Systems
{
[Listener]
public static void Update(ref float message)
{
}
}
```
### Contributing and design
This library is created for composing behaviour of programs using systems, ideally created by
separate isolated projects.
Contributions to this goal are welcome.