TheSingularityWorkshop.FSM_API 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package TheSingularityWorkshop.FSM_API --version 1.0.4
                    
NuGet\Install-Package TheSingularityWorkshop.FSM_API -Version 1.0.4
                    
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.4" />
                    
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.4" />
                    
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.4
                    
#r "nuget: TheSingularityWorkshop.FSM_API, 1.0.4"
                    
#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.4
                    
#: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.4
                    
Install as a Cake Addin
#tool nuget:?package=TheSingularityWorkshop.FSM_API&version=1.0.4
                    
Install as a Cake Tool

FSM_API

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

Designed for flexibility. Built for robustness. Ready for anything.

๐Ÿ” 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 for your application's core logic.

๐Ÿ’ก 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): C#
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: C#
// Optional: Create a named processing group for organizing FSM updates
FSM_API.CreateProcessingGroup("MainLoop");

var fsmDefinition = FSM_API.CreateFiniteStateMachine("LightSwitchFSM", processRate: 1, processingGroup: "MainLoop")
    .State("Off")
        .OnEnter(ctx => { if (ctx is LightSwitch l) l.IsOn = false; }) // Action when entering "Off" state
        .TransitionIf("On", ctx => ctx is LightSwitch l && l.IsOn) // Transition to "On" if IsOn is true
    .State("On")
        .OnEnter(ctx => { if (ctx is LightSwitch l) l.IsOn = true; }) // Action when entering "On" state
        .TransitionIf("Off", ctx => ctx is LightSwitch l && !l.IsOn) // Transition to "Off" if IsOn is false
    .BuildDefinition(); // Finalize the FSM definition
  1. Create an instance for your context: C#
var kitchenLight = new LightSwitch();
// Associate your context with an FSM instance and assign it to a processing group
var handle = FSM_API.CreateInstance("LightSwitchFSM", kitchenLight, "MainLoop");
  1. Tick the FSM from your application's main loop: C#
// Process all FSMs in the "MainLoop" group
FSM_API.Update("MainLoop");

๐Ÿ”ง Core Concepts

FSMBuilder: Fluently define states, transitions, and associated OnEnter/OnExit actions. This is your declarative interface for FSM construction.

FSMHandle: Represents a runtime instance of an FSM operating on a specific context. Provides full control over instance lifecycle, including pausing, resetting, and retrieving current state.

IStateContext: The interface your custom data models (Plain Old C# Objects - POCOs) must implement. This ensures clean separation of FSM logic from your application's data.

Processing Groups: Organize and control the update cycles of multiple FSM instances. Ideal for managing FSMs that need to tick together or at different rates (e.g., UI, AI, physics).

Error Handling: Built-in thresholds and diagnostics prevent runaway logic or invalid state contexts, ensuring application stability without crashing.

Thread-Safe by Design: All modifications to FSM definitions and instances are meticulously deferred and processed safely on the main thread post-update, eliminating common concurrency issues.

๐Ÿ“ฆ 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 For game and interactive application development, a dedicated Unity integration package is available, built on this core FSM_API library.

๐Ÿ“˜ Whatโ€™s Next?

๐Ÿ“– Full Documentation & Wiki (TBD)

๐Ÿงช Unit Tests & Benchmarks (Currently Under Development)

๐Ÿ”Œ Plugins & Extension Framework (e.g., for visual editors, debugging tools)

๐Ÿค Contributing

Contributions welcome! Whether you're integrating FSM_API into your enterprise application, designing new extensions, or just fixing typos, PRs and issues are appreciated.

๐Ÿ“„ 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="https://raw.githubusercontent.com/TrentBest/FSM_API/main/assets/TheSingularityWorkshop.jpg" alt="The Singularity Workshop" width="200" height="200">

Because state shouldn't be a mess.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed. 
.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.
  • 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.5 84 7/27/2025
1.0.4 79 7/27/2025
1.0.3 79 7/27/2025
1.0.2 388 7/25/2025
1.0.0 471 7/22/2025