TheSingularityWorkshop.FSM_API 1.0.9

dotnet add package TheSingularityWorkshop.FSM_API --version 1.0.9
                    
NuGet\Install-Package TheSingularityWorkshop.FSM_API -Version 1.0.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TheSingularityWorkshop.FSM_API" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TheSingularityWorkshop.FSM_API" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="TheSingularityWorkshop.FSM_API" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TheSingularityWorkshop.FSM_API --version 1.0.9
                    
#r "nuget: TheSingularityWorkshop.FSM_API, 1.0.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TheSingularityWorkshop.FSM_API@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TheSingularityWorkshop.FSM_API&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=TheSingularityWorkshop.FSM_API&version=1.0.9
                    
Install as a Cake Tool

FSM_API

License: MIT NuGet version NuGet downloads

Build Status Last commit Code Coverage Known Vulnerabilities

GitHub stars GitHub contributors Open Issues

๐Ÿ’– Support Us


Blazing-fast, software-agnostic Finite State Machine system for any C# application.


๐Ÿ” Overview

FSM_API is a modular, runtime-safe, and fully event-aware Finite State Machine (FSM) system designed to plug directly into any C# application from enterprise software to games, simulations, robotics, or reactive systems. It provides a powerful and decoupled approach to managing complex state-driven logic, ensuring clarity, consistency, and control across diverse domains.

โœ… Thread-safe operations (main thread only, deferred mutation handling)
๐Ÿง  Decoupled state logic from data (POCO-friendly)
๐Ÿ—๏ธ Define once, instantiate many
๐Ÿ› ๏ธ Error-tolerant FSM lifecycle management
๐Ÿงช Dynamic update ticking with frame/process throttling

No external dependencies. No frameworks required. No boilerplate setup. Pure C# power.


๐Ÿ’ก Why FSM_API?

Traditional FSM systems often suffer from tight coupling to specific environments or force rigid coding patterns. FSM_API liberates your state management:

Feature FSM_API โœ… Traditional FSM โŒ
Framework agnostic โœ… โŒ
Runtime-modifiable definitions โœ… โŒ
Deferred mutation safety โœ… โŒ
Named FSMs & Processing Groups โœ… โŒ
Built-in diagnostics & thresholds โœ… โŒ
Pure C# with no external deps โœ… โŒ

๐Ÿš€ Quickstart

  1. Define a simple context (your data model):
public class LightSwitch : IStateContext
{
    public bool IsOn = false;
    public bool IsValid => true; // Essential for FSM validation
    public string Name { get; set; } = "KitchenLight";
}
  1. Define and build your FSM:
FSM_API.CreateProcessingGroup("MainLoop");

// Define the condition for the transition from "Off" to "On".
Func<IStateContext, bool> shouldTurnOn = ctx =>
{
    if (ctx is LightSwitch l)
    {
        return l.IsOn;
    }
    return false;
};

// Define the condition for the transition from "On" to "Off".
Func<IStateContext, bool> shouldTurnOff = ctx =>
{
    if (ctx is LightSwitch l)
    {
        return !l.IsOn;
    }
    return false;
};

// Use the fluent API to create and define the FSM.
// The .BuildDefinition() call finalizes the blueprint.
FSM_API.Create.CreateFiniteStateMachine("LightSwitchFSM", processRate: 1, processingGroup: "MainLoop")
    // Define the "Off" state and its OnEnter action.
    .State("Off", 
        onEnter: ctx => { if (ctx is LightSwitch l) l.IsOn = false; },
        onUpdate: null, 
        onExit: null)
    // Define the "On" state and its OnEnter action.
    .State("On", 
        onEnter: ctx => { if (ctx is LightSwitch l) l.IsOn = true; },
        onUpdate: null,
        onExit: null)
    .WithInitialState("Off") // Set the starting state.
    // Define the transitions using the condition functions.
    .Transition("Off", "On", shouldTurnOn)
    .Transition("On", "Off", shouldTurnOff)
    .BuildDefinition();
  1. Create an instance:
