Skip to content

A simple and user-friendly framework for writing small graphical apps in C#.

License

Notifications You must be signed in to change notification settings

Pouschel/simulationframework

 
 

Repository files navigation


SimulationFramework

asteroids physics

SimulationFramework is a cross-platform library for creative coding, game development, and graphical apps built on .NET 8. Designed with simplicity and ease of use in mind, it cuts down on development time for quick and easy prototyping.

Join the discord server!

SimulationFramework is:

  • Simple: SimulationFramework is designed to be developer-friendly. It is well documented and provides flexible, intuitive, and easy-to-use APIs.

  • Portable: The core package is dependency free, meaning SimulationFramework can run anywhere .NET can.

  • Documented: The SimulationFramework Docs contain everything you need to know about SimulationFramework, its features, and how to use them.

Features:

  • Windowing: automatically creates a configurable window

  • 2D Drawing: A powerful 2D drawing API, backed by SkiaSharp.

  • Input: Mouse, keyboard and controller support.

  • Built-in Dear ImGui Support: Dear ImGui is completely built-in with zero setup.

With more on the way! See Planned Features.

Note: SimulationFramework is still changing with every new version. Breaking changes are frequent.

Getting Started

SimulationFramework requires .NET 8 and Visual Studio 2022.

Create a new Console App using .NET 8. Add the SimulationFramework Nuget Package (and its desktop environment) using Visual Studio or the .NET CLI via the following commands:

dotnet add package SimulationFramework
dotnet add package SimulationFramework.Desktop

Next, either inherit simulation and implement the abstract methods or create two methods OnInitialize and OnRender and pass them to Simulation.Create. To start the simulation, call Simulation.Run():

// Program.cs
using SimulationFramework;
using SimulationFramework.Drawing;

class Program : Simulation
{
    public static void Main()
    {
        Start<Program>(); 
    }

    public override void OnInitialize()
    {

    }

    public override void OnRender(ICanvas canvas)
    {
        
    } 
}

OR

// Program.cs
using SimulationFramework;
using SimulationFramework.Drawing;

Simulation mySimulation = Simulation.Create(OnInitialize, OnRender);
mySimulation.Run();

void OnInitialize()
{
    // called when the simulation starts
}

void OnRender(ICanvas canvas)
{
    // called every frame
}

Running the program will result in a blank window:

blank-simulation

Next, to start drawing. The ICanvas provided in OnRender() contains a variety methods for drawing.

// ...
void OnRender(ICanvas canvas)
{
    // don't forget to clear the screen each frame!
    canvas.Clear(Color.CornflowerBlue); 
    
    // draw a 50 pixel wide red square centered at the mouse position
    canvas.Fill(Color.Red);
    canvas.DrawRect(Mouse.Position, new Vector2(50, 50), Alignment.Center); 
}

Here is what that should look like:

readme-example

To see more, go to the wiki or join the discord server.

A Quick Overview

Most SimulationFramework features are exposed through static classes. Here is a list if the most important ones:

  • Mouse: provides mouse input
  • Gamepad: provides controller input
  • Keyboard: provides keyboard input
  • Graphics: creates textures
  • Time: provides simulation timing values like DeltaTime
  • Window: configures the simulation's window

Planned Features

  • C# shaders: .NET CIL to HLSL/GLSL compilation to write any kind of shader in plain C# (or any other .NET language!). (Coming in v0.3.0, alpha out now!)
  • WebAssembly and Mobile Support: Any simulations you write will run on a web browser or mobile device, no code changes needed.

About

A simple and user-friendly framework for writing small graphical apps in C#.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%