var kitchenLight = new LightSwitch();
var handle = FSM_API.Create.CreateInstance("LightSwitchFSM", kitchenLight, "MainLoop");
  1. Tick the FSM:
FSM_API.Interaction.Update("MainLoop");

๐Ÿ”ง Core Concepts

  • FSMBuilder โ†’ fluently define states, transitions, and actions
  • FSMHandle โ†’ runtime instance control (pause, reset, query state)
  • IStateContext โ†’ implement for your domain objects (POCOs)
  • Processing Groups โ†’ organize FSM ticking (UI, AI, physics, etc.)
  • Error Handling โ†’ thresholds & diagnostics built-in
  • Thread Safety โ†’ deferred mutation model keeps concurrency safe

๐Ÿ“ฆ Features at a Glance

Capability Description
๐Ÿ”„ Deterministic State Logic Effortlessly define predictable state changes based on dynamic conditions or explicit triggers, ensuring your application's behavior is consistent and, where applicable, mathematically provable. Ideal for complex workflows and reliable automation.
๐ŸŽญ Context-Driven Behavior Your FSM logic directly operates on any custom C# object (POCO) that implements IStateContext. This enables clean separation of concerns (logic vs. data) and allows domain experts (e.g., BIM specifiers) to define behavior patterns that developers then implement.
๐Ÿงช Flexible Update Control Choose how FSMs are processed: event-driven, tick-based (every N frames), or manual. This adaptability means it's perfect for real-time systems, background processes, or even complex user interactions within any application loop.
๐Ÿงฏ Robust Error Escalation Benefit from per-instance and per-definition error tracking, providing immediate insights to prevent runaway logic or invalid states without crashing your application. Critical for long-running services and mission-critical software.
๐Ÿ” Runtime Redefinition Adapt your application on the fly! FSM definitions can be redefined while actively running, enabling dynamic updates, live patching, and extreme behavioral variation without recompilation or downtime. Perfect for highly configurable systems.
๐ŸŽฏ Lightweight & Performant Engineered for minimal memory allocations and optimized performance, ensuring your FSMs are efficient even in demanding enterprise or simulation scenarios. No overhead, just pure C# power.
โœ… Easy to Unit Test The inherent decoupling of FSM logic from context data ensures your state machines are highly testable in isolation, leading to more robust and reliable code with simplified unit testing.
๐Ÿ’ฏ Mathematically Provable With clearly defined states and transitions, the FSM architecture lends itself to formal verification and rigorous analysis, providing a strong foundation for high-assurance systems where correctness is paramount.
๐Ÿค Collaborative Design FSMs provide a visual and structured way to define complex behaviors, fostering better communication between developers, designers, and domain experts, and enabling less code-savvy individuals to contribute to core logic definitions.
๐ŸŽฎ Unity Integration Available Now preparing for submission to the Unity Asset Store.

๐Ÿ“˜ Whatโ€™s Next?

  • ๐Ÿ“– Full Documentation & Wiki (TBD)
  • ๐Ÿงช Unit Tests & Benchmarks (in development)
  • ๐Ÿ”Œ Plugins & Extension Framework (e.g., editors, debugging)

๐Ÿค Contributing

PRs, issues, and extensions welcome! Letโ€™s build smarter state logic together.


๐Ÿ“„ License

MIT License โ€“ use it, hack it, build amazing things with it.


๐Ÿง  Brought to you by

The Singularity Workshop โ€“ Tools for the curious, the bold, and the systemically inclined.

<img src="FSM_API/Assets/TheSingularityWorkshop.png" alt="The Singularity Workshop" width="200" height="200">

Because state shouldnโ€™t be a mess.

Support the project: Donate via PayPal


Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9 98 8/31/2025
1.0.8 52 8/23/2025
1.0.7 51 8/23/2025
1.0.6 51 8/23/2025
1.0.5 95 7/27/2025
1.0.4 90 7/27/2025
1.0.3 90 7/27/2025
1.0.2 397 7/25/2025
1.0.0 482 7/22/2025