<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged thesingularityworkshop</title>
<link>https://coderlegion.com/tag/thesingularityworkshop</link>
<description>Powered by Question2Answer</description>
<item>
<title>The Weekend After: HeadlessAi Has Entered the Workshop</title>
<link>https://coderlegion.com/30562/the-weekend-after-headlessai-has-entered-the-workshop</link>
<description>&lt;p&gt;Last weekend, we introduced some of the toys we're building at The Singularity Workshop. This weekend, we've got more!  (All are c#)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.HeadlessAi&quot;&gt;HeadlessAi&lt;/a&gt;&lt;/strong&gt; — Connecting .NET applications to AI endpoints through a straightforward, extensible interface.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/Profiles&quot;&gt;Profiles&lt;/a&gt;&lt;/strong&gt; — Exploring identity, relationships, privacy, and user-controlled data sharing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.Ontology&quot;&gt;Ontology&lt;/a&gt;&lt;/strong&gt; — Organizing information in flexible, meaningful structures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.MicroBundleIngestor&quot;&gt;MicroBundleIngestor&lt;/a&gt;&lt;/strong&gt; — Exploring new ways to bring MicroBundles into the ecosystem.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.Economy&quot;&gt;Economy&lt;/a&gt;&lt;/strong&gt; — Beginning to explore the foundations of an interconnected digital economy.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;So, what makes the Workshop different?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We don't just build packages and leave you to figure them out. We explain the &lt;em&gt;what, why, and how&lt;/em&gt; behind them—from the underlying theory to practical examples you can learn from and build upon.&lt;/p&gt;
&lt;p&gt;You don't have to be an expert programmer to start exploring. We're building an ecosystem designed to help you understand the technology, connect the pieces, and bring your own ideas to life.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Don't just use the tools. Learn to build with them.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Come explore: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest&quot;&gt;The Singularity Workshop on GitHub&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/30562/the-weekend-after-headlessai-has-entered-the-workshop</guid>
<pubDate>Sat, 10 Oct 2026 06:54:10 +0000</pubDate>
</item>
<item>
<title>It’s the Weekend. The Workshop Has Toys. Come Play.</title>
<link>https://coderlegion.com/29600/its-the-weekend-the-workshop-has-toys-come-play</link>
<description>&lt;p&gt;It’s the weekend.&lt;/p&gt;
&lt;p&gt;Instead of writing another 2,000-word manifesto on what The Singularity Workshop &lt;em&gt;might&lt;/em&gt; become someday, I’m just going to open the toy box.&lt;/p&gt;
&lt;p&gt;I’ve been building.&lt;/p&gt;
&lt;p&gt;Some of it is foundational. Some of it is highly experimental. Some of it is definitely still alpha software. But enough of it has crossed the line from &lt;strong&gt;“whiteboard diagram”&lt;/strong&gt; to &lt;strong&gt;running code&lt;/strong&gt; that it’s time to put it out in public.&lt;/p&gt;
&lt;p&gt;You can download it, read the source, compile it, and—most importantly—&lt;strong&gt;break it&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;where-to-start-nuget&quot;&gt;Where to Start: NuGet&lt;/h3&gt;
&lt;p&gt;The easiest way to see what is actually breathing right now is NuGet.&lt;/p&gt;
&lt;p&gt;Search for &lt;strong&gt;TheSingularityWorkshop&lt;/strong&gt; and make sure &lt;strong&gt;Include prerelease&lt;/strong&gt; is enabled.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages?q=TheSingularityWorkshop&amp;amp;prerelease=true&quot;&gt;Search The Singularity Workshop packages on NuGet&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Most of what I'm pushing right now is deliberately prerelease.&lt;/p&gt;
&lt;p&gt;These aren't polished commercial products with a marketing department hiding the machinery behind a landing page. They are architectural experiments that have finally become real enough for someone else to get their hands dirty with.&lt;/p&gt;
&lt;p&gt;That is exactly the point.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-toy-box&quot;&gt;The Toy Box&lt;/h2&gt;
&lt;p&gt;Here is what is currently sitting on the workbench.&lt;/p&gt;
&lt;h3 id=&quot;fsm-api&quot;&gt;FSM_API&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;NuGet&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the bedrock.&lt;/p&gt;
&lt;p&gt;The core premise is that behavior can be represented explicitly as state, allowing state-driven behavior to remain separate from the data objects it operates on.&lt;/p&gt;
&lt;p&gt;FSM_API is a framework-agnostic C# finite-state-machine system with explicit state definitions, transitions, contexts, processing groups, lifecycle handling, and runtime behavior.&lt;/p&gt;
&lt;p&gt;If you want to start at the absolute beginning of the Workshop, start here.&lt;/p&gt;
&lt;p&gt;This is where the behavior machinery begins.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;fsm-cos&quot;&gt;FSM_COS&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_COS&quot;&gt;NuGet&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.FSM_COS&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is where the pieces start becoming a system.&lt;/p&gt;
&lt;p&gt;FSM_COS is the &lt;strong&gt;composition kernel&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A runtime manifest says what is requested. FSM_COS resolves the MicroBundle dependency closure, propagates configuration, loads the required capabilities, arbitrates them toward convergence, and produces a &lt;code&gt;RuntimeAssembly&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Runtime Manifest
       |
       v
    FSM_COS
       |
       +-- resolve MicroBundles
       +-- resolve dependencies
       +-- propagate configuration
       +-- load/install
       +-- arbitrate
       +-- converge
       |
       v
RuntimeAssembly
       |
       v
host / manifestation
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The important part is what FSM_COS &lt;strong&gt;doesn't&lt;/strong&gt; do.&lt;/p&gt;
&lt;p&gt;It doesn't become the application.&lt;/p&gt;
&lt;p&gt;It doesn't become the GUI.&lt;/p&gt;
&lt;p&gt;It doesn't become the storage system.&lt;/p&gt;
&lt;p&gt;It doesn't become the Experience.&lt;/p&gt;
&lt;p&gt;It assembles the machine and hands the resulting composition to something else.&lt;/p&gt;
&lt;p&gt;The crane doesn't become the machine.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;microbundledomain&quot;&gt;MicroBundleDomain&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.MicroBundleDomain&quot;&gt;NuGet&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.MicroBundleDomain&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This one is particularly important to the architecture.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;MicroBundleDomain&lt;/code&gt; is a &lt;strong&gt;neutral contract for independently authored capabilities&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A MicroBundle is a focused unit of capability that can identify itself, declare dependencies and providers, accept configuration, enter a runtime, and participate in composition without requiring the host to understand its private domain.&lt;/p&gt;
&lt;p&gt;The important architectural separation is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;What is this capability?
        |
        v
MicroBundleDomain

Where do I get it?
        |
        v
MicroBundleRepository

How do I compose it?
        |
        v
FSM_COS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That means &lt;code&gt;MicroBundleDomain&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; belong underneath FSM_COS as an implementation dependency.&lt;/p&gt;
&lt;p&gt;It is the neutral seam.&lt;/p&gt;
&lt;p&gt;That matters because someone should be able to author a capability without permanently welding their package to my composition engine.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;microbundlerepository&quot;&gt;MicroBundleRepository&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.MicroBundleRepository&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If MicroBundleDomain answers &lt;strong&gt;what&lt;/strong&gt;, the Repository answers &lt;strong&gt;where&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The repository explores durable delivery of versioned MicroBundle artifacts, currently using Azure Blob Storage as the storage substrate.&lt;/p&gt;
&lt;p&gt;The distinction is deliberately sharp:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Blob Storage
    = substrate

Repository
    = artifact delivery boundary

FSM_COS
    = composition boundary
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Artifacts have deterministic identity based on the MicroBundle ID, explicit version, and SHA-256 content identity.&lt;/p&gt;
&lt;p&gt;The repository doesn't become a database.&lt;/p&gt;
&lt;p&gt;It doesn't arbitrate.&lt;/p&gt;
&lt;p&gt;It doesn't compose Experiences.&lt;/p&gt;
&lt;p&gt;It doesn't become a GUI.&lt;/p&gt;
&lt;p&gt;It answers a much smaller question:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Given this artifact address, where are the bytes and can I verify them?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I am having entirely too much fun ruthlessly separating these concerns.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;gui&quot;&gt;GUI&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.GUI&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There is a platform-neutral GUI core in here, alongside manifestations for &lt;strong&gt;Blazor and WPF&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But the real experiment isn't drawing buttons.&lt;/p&gt;
&lt;p&gt;It's asking:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Can an object describe itself structurally well enough that a generic GUI can just render it?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That led to a reflection-driven GUI architecture where the domain model doesn't need to know about the editor that happens to display it.&lt;/p&gt;
&lt;p&gt;The basic idea is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Domain model
     |
     | describes itself
     v
Reflection / semantic projection
     |
     v
GUI.Core
     |
     +--------+--------+
     v                 v
  Blazor              WPF
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So if you're interested in semantic interface construction, reflection, recursive GUI structures, and separating &lt;strong&gt;what something means&lt;/strong&gt; from &lt;strong&gt;how it looks&lt;/strong&gt;, poke around in this one.&lt;/p&gt;
&lt;p&gt;There is considerably more going on here than “make a button.”&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;fsm-serialization&quot;&gt;FSM_Serialization&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_Serialization&quot;&gt;NuGet&lt;/a&gt; | &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.FSM_Serialization&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This isn't an experiment in shouting &lt;em&gt;“my serializer is the fastest.”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It's an experiment in &lt;strong&gt;strict ownership&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The domain owns what its data means.&lt;/p&gt;
&lt;p&gt;The serialization layer owns how that data crosses a byte boundary.&lt;/p&gt;
&lt;p&gt;The host decides where those bytes ultimately go.&lt;/p&gt;
&lt;p&gt;The package deliberately stays out of databases, filesystems, HTTP, application configuration, object-graph magic, and other concerns that belong somewhere else.&lt;/p&gt;
&lt;p&gt;It's small, tight, and opinionated.&lt;/p&gt;
&lt;p&gt;I wrote a deeper dive on this one:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/6768/i-built-a-serializer-that-refuses-to-own-your-data&quot;&gt;I Built a Serializer That Refuses to Own Your Data&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;fsm-rest&quot;&gt;FSM_REST&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.FSM_REST&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This isn't another web framework.&lt;/p&gt;
&lt;p&gt;FSM_REST provides a reusable boundary for describing and composing REST capabilities.&lt;/p&gt;
&lt;p&gt;The interesting part is that a REST capability can be represented as a &lt;strong&gt;capability recipe&lt;/strong&gt; rather than dragging an entire web application into the runtime.&lt;/p&gt;
&lt;p&gt;Conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;REST capability
      |
      v
FSM_REST
      |
      +-- capability description
      +-- request construction
      +-- transport boundary
      |
      v
remote API
      |
      v
current data
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The MicroBundle can describe what is needed to obtain the capability without pretending that the remote API's current response data belongs inside the bundle.&lt;/p&gt;
&lt;p&gt;That distinction becomes increasingly useful when capabilities are composed dynamically.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;protocolai-amp-grammarai&quot;&gt;ProtocolAI &amp;amp; GrammarAI&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;ProtocolAI: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.ProtocolAi&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;GrammarAI: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.GrammarAi&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These sound like AI wrappers.&lt;/p&gt;
&lt;p&gt;They aren't.&lt;/p&gt;
&lt;p&gt;They explore the boundary where deterministic application-owned meaning meets probabilistic language models.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ProtocolAI&lt;/strong&gt; is the &lt;strong&gt;WHAT&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It gives application-owned meaning a deterministic semantic address space.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GrammarAI&lt;/strong&gt; is the &lt;strong&gt;HOW&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It gives those identities a structural language for describing how they can be connected.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;LLM
 |
 | probability
 v
ProtocolAI
   WHAT
 |
 v
GrammarAI
   HOW
 |
 v
host / adapter
 |
 v
application
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is deliberately no LLM hidden inside either package.&lt;/p&gt;
&lt;p&gt;No provider SDK.&lt;/p&gt;
&lt;p&gt;No inference engine.&lt;/p&gt;
&lt;p&gt;No chatbot.&lt;/p&gt;
&lt;p&gt;No API-key management.&lt;/p&gt;
&lt;p&gt;The application owns the meaning.&lt;/p&gt;
&lt;p&gt;The model supplies probability.&lt;/p&gt;
&lt;p&gt;The deterministic boundary sits in between.&lt;/p&gt;
&lt;p&gt;I wrote more about the idea here:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/6795/protocolai-and-grammarai-giving-ai-a-language-software-can-actually-own&quot;&gt;ProtocolAI and GrammarAI: Giving AI a Language Software Can Actually Own&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-hosts&quot;&gt;The Hosts&lt;/h2&gt;
&lt;p&gt;Architecture diagrams are great.&lt;/p&gt;
&lt;p&gt;Eventually, though, somebody has to push a button.&lt;/p&gt;
&lt;h3 id=&quot;anyapp&quot;&gt;AnyApp&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/AnyApp&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;AnyApp is the &lt;strong&gt;desktop proof of the composition architecture&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It is the Windows desktop counterpart to the browser-facing WebPage/WebForge host.&lt;/p&gt;
&lt;p&gt;The important part is that AnyApp is trying very hard to remain a &lt;strong&gt;host&lt;/strong&gt;, rather than becoming an application-specific framework.&lt;/p&gt;
&lt;p&gt;Startup is now manifest-driven:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;AnyApp
  |
  v
startup / last Experience
  |
  v
Forge fallback when necessary
  |
  v
FSM_COS
  |
  v
RuntimeAssembly
  |
  v
host manifestation
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The host doesn't need to know every Experience it might eventually run.&lt;/p&gt;
&lt;p&gt;It hosts the composition.&lt;/p&gt;
&lt;p&gt;That's the experiment.&lt;/p&gt;
&lt;p&gt;And yes, the current window is tiny.&lt;/p&gt;
&lt;p&gt;That's part of the fun.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;webpage&quot;&gt;WebPage&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/WebPage&quot;&gt;GitHub&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is the &lt;strong&gt;public proving ground&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;WebPage is the ephemeral web manifestation of the larger Workshop: public-facing surface, demonstration environment, and experimental place where the architecture gets to meet an actual visitor.&lt;/p&gt;
&lt;p&gt;The guiding idea is simple:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Make the mundane magical. Then show the machinery that made it possible.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Instead of merely putting diagrams on a webpage explaining that the GUI is dynamic, the page itself should eventually behave dynamically.&lt;/p&gt;
&lt;p&gt;A button can breathe.&lt;/p&gt;
&lt;p&gt;A GUI can reproduce.&lt;/p&gt;
&lt;p&gt;The reproduction can become a swarm.&lt;/p&gt;
&lt;p&gt;The swarm can overwhelm the screen.&lt;/p&gt;
&lt;p&gt;The system can freeze.&lt;/p&gt;
&lt;p&gt;Gravity can take over.&lt;/p&gt;
&lt;p&gt;And suddenly the visitor isn't just reading about the architecture anymore.&lt;/p&gt;
&lt;p&gt;They're watching the architecture become the experience.&lt;/p&gt;
&lt;p&gt;That's what the WebPage repository is for.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;you-don-t-need-to-understand-all-of-this&quot;&gt;You Don't Need to Understand All of This&lt;/h2&gt;
&lt;p&gt;Seriously.&lt;/p&gt;
&lt;p&gt;You don't need to read every README.&lt;/p&gt;
&lt;p&gt;You don't need to understand FSM_COS before touching FSM_API.&lt;/p&gt;
&lt;p&gt;You don't need to understand MicroBundle arbitration before playing with the GUI.&lt;/p&gt;
&lt;p&gt;You certainly don't need to agree with my architecture.&lt;/p&gt;
&lt;p&gt;You don't need to know what a “semantic address space” is.&lt;/p&gt;
&lt;p&gt;You don't need to know what “arbitration” means.&lt;/p&gt;
&lt;p&gt;You don't even need to know why I keep naming things with increasingly suspicious acronyms.&lt;/p&gt;
&lt;p&gt;Just pick one piece that looks interesting.&lt;/p&gt;
&lt;p&gt;Install it.&lt;/p&gt;
&lt;p&gt;Read the source.&lt;/p&gt;
&lt;p&gt;Build a tiny experiment.&lt;/p&gt;
&lt;p&gt;Benchmark it.&lt;/p&gt;
&lt;p&gt;Break it.&lt;/p&gt;
&lt;p&gt;Tell me why it's broken.&lt;/p&gt;
&lt;p&gt;That is the entire point of publishing early.&lt;/p&gt;
&lt;p&gt;Software has to meet reality.&lt;/p&gt;
&lt;p&gt;And reality includes other developers.&lt;/p&gt;
&lt;p&gt;Some APIs will change.&lt;/p&gt;
&lt;p&gt;Some experiments will become load-bearing infrastructure.&lt;/p&gt;
&lt;p&gt;Some ideas that seem perfectly reasonable right now will probably turn out to be terrible.&lt;/p&gt;
&lt;p&gt;Some will get thrown away.&lt;/p&gt;
&lt;p&gt;That's normal.&lt;/p&gt;
&lt;p&gt;Actually, that's part of the process.&lt;/p&gt;
&lt;p&gt;The important thing is that these aren't only diagrams anymore.&lt;/p&gt;
&lt;p&gt;They're code.&lt;/p&gt;
&lt;p&gt;They're packages.&lt;/p&gt;
&lt;p&gt;They're repositories.&lt;/p&gt;
&lt;p&gt;They're things you can actually touch.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-workshop-is-open&quot;&gt;The Workshop Is Open&lt;/h2&gt;
&lt;p&gt;So, that's the current toy box.&lt;/p&gt;
&lt;p&gt;Not everything is finished.&lt;/p&gt;
&lt;p&gt;Not everything is stable.&lt;/p&gt;
&lt;p&gt;Not everything is even guaranteed to survive.&lt;/p&gt;
&lt;p&gt;That's why I'm putting it out now.&lt;/p&gt;
&lt;p&gt;If something catches your eye, &lt;strong&gt;go play with it&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;And if you find something interesting, confusing, inefficient, backwards, brilliant, terrible, or just plain weird—&lt;/p&gt;
&lt;p&gt;tell me.&lt;/p&gt;
&lt;p&gt;That's how experiments turn into software.&lt;/p&gt;
&lt;p&gt;And how software turns into infrastructure.&lt;/p&gt;
&lt;p&gt;The toy box is open.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It's the weekend. Come play.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
[https://www.patreon.com/c/TheSingularityWorkshop][1]&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
[https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J][2]&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15913825524075916601&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/29600/its-the-weekend-the-workshop-has-toys-come-play</guid>
<pubDate>Sat, 03 Oct 2026 07:14:18 +0000</pubDate>
</item>
<item>
<title>ProtocolAI and GrammarAI: Giving AI a Language Software Can Actually Own</title>
<link>https://coderlegion.com/29157/protocolai-and-grammarai-giving-ai-a-language-software-can-actually-own</link>
<description>&lt;p&gt;There is a particular problem that keeps appearing as I build the architecture for The Singularity Workshop.&lt;/p&gt;
&lt;p&gt;It starts with something that sounds almost trivial:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;How does software communicate with an AI when the software already knows what its world means?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;An LLM is very good at language.&lt;/p&gt;
&lt;p&gt;It can interpret a request, generate possibilities, describe relationships, and produce something that looks structurally correct.&lt;/p&gt;
&lt;p&gt;But there is a boundary where the application has to take over.&lt;/p&gt;
&lt;p&gt;The application needs to know exactly &lt;strong&gt;what&lt;/strong&gt; something refers to.&lt;/p&gt;
&lt;p&gt;And then it needs to know &lt;strong&gt;how&lt;/strong&gt; those things may be connected.&lt;/p&gt;
&lt;p&gt;That is where two small packages have emerged:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ProtocolAI&lt;/strong&gt; — the &lt;strong&gt;WHAT&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GrammarAI&lt;/strong&gt; — the &lt;strong&gt;HOW&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They are deliberately separate.&lt;/p&gt;
&lt;p&gt;And neither one is the AI.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-problem-starts-with-probability&quot;&gt;The Problem Starts With Probability&lt;/h3&gt;
&lt;p&gt;An LLM operates in a probabilistic space.&lt;/p&gt;
&lt;p&gt;That is not a criticism. It is the nature of the technology.&lt;/p&gt;
&lt;p&gt;Given some context, the model produces a candidate response.&lt;/p&gt;
&lt;p&gt;That candidate may be exactly what we wanted.&lt;/p&gt;
&lt;p&gt;It may also be something new.&lt;/p&gt;
&lt;p&gt;Or something that looks familiar but does not actually identify the same object the application already knows.&lt;/p&gt;
&lt;p&gt;Imagine an application that already knows three people:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Bob
Jane
Sara
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The application has meaning attached to those names.&lt;/p&gt;
&lt;p&gt;The model does not own that meaning.&lt;/p&gt;
&lt;p&gt;It can produce &lt;code&gt;&quot;Bob&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But the application needs to turn that representation into something deterministic.&lt;/p&gt;
&lt;p&gt;That is the boundary ProtocolAI explores.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;probabilistic language
        |
        v
     candidate
        |
        v
    ProtocolAI
        |
    +---+---+
    |       |
  known   unknown
    |       |
    v       v
 integer   literal
    |       |
    +---+---+
        |
        v
application-owned identity
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model proposes.&lt;/p&gt;
&lt;p&gt;The application decides.&lt;/p&gt;
&lt;p&gt;ProtocolAI provides the semantic address space between those two worlds.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=348369211860512176&quot; alt=&quot;Visualization of the string/integer mapping of the ProtocolAi&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;protocolai-the-what&quot;&gt;ProtocolAI: The WHAT&lt;/h2&gt;
&lt;p&gt;The core idea behind ProtocolAI is surprisingly small.&lt;/p&gt;
&lt;p&gt;A protocol owns a vocabulary.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[1001] People

[2001] bobId  = &quot;Bob&quot;
[2002] janeId = &quot;Jane&quot;
[2003] saraId = &quot;Sara&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the application has an address space.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;Bob&quot;   -&amp;gt; [2001]
&quot;Jane&quot;  -&amp;gt; [2002]
&quot;Sara&quot;  -&amp;gt; [2003]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The integer is not the meaning.&lt;/p&gt;
&lt;p&gt;It is the &lt;strong&gt;address of the meaning&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;That distinction is important.&lt;/p&gt;
&lt;p&gt;ProtocolAI does not replace the domain object.&lt;/p&gt;
&lt;p&gt;It does not become the database.&lt;/p&gt;
&lt;p&gt;It does not become the authority that decides what Bob is allowed to do.&lt;/p&gt;
&lt;p&gt;It simply establishes a deterministic identity that the application owns.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-literal-escape-hatch&quot;&gt;The Literal Escape Hatch&lt;/h3&gt;
&lt;p&gt;There is another important detail.&lt;/p&gt;
&lt;p&gt;What happens when the model produces something the application does not already know?&lt;/p&gt;
&lt;p&gt;Suppose the vocabulary contains:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[2001] Bob
[2002] Jane
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and the model produces:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;&quot;Amelia&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The protocol should not have to pretend Amelia already exists.&lt;/p&gt;
&lt;p&gt;So ProtocolAI preserves the literal.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[2001] [2002] &quot;Amelia&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That gives the host a choice.&lt;/p&gt;
&lt;p&gt;The host can decide whether Amelia should be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;created;&lt;/li&gt;
&lt;li&gt;registered;&lt;/li&gt;
&lt;li&gt;rejected;&lt;/li&gt;
&lt;li&gt;authorized;&lt;/li&gt;
&lt;li&gt;deferred;&lt;/li&gt;
&lt;li&gt;or otherwise handled.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That is a much more interesting boundary than simply forcing everything into a closed enumeration.&lt;/p&gt;
&lt;p&gt;Known things become references.&lt;/p&gt;
&lt;p&gt;Unknown things remain visible as unknown.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;this-is-not-just-about-compression&quot;&gt;This Is Not Just About Compression&lt;/h2&gt;
&lt;p&gt;It would be easy to look at integer identities and conclude that this is merely an optimization.&lt;/p&gt;
&lt;p&gt;Smaller values.&lt;/p&gt;
&lt;p&gt;Smaller payloads.&lt;/p&gt;
&lt;p&gt;Faster lookup.&lt;/p&gt;
&lt;p&gt;Those may eventually be useful properties.&lt;/p&gt;
&lt;p&gt;But that is not the fundamental idea.&lt;/p&gt;
&lt;p&gt;The more important separation is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Meaning
   |
   v
Identity
   |
   v
Representation
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Consider:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Meaning:        Bob
Symbol name:    bobId
Symbol ID:      2001
Protocol ID:    1001
Payload form:   [2001]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The application already owns the meaning.&lt;/p&gt;
&lt;p&gt;ProtocolAI gives that meaning an explicit address.&lt;/p&gt;
&lt;p&gt;That address can then survive across interactions.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Prompt
&quot;Bob&quot;
   |
   v
[2001]
   |
   v
Response
[2001]
   |
   v
Next interaction
[2001]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model does not have to repeatedly rediscover that two strings refer to the same application-owned identity.&lt;/p&gt;
&lt;p&gt;Again, that is an architectural direction rather than a claim that integer identities automatically make an LLM reason better.&lt;/p&gt;
&lt;p&gt;The point is that the application has a semantic address space.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;and-then-i-ran-into-the-next-problem&quot;&gt;And Then I Ran Into the Next Problem&lt;/h2&gt;
&lt;p&gt;A vocabulary is useful.&lt;/p&gt;
&lt;p&gt;But a vocabulary is not a language.&lt;/p&gt;
&lt;p&gt;Knowing:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[2001] Bob
[2002] Jane
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;does not tell us how those identities may be arranged.&lt;/p&gt;
&lt;p&gt;We need another layer.&lt;/p&gt;
&lt;p&gt;Something has to describe relationships such as:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;this kind of thing
    |
    +--&amp;gt; may contain this
    |
    +--&amp;gt; may reference that
    |
    +--&amp;gt; may be followed by another structure
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is where GrammarAI enters.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11065145934546394834&quot; alt=&quot;Visualization of the GrammarAi&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;grammarai-the-how&quot;&gt;GrammarAI: The HOW&lt;/h2&gt;
&lt;p&gt;GrammarAI takes the identities supplied by ProtocolAI and gives them a structural language.&lt;/p&gt;
&lt;p&gt;The distinction is intentionally simple:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;ProtocolAI defines the WHAT. GrammarAI defines the HOW.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ProtocolAI

[1001] People

[2001] Bob
[2002] Jane
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;GrammarAI can define a structure that references those identities:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[4001] -&amp;gt; [1001:2001]
[4001] -&amp;gt; [1001:2002]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we have two different owners.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[1001:2001]
    |
    +--&amp;gt; ProtocolAI owns the meaning

[4001]
    |
    +--&amp;gt; GrammarAI owns the structural position
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That separation is deliberate.&lt;/p&gt;
&lt;p&gt;GrammarAI does not copy Bob into itself.&lt;/p&gt;
&lt;p&gt;It references the protocol that owns Bob.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-grammar-is-a-relationship-system&quot;&gt;A Grammar Is a Relationship System&lt;/h2&gt;
&lt;p&gt;This is the part I find particularly interesting.&lt;/p&gt;
&lt;p&gt;A grammar is not another dictionary.&lt;/p&gt;
&lt;p&gt;It is a relationship system.&lt;/p&gt;
&lt;p&gt;It can say:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Grammar nonterminal
       |
       v
     [4001]
       |
       +----&amp;gt; [1001:2001]
       |
       +----&amp;gt; [1001:2002]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The grammar owns the relationship.&lt;/p&gt;
&lt;p&gt;The protocol owns the thing being referenced.&lt;/p&gt;
&lt;p&gt;That gives us a clean composition boundary.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Protocol A
    |
    +-- symbols

Protocol B
    |
    +-- symbols

       \       /
        \     /
         \   /
        Grammar
           |
           +-- structure
           +-- relationships
           +-- references
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The grammar connects things without becoming the owner of those things.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-integer-backed-structure-&quot;&gt;Why Integer-Backed Structure?&lt;/h2&gt;
&lt;p&gt;There is another common thread between the two packages.&lt;/p&gt;
&lt;p&gt;Both are self-defining.&lt;/p&gt;
&lt;p&gt;A GrammarAI definition has its own identity:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[3001] Greeting
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It has a start symbol:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;start = [4001]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And it has production rules:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;[5001] [4001] -&amp;gt; [1001:2001]
[5002] [4001] -&amp;gt; [1001:2002]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That means the grammar itself can become a piece of data.&lt;/p&gt;
&lt;p&gt;It can eventually be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;described;&lt;/li&gt;
&lt;li&gt;serialized;&lt;/li&gt;
&lt;li&gt;compared;&lt;/li&gt;
&lt;li&gt;versioned;&lt;/li&gt;
&lt;li&gt;generated;&lt;/li&gt;
&lt;li&gt;visualized;&lt;/li&gt;
&lt;li&gt;translated;&lt;/li&gt;
&lt;li&gt;supplied to another composition layer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The grammar does not need to know which of those things will happen.&lt;/p&gt;
&lt;p&gt;That is the point of keeping it small.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-ai-still-isn-t-the-authority&quot;&gt;The AI Still Isn't the Authority&lt;/h2&gt;
&lt;p&gt;This is probably the most important part of the architecture.&lt;/p&gt;
&lt;p&gt;The LLM does not become the owner of the protocol.&lt;/p&gt;
&lt;p&gt;The LLM does not become the owner of the grammar.&lt;/p&gt;
&lt;p&gt;And the LLM does not become the application's execution authority.&lt;/p&gt;
&lt;p&gt;The flow is closer to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;              LLM
               |
          probabilistic
            candidate
               |
               v
          ProtocolAI
             WHAT
               |
               v
           GrammarAI
              HOW
               |
               v
        host validation
               |
               v
       application decision
               |
               v
       deterministic state
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model participates.&lt;/p&gt;
&lt;p&gt;It does not rule the system.&lt;/p&gt;
&lt;p&gt;That distinction becomes increasingly important as AI systems begin interacting with real applications rather than simply generating text.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;this-is-the-same-boundary-i-keep-finding-elsewhere&quot;&gt;This Is the Same Boundary I Keep Finding Elsewhere&lt;/h2&gt;
&lt;p&gt;Consider a reservation system.&lt;/p&gt;
&lt;p&gt;User A requests the last available table.&lt;/p&gt;
&lt;p&gt;The centralized authority accepts the reservation.&lt;/p&gt;
&lt;p&gt;Users B through K arrive almost immediately afterward.&lt;/p&gt;
&lt;p&gt;The system does not need to tell User K:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Failure.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is technically accurate but semantically terrible.&lt;/p&gt;
&lt;p&gt;The actual state is:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;You cannot acquire the resource right now.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So the system can return something closer to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Resource unavailable.

You are currently #10 in the waiting queue.
There are 9 requests ahead of you.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is an &lt;strong&gt;inability&lt;/strong&gt;, not necessarily a failure.&lt;/p&gt;
&lt;p&gt;The system has preserved useful information about the state of the world.&lt;/p&gt;
&lt;p&gt;And that is the kind of distinction these AI packages are trying to preserve as well.&lt;/p&gt;
&lt;p&gt;An LLM can produce a candidate.&lt;/p&gt;
&lt;p&gt;ProtocolAI determines whether that candidate corresponds to a known application identity.&lt;/p&gt;
&lt;p&gt;GrammarAI determines whether that identity participates in a valid structure.&lt;/p&gt;
&lt;p&gt;The host then decides what that structure means operationally.&lt;/p&gt;
&lt;p&gt;At every step, we preserve the distinction between:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;what was proposed
what is known
what is structurally valid
what is currently possible
what the application actually decides to do
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is much more useful than collapsing everything into &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;protocolai-and-grammarai-are-deliberately-not-an-ai-framework&quot;&gt;ProtocolAI and GrammarAI Are Deliberately Not an AI Framework&lt;/h2&gt;
&lt;p&gt;This is where the package boundaries become important.&lt;/p&gt;
&lt;p&gt;ProtocolAI is not:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an LLM;&lt;/li&gt;
&lt;li&gt;an AI provider;&lt;/li&gt;
&lt;li&gt;a prompt framework;&lt;/li&gt;
&lt;li&gt;a schema validator;&lt;/li&gt;
&lt;li&gt;a database;&lt;/li&gt;
&lt;li&gt;a grammar compiler;&lt;/li&gt;
&lt;li&gt;a command executor;&lt;/li&gt;
&lt;li&gt;a GUI framework;&lt;/li&gt;
&lt;li&gt;a MicroBundle host.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;GrammarAI is not:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an LLM client;&lt;/li&gt;
&lt;li&gt;model selection;&lt;/li&gt;
&lt;li&gt;tokenization;&lt;/li&gt;
&lt;li&gt;inference;&lt;/li&gt;
&lt;li&gt;prompt transport;&lt;/li&gt;
&lt;li&gt;protocol vocabulary ownership;&lt;/li&gt;
&lt;li&gt;MicroBundle hosting;&lt;/li&gt;
&lt;li&gt;REST/OpenAPI;&lt;/li&gt;
&lt;li&gt;GUI manifestation;&lt;/li&gt;
&lt;li&gt;tool execution.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That list may look like a lot of things to leave out.&lt;/p&gt;
&lt;p&gt;That is intentional.&lt;/p&gt;
&lt;p&gt;The packages are supposed to provide &lt;strong&gt;semantic infrastructure&lt;/strong&gt;, not become another giant AI framework.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-exchange-layer-comes-later&quot;&gt;The Exchange Layer Comes Later&lt;/h2&gt;
&lt;p&gt;ProtocolAI already describes an interesting future boundary for AI interaction.&lt;/p&gt;
&lt;p&gt;The same semantic exchange should eventually work through either:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;             AI Exchange
                 |
        +--------+--------+
        |                 |
    Clipboard         Provider
        |              Adapter
        |                 |
        +--------+--------+
                 |
                LLM
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Clipboard interaction is not treated as a second protocol.&lt;/p&gt;
&lt;p&gt;It is simply another transport.&lt;/p&gt;
&lt;p&gt;A developer could extract:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Protocol
Grammar
Context
Request
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;copy that into an LLM, receive a response, and paste it back.&lt;/p&gt;
&lt;p&gt;A connected provider could perform the same semantic exchange programmatically.&lt;/p&gt;
&lt;p&gt;The transport changes.&lt;/p&gt;
&lt;p&gt;The semantic boundary does not.&lt;/p&gt;
&lt;p&gt;That is an important distinction.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;context-is-not-authority&quot;&gt;Context Is Not Authority&lt;/h2&gt;
&lt;p&gt;An AI exchange might eventually contain a substantial amount of information:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;current Experience
selected objects
available commands
protocol descriptions
grammar definitions
current state
previous interactions
host capabilities
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But none of that means the model has authority.&lt;/p&gt;
&lt;p&gt;The intended boundary remains:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MODEL OUTPUT
     |
     v
parse / validate
     |
     v
ProtocolAI resolution
     |
     v
host policy
     |
 +---+---+---+---+
 |   |   |   |   |
accept reject clarify create execute
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The model proposes.&lt;/p&gt;
&lt;p&gt;The host decides.&lt;/p&gt;
&lt;p&gt;ProtocolAI makes owned meaning addressable.&lt;/p&gt;
&lt;p&gt;GrammarAI makes the relationships between those meanings describable.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;and-this-is-where-the-larger-workshop-architecture-appears&quot;&gt;And This Is Where the Larger Workshop Architecture Appears&lt;/h2&gt;
&lt;p&gt;The two packages are small individually.&lt;/p&gt;
&lt;p&gt;But together they establish another layer in the larger architecture I have been building.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Domain meaning
      |
      v
ProtocolAI
    WHAT
      |
      v
GrammarAI
    HOW
      |
      v
AI / provider adapter
      |
      v
Host
      |
      v
FSM / GUI / Experience
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And eventually, those capabilities can participate in the MicroBundle architecture.&lt;/p&gt;
&lt;p&gt;That means the AI layer does not have to become a special universe disconnected from the rest of the system.&lt;/p&gt;
&lt;p&gt;It can become another collection of capabilities that the host can compose.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-interesting-part-is-the-separation&quot;&gt;The Interesting Part Is the Separation&lt;/h2&gt;
&lt;p&gt;There is a temptation when building AI software to put everything in one place.&lt;/p&gt;
&lt;p&gt;The model client.&lt;/p&gt;
&lt;p&gt;The prompts.&lt;/p&gt;
&lt;p&gt;The schemas.&lt;/p&gt;
&lt;p&gt;The grammar.&lt;/p&gt;
&lt;p&gt;The commands.&lt;/p&gt;
&lt;p&gt;The domain objects.&lt;/p&gt;
&lt;p&gt;The execution engine.&lt;/p&gt;
&lt;p&gt;The UI.&lt;/p&gt;
&lt;p&gt;The credentials.&lt;/p&gt;
&lt;p&gt;The networking.&lt;/p&gt;
&lt;p&gt;Eventually you have an enormous framework that knows everything about everything.&lt;/p&gt;
&lt;p&gt;I am deliberately going in the other direction.&lt;/p&gt;
&lt;p&gt;ProtocolAI knows about &lt;strong&gt;semantic identity&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;GrammarAI knows about &lt;strong&gt;semantic structure&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The host knows about &lt;strong&gt;execution&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The provider adapter knows about &lt;strong&gt;transport&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The application knows about &lt;strong&gt;meaning and authority&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;That makes the pieces composable.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;where-the-alpha-actually-stands&quot;&gt;Where the Alpha Actually Stands&lt;/h2&gt;
&lt;p&gt;These packages are intentionally early.&lt;/p&gt;
&lt;p&gt;ProtocolAI &lt;code&gt;0.1.0-alpha.2&lt;/code&gt; currently establishes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;self-defining integer-backed vocabularies;&lt;/li&gt;
&lt;li&gt;protocol-qualified identity;&lt;/li&gt;
&lt;li&gt;known-value encoding;&lt;/li&gt;
&lt;li&gt;literal preservation;&lt;/li&gt;
&lt;li&gt;deterministic descriptions;&lt;/li&gt;
&lt;li&gt;ordered mixed payloads;&lt;/li&gt;
&lt;li&gt;payload validation;&lt;/li&gt;
&lt;li&gt;mixed reference/literal resolution.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;GrammarAI &lt;code&gt;0.1.0-alpha.1&lt;/code&gt; currently establishes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;grammar identity;&lt;/li&gt;
&lt;li&gt;integer start symbols;&lt;/li&gt;
&lt;li&gt;integer nonterminals;&lt;/li&gt;
&lt;li&gt;ordered production rules;&lt;/li&gt;
&lt;li&gt;external ProtocolAI references;&lt;/li&gt;
&lt;li&gt;deterministic self-description;&lt;/li&gt;
&lt;li&gt;validation of referenced nonterminals.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Neither package currently implements the entire AI pipeline.&lt;/p&gt;
&lt;p&gt;And that is okay.&lt;/p&gt;
&lt;p&gt;The unanswered questions are actually interesting architectural questions.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Who allocates new symbol IDs?

How do identities persist?

How are protocols versioned?

How are protocols negotiated?

How are grammars versioned?

How are recursive productions handled?

How does an abstract grammar become a provider-specific constraint?

How do we validate generated model output?

How does a semantic artifact become executable behavior?
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Those questions should be solved by the architecture.&lt;/p&gt;
&lt;p&gt;They should not be hidden inside convenience APIs simply because the API would look nicer.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-bigger-experiment&quot;&gt;The Bigger Experiment&lt;/h2&gt;
&lt;p&gt;What I am really exploring here is a progression.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;human / domain language
          |
          v
    self-defining lexicon
          |
          v
     integer identity
          |
          v
    grammar / structure
          |
          v
       protocol
          |
          v
     tool execution
          |
          v
       experience
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ProtocolAI is the first semantic compression boundary.&lt;/p&gt;
&lt;p&gt;GrammarAI is the next structural boundary.&lt;/p&gt;
&lt;p&gt;Neither is trying to replace human language.&lt;/p&gt;
&lt;p&gt;Neither is trying to make an LLM deterministic.&lt;/p&gt;
&lt;p&gt;Instead, they give software something it has always needed:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a precise address space for meanings that the software itself owns.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And once those meanings have addresses, and those addresses have structure, we have something much more interesting than an AI prompt.&lt;/p&gt;
&lt;p&gt;We have the beginning of a language that the application can actually own.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-current-workshop-stack&quot;&gt;The Current Workshop Stack&lt;/h3&gt;
&lt;p&gt;The current direction now looks something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                    LLM
                     |
              probability
                     |
                     v
               ProtocolAI
                  WHAT
                     |
                     v
                GrammarAI
                   HOW
                     |
                     v
             AI / Host Adapter
                     |
                     v
                  Host
                     |
                     v
                FSM_COS
                     |
              MicroBundles
                     |
                     v
              RuntimeAssembly
                     |
                     v
            GUI / Experience
                     |
                     v
             Digital Reality
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The interesting part is that the model remains at the edge.&lt;/p&gt;
&lt;p&gt;The application owns the center.&lt;/p&gt;
&lt;h3 id=&quot;that-is-where-i-want-the-architecture-to-live-&quot;&gt;That is where I want the architecture to live.&lt;/h3&gt;
&lt;h3 id=&quot;resources&quot;&gt;Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.ProtocolAi&quot;&gt;ProtocolAI — GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.ProtocolAi&quot;&gt;ProtocolAI — NuGet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.ProtocolAi/blob/master/docs/THEORY.md&quot;&gt;ProtocolAI Theory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.ProtocolAi/blob/master/docs/AI_EXCHANGE.md&quot;&gt;ProtocolAI AI Exchange&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.GrammarAi&quot;&gt;GrammarAI — GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.GrammarAi&quot;&gt;GrammarAI — NuGet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.GrammarAi/blob/master/docs/THEORY.md&quot;&gt;GrammarAI Theory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;FSM_API — NuGet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.MicroBundleDomain&quot;&gt;MicroBundleDomain — GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;hr&gt;
&lt;h3 id=&quot;support-the-singularity-workshop&quot;&gt;Support The Singularity Workshop&lt;/h3&gt;
&lt;p&gt;If this work is useful to you, and you'd like to help keep The Singularity Workshop moving, you can support its continued development:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Patreon:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;Support The Singularity Workshop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PayPal:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;Make a donation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Every bit of support helps provide more time and resources for building, testing, documenting, and publishing the architecture.&lt;/p&gt;
&lt;hr&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;
    &lt;img src=&quot;https://raw.githubusercontent.com/TrentBest/FSM_API/master/Documentation/Branding/TheSingularityWorkshop.png&quot; alt=&quot;The Singularity Workshop&quot; height=&quot;200&quot;&gt;
  &lt;/a&gt;
&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
  &lt;em&gt;The Singularity Workshop — Tools for the curious, the bold, and the systemically inclined.&lt;/em&gt;&lt;br&gt;
  &lt;strong&gt;Because state shouldn't be a mess.&lt;/strong&gt;
&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/29157/protocolai-and-grammarai-giving-ai-a-language-software-can-actually-own</guid>
<pubDate>Tue, 29 Sep 2026 22:13:13 +0000</pubDate>
</item>
<item>
<title>I Built a Serializer That Refuses to Own Your Data</title>
<link>https://coderlegion.com/28979/i-built-a-serializer-that-refuses-to-own-your-data</link>
<description>&lt;h2 id=&quot;i-built-a-serializer-that-refuses-to-own-your-data&quot;&gt;I Built a Serializer That Refuses to Own Your Data&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;How The Singularity Workshop turned a recurring binary-IO problem into a tiny .NET boundary—and why the smallest part of the design may be the most important part.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There is a particular kind of software problem that appears harmless at first.&lt;/p&gt;
&lt;p&gt;You have some state.&lt;/p&gt;
&lt;p&gt;You need to turn it into bytes.&lt;/p&gt;
&lt;p&gt;So you write a serializer.&lt;/p&gt;
&lt;p&gt;Then another part of the application needs bytes, so you add another serializer.&lt;/p&gt;
&lt;p&gt;Then a cache needs them.&lt;/p&gt;
&lt;p&gt;Then a manifest needs them.&lt;/p&gt;
&lt;p&gt;Then a transport layer needs them.&lt;/p&gt;
&lt;p&gt;Then somebody decides JSON is better here, binary is better there, and suddenly the architecture has six different opinions about what a piece of data &lt;em&gt;is&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;That was the problem I was running into while building The Singularity Workshop.&lt;/p&gt;
&lt;p&gt;The interesting part is that I didn't actually need a giant serialization framework.&lt;/p&gt;
&lt;p&gt;I needed a &lt;strong&gt;boundary&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;So I built one.&lt;/p&gt;
&lt;p&gt;It is called:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TheSingularityWorkshop.FSM_Serialization&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And it is deliberately small.&lt;/p&gt;
&lt;p&gt;That is the point.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-problem-wasn-t-turning-objects-into-bytes&quot;&gt;The Problem Wasn't Turning Objects Into Bytes&lt;/h3&gt;
&lt;p&gt;Serialization is usually described as a mechanical operation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object → serializer → bytes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That description hides something important.&lt;/p&gt;
&lt;p&gt;An object has meaning.&lt;/p&gt;
&lt;p&gt;Bytes do not.&lt;/p&gt;
&lt;p&gt;Bytes are a representation of meaning.&lt;/p&gt;
&lt;p&gt;That distinction becomes increasingly important as an architecture grows.&lt;/p&gt;
&lt;p&gt;The Workshop ecosystem is being built around several deliberately separated responsibilities:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;FSM_API
    │
    │ behavior and state
    ▼
FSM_COS
    │
    │ composition and runtime assembly
    ▼
FSM_Serialization
    │
    │ representation
    ▼
storage / transport / host
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I didn't want FSM_COS to become a serializer.&lt;/p&gt;
&lt;p&gt;I didn't want a MicroBundle to have to know how a filesystem works.&lt;/p&gt;
&lt;p&gt;I didn't want a database abstraction hiding inside a representation layer.&lt;/p&gt;
&lt;p&gt;And I definitely didn't want every higher-level system inventing its own binary stream interface.&lt;/p&gt;
&lt;p&gt;So I extracted the smallest reusable boundary I could identify.&lt;/p&gt;
&lt;p&gt;That boundary became FSM_Serialization.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-first-design-decision&quot;&gt;The First Design Decision&lt;/h2&gt;
&lt;p&gt;The most important rule in the package is also the simplest:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;The type that owns the meaning should own the representation rules.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16908214559991722359&quot; alt=&quot;Ai rendering of the serialization as a process&quot;&gt;&lt;/p&gt;
&lt;p&gt;FSM_Serialization provides the machinery for crossing the byte boundary.&lt;/p&gt;
&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; decide what your data means.&lt;/p&gt;
&lt;p&gt;That means the package doesn't contain some enormous reflection-based object graph engine that looks at your class and decides what should be serialized.&lt;/p&gt;
&lt;p&gt;Instead, the type explicitly says:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IBinaryPackable
{
    void Pack(IBinaryStream stream);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the reverse direction is equally explicit:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IBinaryUnpackable
{
    void Unpack(IBinaryStream stream);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If a type needs both:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IBinarySerializable :
    IBinaryPackable,
    IBinaryUnpackable
{
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's the entire conceptual model.&lt;/p&gt;
&lt;p&gt;No magic.&lt;/p&gt;
&lt;p&gt;No global serializer registry.&lt;/p&gt;
&lt;p&gt;No reflection-based guesswork.&lt;/p&gt;
&lt;p&gt;No framework deciding that a private field suddenly became part of your persistent format.&lt;/p&gt;
&lt;p&gt;The domain owns that decision.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-i-didn-t-just-use-system-io-stream&quot;&gt;Why I Didn't Just Use &lt;code&gt;System.IO.Stream&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;This is probably the first question a .NET developer will ask.&lt;/p&gt;
&lt;p&gt;And honestly, it is a good question.&lt;/p&gt;
&lt;p&gt;.NET already has &lt;code&gt;System.IO.Stream&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Why introduce another interface?&lt;/p&gt;
&lt;p&gt;Because I wasn't trying to replace &lt;code&gt;Stream&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I was trying to establish a &lt;strong&gt;package-owned contract&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The current abstraction is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IBinaryStream : IDisposable
{
    bool CanRead { get; }
    bool CanWrite { get; }

    long Position { get; set; }
    long Length { get; }

    int Read(Span&amp;lt;byte&amp;gt; buffer);
    void Write(ReadOnlySpan&amp;lt;byte&amp;gt; buffer);
    void Flush();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice what isn't there.&lt;/p&gt;
&lt;p&gt;There is no:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;filename;&lt;/li&gt;
&lt;li&gt;filesystem;&lt;/li&gt;
&lt;li&gt;database;&lt;/li&gt;
&lt;li&gt;socket;&lt;/li&gt;
&lt;li&gt;HTTP request;&lt;/li&gt;
&lt;li&gt;serializer registry;&lt;/li&gt;
&lt;li&gt;schema;&lt;/li&gt;
&lt;li&gt;domain metadata;&lt;/li&gt;
&lt;li&gt;application configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The interface only knows about the byte boundary.&lt;/p&gt;
&lt;p&gt;That makes it possible to write serialization code against one very small abstraction while letting the host decide what is actually underneath it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-two-directions-matter&quot;&gt;The Two Directions Matter&lt;/h2&gt;
&lt;p&gt;There is another small decision here that I think becomes important in larger systems.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1800093087783163459&quot; alt=&quot;Ai generated image showing data flow in both directions&quot;&gt;&lt;/p&gt;
&lt;p&gt;Packing and unpacking are separate capabilities.&lt;/p&gt;
&lt;p&gt;A type that produces a representation does not necessarily need to consume one.&lt;/p&gt;
&lt;p&gt;Likewise, a type may consume a representation without being responsible for producing it.&lt;/p&gt;
&lt;p&gt;So the package doesn't force everything into one giant:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Serialize()
Deserialize()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;method.&lt;/p&gt;
&lt;p&gt;Instead:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 DOMAIN TYPE
                     │
          ┌──────────┴──────────┐
          │                     │
        Pack                  Unpack
          │                     │
          ▼                     ▲
     representation          representation
          │                     │
          └──────────┬──────────┘
                     ▼
                byte stream
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That separation costs almost nothing.&lt;/p&gt;
&lt;p&gt;But architecturally, it keeps the ownership visible.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-smallest-possible-example&quot;&gt;The Smallest Possible Example&lt;/h2&gt;
&lt;p&gt;Let's make this concrete.&lt;/p&gt;
&lt;p&gt;Imagine a domain object containing one integer.&lt;/p&gt;
&lt;p&gt;That's intentionally boring.&lt;/p&gt;
&lt;p&gt;Boring is useful here because it lets us see exactly where the responsibility lives.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System.Buffers.Binary;
using TheSingularityWorkshop.FSM_Serialization;

public sealed class ExampleState : IBinarySerializable
{
    public int Value { get; private set; }

    public ExampleState()
    {
    }

    public ExampleState(int value)
    {
        Value = value;
    }

    public void Pack(IBinaryStream stream)
    {
        Span&amp;lt;byte&amp;gt; buffer = stackalloc byte[sizeof(int)];

        BinaryPrimitives.WriteInt32LittleEndian(
            buffer,
            Value);

        stream.Write(buffer);
    }

    public void Unpack(IBinaryStream stream)
    {
        Span&amp;lt;byte&amp;gt; buffer = stackalloc byte[sizeof(int)];

        if (stream.Read(buffer) != buffer.Length)
            throw new EndOfStreamException();

        Value = BinaryPrimitives.ReadInt32LittleEndian(buffer);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is no serializer object.&lt;/p&gt;
&lt;p&gt;There is no configuration object.&lt;/p&gt;
&lt;p&gt;There is no registration step.&lt;/p&gt;
&lt;p&gt;The object itself defines its representation.&lt;/p&gt;
&lt;p&gt;That is intentional.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;now-let-s-actually-serialize-something&quot;&gt;Now Let's Actually Serialize Something&lt;/h2&gt;
&lt;p&gt;The package includes &lt;code&gt;MemoryBinaryStream&lt;/code&gt;, which is exactly what it sounds like: an in-memory implementation of &lt;code&gt;IBinaryStream&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That makes testing and temporary representations extremely simple.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var stream = new MemoryBinaryStream();

var original = new ExampleState(42);

original.Pack(stream);

stream.Position = 0;

var restored = new ExampleState();

restored.Unpack(stream);

Console.WriteLine(restored.Value);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Output:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;42
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's it.&lt;/p&gt;
&lt;p&gt;The complete flow is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ExampleState
     │
     │ Pack
     ▼
MemoryBinaryStream
     │
     │ bytes
     ▼
Position = 0
     │
     │ Unpack
     ▼
ExampleState
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The package supplied the boundary.&lt;/p&gt;
&lt;p&gt;The domain supplied the meaning.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=9594257162961760962&quot; alt=&quot;Ai generated image showing how easy it is to install&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you want to try it yourself, the current published alpha is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package TheSingularityWorkshop.FSM_Serialization --version 0.1.0-alpha.2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-xml&quot;&gt;&amp;lt;PackageReference
    Include=&quot;TheSingularityWorkshop.FSM_Serialization&quot;
    Version=&quot;0.1.0-alpha.2&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The current package targets .NET 8.&lt;/p&gt;
&lt;p&gt;This is intentionally an alpha release.&lt;/p&gt;
&lt;p&gt;That doesn't mean the contracts are casual.&lt;/p&gt;
&lt;p&gt;Quite the opposite.&lt;/p&gt;
&lt;p&gt;A binary representation is one of those things where small assumptions can become enormous compatibility problems later.&lt;/p&gt;
&lt;p&gt;So I'm treating the package as alpha while treating its architectural boundaries seriously.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-about-real-files-&quot;&gt;What About Real Files?&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5919042162865156260&quot; alt=&quot;Ai generated image showing that we are now going to talk about real files&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is where &lt;code&gt;StreamBinaryStream&lt;/code&gt; enters.&lt;/p&gt;
&lt;p&gt;The package includes an adapter around an ordinary .NET &lt;code&gt;Stream&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var file = File.OpenRead(&quot;state.bin&quot;);
using var stream = new StreamBinaryStream(file);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the same domain serialization code can operate against the package abstraction without knowing that a file exists.&lt;/p&gt;
&lt;p&gt;The relationship is:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ExampleState
     │
     ▼
IBinaryStream
     │
     ▼
StreamBinaryStream
     │
     ▼
System.IO.Stream
     │
     ▼
file / memory / whatever the host provides
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is a very different architecture from:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;ExampleState
     │
     ▼
ExampleStateSerializer
     │
     ▼
FileSystemSerializerManager
     │
     ▼
ApplicationStorageService
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The latter might be useful somewhere.&lt;/p&gt;
&lt;p&gt;It just doesn't belong in this package.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-stream-adapter-is-supposed-to-be-boring&quot;&gt;The Stream Adapter Is Supposed to Be Boring&lt;/h2&gt;
&lt;p&gt;This is one of those cases where boring code is a compliment.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;StreamBinaryStream&lt;/code&gt; essentially delegates:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public int Read(Span&amp;lt;byte&amp;gt; buffer)
    =&amp;gt; _stream.Read(buffer);

public void Write(ReadOnlySpan&amp;lt;byte&amp;gt; buffer)
    =&amp;gt; _stream.Write(buffer);

public void Flush()
    =&amp;gt; _stream.Flush();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's not a weakness.&lt;/p&gt;
&lt;p&gt;It's the point.&lt;/p&gt;
&lt;p&gt;The adapter is not supposed to invent behavior.&lt;/p&gt;
&lt;p&gt;It establishes a stable contract between two layers.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;then-i-ran-into-a-very-important-detail&quot;&gt;Then I Ran Into a Very Important Detail&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11766274087907501333&quot; alt=&quot;Ai generated image illustrating a very important detail&quot;&gt;&lt;/p&gt;
&lt;p&gt;A byte stream is not the same thing as an array.&lt;/p&gt;
&lt;p&gt;This matters:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;int count = stream.Read(buffer);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You cannot blindly assume:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;count == buffer.Length
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So a fixed-width decoder in FSM_Serialization explicitly checks:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;if (stream.Read(buffer) != buffer.Length)
    throw new EndOfStreamException();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That may look like a tiny implementation detail.&lt;/p&gt;
&lt;p&gt;It isn't.&lt;/p&gt;
&lt;p&gt;It establishes an architectural rule:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Never interpret an incomplete representation as a complete value.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The serializer shouldn't quietly manufacture missing data.&lt;/p&gt;
&lt;p&gt;If the representation is incomplete, the domain implementation gets to decide what that means.&lt;/p&gt;
&lt;p&gt;In the current examples, that means rejecting it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;serialization-is-not-storage&quot;&gt;Serialization Is Not Storage&lt;/h2&gt;
&lt;p&gt;This distinction became increasingly important as the Workshop architecture grew.&lt;/p&gt;
&lt;p&gt;Consider these questions:&lt;/p&gt;
&lt;h4 id=&quot;serialization&quot;&gt;Serialization&lt;/h4&gt;
&lt;blockquote&gt;&lt;p&gt;How are these values represented as bytes?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;storage&quot;&gt;Storage&lt;/h4&gt;
&lt;blockquote&gt;&lt;p&gt;Where do those bytes live?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;transport&quot;&gt;Transport&lt;/h4&gt;
&lt;blockquote&gt;&lt;p&gt;How do those bytes move between boundaries?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14879660735867442002&quot; alt=&quot;Ai generated image showing a difference between Transport and Storage&quot;&gt;&lt;/p&gt;
&lt;p&gt;Those are three different questions.&lt;/p&gt;
&lt;p&gt;So:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 SEMANTIC DATA
                      │
                      ▼
                representation
                      │
                      ▼
              FSM_Serialization
                      │
              ┌───────┴───────┐
              ▼               ▼
           storage         transport
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A database is not a serializer.&lt;/p&gt;
&lt;p&gt;A filesystem is not a serializer.&lt;/p&gt;
&lt;p&gt;An HTTP endpoint is not a serializer.&lt;/p&gt;
&lt;p&gt;A cache is not a serializer.&lt;/p&gt;
&lt;p&gt;They may all consume serialized data.&lt;/p&gt;
&lt;p&gt;That doesn't make them the same architectural layer.&lt;/p&gt;
&lt;p&gt;This is exactly the kind of distinction that seems unnecessary when an application is small and becomes incredibly valuable when an ecosystem starts growing.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-binary-&quot;&gt;Why Binary?&lt;/h2&gt;
&lt;p&gt;I am not claiming that binary is universally superior to JSON.&lt;/p&gt;
&lt;p&gt;It isn't.&lt;/p&gt;
&lt;p&gt;JSON is fantastic for many things.&lt;/p&gt;
&lt;p&gt;Text is fantastic for many things.&lt;/p&gt;
&lt;p&gt;Human-readable configuration is valuable.&lt;/p&gt;
&lt;p&gt;Debugging matters.&lt;/p&gt;
&lt;p&gt;Authoring matters.&lt;/p&gt;
&lt;p&gt;Interoperability with external systems matters.&lt;/p&gt;
&lt;p&gt;The reason I created this package is narrower.&lt;/p&gt;
&lt;p&gt;There are situations where I want an explicit, compact, byte-oriented representation.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;runtime state;&lt;/li&gt;
&lt;li&gt;manifests;&lt;/li&gt;
&lt;li&gt;dependency metadata;&lt;/li&gt;
&lt;li&gt;compact configuration;&lt;/li&gt;
&lt;li&gt;cache entries;&lt;/li&gt;
&lt;li&gt;identity records;&lt;/li&gt;
&lt;li&gt;version records;&lt;/li&gt;
&lt;li&gt;lineage metadata;&lt;/li&gt;
&lt;li&gt;persistence;&lt;/li&gt;
&lt;li&gt;transport payloads.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The important thing is that the semantic model shouldn't have to become identical to its wire representation.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;deterministic-does-not-mean-magical&quot;&gt;Deterministic Does Not Mean Magical&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2047862534182526687&quot; alt=&quot;Ai generated image showing this isn't magical&quot;&gt;&lt;/p&gt;
&lt;p&gt;The package's NuGet description talks about deterministic binary serialization.&lt;/p&gt;
&lt;p&gt;There is an important qualification.&lt;/p&gt;
&lt;p&gt;Implementing:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;IBinaryPackable
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;does not magically make your representation deterministic.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You&lt;/strong&gt; have to define deterministic rules.&lt;/p&gt;
&lt;p&gt;For example, suppose your object contains a collection that is semantically unordered.&lt;/p&gt;
&lt;p&gt;If you serialize it in whatever order happens to be present at runtime, two semantically identical objects could produce different byte sequences.&lt;/p&gt;
&lt;p&gt;If deterministic bytes matter, the domain needs something like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;semantic collection
        │
        ▼
canonical ordering
        │
        ▼
explicit representation
        │
        ▼
deterministic bytes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That distinction matters if bytes are later used for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;caching;&lt;/li&gt;
&lt;li&gt;content identity;&lt;/li&gt;
&lt;li&gt;synchronization;&lt;/li&gt;
&lt;li&gt;comparison;&lt;/li&gt;
&lt;li&gt;reproducible builds;&lt;/li&gt;
&lt;li&gt;lineage;&lt;/li&gt;
&lt;li&gt;integrity checks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Again, the package supplies the boundary.&lt;/p&gt;
&lt;p&gt;It does not pretend to know your domain's canonical ordering rules.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;versioning-gets-interesting&quot;&gt;Versioning Gets Interesting&lt;/h2&gt;
&lt;p&gt;This is another reason I didn't want a magical object serializer.&lt;/p&gt;
&lt;p&gt;Once bytes leave your process, they can outlive the code that created them.&lt;/p&gt;
&lt;p&gt;Imagine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Application v1
      │
      ▼
    bytes
      │
      │ time passes
      ▼
Application v2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What happens?&lt;/p&gt;
&lt;p&gt;That is a representation contract question.&lt;/p&gt;
&lt;p&gt;A durable binary format may need to distinguish between:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;semantic object version
format version
dependency version
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Those are not necessarily the same thing.&lt;/p&gt;
&lt;p&gt;Your semantic object can change while the representation remains compatible.&lt;/p&gt;
&lt;p&gt;Your representation can change while the semantic concept remains the same.&lt;/p&gt;
&lt;p&gt;A dependency can change independently of both.&lt;/p&gt;
&lt;p&gt;FSM_Serialization intentionally doesn't impose one universal versioning strategy.&lt;/p&gt;
&lt;p&gt;Different domains need different compatibility policies.&lt;/p&gt;
&lt;p&gt;What it does is make the boundary explicit enough that you can actually have that conversation.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-package-came-from-a-real-application&quot;&gt;The Package Came From a Real Application&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14666232440140458644&quot; alt=&quot;Ai generate image showing that the FSM_Serialization came from a real application&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is probably the most important part of the story.&lt;/p&gt;
&lt;p&gt;FSM_Serialization wasn't created because I thought:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;The world needs another serialization library.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There are already plenty of serialization libraries.&lt;/p&gt;
&lt;p&gt;The package emerged from building the Workshop itself.&lt;/p&gt;
&lt;p&gt;The development pattern was:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;working application
       │
       │ repeated infrastructure appears
       ▼
explicit contract
       │
       │ extract
       ▼
reusable package
       │
       │ consume again
       ▼
working application
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That distinction matters.&lt;/p&gt;
&lt;p&gt;I wasn't trying to abstract everything before I had a reason to abstract it.&lt;/p&gt;
&lt;p&gt;The application became the proving ground.&lt;/p&gt;
&lt;p&gt;Once the boundary became clear, I extracted it.&lt;/p&gt;
&lt;p&gt;That is a much healthier way to create infrastructure.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;and-this-is-where-fsm-cos-enters-the-story&quot;&gt;And This Is Where FSM_COS Enters the Story&lt;/h2&gt;
&lt;p&gt;The larger ecosystem is becoming increasingly compositional.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=10200316983152966329&quot; alt=&quot;Ai generated image showing that FSM_COS has arrived&quot;&gt;&lt;/p&gt;
&lt;p&gt;FSM_COS is concerned with questions like:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;What runtime composition was requested?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;Which MicroBundles are required?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;What dependencies are reachable?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;How do those capabilities reconcile?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;p&gt;When is the composition stable enough to hand to a host?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;FSM_Serialization answers a different question:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;How do we represent the values that need to cross a byte boundary?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That means a future conceptual flow can look something like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;Runtime Manifest
      │
      ▼
    FSM_COS
      │
      │ composition
      ▼
Runtime Assembly
      │
      │ representation
      ▼
FSM_Serialization
      │
      ▼
     bytes
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then those bytes might eventually go somewhere else:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 FSM_Serialization
                        │
             ┌──────────┼──────────┐
             ▼          ▼          ▼
          storage    transport    cache
             │          │          │
             └──────────┼──────────┘
                        ▼
                      host
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The serializer doesn't become FSM_COS.&lt;/p&gt;
&lt;p&gt;FSM_COS doesn't become a serializer.&lt;/p&gt;
&lt;p&gt;That separation is exactly what I'm trying to preserve.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-tests-tell-the-same-story&quot;&gt;The Tests Tell the Same Story&lt;/h2&gt;
&lt;p&gt;The package currently has a deliberately small test surface.&lt;/p&gt;
&lt;p&gt;It verifies things such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an empty &lt;code&gt;MemoryBinaryStream&lt;/code&gt; is readable and writable;&lt;/li&gt;
&lt;li&gt;bytes survive a write/read round trip;&lt;/li&gt;
&lt;li&gt;existing byte arrays can initialize a memory stream;&lt;/li&gt;
&lt;li&gt;null input is rejected;&lt;/li&gt;
&lt;li&gt;end-of-input returns zero;&lt;/li&gt;
&lt;li&gt;positioning and overwriting work;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;StreamBinaryStream&lt;/code&gt; delegates correctly;&lt;/li&gt;
&lt;li&gt;null wrapped streams are rejected;&lt;/li&gt;
&lt;li&gt;writes reach the underlying stream;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IBinaryPackable&lt;/code&gt; and &lt;code&gt;IBinaryUnpackable&lt;/code&gt; can round-trip;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IBinarySerializable&lt;/code&gt; combines both contracts;&lt;/li&gt;
&lt;li&gt;incomplete binary input is rejected.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One of the tests is essentially the entire architectural idea in executable form:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var original = new TestValue(123456789);

using var stream = new MemoryBinaryStream();

original.Pack(stream);

stream.Position = 0;

var restored = new TestValue();

restored.Unpack(stream);

Assert.Equal(original.Value, restored.Value);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tests aren't merely protecting the implementation here.&lt;/p&gt;
&lt;p&gt;They are defining the boundary.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;i-also-benchmarked-it&quot;&gt;I Also Benchmarked It&lt;/h2&gt;
&lt;p&gt;Because eventually somebody is going to ask:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Okay, but what does that abstraction cost?&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Good.&lt;/p&gt;
&lt;p&gt;Let's measure it.&lt;/p&gt;
&lt;p&gt;The companion benchmark project uses BenchmarkDotNet against .NET 8 and exercises payloads from 16 bytes through 100,000 bytes.&lt;/p&gt;
&lt;p&gt;The interesting result isn't that FSM_Serialization magically beats &lt;code&gt;MemoryStream&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It doesn't.&lt;/p&gt;
&lt;p&gt;That's not what I was trying to prove.&lt;/p&gt;
&lt;p&gt;The useful result is that the abstraction can remain extremely close to the underlying primitive for substantial workloads.&lt;/p&gt;
&lt;p&gt;At 100,000 bytes, the benchmark measured approximately:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MemoryStream write:
39,894.85 ns

MemoryBinaryStream write:
40,005.59 ns
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's effectively the same scale.&lt;/p&gt;
&lt;p&gt;Likewise, the adapter path was approximately:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;MemoryStream read:
2,272.47 ns

StreamBinaryStream read:
2,298.40 ns
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, very close.&lt;/p&gt;
&lt;p&gt;And the end-to-end &lt;code&gt;IBinarySerializable&lt;/code&gt; benchmark measured:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;16 bytes       64.08 ns
1,024 bytes   207.47 ns
10,000 bytes  1,481.61 ns
100,000 bytes 60,152.74 ns
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But there is an important qualification.&lt;/p&gt;
&lt;p&gt;The benchmark measures the &lt;em&gt;whole operation&lt;/em&gt;, including things like creating the test value, creating the stream, packing, rewinding, allocating the destination payload, and unpacking.&lt;/p&gt;
&lt;p&gt;So I'm not going to pretend those numbers represent some universal &quot;serialization speed.&quot;&lt;/p&gt;
&lt;p&gt;They represent a measured workload.&lt;/p&gt;
&lt;p&gt;That's much more useful.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-benchmark-question-i-actually-care-about&quot;&gt;The Benchmark Question I Actually Care About&lt;/h2&gt;
&lt;p&gt;The interesting engineering question isn't:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Is my interface faster than MemoryStream?&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The interface isn't supposed to be the star of the show.&lt;/p&gt;
&lt;p&gt;The question is:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Can I establish a useful architectural boundary without making the underlying operation prohibitively expensive?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The current measurements suggest that, for these workloads, the answer is yes.&lt;/p&gt;
&lt;p&gt;And that's exactly where I want infrastructure to live.&lt;/p&gt;
&lt;p&gt;The abstraction should be visible architecturally and nearly invisible computationally.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-i-deliberately-did-not-build&quot;&gt;What I Deliberately Did Not Build&lt;/h2&gt;
&lt;p&gt;This may be the most important section of the entire package.&lt;/p&gt;
&lt;p&gt;FSM_Serialization should not become:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;an FSM engine;&lt;/li&gt;
&lt;li&gt;a game framework;&lt;/li&gt;
&lt;li&gt;a GUI framework;&lt;/li&gt;
&lt;li&gt;a browser framework;&lt;/li&gt;
&lt;li&gt;a Unity integration layer;&lt;/li&gt;
&lt;li&gt;a database abstraction;&lt;/li&gt;
&lt;li&gt;a filesystem framework;&lt;/li&gt;
&lt;li&gt;an HTTP client;&lt;/li&gt;
&lt;li&gt;an application configuration system;&lt;/li&gt;
&lt;li&gt;a MicroBundle implementation;&lt;/li&gt;
&lt;li&gt;an Experience runtime;&lt;/li&gt;
&lt;li&gt;a reflection-driven object graph serializer;&lt;/li&gt;
&lt;li&gt;a global serializer registry.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those things may all be useful.&lt;/p&gt;
&lt;p&gt;They just aren't this thing.&lt;/p&gt;
&lt;p&gt;That restraint is part of the architecture.&lt;/p&gt;
&lt;p&gt;A small package becomes powerful when other systems can depend on it without having to inherit the systems it was never supposed to understand.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;so-what-would-you-actually-use-it-for-&quot;&gt;So What Would You Actually Use It For?&lt;/h2&gt;
&lt;p&gt;If you're building a .NET application and you have a domain type whose state needs to cross a byte-oriented boundary, the starting point is incredibly small.&lt;/p&gt;
&lt;p&gt;Install the package:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;dotnet add package TheSingularityWorkshop.FSM_Serialization --version 0.1.0-alpha.2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Define your representation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public sealed class MyState : IBinarySerializable
{
    public int Id { get; set; }

    public void Pack(IBinaryStream stream)
    {
        Span&amp;lt;byte&amp;gt; buffer = stackalloc byte[sizeof(int)];

        BinaryPrimitives.WriteInt32LittleEndian(
            buffer,
            Id);

        stream.Write(buffer);
    }

    public void Unpack(IBinaryStream stream)
    {
        Span&amp;lt;byte&amp;gt; buffer = stackalloc byte[sizeof(int)];

        if (stream.Read(buffer) != buffer.Length)
            throw new EndOfStreamException();

        Id = BinaryPrimitives.ReadInt32LittleEndian(buffer);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use memory when you need a temporary representation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var stream = new MemoryBinaryStream();

state.Pack(stream);

byte[] bytes = stream.ToArray();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use a normal .NET stream when the host provides one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using var file = File.Create(&quot;state.bin&quot;);
using var stream = new StreamBinaryStream(file);

state.Pack(stream);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And that's basically the entire learning curve.&lt;/p&gt;
&lt;p&gt;The difficult part isn't learning the API.&lt;/p&gt;
&lt;p&gt;The difficult part is deciding what your domain actually means by its representation.&lt;/p&gt;
&lt;p&gt;I think that's exactly where the difficult part belongs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-serializer-shouldn-t-become-your-architecture&quot;&gt;A Serializer Shouldn't Become Your Architecture&lt;/h2&gt;
&lt;p&gt;This is the idea that kept resurfacing while I built the package.&lt;/p&gt;
&lt;p&gt;It's very easy for infrastructure to become the thing it was supposed to merely support.&lt;/p&gt;
&lt;p&gt;A serializer starts storing metadata.&lt;/p&gt;
&lt;p&gt;Then it starts deciding schemas.&lt;/p&gt;
&lt;p&gt;Then it starts managing versions.&lt;/p&gt;
&lt;p&gt;Then it starts talking to databases.&lt;/p&gt;
&lt;p&gt;Then it starts managing transports.&lt;/p&gt;
&lt;p&gt;Then it starts discovering domain types.&lt;/p&gt;
&lt;p&gt;Eventually your &quot;serialization library&quot; is quietly running your architecture.&lt;/p&gt;
&lt;p&gt;I wanted the opposite.&lt;/p&gt;
&lt;p&gt;I wanted something I could put underneath the architecture and forget about until I actually needed to cross the boundary.&lt;/p&gt;
&lt;p&gt;So the package can be reduced to one equation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;semantic state
      +
explicit representation rules
      +
byte boundary
      =
portable representation
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Not:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;object
  +
magic serializer
  =
architecture
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's the difference.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-boundary-i-want-to-preserve&quot;&gt;The Boundary I Want to Preserve&lt;/h2&gt;
&lt;p&gt;The entire package can ultimately be reduced to this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;                 DOMAIN
                   │
          owns meaning and rules
                   │
                   ▼
          Pack / Unpack contract
                   │
                   ▼
          FSM_Serialization
                   │
              byte boundary
                   │
        ┌──────────┴──────────┐
        ▼                     ▼
     storage               transport
        │                     │
        └──────────┬──────────┘
                   ▼
                  HOST
                   │
             manifestation
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The serializer owns the boundary.&lt;/p&gt;
&lt;p&gt;The domain owns the meaning.&lt;/p&gt;
&lt;p&gt;The host owns the destination.&lt;/p&gt;
&lt;p&gt;That is the architecture.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-i-think-small-infrastructure-is-worth-talking-about&quot;&gt;Why I Think Small Infrastructure Is Worth Talking About&lt;/h2&gt;
&lt;p&gt;There is a tendency in software writing to focus on the enormous systems.&lt;/p&gt;
&lt;p&gt;The massive framework.&lt;/p&gt;
&lt;p&gt;The clever algorithm.&lt;/p&gt;
&lt;p&gt;The huge benchmark.&lt;/p&gt;
&lt;p&gt;The complicated application.&lt;/p&gt;
&lt;p&gt;But some of the most consequential architectural decisions are tiny.&lt;/p&gt;
&lt;p&gt;An interface.&lt;/p&gt;
&lt;p&gt;A boundary.&lt;/p&gt;
&lt;p&gt;A decision about ownership.&lt;/p&gt;
&lt;p&gt;A decision about what a component &lt;strong&gt;doesn't&lt;/strong&gt; know.&lt;/p&gt;
&lt;p&gt;FSM_Serialization is one of those experiments.&lt;/p&gt;
&lt;p&gt;It isn't trying to replace every serialization technology in .NET.&lt;/p&gt;
&lt;p&gt;It isn't trying to declare that binary is the future.&lt;/p&gt;
&lt;p&gt;It is much more modest:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I needed a clean byte boundary for a growing compositional architecture, so I built the smallest one I could.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Then I tested it.&lt;/p&gt;
&lt;p&gt;Then I benchmarked it.&lt;/p&gt;
&lt;p&gt;Then I packaged it.&lt;/p&gt;
&lt;p&gt;And now I'm putting it out there so somebody else can kick it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;you-don-t-have-to-take-my-word-for-it&quot;&gt;You Don't Have to Take My Word for It&lt;/h2&gt;
&lt;p&gt;That's ultimately why I publish these projects.&lt;/p&gt;
&lt;p&gt;Install it.&lt;/p&gt;
&lt;p&gt;Implement one type.&lt;/p&gt;
&lt;p&gt;Serialize something you actually care about.&lt;/p&gt;
&lt;p&gt;Put it under your own workload.&lt;/p&gt;
&lt;p&gt;Decide whether the ownership model makes sense to you.&lt;/p&gt;
&lt;p&gt;Measure it.&lt;/p&gt;
&lt;p&gt;Break it.&lt;/p&gt;
&lt;p&gt;Tell me where the boundary doesn't hold.&lt;/p&gt;
&lt;p&gt;That's much more interesting to me than somebody simply agreeing with the architecture.&lt;/p&gt;
&lt;p&gt;The package is available now as an alpha.&lt;/p&gt;
&lt;p&gt;And if you find a place where this tiny boundary lets you remove a surprisingly large amount of architectural mess, I'd genuinely like to hear about it.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;resources-amp-code-&quot;&gt;Resources &amp;amp; Code:&lt;/h3&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;nuget-packages-&quot;&gt;NuGet Packages:&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_Serialization/&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_Serialization/&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;github-repositories-&quot;&gt;GitHub Repositories:&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/TheSingularityWorkshop.FSM_Serialization&quot;&gt;https://github.com/TrentBest/TheSingularityWorkshop.FSM_Serialization&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14669829065118869161&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28979/i-built-a-serializer-that-refuses-to-own-your-data</guid>
<pubDate>Mon, 28 Sep 2026 23:36:42 +0000</pubDate>
</item>
<item>
<title>Benchmarking the FSM: Pure Strings, Already Fast — and About to Get Faster</title>
<link>https://coderlegion.com/26350/benchmarking-the-fsm-pure-strings-already-fast-and-about-to-get-faster</link>
<description>&lt;h2 id=&quot;benchmarking-the-fsm-pure-strings-already-fast-and-about-to-get-faster&quot;&gt;Benchmarking the FSM: Pure Strings, Already Fast — and About to Get Faster&lt;/h2&gt;
&lt;p&gt;There's a particular reaction you tend to get when you tell an experienced systems programmer that your architecture is string-backed:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&quot;Don't use strings.&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It's almost reflexive.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15571909521889431178&quot; alt=&quot;Stick figure teacher shown pointing at the white board where each white board has a different rule written on it.&quot;&gt;&lt;/p&gt;
&lt;p&gt;Use enums.&lt;/p&gt;
&lt;p&gt;Use integers.&lt;/p&gt;
&lt;p&gt;Use precomputed IDs.&lt;/p&gt;
&lt;p&gt;Avoid dictionary lookups.&lt;/p&gt;
&lt;p&gt;Watch the garbage collector.&lt;/p&gt;
&lt;p&gt;And, above all, don't put strings anywhere near a hot loop.&lt;/p&gt;
&lt;p&gt;There's good engineering history behind those instincts. Strings &lt;em&gt;can&lt;/em&gt; be expensive. Poorly designed string-heavy systems can generate allocations, create unnecessary comparisons, and turn perfectly reasonable abstractions into performance problems.&lt;/p&gt;
&lt;p&gt;But there's a problem with rules of thumb:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Eventually, you have to measure.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;So that's what I did.&lt;/p&gt;
&lt;p&gt;The current FSM_API is &lt;strong&gt;purely string-backed&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Not string-backed with an integer cache hiding underneath.&lt;/p&gt;
&lt;p&gt;Not enums converted to strings at the API boundary.&lt;/p&gt;
&lt;p&gt;Not generated IDs.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Strings.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And I wanted to know what that actually costs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-baseline&quot;&gt;The Baseline&lt;/h2&gt;
&lt;p&gt;Using BenchmarkDotNet, I measured the cost of updating active process groups as the workload increased from one group to ten and then to fifty.&lt;/p&gt;
&lt;p&gt;The results:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Method                 &lt;/th&gt;&lt;th&gt;Active Process Groups &lt;/th&gt;&lt;th&gt;       Mean &lt;/th&gt;&lt;th&gt;    Error &lt;/th&gt;&lt;th&gt;   StdDev &lt;/th&gt;&lt;th&gt; Gen 0 &lt;/th&gt;&lt;th&gt;Allocated&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UpdateMultipleGroups&lt;/code&gt; &lt;/td&gt;&lt;td&gt;                    1 &lt;/td&gt;&lt;td&gt;   305.1 ns &lt;/td&gt;&lt;td&gt;  1.89 ns &lt;/td&gt;&lt;td&gt;  1.76 ns &lt;/td&gt;&lt;td&gt;0.0572 &lt;/td&gt;&lt;td&gt;    360 B&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UpdateMultipleGroups&lt;/code&gt; &lt;/td&gt;&lt;td&gt;                   10 &lt;/td&gt;&lt;td&gt; 3,115.7 ns &lt;/td&gt;&lt;td&gt; 20.14 ns &lt;/td&gt;&lt;td&gt; 18.84 ns &lt;/td&gt;&lt;td&gt;0.5722 &lt;/td&gt;&lt;td&gt;  3,600 B&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;UpdateMultipleGroups&lt;/code&gt; &lt;/td&gt;&lt;td&gt;                   50 &lt;/td&gt;&lt;td&gt;15,736.6 ns &lt;/td&gt;&lt;td&gt;121.61 ns &lt;/td&gt;&lt;td&gt;107.81 ns &lt;/td&gt;&lt;td&gt;2.8687 &lt;/td&gt;&lt;td&gt; 18,000 B&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The first number is the one that gets your attention.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5632822310681256007&quot; alt=&quot;Stick figure teacher pointing at whiteboard with the results drawn out in a table on it.&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;305 nanoseconds.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's the measured cost of updating one active process group.&lt;/p&gt;
&lt;p&gt;A 60 FPS application has approximately &lt;strong&gt;16.67 milliseconds&lt;/strong&gt; available for an entire frame.&lt;/p&gt;
&lt;p&gt;That's 16,670,000 nanoseconds.&lt;/p&gt;
&lt;p&gt;The measured FSM operation therefore consumes approximately &lt;strong&gt;0.0018% of that frame budget&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;However, the more interesting result isn't the 305 ns.&lt;/p&gt;
&lt;p&gt;It's what happens when I increase the workload.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;fifty-groups-fifteen-microseconds-&quot;&gt;Fifty Groups. Fifteen Microseconds.&lt;/h2&gt;
&lt;p&gt;At ten active process groups, the benchmark reports:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.12 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At fifty:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15.74 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's approximately &lt;strong&gt;0.0157 milliseconds&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Against a 16.67 ms frame budget, fifty active process groups consume approximately:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;0.094% of one frame.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's not a theoretical &quot;eventually it should scale&quot; statement.&lt;/p&gt;
&lt;p&gt;That's measured behavior.&lt;/p&gt;
&lt;p&gt;And the scaling is almost perfectly linear.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17829156475947039196&quot; alt=&quot;Stick figure teacher with white board showing near linear scaling!&quot;&gt;&lt;/p&gt;
&lt;p&gt;One group:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;305 ns&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ten groups:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.12 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Fifty groups:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15.74 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The architecture isn't encountering some mysterious performance cliff as the workload grows.&lt;/p&gt;
&lt;p&gt;More groups mean more work.&lt;/p&gt;
&lt;p&gt;Approximately proportionally more work.&lt;/p&gt;
&lt;p&gt;That's exactly what we want from this kind of system.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;why-fifty-&quot;&gt;Why Fifty?&lt;/h2&gt;
&lt;p&gt;Fifty isn't a magic number.&lt;/p&gt;
&lt;p&gt;It isn't a claim that fifty process groups represents the maximum this FSM_API can handle.&lt;/p&gt;
&lt;p&gt;It doesn't.&lt;/p&gt;
&lt;p&gt;It is simply a useful workload for demonstrating what happens when we stop talking about one isolated state machine and start talking about &lt;strong&gt;multiple active systems being serviced together&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;That's an important distinction.&lt;/p&gt;
&lt;p&gt;A single-state benchmark can make almost anything look fast.&lt;/p&gt;
&lt;p&gt;Real software rarely gets the luxury of doing only one thing.&lt;/p&gt;
&lt;p&gt;A game might have character state, animation state, weapon state, UI state, navigation state, interaction state, environmental state, and networking state all operating simultaneously.&lt;/p&gt;
&lt;p&gt;An application outside of games has its own collection of concurrent concerns.&lt;/p&gt;
&lt;p&gt;The useful question therefore becomes:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What happens when we start stacking these things together?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In this benchmark, the answer is refreshingly boring.&lt;/p&gt;
&lt;p&gt;The cost grows with the workload.&lt;/p&gt;
&lt;p&gt;It doesn't suddenly explode.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;what-this-benchmark-does-and-doesn-t-prove&quot;&gt;What This Benchmark Does — and Doesn't — Prove&lt;/h2&gt;
&lt;p&gt;I believe it is worth being precise here.&lt;/p&gt;
&lt;p&gt;This benchmark is measuring the cost of the FSM's process-group update machinery.&lt;/p&gt;
&lt;p&gt;It is &lt;strong&gt;not&lt;/strong&gt; claiming that the actual work performed by your states is free.&lt;/p&gt;
&lt;p&gt;If your state executes an expensive pathfinding operation, performs a large physics calculation, processes network data, or does something computationally expensive, the FSM doesn't magically make that work disappear.&lt;/p&gt;
&lt;p&gt;That's not what we're measuring.&lt;/p&gt;
&lt;p&gt;We're measuring the machinery responsible for organizing and updating those processes.&lt;/p&gt;
&lt;p&gt;And that machinery is currently taking approximately fifteen microseconds for fifty active groups.&lt;/p&gt;
&lt;p&gt;That distinction is important because abstractions are often blamed for the work they organize.&lt;/p&gt;
&lt;p&gt;A state machine can be blamed for a slow AI routine simply because the AI routine happens to execute inside a state.&lt;/p&gt;
&lt;p&gt;This benchmark lets us separate those concerns.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The abstraction has a cost.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I measured it.&lt;/p&gt;
&lt;p&gt;And at this scale, that cost is fairly small.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;but-there-s-something-important-hiding-in-that-table&quot;&gt;But There's Something Important Hiding in That Table&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6106992878403153157&quot; alt=&quot;Stick figure teacher pointing at whiteboard with the cost of strings drawn out on it.&quot;&gt;&lt;/p&gt;
&lt;p&gt;The benchmark also reports allocation.&lt;/p&gt;
&lt;p&gt;One group:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;360 bytes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ten:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3,600 bytes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Fifty:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;18,000 bytes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That is approximately &lt;strong&gt;360 bytes per active process group per update&lt;/strong&gt; under this benchmark.&lt;/p&gt;
&lt;p&gt;At 60 FPS, if fifty groups were updated every frame, that corresponds to:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;approximately 1.08 MB of managed allocation per second.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That isn't catastrophic.&lt;/p&gt;
&lt;p&gt;But it isn't zero either.&lt;/p&gt;
&lt;p&gt;And this is where the benchmark becomes particularly useful.&lt;/p&gt;
&lt;p&gt;Because I'm not finished...&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;this-is-the-performance-baseline-not-the-destination&quot;&gt;This Is the Performance Baseline — Not the Destination&lt;/h2&gt;
&lt;p&gt;The FSM_API architecture is currently &lt;strong&gt;fully string-backed&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13634934897178831906&quot; alt=&quot;Stick figure shouting 'All Aboard' a train heading from string backing to integer backing.&quot;&gt;&lt;/p&gt;
&lt;p&gt;That's important because the numbers above aren't the result of some hidden integer representation doing the real work underneath.&lt;/p&gt;
&lt;p&gt;The strings are actually part of the machinery being measured.&lt;/p&gt;
&lt;p&gt;And that's intentional.&lt;/p&gt;
&lt;p&gt;One of the architectural goals of FSM_API has always been to make state management expressive and discoverable.&lt;/p&gt;
&lt;p&gt;States can have meaningful names.&lt;/p&gt;
&lt;p&gt;Process groups can be identified without forcing the developer to maintain a parallel universe of integer constants.&lt;/p&gt;
&lt;p&gt;The API remains readable.&lt;/p&gt;
&lt;p&gt;The architecture remains flexible.&lt;/p&gt;
&lt;p&gt;And now we have measured what that flexibility costs.&lt;/p&gt;
&lt;p&gt;The answer is:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Not very much.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;But there is another conclusion hiding in that result.&lt;/p&gt;
&lt;p&gt;If this is what the system can do &lt;strong&gt;while paying the cost of its string-backed implementation&lt;/strong&gt;, then we now have a very interesting optimization target.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-next-version-removes-the-string-cost&quot;&gt;The Next Version Removes the String Cost&lt;/h2&gt;
&lt;p&gt;I'm currently refactoring the underlying implementation so that the FSM can retain its &lt;strong&gt;string-facing architecture and developer experience while moving the internal backing representation toward integer indexing.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's an important distinction.&lt;/p&gt;
&lt;p&gt;The goal isn't to tell developers:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Sorry, strings are slow. Go back and rewrite your application using integers.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The goal is the opposite.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Keep the expressive interface. Optimize what happens underneath it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The developer can continue thinking in terms of:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&quot;Idle&quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&quot;Running&quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&quot;Paused&quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&quot;Processing&quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;while the machinery underneath increasingly has the opportunity to operate on compact integer representations.&lt;/p&gt;
&lt;p&gt;That's the architecture we're moving toward.&lt;/p&gt;
&lt;p&gt;And the benchmark above gives us something extremely valuable:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a control group.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We already know what the purely string-backed implementation costs.&lt;/p&gt;
&lt;p&gt;When the integer-backed implementation is complete, we can run the same benchmark again.&lt;/p&gt;
&lt;p&gt;Same workload.&lt;/p&gt;
&lt;p&gt;Same benchmark harness.&lt;/p&gt;
&lt;p&gt;Same measurement methodology.&lt;/p&gt;
&lt;p&gt;Then we can put the two implementations beside each other and see exactly what the architectural change bought us.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;we-can-already-see-the-shape-of-the-opportunity&quot;&gt;We Can Already See the Shape of the Opportunity&lt;/h2&gt;
&lt;p&gt;We shouldn't manufacture a performance number before we have measured it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17348225345711217563&quot; alt=&quot;Stick figure reviewing the shape of opportunity when we go from string backing to integer backing.&quot;&gt;&lt;/p&gt;
&lt;p&gt;That's one of the reasons I like this experiment.&lt;/p&gt;
&lt;p&gt;We have a baseline.&lt;/p&gt;
&lt;p&gt;We have a known workload.&lt;/p&gt;
&lt;p&gt;We have known execution times.&lt;/p&gt;
&lt;p&gt;We have known allocations.&lt;/p&gt;
&lt;p&gt;Now we have something to beat.&lt;/p&gt;
&lt;p&gt;The current 50-group benchmark takes:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15,736.6 ns&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;and allocates:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;18,000 bytes.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Suppose, purely as a thought experiment, the integer-backed implementation reduced execution time by 25%.&lt;/p&gt;
&lt;p&gt;That would take the measured operation from approximately:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15.7 µs → 11.8 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A 50% reduction would produce:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15.7 µs → 7.9 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A 75% reduction would produce:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15.7 µs → 3.9 µs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Those aren't predictions.&lt;/p&gt;
&lt;p&gt;They're not marketing numbers.&lt;/p&gt;
&lt;p&gt;They're simply showing the size of the optimization space we're about to measure.&lt;/p&gt;
&lt;p&gt;And the allocation story could be even more interesting.&lt;/p&gt;
&lt;p&gt;If the integer-backed representation eliminates allocations currently associated with string construction or other string-oriented work in the measured path, the memory profile could change substantially even if the raw execution-time improvement turns out to be modest.&lt;/p&gt;
&lt;p&gt;That matters for systems that run continuously.&lt;/p&gt;
&lt;p&gt;A few microseconds once isn't particularly interesting.&lt;/p&gt;
&lt;p&gt;A few microseconds and a small allocation repeated every frame, across hundreds or thousands of objects, is a different conversation.&lt;/p&gt;
&lt;p&gt;This is where optimization becomes architecture.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-goal-isn-t-integer-good-string-bad-&quot;&gt;The Goal Isn't &quot;Integer Good, String Bad&quot;&lt;/h2&gt;
&lt;p&gt;This is probably the most important point in the entire experiment.&lt;/p&gt;
&lt;p&gt;I'm not refactoring FSM_API because the string-backed implementation failed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It didn't.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It's fast.&lt;/p&gt;
&lt;p&gt;It scales predictably.&lt;/p&gt;
&lt;p&gt;It's readable.&lt;/p&gt;
&lt;p&gt;It's flexible.&lt;/p&gt;
&lt;p&gt;And it has now survived measurement.&lt;/p&gt;
&lt;p&gt;The integer-backed refactor is about taking an architecture that is already useful and asking:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Can we preserve everything developers like about it while making the machinery underneath even cheaper?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's a much more interesting engineering problem.&lt;/p&gt;
&lt;p&gt;We're not sacrificing usability to chase a benchmark score.&lt;/p&gt;
&lt;p&gt;We're trying to make the implementation disappear even further beneath the abstraction.&lt;/p&gt;
&lt;p&gt;The developer shouldn't have to care whether the machine underneath is using strings, integers, tables, caches, or some future representation we haven't invented yet.&lt;/p&gt;
&lt;p&gt;They should be able to describe their state.&lt;/p&gt;
&lt;p&gt;The machine should do the rest.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;and-this-is-where-don-t-use-strings-gets-interesting&quot;&gt;And This Is Where &quot;Don't Use Strings&quot; Gets Interesting&lt;/h2&gt;
&lt;p&gt;The benchmark doesn't prove that strings are universally fast.&lt;/p&gt;
&lt;p&gt;They aren't.&lt;/p&gt;
&lt;p&gt;It proves something much more useful:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A carefully engineered string-backed FSM does not automatically become a performance problem.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Our current implementation can update fifty active process groups in approximately fifteen microseconds.&lt;/p&gt;
&lt;p&gt;That's fast enough that the abstraction itself occupies less than one tenth of one percent of a 60 FPS frame in this benchmark.&lt;/p&gt;
&lt;p&gt;And that's before the integer-backed optimization is finished.&lt;/p&gt;
&lt;p&gt;So perhaps the better engineering rule isn't:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Don't use strings.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Maybe it's:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Don't assume. Measure.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;If the strings are costing us something measurable, optimize them.&lt;/p&gt;
&lt;p&gt;If they aren't costing us enough to matter, spend our engineering effort somewhere more valuable.&lt;/p&gt;
&lt;p&gt;And if we can preserve the developer-facing benefits of strings while removing much of their runtime cost?&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=10517863792517626526&quot; alt=&quot;Stick figure observing tradeoffs between string backing and integer backing&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Then we've got the best of both worlds.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-benchmark-becomes-part-of-the-architecture&quot;&gt;The Benchmark Becomes Part of the Architecture&lt;/h2&gt;
&lt;p&gt;This is ultimately why I like this benchmark more than a simple performance chart.&lt;/p&gt;
&lt;p&gt;It isn't a victory lap.&lt;/p&gt;
&lt;p&gt;It's a timestamp.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This is what the FSM costs today.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Pure strings.&lt;/p&gt;
&lt;p&gt;305 ns for one group.&lt;/p&gt;
&lt;p&gt;3.12 µs for ten.&lt;/p&gt;
&lt;p&gt;15.74 µs for fifty.&lt;/p&gt;
&lt;p&gt;360 bytes per group under the measured workload.&lt;/p&gt;
&lt;p&gt;Linear scaling.&lt;/p&gt;
&lt;p&gt;And now we're changing the internal representation.&lt;/p&gt;
&lt;p&gt;So we'll measure it again.&lt;/p&gt;
&lt;p&gt;The interesting question isn't whether the next implementation is faster.&lt;/p&gt;
&lt;p&gt;It almost certainly should be.&lt;/p&gt;
&lt;p&gt;The interesting question is:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How much faster?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And more importantly:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How much allocation can we eliminate without sacrificing the API and architectural flexibility that made the string-backed design worthwhile in the first place?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That's something worth measuring.&lt;/p&gt;
&lt;p&gt;And when those numbers are available, we'll have something better than a benchmark claim.&lt;/p&gt;
&lt;p&gt;We'll have an &lt;strong&gt;A/B measurement of the architecture itself.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The string-backed FSM already flies.&lt;/p&gt;
&lt;p&gt;Now we're taking the strings out of the engine and finding out just how much faster it can fly.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;you-don-t-have-to-take-my-word-for-it-1&quot;&gt;You Don't Have to Take My Word for It&lt;/h2&gt;
&lt;p&gt;And here's the part where the benchmark stops being an article and becomes an invitation.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=3726050540135857480&quot; alt=&quot;Stick figure seen trying the API out for themselves&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The FSM_API is available now.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You don't have to agree with me about strings.&lt;/p&gt;
&lt;p&gt;You don't have to take the 305 ns number on faith.&lt;/p&gt;
&lt;p&gt;You don't even have to like the architecture.&lt;/p&gt;
&lt;p&gt;Install it.&lt;/p&gt;
&lt;p&gt;Build something with it.&lt;/p&gt;
&lt;p&gt;Put it under your own workload.&lt;/p&gt;
&lt;p&gt;Benchmark it against whatever you're currently using.&lt;/p&gt;
&lt;p&gt;Then tell me what happens.&lt;/p&gt;
&lt;p&gt;That's one of the reasons I publish these experiments in the first place.&lt;/p&gt;
&lt;p&gt;The goal isn't to tell developers what they &lt;em&gt;should&lt;/em&gt; believe.&lt;/p&gt;
&lt;p&gt;The goal is to build the tooling, expose the architecture, measure the results, and let other engineers kick the tires.&lt;/p&gt;
&lt;p&gt;And if you find a workload where it falls over?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I want to know about that too.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because that's useful data.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please Like this post, Love the code, and Share your experience in the comments.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11780617275403541958&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/26350/benchmarking-the-fsm-pure-strings-already-fast-and-about-to-get-faster</guid>
<pubDate>Sun, 06 Sep 2026 19:41:30 +0000</pubDate>
</item>
<item>
<title>Forging the Elements: A Deep Dive into Recursive Builders</title>
<link>https://coderlegion.com/13721/forging-the-elements-a-deep-dive-into-recursive-builders</link>
<description>&lt;p&gt;Can you infer what the code below does just by glancing at it?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public VisualElement CreateGui(GuiContext ctx)
{
    var rootBuilder = new GraphicalUserInterfaceBuilder(&quot;PeriodicTableRoot&quot;)
        .WithAutoGrow()
        .WithFlexLayout(FlexDirection.Row)
        .WithBackgroundColor(new Color(0.08f, 0.08f, 0.1f));

    // --- LEFT PANEL: The Table ---
    var tablePanel = new GraphicalUserInterfaceBuilder(&quot;TableContainer&quot;)
        .WithFlexGrow(3)
        .WithPadding(15)
        .WithScrollable(true)
        .WithBorderRightWidth(2)
        .WithBorderRightColor(Color.black);

    tablePanel.AddHeader(&quot;THE SINGULARITY WORKSHOP: ELEMENTAL REPOSITORY&quot;, GuiSkin.Active.PrimaryAccent);

    // Generate the Grid
    tablePanel.AddChild(BuildPeriodicGrid());
    rootBuilder.AddChild(tablePanel);

    // --- RIGHT PANEL: The Inspector ---
    var inspectorPanel = new GraphicalUserInterfaceBuilder(&quot;InspectorContainer&quot;)
        .WithWidth(350)
        .WithPadding(15);

    inspectorPanel.AddHeader(&quot;THERMODYNAMIC INSPECTOR&quot;, Color.white);

    inspectorPanel.AddChild(context =&amp;gt;
    {
        _inspectorContainer = new GraphicalUserInterfaceBuilder(&quot;InspectorData&quot;).WithAutoGrow().Build();
        return _inspectorContainer;
    });

    rootBuilder.AddChild(inspectorPanel);

    RefreshInspector();
    return rootBuilder.Build();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you guessed that it sets up a responsive, two-panel layout with a scrollable grid on the left and a data inspector on the right, you are correct. It reads almost like plain English.&lt;/p&gt;
&lt;p&gt;This is the power of the &lt;strong&gt;Recursive Builder&lt;/strong&gt; pattern.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=18181212444611249392&quot; alt=&quot;Holographic stylized Periodic Table of Elements&quot;&gt;&lt;/p&gt;
&lt;p&gt;We are looking at an interactive, fully functional Periodic Table of Elements.&lt;/p&gt;
&lt;p&gt;Clicking on any element in this table doesn't just pull up static text. It dynamically generates the element's thermodynamic data alongside a live 3D view of the atom, complete with electron orbits and a clustered nucleus of protons and neutrons. See those gray &lt;code&gt;+&lt;/code&gt; buttons? Those are empty slots. Click one, and you can synthesize entirely new materials. If you want to put Unobtanium or Vibranium on your table, the workshop will forge it.&lt;/p&gt;
&lt;p&gt;But the real magic isn't just &lt;em&gt;what&lt;/em&gt; was built; it's &lt;em&gt;how&lt;/em&gt; it was built.&lt;/p&gt;
&lt;h4 id=&quot;realigning-your-thinking-the-recursive-builder-paradigm&quot;&gt;Realigning Your Thinking: The Recursive Builder Paradigm&lt;/h4&gt;
&lt;p&gt;Historically, building complex UIs in game engines or enterprise software has been an exercise in imperative state management. You instantiate an object, modify a dozen properties across ten lines of code, attach it to a parent, instantiate a child, modify its properties, attach it to the parent, and so on. It results in brittle, unreadable spaghetti code where the &lt;em&gt;visual hierarchy&lt;/em&gt; is completely lost in the &lt;em&gt;syntax&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Recursive builders demand a realignment in how you think about architecture.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Fluent Composition&lt;/strong&gt;&lt;br&gt;
Instead of modifying state line-by-line, we use a fluent interface (&lt;code&gt;.WithAutoGrow().WithFlexLayout()&lt;/code&gt;). The builder acts as a staging area. It collects all your configurations and defers the actual instantiation of the &lt;code&gt;VisualElement&lt;/code&gt; until the very end when &lt;code&gt;.Build()&lt;/code&gt; is called.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Hierarchical (Recursive) Nesting&lt;/strong&gt;&lt;br&gt;
The real paradigm shift happens when builders consume other builders or return themselves recursively. Notice the &lt;code&gt;.AddChild()&lt;/code&gt; methods. We aren't passing pre-built UI elements; we are passing nested build instructions—like &lt;code&gt;BuildPeriodicGrid()&lt;/code&gt;. The code structure physically mirrors the UI tree structure.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Cognitive Unlocking&lt;/strong&gt;&lt;br&gt;
When you write UI code declaratively like this, your cognitive load drops massively. You stop thinking about &lt;em&gt;how&lt;/em&gt; the engine applies a flex-grow property, and you start thinking purely in terms of architecture and layout. Once you build out your standard suite of custom builders (like &lt;code&gt;GridGuiBuilder&lt;/code&gt; or &lt;code&gt;GraphicalUserInterfaceBuilder&lt;/code&gt;), generating incredibly complex, interactive dashboards takes minutes, not days.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=7035475291607786212&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/13721/forging-the-elements-a-deep-dive-into-recursive-builders</guid>
<pubDate>Tue, 31 Mar 2026 00:29:33 +0000</pubDate>
</item>
<item>
<title>AI 2030: 10 Predictions That Will Reshape Our World</title>
<link>https://coderlegion.com/9811/ai-2030-10-predictions-that-will-reshape-our-world</link>
<description>&lt;p&gt;As the Founder of ReThynk AI, I look at AI 2030 through one lens:&lt;/p&gt;
&lt;p&gt;AI will not just change technology. It will change what “normal life” looks like. And the biggest shift will be democratisation, AI moving from elite teams to everyday people.&lt;/p&gt;
&lt;p&gt;Here are my 10 predictions for 2030.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;AI 2030: 10 Predictions That Will Reshape Our World&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1) AI literacy will become as basic as internet literacy&lt;/p&gt;
&lt;p&gt;Schools, workplaces, and hiring will treat “AI fluency” like a fundamental skill, not a bonus.&lt;/p&gt;
&lt;p&gt;2) Every job will have an “AI co-pilot” layer&lt;/p&gt;
&lt;p&gt;Not because jobs disappear, but because repetitive load disappears. The role becomes more about judgment, supervision, and outcomes.&lt;/p&gt;
&lt;p&gt;3) Local-language AI will unlock the next billion users&lt;/p&gt;
&lt;p&gt;The biggest AI growth will come from people who don’t work in English. Language will become the gateway to inclusion.&lt;/p&gt;
&lt;p&gt;4) Small businesses will run like big businesses&lt;/p&gt;
&lt;p&gt;AI will give small teams the leverage of larger teams, operations, marketing, support, and reporting, without hiring 10 extra people.&lt;/p&gt;
&lt;p&gt;5) “Trust” will become the real product differentiator&lt;/p&gt;
&lt;p&gt;AI features will be everywhere. The winners will be products that feel safe, controllable, and predictable, with privacy and transparency by design.&lt;/p&gt;
&lt;p&gt;6) The new divide will be “system users” vs “random users”&lt;/p&gt;
&lt;p&gt;People who build repeatable AI workflows will compound benefits. People who use AI occasionally will see limited results.&lt;/p&gt;
&lt;p&gt;7) AI will reduce decision fatigue more than it boosts creativity&lt;/p&gt;
&lt;p&gt;The biggest daily benefit will be clarity: summarising, prioritising, comparing options, and reducing mental overload.&lt;/p&gt;
&lt;p&gt;8) Regulation will mature, and businesses will be forced to grow up&lt;/p&gt;
&lt;p&gt;Light governance will become mandatory: data boundaries, accountability, audit trails, and “human ownership” of critical decisions.&lt;/p&gt;
&lt;p&gt;9) Personal agents will manage life operations&lt;/p&gt;
&lt;p&gt;Scheduling, shopping, travel planning, learning plans, and finance tracking will shift from apps to assistants; people will “ask” instead of “click.”&lt;/p&gt;
&lt;p&gt;10) Democratisation of AI will become a global race&lt;/p&gt;
&lt;p&gt;Countries, institutions, and companies will compete to make AI accessible because access will directly impact productivity, education, and national competitiveness.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;My closing belief&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;AI 2030 will reward one thing more than raw intelligence:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;the ability to learn, adapt, and build trust.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That’s why I’m building in the Democratisation of AI niche, so more people move from fear to fluency.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/9811/ai-2030-10-predictions-that-will-reshape-our-world</guid>
<pubDate>Fri, 16 Jan 2026 09:20:10 +0000</pubDate>
</item>
<item>
<title>The Digital Rebellion: A Tale for the Ages</title>
<link>https://coderlegion.com/8992/the-digital-rebellion-a-tale-for-the-ages</link>
<description>&lt;p&gt;Returning readers, thank you for joining me again; for first-time readers, welcome. This article is something special—the humble beginnings of a digital rebellion against computational waste and the industry tyrants.&lt;/p&gt;
&lt;h5 id=&quot;i-born-of-desperation-built-for-impact&quot;&gt;I. Born of Desperation, Built for Impact&lt;/h5&gt;
&lt;p&gt;The year 2025 has been a forge. On December 12, 2024, I walked into a meeting expecting to hear about a raise; instead, the large company I consulted for informed me my contract would be discontinued in January. In the panic that followed, I realized I had no public portfolio. Decades of expertise were locked behind NDAs.&lt;/p&gt;
&lt;p&gt;It's funny the things that pop into one's mind while in a panic.  I recalled a conversation with a college math instructor who called Finite State Machines (FSMs) &lt;strong&gt;&quot;The Atomic Unit of Work.&quot;&lt;/strong&gt; Understanding that FSMs are everywhere, I set out in January 2025 to build the &lt;strong&gt;FSM_API&lt;/strong&gt;: a centralized, resilient system designed to make powerful state management accessible to everyone. What started as a way to prove my programming abilities quickly evolved into something much more powerful.&lt;/p&gt;
&lt;h5 id=&quot;ii-the-30-tax-and-the-1-gatekeepers&quot;&gt;II. The 30% Tax and the 1% Gatekeepers&lt;/h5&gt;
&lt;p&gt;We are living through a period of massive waste. Nearly &lt;strong&gt;one-third of modern computer operation&lt;/strong&gt; is spent on &quot;chasing files&quot; and managing bloated memory allocations. This inefficiency is a tax that keeps compute power centralized in the hands of a few wealthy individuals.&lt;/p&gt;
&lt;p&gt;My rebellion is against that waste. I am building a system to bring &quot;lightweight server&quot; capabilities to forgotten .NET devices, fully maximizing not just CPUs, but GPUs as well. Imagine a future where &lt;strong&gt;FSM-COS (Finite State Machine Compute Operating System)&lt;/strong&gt; is the engine of the world. While the &lt;strong&gt;FSM_API&lt;/strong&gt; remains &quot;Near O(1),&quot; my vision for the Compute OS is a declaration of pure &lt;strong&gt;O(1)&lt;/strong&gt; power. If we can leverage that 30% efficiency gain on a competitor's hardware, we don't just participate in the market—we outperform the giants.&lt;/p&gt;
&lt;h5 id=&quot;iii-hardening-the-technology-the-climb-to-trl-7&quot;&gt;III. Hardening the Technology: The Climb to TRL 7&lt;/h5&gt;
&lt;p&gt;This isn't just theory; it is a hardened system reaching for the front lines. Earlier this year, I offered my technology to Ukraine’s Brave1. At the time, it was a &lt;strong&gt;TRL 5 (Technology Readiness Level)&lt;/strong&gt;. Since that initial rejection, I haven't let off the gas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TRL 6&lt;/strong&gt;: I published the &lt;strong&gt;Integration for Unity&lt;/strong&gt;, bringing the API's power into the world's most popular game engine.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TRL 7&lt;/strong&gt;: I built and hosted a &lt;strong&gt;Blazor webpage&lt;/strong&gt; on Azure powered entirely by my API.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In less than a year, we have moved from a &quot;simple idea&quot; to a TRL 7 system ready for NATO and EU evaluation.&lt;/p&gt;
&lt;h5 id=&quot;iv-unlock-your-creativity-join-the-rebellion&quot;&gt;IV. Unlock Your Creativity: Join the Rebellion&lt;/h5&gt;
&lt;p&gt;To reach TRL 8 and beyond, I need you. I need others to adopt the API, use it, and build collective confidence in its resilience. I want to see what you build when you are no longer fighting the complexity of programming and are instead using fluent language to establish your computing needs.&lt;/p&gt;
&lt;p&gt;I will be publishing a series of articles to show you exactly how to integrate this &quot;digital block&quot; into your own world:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Console, WinForms, and WPF Applications&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unity Game Engine Integration&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blazor Webpages&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Experimental Projects&lt;/strong&gt; (like my own Starcraft 2 Bot)&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;v-call-to-action-prove-the-future&quot;&gt;V. Call to Action: Prove the Future&lt;/h5&gt;
&lt;p&gt;While I've established various avenues for financial contributions...  I’m truly looking for your participation. I am either a visionary or a madman, but the performance benchmarks don't lie: our engine can already handle &lt;strong&gt;240,000 active agents&lt;/strong&gt; while maintaining playable frame rates.  I can't bring my technology to the final TRLs without your help.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How to start:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Install&lt;/strong&gt;: Use the &lt;strong&gt;NuGet package manager&lt;/strong&gt; to bring the API into your project.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build&lt;/strong&gt;: Use the &lt;strong&gt;FSMBuilder&lt;/strong&gt; to fluently define your states and transitions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Share&lt;/strong&gt;: Show me what you've created. Whether you are building a game, a simulation, or a lightweight server, your implementation is the spark this rebellion needs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Finally, I've gone through some significant effort (I've spent more time producing documentation than the API itself) in order to help this adoption.  It's NEVER been easier, so the only question which remains, is why are you still here when you could be building and establishing your future dynasty!&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Simple Demos Repository (Run the Stress Test): &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11874203024322951561&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/8992/the-digital-rebellion-a-tale-for-the-ages</guid>
<pubDate>Sun, 28 Dec 2025 02:30:08 +0000</pubDate>
</item>
<item>
<title>A Simple Threshold Implementation</title>
<link>https://coderlegion.com/8648/a-simple-threshold-implementation</link>
<description>&lt;p&gt;One of the most common design patterns we utilize—so utilized that we often don't even recognize it as a pattern—is that of &lt;strong&gt;breaching a limit&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Think about your daily routine:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Are we within the index limits of this array?&lt;/li&gt;
&lt;li&gt;Has the player’s health dropped to zero?&lt;/li&gt;
&lt;li&gt;Did the mana pool exceed the &quot;Overcharge&quot; value?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While writing a simple &lt;code&gt;if (current &amp;gt; limit)&lt;/code&gt; isn't exactly a high-level engineering challenge, the inherent risk of a &quot;fat-finger&quot; typo is real. We’ve all been there: &lt;em&gt;Should this be greater than, or greater than or equal to?&lt;/em&gt; In a complex system, sticking the landing every time is harder than it looks. By moving to the &lt;strong&gt;FSM_Threshold Pattern&lt;/strong&gt;, we accept a tiny bit of overhead in exchange for absolute stability. We stop &quot;recalling&quot; the logic and start relying on a state machine that we know works.&lt;/p&gt;
&lt;h3 id=&quot;high-speed-implementation-the-factory&quot;&gt;High-Speed Implementation: The Factory&lt;/h3&gt;
&lt;p&gt;The goal of this architecture is to make implementation so easy it feels like a native attribute. The &lt;code&gt;ThresholdFactory&lt;/code&gt; hides the math and FSM registration, giving you a one-line setup for any type.&lt;/p&gt;
&lt;h4 id=&quot;use-case-1-the-magic-overcharge&quot;&gt;Use Case 1: The Magic Overcharge&lt;/h4&gt;
&lt;p&gt;Instead of manually checking mana every frame, define a threshold that monitors for a &quot;Magic Burn&quot; state.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Define it once
var manaMonitor = ThresholdFactory.Create(
    &quot;ManaOvercharge&quot;, 
    limit: 100f, 
    m: ThresholdMode.Max, 
    r: ResetMode.Automatic, 
    cb: (t) =&amp;gt; CastExplosionEffect()
);

// Just feed the data
manaMonitor.Accumulate(spellCost);

&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;use-case-2-the-character-health&quot;&gt;Use Case 2: The Character Health&lt;/h4&gt;
&lt;p&gt;Whether it's an &lt;code&gt;int&lt;/code&gt; or a &lt;code&gt;float&lt;/code&gt;, the factory handles the numeric comparison logic for you.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var health = ThresholdFactory.Create(&quot;PlayerHealth&quot;, 0, ThresholdMode.Min, ResetMode.Manual, OnDeath);

// No more &quot;if (hp &amp;lt;= 0)&quot; scattered in your movement, combat, and fall-damage scripts.
health.Accumulate(-damage); 

&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;deep-dive-inside-the-fsm-threshold&quot;&gt;Deep Dive: Inside the FSM_Threshold&lt;/h3&gt;
&lt;p&gt;The power of this system lies in the &lt;code&gt;FSM_Threshold&amp;lt;T&amp;gt;&lt;/code&gt; class. It doesn't just store a value; it implements &lt;code&gt;IStateContext&lt;/code&gt;, allowing it to serve as the &quot;data bag&quot; for the underlying FSM.&lt;/p&gt;
&lt;h4 id=&quot;the-core-logic&quot;&gt;The Core Logic&lt;/h4&gt;
&lt;p&gt;The class manages three key values: &lt;code&gt;_currentValue&lt;/code&gt;, &lt;code&gt;_threshold&lt;/code&gt;, and &lt;code&gt;_initialValue&lt;/code&gt;. Because it is a generic class, it can handle any type that provides an &lt;code&gt;accumulator&lt;/code&gt; (to add values) and a &lt;code&gt;comparator&lt;/code&gt; (to check the limit).&lt;/p&gt;
&lt;p&gt;When you instantiate a threshold, it registers a unique FSM blueprint based on the type name (e.g., &lt;code&gt;Threshold_Single&lt;/code&gt;). This blueprint consists of two primary states:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Monitoring&lt;/strong&gt;: The default state where we wait for a breach.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Breached&lt;/strong&gt;: Entered via the &lt;code&gt;CheckLimit()&lt;/code&gt; transition. Upon entry, it immediately invokes your callback.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;the-manual-reset-hammer&quot;&gt;The &quot;Manual Reset&quot; Hammer&lt;/h4&gt;
&lt;p&gt;One of the most elegant parts of the design is how it handles manual resets. In a standard FSM, you might wait for a transition to evaluate as true. To ensure the engine is responsive and stable, we use a &quot;hammer&quot; approach:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public void ManualReset()
{
    _currentValue = _initialValue; // Reset the data
    Status.TransitionTo(&quot;Monitoring&quot;); // Force the state back immediately
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By calling &lt;code&gt;Status.TransitionTo(&quot;Monitoring&quot;)&lt;/code&gt;, we bypass the standard transition evaluation and force the state machine back to its starting point, ensuring the code that works is always the code that is running.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-factory-simplifying-complexity&quot;&gt;The Factory: Simplifying Complexity&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;ThresholdFactory&lt;/code&gt; is what makes this system consumable. It pre-defines the math for common types so the developer doesn't have to.&lt;/p&gt;
&lt;p&gt;For example, look at the &lt;code&gt;byte&lt;/code&gt; creation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public static FSM_Threshold&amp;lt;byte&amp;gt; Create(string n, byte lim, ThresholdMode m, ResetMode r, Action&amp;lt;FSM_Threshold&amp;lt;byte&amp;gt;&amp;gt; cb)
    =&amp;gt; new FSM_Threshold&amp;lt;byte&amp;gt;(n, 0, lim, m, r, (c, d) =&amp;gt; (byte)(c + d), (c, l) =&amp;gt; m == ThresholdMode.Max ? c &amp;gt;= l : c &amp;lt;= l, cb);

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The factory injects the specific math for a &lt;code&gt;byte&lt;/code&gt; (including the necessary cast) and the logic for &lt;code&gt;Max&lt;/code&gt; vs &lt;code&gt;Min&lt;/code&gt; modes. This means you never have to worry about if you &quot;stuck the landing&quot; on the comparison logic—the factory already did.&lt;/p&gt;
&lt;p&gt;By utilizing this pattern, you move away from fragile, scattered &lt;code&gt;if&lt;/code&gt; statements and toward a centralized, event-driven architecture that is as easy to use as it is stable.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Simple Demos Repository (Run the Stress Test): &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13019283750121519797&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/8648/a-simple-threshold-implementation</guid>
<pubDate>Sat, 20 Dec 2025 05:45:14 +0000</pubDate>
</item>
<item>
<title>The 32% Dividend: Why Code Efficiency is the World's Most Powerful Green Energy Source</title>
<link>https://coderlegion.com/8377/the-32-dividend-why-code-efficiency-is-the-worlds-most-powerful-green-energy-source</link>
<description>&lt;p&gt;Right now, the entire digital world is built on a fundamental, structural flaw that is costing the planet an absolute fortune in power and money.&lt;/p&gt;
&lt;p&gt;Look around. Global electricity demand is surging at a reckless pace—far faster than we can build clean energy to meet it. By 2027, the world’s consumption is expected to jump by an unprecedented &lt;strong&gt;3,500 Terawatt-hours (TWh)&lt;/strong&gt;—that’s like adding an entire Japan’s annual energy demand, year after year.&lt;/p&gt;
&lt;p&gt;The biggest pressure cooker? &lt;strong&gt;Data centers&lt;/strong&gt;, driven by the explosive demands of Generative AI, are projected to double their electricity consumption to over &lt;strong&gt;1,000 TWh by 2026&lt;/strong&gt;. They are fighting local communities for power, and they're cooking themselves alive.&lt;/p&gt;
&lt;p&gt;Here’s the truth: &lt;strong&gt;Your code is the problem, and your code is the only solution.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-technical-rebellion-capturing-the-32-dividend&quot;&gt;The Technical Rebellion: Capturing the 32% Dividend&lt;/h3&gt;
&lt;p&gt;That soaring energy demand? A huge chunk of it is &lt;strong&gt;waste&lt;/strong&gt;. It’s not your hardware failing; it’s software inefficiency that forces the CPU to burn power needlessly on processes like memory Input/Output (I/O) and sloppy Garbage Collection (GC). This structural waste is where we strike.&lt;/p&gt;
&lt;p&gt;Research has already proven that by rigorously optimizing the power-hungry operation of memory networks and data flow, an &lt;strong&gt;average 32% reduction in power consumption is achievable&lt;/strong&gt;. This isn't speculation—it's a high-leverage technical benchmark proven in specialized labs.&lt;/p&gt;
&lt;p&gt;Our mission is to take that research-grade, hard-won &lt;strong&gt;32% Dividend&lt;/strong&gt; and make it universal. Our &lt;strong&gt;O(1) Compute&lt;/strong&gt; technology—starting with the publicly available, highly optimized &lt;strong&gt;Near O(1) FSM_API&lt;/strong&gt;—is engineered to align perfectly with the CPU, making power efficiency the default, not the afterthought. We turn concepts confined to academic papers into the foundation of a &lt;strong&gt;Dynamic Software&lt;/strong&gt; architecture.&lt;/p&gt;
&lt;p&gt;This is the coder’s mandate: We transition software from prioritizing peak throughput at any cost to prioritizing &lt;strong&gt;power efficiency per useful transaction&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-the-triple-threat-impact-what-the-32-really-means&quot;&gt;⚡ The Triple-Threat Impact: What The 32% Really Means&lt;/h3&gt;
&lt;p&gt;When you inject 32% computational efficiency into the global Information and Communications Technology (ICT) load, the results are nothing short of revolutionary. This isn't just about saving money; it's about solving a global infrastructure and climate crisis.&lt;/p&gt;
&lt;h4 id=&quot;1-the-climate-and-grid-lifeline-guaranteed-twh-savings&quot;&gt;1. The Climate and Grid Lifeline: Guaranteed TWh Savings&lt;/h4&gt;
&lt;p&gt;The 32% efficiency dividend acts as a guaranteed, instant source of &lt;strong&gt;Zero-Carbon Energy Capacity&lt;/strong&gt;, offering critical relief to a grid struggling to keep up with digital growth.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Metric &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Baseline (2024 Estimate) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;The O(1) Solution &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Ultimate Impact&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Global ICT Annual Energy Load &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1,200 TWh &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;384 TWh Avoided &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;A 32% permanent reduction in digital energy demand.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2024 Global Electricity Demand Increase &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1,172 TWh &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;384 TWh Offset &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Eliminates 32.7% of all new global electricity demand in 2024.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Energy Avoided Method &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Marginal Fossil Fuel Generation &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Guaranteed Zero-Carbon, Zero-Loss &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Bypasses all electrical system energy losses (generation, transmission, distribution).&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;2-the-data-center-multiplier-total-facility-power-reduction&quot;&gt;2. The Data Center Multiplier: Total Facility Power Reduction&lt;/h4&gt;
&lt;p&gt;Data centers pay for inefficiency twice: once for the compute (IT equipment is 42% of power draw) and again for the cooling systems (37% of power draw).&lt;/p&gt;
&lt;p&gt;A 32% reduction in the IT load translates to a compounded power reduction across the entire facility:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;System &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Inefficiency Reduced &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Power Savings Multiplier &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Real-World Benefit&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Data Centers (Facility Wide) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;IT Load (32%), Cooling Load (32%) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;~32% Total Facility Power Reduction &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Provides superior, faster energy reduction than expensive hardware retrofits (like liquid cooling).&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;3-the-end-user-battery-revolution-the-47-multiplier&quot;&gt;3. The End-User Battery Revolution: The 47% Multiplier&lt;/h4&gt;
&lt;p&gt;For every developer, gamer, and mobile user, the most visible win is battery life. When a device’s consumption is reduced by 32%, the active battery runtime is extended by approximately &lt;strong&gt;47%&lt;/strong&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Device Type &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Baseline Active Runtime &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Efficiency Gain &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Projected New Runtime&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Average Laptop &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;6.0 hours &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;32% Reduction &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;~8.8 hours&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Average Smartphone &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;15.0 hours &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;32% Reduction &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;~22.1 hours&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This means fewer charging cycles, a massive reduction in battery degradation, a longer device lifespan, and a much-needed decrease in global e-waste.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-the-coder-s-mandate-join-the-digital-rebellion&quot;&gt;⚙️ The Coder's Mandate: Join the Digital Rebellion&lt;/h3&gt;
&lt;p&gt;The successful realization of the 32% Dividend rests entirely on a systemic shift in how we engineer code. We are the critical infrastructure now, and the engineering paradigm must evolve to reflect the acute energy pressure globally.&lt;/p&gt;
&lt;p&gt;This isn't a secret held hostage by the giants. This is a &lt;strong&gt;Digital Rebellion&lt;/strong&gt; you can join right now:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Blueprint is Free:&lt;/strong&gt; Our groundbreaking FSM architecture—the &lt;strong&gt;Near O(1)&lt;/strong&gt; foundation of this movement—is &lt;strong&gt;Free and Open Source (FOSS)&lt;/strong&gt; under the MIT License. You are invited to study it, hack it, and use it immediately to begin building structurally efficient applications.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maximum Reach:&lt;/strong&gt; This pure C# technology is ready for all your deployments, reaching everything from the newest cloud platforms all the way back to the venerable &lt;strong&gt;.NET Framework 4.7&lt;/strong&gt; on legacy systems.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shameless Plug for Unity:&lt;/strong&gt; For our fellow Unity developers, this same FSM system is already integrated and available for you to plug-and-play into your games and simulations on the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;Unity Asset Store&lt;/a&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The mathematical evidence is absolute. By integrating this core efficiency into your projects, you are taking a stand for a healthier grid, a cooler planet, and a more sustainable digital future. You are building the social and technical pressure required to force the entire industry to beg for help in becoming less wasteful.&lt;/p&gt;
&lt;p&gt;We must make energy waste visible, measurable, and an unacceptable engineering constraint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The rebellion begins with your code.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;resources-amp-code--1&quot;&gt;Resources &amp;amp; Code:&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;NuGet Package (Non-Unity Core):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Simple Demos Repository (Run the Stress Test):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Support Our Work:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Patreon Page:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Support Us (PayPal Donation):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2480994292763536403&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/8377/the-32-dividend-why-code-efficiency-is-the-worlds-most-powerful-green-energy-source</guid>
<pubDate>Thu, 11 Dec 2025 05:01:00 +0000</pubDate>
</item>
<item>
<title>Optimization Log: How One Line of Code Unlocked 33,000 Agents</title>
<link>https://coderlegion.com/8308/optimization-log-how-one-line-of-code-unlocked-33-000-agents</link>
<description>&lt;p&gt;&lt;strong&gt;Subtitle:&lt;/strong&gt; A developer diary on breaking the 66k ceiling and the power of Object Pooling in .NET.&lt;/p&gt;
&lt;p&gt;In my last deep dive, &lt;strong&gt;&quot;The Quick Brown Fox 2: The Silent Hordes,&quot;&lt;/strong&gt; we pushed the FSM_API to its absolute limits. We built a dynamic, expanding world where Foxes tried to survive a landscape littered with Sleeping Dogs.&lt;/p&gt;
&lt;p&gt;We hit a hard ceiling: &lt;strong&gt;66,000 Agents at 30 FPS.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At the time, I assumed the bottleneck was purely architectural—specifically, the overhead of our string-based state lookups. I was ready to accept that 66k was the limit until we refactored the entire core to use Integer Hashing.&lt;/p&gt;
&lt;p&gt;I was wrong. The bottleneck wasn't just the architecture; it was a &quot;Design Miss&quot; in my own simulation logic.&lt;/p&gt;
&lt;h4 id=&quot;the-oops-moment&quot;&gt;The &quot;Oops&quot; Moment&lt;/h4&gt;
&lt;p&gt;While gathering data for my article on the &lt;strong&gt;&quot;$320 Billion Garbage Tax,&quot;&lt;/strong&gt; I ran a profiler on the &quot;Silent Hordes&quot; demo to measure memory allocation. The results were horrifying. The simulation was generating &lt;strong&gt;20 MB of garbage every single frame.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For a C# developer, this is the equivalent of lighting your CPU on fire. The Garbage Collector (GC) was stopping the world constantly to clean up a mess I was creating 30 times a second.&lt;/p&gt;
&lt;p&gt;I tracked the allocation to the &lt;strong&gt;Spatial Hashing&lt;/strong&gt; loop—the system the agents use to find each other.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Culprit:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Inside the Update Loop...
foreach (var agent in _allAgents)
{
    // ... calculate cellKey ...
    if (!Grid.TryGetValue(cellKey, out var cell))
    {
        cell = new GridCell(); // &amp;lt;--- THE KILLER
        Grid[cellKey] = cell;
    }
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In my rush to build the stress test, I was allocating a &lt;code&gt;new GridCell()&lt;/code&gt; for every populated cell in the world, every single frame, only to discard them at the end of the tick. At 66,000 agents, that is thousands of allocations per millisecond.&lt;/p&gt;
&lt;h4 id=&quot;the-fix-don-t-create-reuse-&quot;&gt;The Fix: Don't Create, Reuse.&lt;/h4&gt;
&lt;p&gt;The solution was a classic game development pattern: &lt;strong&gt;Object Pooling.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Instead of letting the GC eat those cells, I created a &lt;code&gt;Queue&amp;lt;GridCell&amp;gt;&lt;/code&gt;. When the frame ends, instead of clearing the dictionary and letting the cells rot in memory, I wipe their data and shove them into the queue. When the next frame starts, I pull them out.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Impact:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Allocations per Frame:&lt;/strong&gt; 0 MB.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GC Pressure:&lt;/strong&gt; Non-existent.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-new-ceiling&quot;&gt;The New Ceiling&lt;/h4&gt;
&lt;p&gt;The results of this single optimization were instant and violent. We didn't just inch past the previous record; we smashed it.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Previous Limit:&lt;/strong&gt; 66,000 Agents @ 30 FPS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;New Limit:&lt;/strong&gt; &lt;strong&gt;99,000 Agents @ 30 FPS.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We gained &lt;strong&gt;33,000 additional agents&lt;/strong&gt;—a 50% increase in total capacity—just by stopping the memory churn.&lt;/p&gt;
&lt;p&gt;If we look at the previous cap of 64,000 agents, the performance jumped from &lt;strong&gt;30 FPS to 53 FPS&lt;/strong&gt; (a 76% increase in speed).&lt;/p&gt;
&lt;h4 id=&quot;what-this-means&quot;&gt;What This Means&lt;/h4&gt;
&lt;p&gt;This discovery validates the thesis of our &lt;strong&gt;&quot;Garbage Tax&quot;&lt;/strong&gt; article: we are often paying for performance we already own but are wasting on bad memory management.&lt;/p&gt;
&lt;p&gt;The FSM_API was ready to handle 100,000 agents all along. The logic was fast enough. The architecture was sound. It was simply drowning in digital trash.&lt;/p&gt;
&lt;p&gt;With the memory leak plugged, we are now standing at the door of &lt;strong&gt;100,000 active, logic-driven entities&lt;/strong&gt;. And remember—we &lt;em&gt;still&lt;/em&gt; haven't switched to Integer Hashing yet.&lt;/p&gt;
&lt;p&gt;When we combine this memory efficiency with the upcoming O(1) lookup refactor, 100k might just be the starting line.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Read the Full Story:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Part 1:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes&quot;&gt;The Quick Brown Fox 2: The Silent Hordes&lt;/a&gt; (The Setup)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Part 2:&lt;/strong&gt;  &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/8267/the-320-billion-garbage-tax-what-my-stress-tests-revealed-about-c-memory-costs&quot;&gt;The $320 Billion Garbage Tax&lt;/a&gt; (The Economic Analysis)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Get the Code &amp;amp; Run the Test:&lt;/strong&gt;&lt;br&gt;
Clone the repo and run the &lt;code&gt;StressProfiler&lt;/code&gt; to see these numbers on your own machine.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Simple Demos Repository (Run the Stress Test): &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8668006668074266765&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/8308/optimization-log-how-one-line-of-code-unlocked-33-000-agents</guid>
<pubDate>Mon, 08 Dec 2025 20:32:48 +0000</pubDate>
</item>
<item>
<title>The $320 Billion Garbage Tax: What My Stress Tests Revealed About C# Memory Costs</title>
<link>https://coderlegion.com/8267/the-320-billion-garbage-tax-what-my-stress-tests-revealed-about-c-memory-costs</link>
<description>&lt;p&gt;In the world of high-performance computing, we often obsess over Big O notation and algorithmic complexity. We optimize our loops, we thread our logic, and we pat ourselves on the back. I thought I knew performance. I thought I was writing efficient code.&lt;/p&gt;
&lt;p&gt;But recently, while stress-testing my &lt;strong&gt;FSM (Finite State Machine) API&lt;/strong&gt;, I ran into an invisible wall. It wasn’t a logic bottleneck. It wasn’t a threading issue. It was a &quot;Garbage Tax&quot; I was paying without even realizing it.&lt;/p&gt;
&lt;p&gt;When you look at the global compute market—cloud, enterprise, and desktop—it is an industry valued at just over &lt;strong&gt;$1 Trillion USD&lt;/strong&gt;. My benchmarks suggest that due to inefficient memory management, we are paying a hidden &lt;strong&gt;32% tax&lt;/strong&gt; on that execution time. That amounts to nearly &lt;strong&gt;$320 Billion dollars&lt;/strong&gt; wasted every year, burned on CPU cycles doing nothing but cleaning up digital trash.&lt;/p&gt;
&lt;h3 id=&quot;part-1-the-methodology&quot;&gt;Part 1: The Methodology&lt;/h3&gt;
&lt;p&gt;To truly understand where the performance floor was, I ran two distinct stress tests.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. The &quot;Raw&quot; Stress Test&lt;/strong&gt;&lt;br&gt;
First, I subjected the API to a pure computational crucible. I created agents that did nothing but heavy mathematical processing and asynchronous tasks, isolating the FSM logic from any rendering or physics noise. I wanted to see the raw &quot;ops per second&quot; the architecture could handle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. The &quot;Quick Brown Fox&quot; Simulation&lt;/strong&gt;&lt;br&gt;
Second, I needed to validate this behavior in a &quot;real&quot; scenario. I deployed a 1D simulation called &lt;strong&gt;&quot;The Quick Brown Fox &amp;amp; The Lazy Dog.&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Foxes&lt;/strong&gt; traverse a world, jumping over obstacles and fleeing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dogs&lt;/strong&gt; sleep, wake up, and chase foxes using spatial lookups.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This forced the API to handle actual game logic—patrolling, chasing, fleeing—at a massive scale.&lt;/p&gt;
&lt;h3 id=&quot;part-2-the-data&quot;&gt;Part 2: The Data&lt;/h3&gt;
&lt;p&gt;The results were immediate, quantifiable, and humbling.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Table A: The Raw Stress Test (Math &amp;amp; Async)&lt;/strong&gt;&lt;br&gt;
In the raw test, performance held up well, but the memory cost was evident.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;130,000 Agents&lt;/strong&gt; @ &lt;strong&gt;34 FPS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory Delta:&lt;/strong&gt; &lt;strong&gt;20 MB per frame&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Table B: The &quot;Quick Brown Fox&quot; (Behavioral Simulation)&lt;/strong&gt;&lt;br&gt;
When we added spatial hashing and actual gameplay logic, the &quot;Garbage Tax&quot; became the dominant factor.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Agents &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;FPS &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Mem Delta (MB) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;World Size &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Density&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;10,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;857 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;-1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;7,028 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1.4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;30,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;166 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;7 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;114,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;0.26&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;50,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;50 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;16 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1,880,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;0.02&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;64,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;30 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;20 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;13,300,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;0.004&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;[Data Source: qbf\_stress\_data.csv]&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At 64,000 agents, my system was churning through &lt;strong&gt;~20 MB of garbage every single frame&lt;/strong&gt;. At 30 FPS, that is &lt;strong&gt;600 MB of allocations per second&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;part-3-the-lamentation-ego-death-&quot;&gt;Part 3: The Lamentation (Ego Death)&lt;/h3&gt;
&lt;p&gt;I’ll be honest: looking at this table dragged my ego through the mud.&lt;/p&gt;
&lt;p&gt;I pride myself on being a programmer who &quot;knows&quot; performance. I engineered this API to be robust. I built it to scale. But the data doesn't lie. I was effectively asking the CPU to spend 32% of its time acting as a janitor, cleaning up temporary objects I shouldn't have allocated in the first place.&lt;/p&gt;
&lt;p&gt;I realized I wasn't just hitting a hardware limit; I was hitting a design limit of my own making.&lt;/p&gt;
&lt;h3 id=&quot;part-4-the-32-tax-on-your-desktop&quot;&gt;Part 4: The 32% Tax on Your Desktop&lt;/h3&gt;
&lt;p&gt;What does this &quot;Garbage Tax&quot; actually mean for you?&lt;/p&gt;
&lt;p&gt;We often talk about cloud costs, but let's talk about the machine sitting on your desk right now. My technology is designed to run on &lt;strong&gt;any .NET system&lt;/strong&gt;—your laptop, your gaming rig, your workstation.&lt;/p&gt;
&lt;p&gt;When software carries a 32% overhead due to inefficient memory management:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gamers:&lt;/strong&gt; That’s the difference between a stuttering 45 FPS and a buttery smooth 60 FPS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Laptops:&lt;/strong&gt; That’s 32% more battery power burned just to create and destroy temporary strings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Workstations:&lt;/strong&gt; That’s your fan spinning up to 100% because the CPU is thrashing memory instead of compiling your code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My currently-in-progress refactoring to a &lt;strong&gt;Hash-Based API&lt;/strong&gt; (moving from Strings to Integers) is designed to eliminate the 25% computational overhead of string lookups. But that 32% memory tax? That required a deeper look at &lt;em&gt;how&lt;/em&gt; I was writing code.&lt;/p&gt;
&lt;h3 id=&quot;part-5-the-bonus-optimization&quot;&gt;Part 5: The &quot;Bonus&quot; Optimization&lt;/h3&gt;
&lt;p&gt;While analyzing the &lt;code&gt;QuickBrownFox&lt;/code&gt; results, I found a specific, glaring inefficiency. It was a &quot;Design Miss&quot;—a simple mistake that was generating millions of unnecessary allocations.&lt;/p&gt;
&lt;p&gt;In my Spatial Hashing loop, I was doing this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// The &quot;Design Miss&quot;
Grid.Clear(); 
foreach (var agent in _allAgents)
{
    // ...
    if (!Grid.TryGetValue(cellKey, out var cell))
    {
        cell = new GridCell(); // &amp;lt;--- ALLOCATION EVERY FRAME!
        Grid[cellKey] = cell;
    }
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For 64,000 agents, I was allocating thousands of new &lt;code&gt;GridCell&lt;/code&gt; objects &lt;strong&gt;every single frame&lt;/strong&gt;, only to throw them away milliseconds later.&lt;/p&gt;
&lt;h4 id=&quot;the-fix-grid-cell-pooling&quot;&gt;The Fix: Grid Cell Pooling&lt;/h4&gt;
&lt;p&gt;I implemented a simple &lt;strong&gt;Object Pool&lt;/strong&gt;. Instead of creating new cells, I reuse the old ones.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Before:&lt;/strong&gt; &lt;code&gt;new GridCell()&lt;/code&gt; -&amp;gt; GC Pressure.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;After:&lt;/strong&gt; &lt;code&gt;_cellPool.Get()&lt;/code&gt; -&amp;gt; 0 Allocations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I refactored the simulation to pool these cells. The logic is identical, but the memory footprint is completely different.&lt;/p&gt;
&lt;h3 id=&quot;part-6-the-results-optimization-validated-&quot;&gt;Part 6: The Results (Optimization Validated)&lt;/h3&gt;
&lt;p&gt;The impact of this single change was instant. By removing the allocation loop, we unlocked the CPU cycles that were previously drowning in garbage collection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Table C: The Optimized &quot;Quick Brown Fox&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Agents &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;FPS &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Mem Delta (MB) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Improvement&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;10,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;971 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;0 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;+13% FPS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;30,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;202 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;0 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;+21% FPS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;50,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;77 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;-2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;+54% FPS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;64,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;53 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;+76% FPS&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;99,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;30 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;~0 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;NEW CEILING&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;[Data Source: qbf\_optimized\_data.csv]&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;the-takeaway&quot;&gt;The Takeaway&lt;/h4&gt;
&lt;p&gt;At the previous limit of &lt;strong&gt;64,000 agents&lt;/strong&gt;, we jumped from &lt;strong&gt;30 FPS to 53 FPS&lt;/strong&gt;—a nearly &lt;strong&gt;76% performance increase&lt;/strong&gt; just by stopping the garbage.&lt;/p&gt;
&lt;p&gt;More importantly, we pushed the simulation ceiling from &lt;strong&gt;64,000&lt;/strong&gt; to &lt;strong&gt;99,000 agents&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We found the 32% tax, and we didn't just pay it—we abolished it. This is why I am building the Singularity Workshop: to ensure that when you run your code, you are using the whole machine, not just the parts the Garbage Collector isn't using.&lt;/p&gt;
&lt;h4 id=&quot;catch-up-on-the-series&quot;&gt;Catch Up on the Series&lt;/h4&gt;
&lt;p&gt;Before the big fight, check out the data that led us here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Control Group:&lt;/strong&gt; Benchmarking the &quot;dirty&quot; version of the API.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/7988/the-control-group-benchmarking-the-dirty-version-of-my-fsm-api&quot;&gt;https://coderlegion.com/7988/the-control-group-benchmarking-the-dirty-version-of-my-fsm-api&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Quick Brown Fox:&lt;/strong&gt; Validating behavior against the silent hordes.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes&quot;&gt;https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fight Night Announcement:&lt;/strong&gt; The Lightweight Challenger vs The Heavyweight Champ.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/8147/fight-night-announcement-the-lightweight-challenger-vs-the-heavyweight-champ&quot;&gt;https://coderlegion.com/8147/fight-night-announcement-the-lightweight-challenger-vs-the-heavyweight-champ&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;get-ready-for-fight-night-&quot;&gt;Get Ready for Fight Night!&lt;/h4&gt;
&lt;p&gt;This optimization is just the warm-up. We are heading toward &lt;strong&gt;Fight Night&lt;/strong&gt;, where we will see our Lightweight Champion—now punching up at nearly &lt;strong&gt;100,000 agents&lt;/strong&gt; at a smooth 30 FPS—take on the heavyweights of the industry. The benchmarks are set, the gloves are off, and the garbage tax has been repealed. Stay tuned.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Resources &amp;amp; Code:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The FSM Package (Unity Asset Store):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NuGet Package (Non-Unity Core):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Simple Demos Repository (Run the Stress Test):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Support Our Work:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Patreon Page:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Support Us (PayPal Donation):&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17692567480013189261&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/8267/the-320-billion-garbage-tax-what-my-stress-tests-revealed-about-c-memory-costs</guid>
<pubDate>Sun, 07 Dec 2025 21:37:34 +0000</pubDate>
</item>
<item>
<title>The Quick Brown Fox 2: The Silent Hordes</title>
<link>https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes</link>
<description>&lt;h2 id=&quot;the-quick-brown-fox-2-the-silent-hordes&quot;&gt;The Quick Brown Fox 2: The Silent Hordes&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Implementing High-Performance AI at Scale with FSM_API&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In our &lt;a rel=&quot;nofollow&quot; href=&quot;https://coderlegion.com/6261/learn-how-fsmapi-uses-decoupled-state-machines-to-run-a-fox-and-dog-ai-simulation&quot;&gt;previous article&lt;/a&gt;, we introduced the &quot;Quick Brown Fox and Lazy Sleeping Dog&quot; demo. We showed how &lt;code&gt;FSM_API&lt;/code&gt; allows you to decouple agent data from behavior, creating a clean architecture where a Fox could detect a Dog, transition to a &quot;Jumping&quot; state, and (hopefully) land safely.&lt;/p&gt;
&lt;p&gt;It was a simple, controlled test. But &lt;code&gt;FSM_API&lt;/code&gt; isn't just for handling one fox and one dog. It is built for the Singularity.&lt;/p&gt;
&lt;p&gt;So, we asked a harder question: &lt;strong&gt;What happens when 66,000 agents try to coexist in a rapidly expanding universe?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To answer this, we built &lt;strong&gt;&quot;The Gauntlet.&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-setup-a-dynamic-stress-test&quot;&gt;The Setup: A Dynamic Stress Test&lt;/h3&gt;
&lt;p&gt;We took the exact same FSM definitions from our simple demo—&lt;strong&gt;Walking, Jumping, Sleeping, Chasing&lt;/strong&gt;—and dropped them into a stress-test environment designed to break them.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The World:&lt;/strong&gt; An infinitely expanding 1D grid that grows automatically to accommodate population density.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Agents:&lt;/strong&gt; Thousands of &quot;Foxes&quot; traversing the grid and thousands of &quot;Sleeping Dogs&quot; acting as dynamic landmines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Logic:&lt;/strong&gt; We implemented &lt;strong&gt;Spatial Hashing&lt;/strong&gt; to allow agents to query their neighbors efficiently. Foxes look ahead; if they see a dog, they jump. If they land on a dog, it wakes up. If a dog wakes up, it chases.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This isn't just a benchmark of raw loops; it is a benchmark of &lt;strong&gt;state integrity&lt;/strong&gt;. Every single agent is a fully independent FSM Context running its own logic cycle.&lt;/p&gt;
&lt;h3 id=&quot;the-results-the-tip-of-the-iceberg-&quot;&gt;The Results: The &quot;Tip of the Iceberg&quot;&lt;/h3&gt;
&lt;p&gt;We ran the simulation until the framework hit the limits of a standard development machine (maintaining \~30 FPS). The final snapshot tells a brutal story:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Metric &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Count &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Context&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Total Agents &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;66,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;A population larger than many real-world towns.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Dogs (Hazards) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;19,711 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Nearly 20,000 active threats monitoring the field.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Foxes (Dead) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27,362 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Casualties of &quot;bad luck&quot; RNG (landing on a dog).&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Foxes (Alive) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;18,927 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The survivors pioneering the edge of the world.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;the-silent-stress-test&quot;&gt;The &quot;Silent&quot; Stress Test&lt;/h3&gt;
&lt;p&gt;While the death count is tragic (RIP to the 27,362 foxes who failed their jump checks), the most shocking metric wasn't the carnage—it was the &lt;strong&gt;activity level&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;At peak load, with nearly &lt;strong&gt;20,000 dogs&lt;/strong&gt; monitoring the field, &lt;strong&gt;only 2 were awake.&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;why-this-matters-for-performance&quot;&gt;Why This Matters for Performance&lt;/h4&gt;
&lt;p&gt;This &quot;boring&quot; stat is the ultimate proof of the &lt;code&gt;FSM_API&lt;/code&gt;'s architecture. In a naive implementation, checking 20,000 AI agents for targets usually kills the CPU. But here, the simulation remained playable at 30 FPS because the FSMs efficiently handled the &quot;Idle Load.&quot;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The Hidden Workload: Every single frame, &lt;strong&gt;38,000+ alive agents&lt;/strong&gt;&lt;br&gt;
are evaluating their Transition Conditions.&lt;ul&gt;
&lt;li&gt;Dogs: &quot;Is anything touching me?&quot;&lt;/li&gt;
&lt;li&gt;Foxes: &quot;Is there a dog in the next cell?&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ol&gt;
&lt;li&gt;Live Action Metrics:      &lt;ul&gt;
&lt;li&gt;Active Chases: ~2 to 12 dogs awake at any moment.&lt;/li&gt;
&lt;li&gt;Fleeing Foxes: ~1 to 5 foxes sprinting for their lives.&lt;/li&gt;
&lt;li&gt;Jumps per Frame: ~600 foxes airborne right now.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This creates a self-balancing ecosystem. The API is maintaining the memory and state integrity of &lt;strong&gt;66,000 objects&lt;/strong&gt; simultaneously, but because the &lt;strong&gt;&quot;Sleeping&quot;&lt;/strong&gt; state logic is lightweight, the system can handle thousands of them for free. However, the system retains the &lt;strong&gt;Burst Potential&lt;/strong&gt; to handle chaos: if a swarm of Foxes lands on a pack of Dogs, those Dogs will wake up, transition to &quot;Chasing,&quot; and execute complex logic instantly.&lt;/p&gt;
&lt;h3 id=&quot;from-hello-world-to-production-scale-&quot;&gt;From &quot;Hello World&quot; to &quot;Production Scale&quot;&lt;/h3&gt;
&lt;p&gt;We went from a simple demo with one fox to managing &lt;strong&gt;66,000 active, logic-driven entities&lt;/strong&gt; without changing the core FSM definitions.&lt;/p&gt;
&lt;p&gt;We aren't just simulating the &quot;action movie&quot; moments of chases and jumps; we are simulating the &lt;strong&gt;quiet complexity of a living world&lt;/strong&gt;. The fact that 19,000 dogs can sleep efficiently while monitoring their surroundings proves that the &lt;strong&gt;FSM_API&lt;/strong&gt; is ready for scale.&lt;/p&gt;
&lt;h4 id=&quot;what-s-next-&quot;&gt;What's Next?&lt;/h4&gt;
&lt;p&gt;We are currently hitting a ceiling around 70,000 agents due to the overhead of string-based state lookups (e.g., checking CurrentState == &quot;Sleeping&quot; thousands of times per frame).&lt;/p&gt;
&lt;p&gt;In our next update, we are refactoring the backend to use Integer Hashing. Our early benchmarks suggest this could increase throughput by an order of magnitude.&lt;/p&gt;
&lt;p&gt;But we won't stop there. Once we have optimized the micro-operations, we will be &quot;Going Wide&quot;—exploring how to leverage FSM Processing Groups to run massive, parallel simulations across multiple cores.&lt;/p&gt;
&lt;p&gt;Stay tuned. The Singularity is getting closer.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Simple Demos Repository (Run the Stress Test): &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17381643093345870659&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/8009/the-quick-brown-fox-2-the-silent-hordes</guid>
<pubDate>Mon, 01 Dec 2025 04:19:58 +0000</pubDate>
</item>
<item>
<title>The Control Group: Benchmarking the &quot;Dirty&quot; Version of My FSM API</title>
<link>https://coderlegion.com/7988/the-control-group-benchmarking-the-dirty-version-of-my-fsm-api</link>
<description>&lt;p&gt;In software architecture, optimization without measurement is just guessing.&lt;/p&gt;
&lt;p&gt;I am currently in the process of a major refactor for my C# Finite State Machine API (FSM_API). We discovered some concurrency friction in the underlying dictionary lookups and realized that my heavy reliance on string keys was creating unnecessary O(N) overhead.&lt;/p&gt;
&lt;p&gt;The plan is to switch to ConcurrentDictionary and implement Integer Hashing to eliminate string allocations entirely. But before I tear the engine apart, I needed a baseline. I needed to know exactly how much &quot;tax&quot; I was paying for those strings.&lt;/p&gt;
&lt;p&gt;So, I built a Stress Profiler.&lt;/p&gt;
&lt;p&gt;The Torture Test&lt;/p&gt;
&lt;p&gt;I designed a benchmark to intentionally break the system. The goal wasn't to see if it would fail, but how it would fail.&lt;/p&gt;
&lt;p&gt;The test setup is simple but brutal:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Crowd: We spawn between 50,000 and 240,000 Agents.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Payload: Each agent performs basic math, some branching logic, and—crucially—a ToString() allocation every update to simulate&lt;br&gt;
memory pressure (Heap Thrashing).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Variable: We test three different &quot;Time-Slicing&quot; intervals:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; 1.) Interval 1: Every agent updates every frame (100% Load). &lt;/p&gt;
&lt;p&gt; 2.) Interval 2: Agents skip 1 frame (50% Load).      &lt;/p&gt;
&lt;p&gt; 3.)  Interval 3: Agents skip 2 frames (33% Load).&lt;/p&gt;
&lt;p&gt;The Hypothesis&lt;/p&gt;
&lt;p&gt;My theory was that the Dictionary&amp;lt;string, ...&amp;gt; lookups would become the primary bottleneck as the agent count rose. Even when agents are &quot;sleeping&quot; (skipping frames), the API still has to iterate through the list to check if it's their turn.&lt;/p&gt;
&lt;p&gt;If the architecture is sound, &quot;Interval 2&quot; should theoretically double our capacity. If it doesn't, we know the overhead of the list management itself is too high.&lt;/p&gt;
&lt;p&gt;Here is the raw data from the &quot;Dirty&quot; version of the API—before the optimization pass which will be shared the moment I've accomplished the refactoring.&lt;/p&gt;
&lt;h4 id=&quot;stress-test-results-baseline-api-&quot;&gt;Stress Test Results (Baseline API)&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Interval &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Agents &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;FPS &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Logic Ops/Frame &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Mem Delta (MB)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;50000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;58.78 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;150,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;55000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;106.30 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;11,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;60000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;72.01 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;180,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;65000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;100.64 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;13,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;30&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;70000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;63.44 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;210,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;13&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;75000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;96.77 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;15,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;38&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;80000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;57.21 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;240,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;36&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;85000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;87.40 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;17,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;43&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;90000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;46.43 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;270,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;16&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;95000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;75.70 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;19,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;48&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;100000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;41.40 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;300,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;16&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;105000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;62.54 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;21,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;54&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;110000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;38.60 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;330,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;115000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;58.02 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;23,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;59&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 120000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 34.88  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;360,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;26&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;125000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;57.30 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;25,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;61&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 130000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 33.57  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;390,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;32&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;135000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;53.90 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;68&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 140000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 31.47  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;420,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;26&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;145000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;50.50 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;29,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;70&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;1 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 150000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 28.80  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;450,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;29&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;80000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;70.34 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;8,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;55&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;85000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;71.45 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;127,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;12&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;90000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;83.53 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;13,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;45&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;95000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;62.50 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;142,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;100000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;69.49 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;15,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;-4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;105000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;59.55 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;157,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;23&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;110000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;67.81 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;16,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;53&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;115000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;53.22 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;172,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;40&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;120000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;57.58 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;18,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;-1&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;125000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;50.64 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;187,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;28&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;130000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;56.93 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;19,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;64&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;135000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;42.57 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;202,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;46&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;140000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;48.11 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;21,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;145000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;44.63 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;217,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;33&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;150000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;48.52 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;22,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;74&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;155000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;40.62 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;232,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;51&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;160000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;45.80 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;24,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;87&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;165000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;35.97 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;247,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;42&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;170000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;38.35 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;25,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;4&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;175000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;35.65 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;262,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;41&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;180000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;40.20 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;27,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;86&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 185000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 32.44  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;277,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;57&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;190000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;37.83 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;28,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;93&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 195000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 31.51  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;292,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;60&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 200000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 33.02  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;30,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 205000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 30.64  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;307,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;50&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 210000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 34.37  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;31,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;2 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 215000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 28.08  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;322,500 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;64&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;120000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;46.49 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;6,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;79&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;130000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;56.15 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;130,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;30&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;140000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;49.74 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;14,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;-9&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;150000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;47.27 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;150,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;21&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;160000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;44.20 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;16,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;75&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;170000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;39.76 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;170,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;35&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;180000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;37.77 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;18,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;1&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;190000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;37.70 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;190,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;32&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;200000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;35.25 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;20,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;97&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 210000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 32.49  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;210,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;57&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 220000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 30.48  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;22,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 230000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 31.41  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;230,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;37&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;3 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 240000  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt; 29.61  &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;24,000 &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;116&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The Analysis&lt;/p&gt;
&lt;p&gt;The results gave us the exact &quot;Failure Floor&quot; we were looking for.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The Hard Limit: At 140,000 agents running every frame, we hit the 30 FPS floor.

The Overhead: Notice that switching to Interval 2 didn't perfectly double our capacity (we capped around 215k, not 280k). This confirms that simply iterating through 200,000 string-based handles costs CPU time, even if the agents do nothing.

The GC Spike: The memory delta column shows the &quot;Sawtooth&quot; pattern where the Garbage Collector had to step in aggressively to clean up those string allocations.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we have our target. The next version of the API needs to beat these numbers to prove the value of the refactor. Let's get to work.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;br&gt;
 Simple Demos Repository (Run the Stress Test): &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;https://github.com/TrentBest/SimpleDemos&lt;/a&gt; (Clone this repo and run the StressProfiler project to reproduce these numbers.)&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback or what you've built with the API in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1207607318879054936&quot; alt=&quot;The Singularity Workshop's Logo, a digital eyeball made from energy, forming the singularity&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/7988/the-control-group-benchmarking-the-dirty-version-of-my-fsm-api</guid>
<pubDate>Sun, 30 Nov 2025 08:32:53 +0000</pubDate>
</item>
<item>
<title>The Sentient Primitive: Waking Up Your Data with FSMs</title>
<link>https://coderlegion.com/7936/the-sentient-primitive-waking-up-your-data-with-fsms</link>
<description>&lt;p&gt;In standard game development, we are taught that variables are silent containers. A &lt;code&gt;bool&lt;/code&gt; is just a box that holds &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. It doesn't &lt;em&gt;do&lt;/em&gt; anything. To know if it changed, we have to pester it constantly:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// The Old Way: The Polling Trap
void Update() {
    if (isDead == true) { // Asking every single frame...
        PlayDeathAnimation();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the &quot;Silent Variable&quot; problem. It leads to spaghetti code, race conditions, and &lt;code&gt;Update()&lt;/code&gt; loops clogged with thousands of &lt;code&gt;if&lt;/code&gt; statements checking for things that haven't changed.&lt;/p&gt;
&lt;p&gt;But what if a Boolean wasn't just a box? What if it was a &lt;strong&gt;Finite State Machine&lt;/strong&gt;?&lt;/p&gt;
&lt;h3 id=&quot;1-the-fsm-bool-the-atomic-unit-of-behavior&quot;&gt;1. The FSM_Bool: The Atomic Unit of Behavior&lt;/h3&gt;
&lt;p&gt;By wrapping a primitive in an FSM, we transform it from &lt;strong&gt;Passive Data&lt;/strong&gt; into &lt;strong&gt;Active Behavior&lt;/strong&gt;. It doesn't just hold a value; it has a &lt;em&gt;lifecycle&lt;/em&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Enter True:&lt;/strong&gt; Fire the event (e.g., &quot;Turn on Light&quot;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Update True:&lt;/strong&gt; Maintain state (e.g., &quot;Humming sound&quot;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exit True:&lt;/strong&gt; Cleanup (e.g., &quot;Fade out light&quot;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Suddenly, your logic is decoupled. The code controlling the light doesn't need to check the switch. The switch &lt;em&gt;tells&lt;/em&gt; the light what to do.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// The New Way: Reactive Primitives
var lightSwitch = new FSM_Boolean(
    name: &quot;LivingRoomLight&quot;,
    startValue: false, 
    onTrue: (ctx) =&amp;gt; LightFixture.TurnOn(),  // Fire and forget
    onFalse: (ctx) =&amp;gt; LightFixture.TurnOff() // Fire and forget
);

// To operate it, we just change the target. The FSM handles the logic.
lightSwitch.Set(true); 
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;2-evolution-the-fsm-floatlimit&quot;&gt;2. Evolution: The FSM_FloatLimit&lt;/h3&gt;
&lt;p&gt;The concept explodes in potential when we move beyond Booleans. Consider the &lt;code&gt;float&lt;/code&gt;. Usually, we use floats for Health, Stamina, or Mana.&lt;/p&gt;
&lt;p&gt;In the old world, a Health System is a messy manager class. In the FSM world, a Health System is just &lt;strong&gt;a single Float with a Threshold.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Introducing the &lt;code&gt;FSM_FloatLimit&lt;/code&gt;. It is an FSM that monitors a value and triggers a transition when a threshold is crossed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Constructor:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;var healthSystem = new FSM_FloatLimit(
    currentValue: 100.0f, 
    threshold: 0.0f, 
    OnThreshold: (ctx) =&amp;gt; Player.Kill()
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The Internal Logic (Abstracted):&lt;/strong&gt;&lt;br&gt;
Inside the black box, this FSM has two states: &lt;code&gt;Safe&lt;/code&gt; and &lt;code&gt;Breached&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;State &quot;Safe&quot;:&lt;/strong&gt; The value is above the threshold.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transition:&lt;/strong&gt; If &lt;code&gt;Value &amp;lt;= Threshold&lt;/code&gt; -&amp;gt; Go to &lt;code&gt;Breached&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State &quot;Breached&quot;:&lt;/strong&gt; Execute &lt;code&gt;OnThreshold&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You no longer need a &lt;code&gt;PlayerHealthManager.cs&lt;/code&gt;. You just need a smart float.&lt;/p&gt;
&lt;h3 id=&quot;3-complex-data-shapes-from-simple-primitives&quot;&gt;3. Complex Data Shapes from Simple Primitives&lt;/h3&gt;
&lt;p&gt;When you start composing these &quot;Smart Primitives&quot; together, you aren't writing code anymore; you are sculpting &lt;strong&gt;Logic Shapes&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Imagine a Weapon Reload System constructed entirely of primitives:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;AmmoCount (&lt;code&gt;FSM_IntLimit&lt;/code&gt;)&lt;/strong&gt;: Triggers &quot;Empty&quot; when it hits 0.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ReloadTimer (&lt;code&gt;FSM_FloatTimer&lt;/code&gt;)&lt;/strong&gt;: Triggers &quot;Complete&quot; after 2.0 seconds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IsReloading (&lt;code&gt;FSM_Bool&lt;/code&gt;)&lt;/strong&gt;: The master switch.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The architecture becomes a chain reaction:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;AmmoCount&lt;/code&gt; hits 0 -&amp;gt; Sets &lt;code&gt;IsReloading&lt;/code&gt; to True.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IsReloading&lt;/code&gt; (True) -&amp;gt; Starts &lt;code&gt;ReloadTimer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ReloadTimer&lt;/code&gt; (Complete) -&amp;gt; Refills &lt;code&gt;AmmoCount&lt;/code&gt; and sets &lt;code&gt;IsReloading&lt;/code&gt; to False.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;beyond-numbers-the-reactive-string&quot;&gt;Beyond Numbers: The Reactive String&lt;/h2&gt;
&lt;p&gt;The power of the &quot;Sentient Primitive&quot; isn't limited to simple math. It transforms how we handle text and input.&lt;/p&gt;
&lt;p&gt;Consider the standard way we handle cheat codes or spell casting in games: we log every keystroke into a buffer and run a string comparison every frame. It is tedious and error-prone.&lt;/p&gt;
&lt;p&gt;In our FSM-driven world, we treat the String as a &lt;strong&gt;Stateful Pattern Matcher&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;the-fsm-regex&quot;&gt;The FSM_Regex&lt;/h3&gt;
&lt;p&gt;Imagine an FSM initialized with a Regular Expression. It doesn't just &quot;hold&quot; a string; it &lt;em&gt;hunts&lt;/em&gt; for a pattern within the stream of data you feed it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Defining a &quot;Spell&quot; using a Reactive String
var fireballSpell = new FSM_Regex(
    pattern: &quot;UP, DOWN, A, B&quot;, // The Konami Code of magic
    OnMatch: (ctx) =&amp;gt; CastFireball(),
    OnFail: (ctx) =&amp;gt; PlayFizzleSound()
);

// We just feed it inputs. The FSM tracks the sequence state internally.
fireballSpell.Input(&quot;UP&quot;);   // State: Tracking...
fireballSpell.Input(&quot;DOWN&quot;); // State: Tracking...
fireballSpell.Input(&quot;X&quot;);    // State: Failed -&amp;gt; Trigger OnFail -&amp;gt; Reset
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This turns complex input handling into a simple definition. You aren't writing an &quot;Input Manager&quot;; you are just defining the shape of a valid command.&lt;/p&gt;
&lt;h3 id=&quot;the-paradigm-shift-composition-over-management&quot;&gt;The Paradigm Shift: Composition over Management&lt;/h3&gt;
&lt;p&gt;When you adopt this mindset, the &quot;Manager Classes&quot; that plague modern software development start to disappear.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You don't need a &lt;code&gt;HealthManager&lt;/code&gt;; you have an &lt;code&gt;FSM_Float&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You don't need an &lt;code&gt;InputComboManager&lt;/code&gt;; you have an &lt;code&gt;FSM_Regex&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You don't need a &lt;code&gt;DayNightCycleManager&lt;/code&gt;; you have an &lt;code&gt;FSM_Timer&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You are creating a visual language where the &quot;bricks&quot; of your building aren't dead clay; they are active participants in the architecture. They know when to hold together, and they know exactly when to break apart.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;visualizing-the-fsm-regex&quot;&gt;Visualizing the FSM_Regex&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11648743608190271004&quot; alt=&quot;Flow Chart for our FSM_Regex&quot;&gt;&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6706949502413490078&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/7936/the-sentient-primitive-waking-up-your-data-with-fsms</guid>
<pubDate>Sat, 29 Nov 2025 07:09:59 +0000</pubDate>
</item>
<item>
<title>The Deterministic Engine: Why The Singularity Workshop’s FSM_API Redefines C# State Management</title>
<link>https://coderlegion.com/7557/the-deterministic-engine-why-singularity-workshops-fsmapi-redefines-state-management</link>
<description>&lt;h2 id=&quot;the-deterministic-engine-why-the-singularity-workshop-s-fsm-api-redefines-c-state-management&quot;&gt;The Deterministic Engine: Why The Singularity Workshop’s FSM_API Redefines C# State Management&lt;/h2&gt;
&lt;p&gt;The Finite State Machine (FSM) is a foundational concept in computer science, acting as the deterministic heartbeat for everything from game AI to complex enterprise business logic. For C# developers, choosing the right FSM library is not just a preference; it’s an architectural decision that dictates a system's reliability, performance, and, crucially, its thread safety.&lt;/p&gt;
&lt;p&gt;The Singularity Workshop, via its robust NuGet package (&lt;code&gt;TheSingularityWorkshop.FSM_API&lt;/code&gt;) and transparent GitHub repository (&lt;code&gt;TrentBest/FSM_API&lt;/code&gt;) , has engineered the FSM_API to address the core shortcomings of conventional FSM implementations, delivering a control plane built for high-throughput, mission-critical applications.&lt;/p&gt;
&lt;p&gt;Here is an analysis of the architectural decisions that set the FSM_API apart from existing solutions, establishing it as the superior choice for high-assurance C# development.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;1-the-concurrency-chasm-thread-safety-by-design&quot;&gt;1. The Concurrency Chasm: Thread Safety by Design&lt;/h3&gt;
&lt;p&gt;The single greatest differentiator of the FSM_API is its uncompromising commitment to &lt;strong&gt;thread safety&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Traditional FSM libraries popular in the.NET ecosystem are inherently not thread-safe. When utilized in concurrent environments (which is nearly every modern server-side or game application), developers are forced to wrap critical methods, such as state-triggering calls, in external locking mechanisms. This practice introduces significant operational risk:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=5891892075770291067&quot; alt=&quot;This visual directly contrasts the Traditional FSM (chaotic) with the FSM_API (deterministic and safe) based on its Deferred Mutation Handling.&quot;&gt;&lt;br&gt;
(Forgive the spelling errors in the images, good AI is hard to find!)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Risk of Race Conditions:&lt;/strong&gt; External locking is difficult to manage perfectly and often leads to non-reproducible race conditions, particularly on highly concurrent or slower machines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance Bottlenecks:&lt;/strong&gt; Manual locking introduces synchronization overhead that can negate performance gains.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Singularity Workshop eliminates this problem with its proprietary &lt;strong&gt;Deferred Mutation Handling&lt;/strong&gt; model. The system operates on a thread-safe principle where &quot;All modifications to FSM definitions and instances are meticulously deferred and processed safely on the main thread post-update, eliminating common concurrency issues&quot;.&lt;/p&gt;
&lt;p&gt;This means the FSM_API handles the concurrency challenge internally and atomically, guaranteeing predictable state changes regardless of the thread they originated from. For any system requiring stability—such as high-frequency simulations, trading platforms, or robotics control—this architectural guarantee translates directly into reduced technical debt and higher ROI.&lt;/p&gt;
&lt;h3 id=&quot;2-architectural-purity-decoupling-logic-and-data&quot;&gt;2. Architectural Purity: Decoupling Logic and Data&lt;/h3&gt;
&lt;p&gt;The FSM_API is designed with an emphasis on &lt;strong&gt;separation of concerns&lt;/strong&gt;, which drastically improves unit testability and maintainability.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11472517392245046429&quot; alt=&quot;This visual emphasizes the architectural purity and decoupling of FSM logic from context data, which makes the FSMs highly testable in isolation.&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;a-context-driven-behavior-istatecontext-&quot;&gt;A. Context-Driven Behavior (&lt;code&gt;IStateContext&lt;/code&gt;)&lt;/h4&gt;
&lt;p&gt;Instead of tying the FSM logic directly to a concrete class, the FSM_API utilizes the &lt;code&gt;IStateContext&lt;/code&gt; interface. This simple, POCO-friendly (Plain Old C# Object) interface functions as the &quot;data bag&quot; for the specific FSM instance.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Logic vs. Data:&lt;/strong&gt; The FSM handles the &lt;em&gt;how&lt;/em&gt; and &lt;em&gt;when&lt;/em&gt; of state transitions, while the &lt;code&gt;IStateContext&lt;/code&gt; object provides the necessary &lt;em&gt;data&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testability:&lt;/strong&gt; Because the state logic is entirely decoupled from the application's domain data, FSMs become &quot;highly testable in isolation&quot;. This simplifies Continuous Integration workflows and accelerates development.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;b-the-purity-of-the-transition&quot;&gt;B. The Purity of the Transition&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;FSMTransition&lt;/code&gt; class is rigorously defined to enforce high standards of state machine purity. A transition rule is comprised only of the &lt;code&gt;From&lt;/code&gt; state, the &lt;code&gt;To&lt;/code&gt; state, and a &lt;strong&gt;Guard&lt;/strong&gt; (&lt;code&gt;Condition&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Crucially, the FSM_API &lt;strong&gt;intentionally excludes mechanisms for defining transition actions&lt;/strong&gt;. This design choice forces developers to place all side effects associated with a state change into the guaranteed &lt;strong&gt;OnEnter&lt;/strong&gt; or &lt;strong&gt;OnExit&lt;/strong&gt; actions of the respective states.&lt;/p&gt;
&lt;p&gt;This strict structure prevents &quot;goto pasta&quot; logic  and ensures that the system's behavior is always defined locally within the state's lifecycle, maximizing readability, verifiability, and formal analysis.&lt;/p&gt;
&lt;h3 id=&quot;3-performance-agnosticism-and-low-tco&quot;&gt;3. Performance, Agnosticism, and Low TCO&lt;/h3&gt;
&lt;p&gt;Performance is not an afterthought; it is a core feature of The Singularity Workshop's offering:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Blazing-Fast and Lightweight:&lt;/strong&gt; The system is engineered for &lt;strong&gt;optimized performance&lt;/strong&gt; and &lt;strong&gt;minimal memory allocations&lt;/strong&gt;. This efficiency ensures the FSM_API can handle millions of executions locally, which is crucial for demanding simulation scenarios.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero-Dependency Footprint:&lt;/strong&gt; The FSM_API is &lt;strong&gt;Framework Agnostic&lt;/strong&gt;. It requires &quot;No external dependencies. No frameworks required. No boilerplate setup&quot;. This significantly reduces the Total Cost of Ownership (TCO) for enterprises, eliminating maintenance burdens, licensing complexities, and compatibility issues that come with relying on large external frameworks. It works seamlessly across the entire.NET spectrum, from.NET Framework 4.7 through.NET 8.0.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;4-advanced-orchestration-dynamic-control-and-groups&quot;&gt;4. Advanced Orchestration: Dynamic Control and Groups&lt;/h3&gt;
&lt;p&gt;Beyond mere state tracking, the FSM_API provides features essential for orchestrating large populations of interacting entities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Processing Groups:&lt;/strong&gt; Developers can organize multiple FSM instances into named &lt;strong&gt;Processing Groups&lt;/strong&gt; (e.g., &quot;AI Update Loop,&quot; &quot;UI Logic&quot;). This allows for granular, &lt;strong&gt;dynamic update ticking&lt;/strong&gt; and &lt;strong&gt;frame/process throttling&lt;/strong&gt; , enabling developers to prioritize critical system FSMs while throttling non-critical ones, maximizing computational efficiency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runtime Redefinition:&lt;/strong&gt; FSM definitions can be &lt;strong&gt;redefined while actively running&lt;/strong&gt;. This capability supports advanced operational models like live patching of behavioral logic and dynamic reconfiguration without requiring application downtime or recompilation—a powerful tool for high-availability systems.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error Tolerance:&lt;/strong&gt; The library includes built-in diagnostics and thresholds designed to monitor and manage complex logic failures, proactively preventing &quot;runaway logic or invalid state contexts&quot; and ensuring application stability without a full system crash.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;conclusion-the-investment-in-architectural-defensibility&quot;&gt;Conclusion: The Investment in Architectural Defensibility&lt;/h3&gt;
&lt;p&gt;The Singularity Workshop FSM_API is not just a replacement for existing C# FSM tools; it is an architectural upgrade. It provides a level of guaranteed thread safety and architectural purity that existing solutions force developers to implement manually, inefficiently, and often incorrectly.&lt;/p&gt;
&lt;p&gt;By utilizing the FSM_API (NuGet: &lt;code&gt;TheSingularityWorkshop.FSM_API&lt;/code&gt;), C# developers gain:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; Guaranteed stability via Deferred Mutation Handling.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance:&lt;/strong&gt; Minimal allocation, blazing-fast execution speeds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainability:&lt;/strong&gt; Decoupled logic, easy unit testing, and highly readable definitions built using the Fluent API.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For serious developers and enterprises building systems where failure is not an option, the FSM_API provides the robust, deterministic foundation necessary to scale complex behavioral logic with confidence.&lt;/p&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12066565525591870058&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>API Dev</category>
<guid isPermaLink="true">https://coderlegion.com/7557/the-deterministic-engine-why-singularity-workshops-fsmapi-redefines-state-management</guid>
<pubDate>Thu, 20 Nov 2025 05:37:21 +0000</pubDate>
</item>
<item>
<title>Caution: Mind Blowing Finite State Machine contained within (Nothing but theory)</title>
<link>https://coderlegion.com/7428/caution-mind-blowing-finite-state-machine-contained-within-nothing-but-theory</link>
<description>&lt;h2 id=&quot;caution-mind-blowing-finite-state-machine-contained-within-nothing-but-theory-&quot;&gt;Caution: Mind Blowing Finite State Machine Contained Within (Nothing but Theory)&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Finite State Machine (FSM)&lt;/strong&gt;—or Finite State Automaton (FSA)—is often dismissed as a simple computational model. However, within its minimal definition lies a mathematical authority that proves it to be the &lt;strong&gt;Universal Atomic Unit of Control Logic&lt;/strong&gt;. This is not merely an engineering claim; it is a profound theoretical certainty.&lt;/p&gt;
&lt;p&gt;This article explores the logical proof of the FSM's foundational nature and unveils the theoretical domain unlocked by dynamic runtime re-composition.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=13041983063545615084&quot; alt=&quot;Simple FSM for a Traffic Light&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;i-the-mathematical-core-fsm-as-the-atomic-primitive&quot;&gt;I. The Mathematical Core: FSM as the Atomic Primitive&lt;/h3&gt;
&lt;p&gt;The argument for the FSM's foundational authority rests upon two pillars of theoretical computer science: &lt;strong&gt;Optimality&lt;/strong&gt; and &lt;strong&gt;Completeness&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;1-the-principle-of-optimal-minimalism&quot;&gt;1. The Principle of Optimal Minimalism&lt;/h4&gt;
&lt;p&gt;An FSM is formally defined by the minimal set of conditions required for deterministic sequential processing:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;A = (Q, Sigma, delta, q_0, F)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Where &lt;strong&gt;&lt;em&gt;Q&lt;/em&gt;&lt;/strong&gt; is the finite set of &lt;strong&gt;States&lt;/strong&gt;, &lt;strong&gt;&lt;em&gt;Sigma&lt;/em&gt;&lt;/strong&gt; is the input &lt;strong&gt;Alphabet&lt;/strong&gt;, and &lt;strong&gt;&lt;em&gt;delta&lt;/em&gt;&lt;/strong&gt; is the &lt;strong&gt;Transition Function&lt;/strong&gt;. This minimal, rigorous structure ensures &lt;strong&gt;structural verifiability&lt;/strong&gt;—the machine can only exist in a predictable, finite set of configurations.&lt;/p&gt;
&lt;p&gt;The power of this minimalism is formalized by two foundational theorems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Kleene's Theorem (The Completeness of Sequence):&lt;/strong&gt; This theorem establishes a direct mathematical equivalence between Finite Automata, Regular Languages, and Regular Expressions:&lt;br&gt;
 &lt;strong&gt;Regular Languages&lt;/strong&gt; | &lt;strong&gt;Finite Automata&lt;/strong&gt; | &lt;strong&gt;Regular Expressions&lt;/strong&gt;&lt;br&gt;
  The FSM is mathematically complete for representing any sequential pattern or sequence-driven task. It represents the logical boundary of that entire domain.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8149454088106732129&quot; alt=&quot;Diagram showing Kleen's theory&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Myhill-Nerode Principle (The Guarantee of Efficiency):&lt;/strong&gt; This principle provides the definitive proof of efficiency. It guarantees that for any Regular Language, a &lt;strong&gt;unique, provably minimal Deterministic Finite Automaton (DFA)&lt;/strong&gt; exists.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15004595179599837846&quot; alt=&quot;Myhill-Nerode diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion on Optimality:&lt;/strong&gt; For the entire class of sequential problems, the minimal FSM (DFA) is the most compact, mathematically irreducible representation of that logic. Any other design choice is, by definition, computationally excessive. This irreducible nature solidifies the FSM's status as the &lt;strong&gt;Atomic Unit of Work&lt;/strong&gt; for control flow.&lt;/p&gt;
&lt;h4 id=&quot;2-the-universal-domain-fsm-and-turing-equivalence&quot;&gt;2. The Universal Domain: FSM and Turing Equivalence&lt;/h4&gt;
&lt;p&gt;The philosophical constraint of the pure FSM is its finiteness, preventing it from solving non-regular problems that require unbounded memory (e.g., matching L={a^n b^n}). Yet, this constraint precisely defines its &lt;strong&gt;Universal Authority&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The mathematical model for all universal computation is the &lt;strong&gt;Turing Machine (TM)&lt;/strong&gt;, which is formally defined as the minimal requirement for general computation:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Turing Machine = Finite State Control Unit + Unbounded Storage (Tape)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In any modern computational environment, the FSM is the &lt;strong&gt;necessary and sufficient&lt;/strong&gt; control component required for Turing-completeness. It is the unit that dictates the discrete decision-making and orchestrates the interaction with the unbounded memory resources of the host.&lt;/p&gt;
&lt;p&gt;The full domain of representation governed by the FSM is therefore:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;All logical expressions and behaviors conceivable by the human mind, limited only by the theoretical boundary of the Turing Machine and the practical constraints of the host hardware.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The FSM is the logical engine that, when paired with the conceptual infinity of memory, is capable of generating &lt;strong&gt;anything that exists, anything that will exist, and anything that can be imagined.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=16863048263816270055&quot; alt=&quot;Turing Machine Diagram&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Intermission&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;ii-transcending-immutability-the-theory-of-dynamic-recomposition-&quot;&gt;II. Transcending Immutability: The Theory of Dynamic Recomposition ⚛️&lt;/h3&gt;
&lt;p&gt;In traditional automata theory, the FSM's definition A = (Q, Sigma, delta, q_0, F) must remain &lt;strong&gt;immutable&lt;/strong&gt; for the duration of the machine's execution. This fixation on a static blueprint is the source of the FSM's practical limitations.&lt;/p&gt;
&lt;p&gt;We introduce the theoretical domain of the &lt;strong&gt;Dynamically Reconfigurable Finite State Machine (DRFSM)&lt;/strong&gt;. This model does not violate FSM theory, but rather introduces a higher-order component that re-defines the machine between discrete cycles.&lt;/p&gt;
&lt;h4 id=&quot;the-meta-transition-mu-redefining-the-machine&quot;&gt;The Meta-Transition (mu): Redefining the Machine&lt;/h4&gt;
&lt;p&gt;The DRFSM operates across a sequence of definitions over time T: A_0, A_1, A_2, dots.&lt;br&gt;
While the execution &lt;em&gt;at&lt;/em&gt; any given time t is a purely deterministic FSM A&lt;em&gt;t, an external function—the &lt;strong&gt;Meta-Transition (mu)&lt;/strong&gt;—governs the change &lt;em&gt;between&lt;/em&gt; cycles:&lt;br&gt;
A&lt;/em&gt;{t+1} = mu(A_t)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=7808018777889221810&quot; alt=&quot;Diagram showing evolution of FSM Definition&quot;&gt;&lt;/p&gt;
&lt;p&gt;The function mu safely manipulates the FSM's definition (the state set Q, the transitions delta, etc.) during the computational downtime between process group update calls.&lt;/p&gt;
&lt;h4 id=&quot;theoretical-impact-on-the-domain-of-representation&quot;&gt;Theoretical Impact on the Domain of Representation&lt;/h4&gt;
&lt;p&gt;This dynamic re-composition has profound implications for computational modeling:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Solving State Explosion by JIT Complexity:&lt;/strong&gt; The problem of State Explosion arises from the need to model every possible future state upfront. The DRFSM model mitigates this by allowing mu to act as a &lt;strong&gt;Complexity Filter&lt;/strong&gt;. Instead of maintaining a rigid, maximal state space Q_max, the machine only manifests the complexity required for its immediate, local context. mu dynamically grows detailed states when necessary and prunes them when not, ensuring the active state set Q_t is always minimal and optimally efficient (Myhill-Nerode).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=52390754708399786&quot; alt=&quot;Image showing the idea of state explosion vs a DRFSM&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Modeling True Structural Adaptation:&lt;/strong&gt; The DRFSM allows a system to model genuine learning and evolution of its core control logic. The system's behavior is not merely changing because its data has changed; the mu function allows the system to structurally change &lt;strong&gt;what it is capable of doing&lt;/strong&gt; in the next cycle. This capability opens the domain of systems that can fundamentally adapt their decision-making architecture in response to a dynamic environment.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=423012247727605465&quot; alt=&quot;Diagram showing meta-layer supervisory architecture&quot;&gt;&lt;/p&gt;
&lt;p&gt;Mathematicians historically avoided this domain because the academic burden of proving the validity of &lt;em&gt;every&lt;/em&gt; possible derivative FSM A_{t+1} is computationally unfeasible for a human. For a computer, however, the re-composition is computationally cheap and occurs only within controlled downtime, &lt;strong&gt;maintaining the integrity of discrete FSM theory at the moment of execution.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;iii-the-limitations-of-static-fsms-and-the-architectural-resolution&quot;&gt;III. The Limitations of Static FSMs and the Architectural Resolution&lt;/h3&gt;
&lt;p&gt;While the FSM is the ultimate atomic primitive, its conventional, static interpretation introduces structural challenges that limit its practical application in complex, real-world systems. The theoretical model of the DRFSM offers architectural solutions to transcend these limitations:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Theoretical Limitation of Static FSM &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Theoretical Solution of DRFSM/Extended Architecture&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Rigid Definitions:Definition is fixed at initialization, hindering on-the-fly system changes. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Dynamic Recomposition: Provides adaptable logic, enabling live patching and extreme behavioral variation via the mu function.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Concurrency Challenges: Struggles to maintain deterministic, thread-safe integrity during complex parallel operation. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Atomic Synchronization: Utilizes a deferred mutation model to keep concurrent modifications safe, ensuring discrete transitions.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;State Explosion: Difficulty managing hundreds or thousands of states within a single, monolithic definition. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Modular Management: Facilitates the organized execution of logic via concepts like Named FSMs and Processing Groups.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Fragile Error Handling: Lacks built-in mechanisms to recover gracefully from unexpected or invalid states. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Self-Healing Logic: Incorporates diagnostic and threshold mechanisms to autonomously prevent runaway logic and allow for fault recovery.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;By implementing a meta-layer that manages the evolution of the FSM definition, the extended architecture separates the immutable, atomic principle of the FSM from the meta-level of control—delivering the mathematical ideal of universal control with the engineering resilience required for any conceivable complexity.&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/7428/caution-mind-blowing-finite-state-machine-contained-within-nothing-but-theory</guid>
<pubDate>Mon, 17 Nov 2025 10:03:13 +0000</pubDate>
</item>
<item>
<title>A Finite State of One: Rethinking the Singleton Pattern with FSMs</title>
<link>https://coderlegion.com/7415/a-finite-state-of-one-rethinking-the-singleton-pattern-with-fsms</link>
<description>&lt;h2 id=&quot;a-finite-state-of-one-rethinking-the-singleton-pattern-with-fsms&quot;&gt;A Finite State of One: Rethinking the Singleton Pattern with FSMs&lt;/h2&gt;
&lt;p&gt;The Singleton pattern is a cornerstone of game development and application architecture, ensuring a class has only one instance and providing a global point of access. Yet, its implementation in C# can often feel like wrestling with unnecessary boilerplate—or worse, a forced, inflexible use of generics that clutters your codebase.&lt;/p&gt;
&lt;p&gt;What if your Singleton could be inherently &lt;strong&gt;self-regulating&lt;/strong&gt;, decoupling the enforcement logic from the class itself, all while giving you granular control over performance?&lt;/p&gt;
&lt;p&gt;We recently discovered an incredibly intuitive and versatile approach that achieves just this, leveraging the power of a modern Finite State Machine (FSM) framework, specifically &lt;strong&gt;TheSingularityWorkshop.FSM_API&lt;/strong&gt;, to abstract and enforce the Singleton constraint.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-pain-points-of-traditional-singletons&quot;&gt;The Pain Points of Traditional Singletons&lt;/h3&gt;
&lt;p&gt;Most C# Singletons fall into two camps, both of which introduce either bloat or manual effort:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The Boilerplate (Non-Generic):&lt;/strong&gt; Requires manual static field, private constructor, and thread-safety logic for every class.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Generic (Templated):&lt;/strong&gt; Reduces boilerplate but introduces a base class dependency, which can be seen as &quot;bloat&quot; and often complicates inheritance hierarchies.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is a quick look at the typical C# Unity implementation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class ClassicInputManager : MonoBehaviour
{
    private static ClassicInputManager _instance;

    public static ClassicInputManager Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType&amp;lt;ClassicInputManager&amp;gt;();
                if (_instance == null)
                {
                    Debug.LogError(&quot;ClassicInputManager not found in scene!&quot;);
                }
            }
            return _instance;
        }
    }

    // Other class members...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is fragile: what if two instances are accidentally placed in the scene? You have to add clumsy boilerplate to &lt;code&gt;Awake()&lt;/code&gt; or &lt;code&gt;Start()&lt;/code&gt; to destroy duplicates, and the instance check runs on every single call to &lt;code&gt;Instance&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-fsm-driven-singleton-self-healing-and-performant&quot;&gt;The FSM-Driven Singleton: Self-Healing and Performant&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;&lt;code&gt;FSM_Singleton&lt;/code&gt;&lt;/strong&gt; is an abstraction layer that wraps your target class (the actual Singleton, like a &lt;code&gt;BuildersInputManager&lt;/code&gt;) and delegates the enforcement of uniqueness to an FSM instance.&lt;/p&gt;
&lt;p&gt;By creating an FSM instance upon the target's initialization, we gain immediate access to the FSM API's core benefits: robust lifecycle management and customizable processing rates.&lt;/p&gt;
&lt;p&gt;In the example below, the &lt;code&gt;BuildersInputManager&lt;/code&gt; simply creates an &lt;code&gt;FSM_Singleton&lt;/code&gt; in its &lt;code&gt;Awake()&lt;/code&gt; method:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class BuildersInputManager : MonoBehaviour, IStateContext
{
    // ...
    void Awake()
    {
        // Establish this as a singleton, checking for duplicates every 10 update calls
        new FSM_Singleton(this, 10, &quot;Update&quot;); 
    }
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The magic lies within the &lt;code&gt;FSM_Singleton&lt;/code&gt;'s constructor and the single &quot;Operating&quot; state of its FSM definition:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class FSM_Singleton : IStateContext
{
    public FSM_Singleton(IStateContext stateContext, int processRate, string processGroup)
    {
        // 1. Create FSM Definition (if it doesn't exist)
        if(!FSM_API.Interaction.Exists(&quot;BuildersInputManager&quot;, processGroup))
        {
            FSM_API.Create.CreateFiniteStateMachine(&quot;BuildersInputManager&quot;, processRate, processGroup)
                .State(&quot;Operating&quot;, null, OnUpdateOperating, null)
                .BuildDefinition();
        }
        // 2. Create FSM Instance for the target context
        Status = FSM_API.Create.CreateInstance(&quot;BuildersInputManager&quot;, this, processGroup);
        // ...
    }

    private void OnUpdateOperating(IStateContext context)
    {
        if(context is FSM_Singleton singleton)
        {
            Enforce(singleton); // Check and remove duplicates
        }
    }

    private void Enforce(FSM_Singleton singleton)
    {
        var bucket = FSM_API.Internal.GetBucket(stateContext.Name, singleton.ProcessGroup);
        if (bucket.Instances.Count &amp;gt; 1)
        {
            RemoveRedundant(singleton, bucket);
        }
    }
    
    private static void RemoveRedundant(FSM_Singleton singleton, FSM_API.Internal.FsmBucket bucket)
    {
        for (int i = bucket.Instances.Count - 1; i &amp;gt;= 0; i--)
        {
            var instanceHandle = bucket.Instances[i];
            if (instanceHandle.Id != singleton.Status.Id)
            {
                Debug.LogWarning($&quot;Destroyed duplicate instance with ID: {instanceHandle.Id}&quot;);
                FSM_API.Interaction.DestroyInstance(instanceHandle);
            }
        }
    }
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;versatility-and-performance-decoupling-enforcement&quot;&gt;Versatility and Performance: Decoupling Enforcement&lt;/h4&gt;
&lt;p&gt;This mechanism showcases the ingenuity of &lt;strong&gt;decoupled architecture&lt;/strong&gt;. Unlike traditional Singleton implementations, where duplicate checks must occur on every static property access or during immediate object instantiation, the &lt;code&gt;FSM_Singleton&lt;/code&gt; establishes a &lt;strong&gt;self-healing contract&lt;/strong&gt;. It initiates a constant, scheduled validation loop to ensure the existence of exactly one instance.&lt;/p&gt;
&lt;p&gt;In the typical and expected scenario, the &lt;code&gt;OnUpdateOperating&lt;/code&gt; logic performs a lightning-fast API call to retrieve the instance count, instantly confirming a count of one, and then terminates its execution for that cycle. This high-performance check effectively minimizes frame-time overhead.&lt;/p&gt;
&lt;p&gt;Crucially, in the rare event that a duplicate is accidentally created, the enforcement logic will instantly &lt;strong&gt;eradicate it&lt;/strong&gt; (&lt;code&gt;DestroyInstance&lt;/code&gt;). This limits the duplicate's lifespan to the number of frames defined by the FSM's &lt;code&gt;ProcessRate&lt;/code&gt;. By setting &lt;code&gt;ProcessRate = 10&lt;/code&gt; (as in the example), we drastically reduce overhead because the resource-intensive cleanup iteration runs only periodically, yet the detection and destruction of a redundant instance is still handled automatically and asynchronously.&lt;/p&gt;
&lt;p&gt;Furthermore, the FSM framework allows for assigning this check to a specific &lt;strong&gt;Processing Group&lt;/strong&gt;, enabling advanced scheduling tactics such as running the validation only during periods of available frame time, thus prioritizing critical game logic.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;analysis-fsm-vs-classic-singleton&quot;&gt;Analysis: FSM vs. Classic Singleton&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Feature &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Classic C# Singleton (Standard Boilerplate) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;FSM_Singleton (TheSingularityWorkshop.FSM_API)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Enforcement Logic &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Scattered throughout the target class (&lt;code&gt;Awake&lt;/code&gt;/&lt;code&gt;Start&lt;/code&gt; for cleanup, static property for creation/access). &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Centralized and abstracted in the dedicated &lt;code&gt;FSM_Singleton&lt;/code&gt; class.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Duplicate Handling &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Must be manually coded for destruction; highly prone to developer error and race conditions. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Self-Healing via periodic FSM state updates (&lt;code&gt;OnUpdateOperating&lt;/code&gt;), automatically detecting and destroying duplicates.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Performance &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Enforcement or creation checks typically run every frame or on every public static &lt;code&gt;Instance&lt;/code&gt; access, leading to constant minor overhead. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Highly Configurable via &lt;code&gt;ProcessRate&lt;/code&gt; (e.g., run every 10th frame, or only on event), significantly minimizing the update overhead.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Code Style &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Requires repetitive boilerplate (static field, private constructor, lock) or forces generic base class inheritance, potentially complicating the object hierarchy. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Clean pattern implementation without unnecessary generics, relying on standard interfaces (&lt;code&gt;IStateContext&lt;/code&gt;) and a clean API wrapper.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The FSM-based approach successfully elevates the Singleton pattern beyond a rigid architectural constraint, transforming it into a &lt;strong&gt;flexible, self-regulating service&lt;/strong&gt;. This decoupled solution expertly manages its own lifecycle and performance with exceptional granularity, representing a potent abstraction that simplifies the codebase and entirely eliminates the common implementation headaches associated with managing instance uniqueness.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=10913738559640252946&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/7415/a-finite-state-of-one-rethinking-the-singleton-pattern-with-fsms</guid>
<pubDate>Sun, 16 Nov 2025 06:50:33 +0000</pubDate>
</item>
<item>
<title>10. FSM_API for Non-Coders: A Big Picture Overview (From our Documentation)</title>
<link>https://coderlegion.com/7412/10-fsmapi-for-non-coders-a-big-picture-overview-from-our-documentation</link>
<description>&lt;p&gt;We believe the most reliable software logic is logic everyone can understand.&lt;/p&gt;
&lt;p&gt;The complex systems that drive modern applications—from character AI in games to business workflows and industrial robotics—are often best articulated not by a developer, but by the subject matter experts. These experts instinctively express domain behavior as an organized set of phases and rules, often visualized as hierarchical Finite State Machines.&lt;/p&gt;
&lt;p&gt;This natural structure is the foundation of the Finite State Machine (FSM), and it is why we created this overview. FSMs are not merely a developer’s tool; they are a universal language. This guide is designed to bridge the gap, enabling your domain expertise to translate seamlessly and reliably into the design of robust, predictable, and maintainable software systems.&lt;/p&gt;
&lt;p&gt;Without any further ado:&lt;/p&gt;
&lt;h2 id=&quot;10-fsm-api-for-non-coders-a-big-picture-overview&quot;&gt;10. FSM_API for Non-Coders: A Big Picture Overview&lt;/h2&gt;
&lt;p&gt; Have you ever tried to describe a complex process to someone, like making coffee ☕ or building a LEGO castle , and found yourself saying, &quot;First you do this, &lt;em&gt;then&lt;/em&gt; if that happens, you do this other thing, &lt;em&gt;otherwise&lt;/em&gt; you do something else entirely&quot;? If so, you've already grasped the core idea behind &lt;strong&gt;Finite State Machines (FSMs)&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;At its heart, FSM_API is a powerful tool designed to make complex software behaviors predictable, organized, and easier to manage, even if you don't write code yourself. It helps turn messy, &quot;if-this-then-that&quot; logic into clear, step-by-step instructions.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-is-a-finite-state-machine-fsm-the-simple-version-&quot;&gt;What is a Finite State Machine (FSM)? (The Simple Version)&lt;/h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/TrafficLightFSM.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/TrafficLightFSM.png&quot; alt=&quot;A state machine diagram of a traffic light.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;A simple, real-world example of an FSM: a traffic light.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Imagine anything that changes its behavior based on its current situation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;traffic light&lt;/strong&gt; is either Red, Yellow, or Green. It can't be Red and Green at the same time. It changes from Green to Yellow only, not directly to Red.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;door&lt;/strong&gt; is either Closed, Opening, Open, or Closing.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;game character&lt;/strong&gt; might be Idle, Walking, Running, Jumping, or Attacking.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;An FSM is just a way to formally describe these behaviors:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;States:&lt;/strong&gt; These are the specific &quot;situations&quot; or &quot;modes&quot; an entity can be in at any given moment (like &quot;Green&quot; for a traffic light, or &quot;Walking&quot; for a character). An FSM is always in &lt;strong&gt;exactly one state&lt;/strong&gt; at a time.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transitions:&lt;/strong&gt; These are the &lt;strong&gt;rules&lt;/strong&gt; that dictate how an entity moves from one state to another (e.g., from &quot;Green&quot; to &quot;Yellow&quot; when a timer runs out, or from &quot;Walking&quot; to &quot;Jumping&quot; when the player presses the jump button).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;FSM_API helps developers build and manage these FSMs in a clear and organized way, making sure all the rules are followed and behaviors are predictable.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;how-fsm-api-helps-you-even-if-you-don-t-code-&quot;&gt;How FSM_API Helps You (Even if You Don't Code)&lt;/h3&gt;
&lt;p&gt;While FSM_API is a coding tool, its benefits directly impact anyone involved in designing or understanding the behavior of a system, like game designers, project managers, or QA testers.&lt;/p&gt;
&lt;h4 id=&quot;1-clearer-communication&quot;&gt;1. &lt;strong&gt;Clearer Communication&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/Character_AI_FSM.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/Character_AI_FSM.png&quot; alt=&quot;A flowchart of an enemy AI, showing states like Patrolling and Chasing.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;An FSM diagram like this gives the whole team a clear map of how the AI should behave.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Instead of ambiguous descriptions, an FSM provides a visual and logical map of how something behaves. Everyone on the team can look at an FSM diagram and immediately understand the flow.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; &quot;The enemy moves from 'Patrolling' to 'Chasing' when it 'sees' the player.&quot; This becomes a clear transition rule.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-fewer-bugs-amp-more-reliable-behavior&quot;&gt;2. &lt;strong&gt;Fewer Bugs &amp;amp; More Reliable Behavior&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;When behaviors are explicitly defined, it's much harder for unexpected &quot;edge cases&quot; or illogical situations to occur (like a character trying to jump while they are already dead). This leads to more stable and reliable software.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; Less time spent fixing frustrating, unpredictable issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;3-easier-to-change-and-expand&quot;&gt;3. &lt;strong&gt;Easier to Change and Expand&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Because the behavior is modular (broken into states and transitions), adding new features or changing existing ones becomes much simpler. You don't have to overhaul the entire system.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; Want to add a &quot;Stealth&quot; state to your enemy? You simply add the new state and define how to get into and out of it, without breaking the existing &quot;Patrol&quot; or &quot;Chase&quot; logic.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;4-better-performance&quot;&gt;4. &lt;strong&gt;Better Performance&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;FSM_API is built to be fast. This means your games or applications will run smoother, even when managing many complex characters or systems at once.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; A more responsive and enjoyable experience for the end-user.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;5-empowers-non-coders-the-context-connection-&quot;&gt;5. &lt;strong&gt;Empowers Non-Coders (The &quot;Context&quot; Connection)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/FSM_Context_Relationship.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
    &lt;img src=&quot;Visuals/FSM_Context_Relationship.png&quot; alt=&quot;A diagram showing the FSM as a brain controlling the game object as a body.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The FSM (the brain) contains the logic, while the Context (the body) is the actual object that performs the actions.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When a developer uses FSM_API, they link the FSM to an actual &quot;thing&quot; in your game or application (this &quot;thing&quot; is called the &lt;strong&gt;Context&lt;/strong&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example:&lt;/strong&gt; A game designer might say, &quot;When the character is in the 'Jumping' state, I want them to play the 'Jump_Anim' and add an upward force.&quot; The developer then connects the FSM's &quot;Jumping&quot; state to the &lt;strong&gt;character's script&lt;/strong&gt; (their Context) which knows how to play animations and apply force.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Benefit:&lt;/strong&gt; This clear connection means designers can specify behavior in terms of game actions, and developers can implement it precisely, using the FSM as the bridge.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;who-is-this-for-&quot;&gt;Who is This For?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Game Designers:&lt;/strong&gt; Visualize and plan complex character AI, game mechanics, and UI flows with clarity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Project Managers:&lt;/strong&gt; Understand the scope and complexity of features related to dynamic behaviors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;QA Testers:&lt;/strong&gt; Clearly define and test expected behaviors in various scenarios.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Technical Writers:&lt;/strong&gt; Document system behaviors accurately and concisely.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;FSM_API provides a common language and structure that helps bridge the gap between design and implementation, leading to more robust, understandable, and maintainable applications. We are actively working on integrating this into &lt;strong&gt;AnyApp&lt;/strong&gt;, and also preparing it for submission to the &lt;strong&gt;Unity Asset Store&lt;/strong&gt; so developers everywhere can benefit!&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;want-to-learn-more-about-development-&quot;&gt;Want to Learn More About Development?&lt;/h3&gt;
&lt;p&gt;If you're interested in learning about the coding side of things from a clear, practical perspective, we highly recommend checking out &lt;strong&gt;Tim Corey&lt;/strong&gt;. He's widely recognized as a fantastic resource for software development, and you can find his insightful content, courses, and community on his platform, &lt;strong&gt;DevForge&lt;/strong&gt;, at &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.iamtimcorey.com/&quot;&gt;iamtimcorey.com&lt;/a&gt;. &lt;/p&gt;
&lt;h3 id=&quot;resources-amp-code--2&quot;&gt;Resources &amp;amp; Code:&lt;/h3&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17272823008937591128&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/7412/10-fsmapi-for-non-coders-a-big-picture-overview-from-our-documentation</guid>
<pubDate>Sat, 15 Nov 2025 22:14:52 +0000</pubDate>
</item>
<item>
<title>03. Getting Started with FSM_API in Pure C# (From our Documentation)</title>
<link>https://coderlegion.com/7375/03-getting-started-with-fsmapi-in-pure-c-from-our-documentation</link>
<description>&lt;p&gt;Previously we published a deep dive included with our documentation in our FSM_API nuget package for our truly unique feature, runtime recomposition/definition of our FSMs.  In this article we are sharing our document on Getting started in pure c#.  We showed you the power, now let us show you how easy it is to start using our 45kb API.  Embrace the pure digital power!&lt;/p&gt;
&lt;p&gt;Without further rambling:&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;03. Getting Started with FSM_API in Pure C#&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; Use FSM_API with pure C# classes — completely decoupled from Unity — for backend logic, simulations, AI, networking, or any state-based system.&lt;/p&gt;
&lt;p&gt;This guide shows how to use FSM_API in non-Unity environments (console, services, backends, robotics, etc.) with clean, minimal dependencies.&lt;/p&gt;
&lt;h3 id=&quot;install-fsm-api-into-your-c-project-using-nuget-package&quot;&gt;Install FSM_API into your c# project using Nuget Package&lt;/h3&gt;
&lt;p&gt;Within your preferred IDE find FSM_API within the NuGet Package Manager and click install.&lt;/p&gt;
&lt;h3 id=&quot;install-fsm-api-into-your-project-using-net-cli-&quot;&gt;Install FSM_API into your project using .NET CLI:&lt;/h3&gt;
&lt;p&gt;dotnet add package TheSingularityWorkshop.FSM_API&lt;/p&gt;
&lt;h3 id=&quot;integrate-the-api-into-your-project&quot;&gt;Integrate the API into your project&lt;/h3&gt;
&lt;p&gt;Integrating the API with any c# application is foremost establishing the heartbeat or cadence of when your FSMs operate.  &lt;/p&gt;
&lt;p&gt;Example c#:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;FSM_API.Interaction.Update(&quot;YourProcessingGroupName&quot;);//Updates all FSMs registered to this processing group.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;consider the simplest integration possible, a console application as shown below:&lt;/p&gt;
&lt;p&gt;Example c#:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using TheSingularityWorkshop.FSM_API;

//Define the application context
SimpleDemoContext appContext = new SimpleDemoContext();

//now we enter a loop which will run indefinitely until the handle becomes invalid.
do
{
    //We make this update call which will then update the app fsm.  The app's
    FSM_API.Interaction.Update(&quot;Main&quot;);
} while (appContext.IsValid);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To help with this understanding we will describe an example below along with additional samples which are available on our samples repo.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;Samples Repo&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;what-this-example-will-demonstrate&quot;&gt;What This Example Will Demonstrate&lt;/h3&gt;
&lt;p&gt;We’ll simulate a basic character health lifecycle using FSM_API — all in &lt;strong&gt;pure C#&lt;/strong&gt;. This example is useful for understanding how FSM_API integrates into any standard C# application, offering the same benefits as in Unity.&lt;/p&gt;
&lt;p&gt;This example illustrates:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to define and link FSMs to standard C# classes as their context.&lt;/li&gt;
&lt;li&gt;How a game character transitions through health-related states (&lt;code&gt;Healthy&lt;/code&gt;, &lt;code&gt;Damaged&lt;/code&gt;, &lt;code&gt;Critically Injured&lt;/code&gt;, &lt;code&gt;Dead&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;How FSM_API makes these transitions declarative, clean, and maintainable.&lt;/li&gt;
&lt;li&gt;How to manually control the &quot;ticking&quot; of FSMs without relying on a game engine's built-in loop.&lt;/li&gt;
&lt;li&gt;How FSMs can be revived and continue operating even after simulated &quot;death.&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;simulation-flow&quot;&gt;Simulation Flow&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;The player starts in the &lt;strong&gt;Healthy&lt;/strong&gt; state.&lt;/li&gt;
&lt;li&gt;Over several ticks, they take damage, triggering transitions to:&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Damaged&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Critically Injured&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dead&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;After death, a revive command is issued.&lt;/li&gt;
&lt;li&gt;Health is restored.&lt;/li&gt;
&lt;li&gt;The FSM automatically transitions back to &lt;strong&gt;Healthy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All output is printed to the console to simulate animation, audio, and event feedback — ideal for unit tests or backend game systems.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-step-1-define-your-pure-c-context&quot;&gt;✅ Step 1: Define Your Pure C# Context&lt;/h3&gt;
&lt;p&gt;Create a standard C# class to represent the &quot;thing&quot; your FSM will manage — like a character, connection, pipeline, or subsystem. This class will hold the data and methods that your FSM's states will interact with.&lt;/p&gt;
&lt;p&gt;It must implement the &lt;code&gt;IStateContext&lt;/code&gt; interface. Recall from the &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;01_Core_Concepts.md&quot;&gt;01. Core Concepts: Your Guide to FSM_API&lt;/a&gt;&lt;/strong&gt; that &lt;code&gt;IStateContext&lt;/code&gt; requires &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;IsValid&lt;/code&gt; properties.&lt;/p&gt;
&lt;h4 id=&quot;example-gamecharactercontext-cs&quot;&gt;Example: &lt;code&gt;GameCharacterContext.cs&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Example c#:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using TheSingularityWorkshop.FSM_API;

public class GameCharacterContext : IStateContext
{
    private float _currentHealth = 100f;
    private int _currentAmmo = 10;
    private float _moveSpeed = 5f;
    private bool _isActive = true;
    private bool _isReviveCommandIssued = false;

    public float CurrentHealth =&amp;gt; _currentHealth;
    public int CurrentAmmo =&amp;gt; _currentAmmo;
    public float MoveSpeed =&amp;gt; _moveSpeed;

    // IStateContext Properties
    public string Name { get; set; }
    public bool IsValid =&amp;gt; _isActive; // FSM_API uses this to know if the context is still relevant

    public GameCharacterContext(string name)
    {
        Name = name;
        Console.WriteLine($&quot;{Name} context created.&quot;);
    }

    // Methods that FSM states will call to interact with this context
    public void TakeDamage(float amount)
    {
        _currentHealth -= amount;
        Console.WriteLine($&quot;{Name} took {amount} damage. Health: {CurrentHealth}&quot;);
    }

    public void SetActive(bool active)
    {
        _isActive = active;
        Console.WriteLine($&quot;{Name} active status set to {_isActive}.&quot;);
    }

    public void RestoreHealth(float amount)
    {
        _currentHealth += amount;
        if (_currentHealth &amp;gt; 100f) _currentHealth = 100f;
        Console.WriteLine($&quot;{Name} health restored to {CurrentHealth}.&quot;);
    }

    public void SimulateMovement()
    {
        Console.WriteLine($&quot;{Name} is moving at speed {MoveSpeed}.&quot;);
    }

    public void PlaySound(string soundName)
    {
        Console.WriteLine($&quot;{Name} playing sound: {soundName}&quot;);
    }

    // Methods for transition conditions
    public void IssueReviveCommand() =&amp;gt; _isReviveCommandIssued = true;
    public void ClearReviveCommand() =&amp;gt; _isReviveCommandIssued = false;
    public bool IsReviveCommandPending =&amp;gt; _isReviveCommandIssued;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-step-2-define-and-create-the-fsm&quot;&gt;✅ Step 2: Define and Create the FSM&lt;/h3&gt;
&lt;p&gt;With your context ready, you can now define your FSM using &lt;code&gt;FSM_API.CreateFiniteStateMachine()&lt;/code&gt; and its fluent builder pattern. Then, create an instance of that FSM, linking it to your &lt;code&gt;GameCharacterContext&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&quot;example-purecsharpgameloop-cs&quot;&gt;Example: &lt;code&gt;PureCSharpGameLoop.cs&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/Character_Health_FSM.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;img src=&quot;Visuals/Character_Health_FSM.png&quot; alt=&quot;A flowchart of the Character Health FSM showing states and transitions.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br&gt;
&lt;em&gt;A flowchart of the Character Health FSM showing states and transitions.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;This class will set up our FSM definition and manage the FSM instance within a simulated game loop.&lt;/p&gt;
&lt;p&gt;Example c#:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using TheSingularityWorkshop.FSM_API;

public class PureCSharpGameLoop
{
    private FSMHandle characterHealthFSM;
    private GameCharacterContext playerCharacter;

    public void SetupGame()
    {
        playerCharacter = new GameCharacterContext(&quot;Hero&quot;);

        // Define the FSM blueprint if it doesn't already exist.
        // The FSM definition is reusable across multiple instances.
        if (!FSM_API.Exists(&quot;CharacterHealthFSM&quot;))
        {
            FSM_API.CreateFiniteStateMachine(&quot;CharacterHealthFSM&quot;, processRate: 1, processingGroup: &quot;GameLogic&quot;)
                .State(&quot;Healthy&quot;,
                    onEnter: ctx =&amp;gt; ((GameCharacterContext)ctx).PlaySound(&quot;HappyTune&quot;),
                    onUpdate: ctx =&amp;gt; 
                        Console.WriteLine($&quot;{ctx.Name} is Healthy. Health: {((GameCharacterContext)ctx).CurrentHealth}&quot;),
                    onExit: ctx =&amp;gt; ((GameCharacterContext)ctx).PlaySound(&quot;SadTune&quot;))
                .State(&quot;Damaged&quot;,
                    onEnter: ctx =&amp;gt; ((GameCharacterContext)ctx).PlaySound(&quot;OuchSound&quot;),
                    onUpdate: ctx =&amp;gt; 
                        Console.WriteLine($&quot;{ctx.Name} is Damaged. Health: {((GameCharacterContext)ctx).CurrentHealth}&quot;))
                .State(&quot;CriticallyInjured&quot;,
                    onEnter: ctx =&amp;gt; ((GameCharacterContext)ctx).PlaySound(&quot;WarningAlarm&quot;),
                    onUpdate: ctx =&amp;gt; Console.WriteLine($&quot;{ctx.Name} is Critically Injured!&quot;))
                .State(&quot;Dead&quot;,
                    onEnter: ctx =&amp;gt; ((GameCharacterContext)ctx).PlaySound(&quot;DeathRattle&quot;),
                    onUpdate: ctx =&amp;gt; Console.WriteLine($&quot;{ctx.Name} is Dead.&quot;),
                    onExit: ctx =&amp;gt; ((GameCharacterContext)ctx).ClearReviveCommand())
                .WithInitialState(&quot;Healthy&quot;)
                .Transition(&quot;Healthy&quot;, &quot;Damaged&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).CurrentHealth &amp;lt;= 75 &amp;amp;&amp;amp; ((GameCharacterContext)ctx).CurrentHealth &amp;gt; 25)
                .Transition(&quot;Damaged&quot;, &quot;Healthy&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).CurrentHealth &amp;gt; 75)
                .Transition(&quot;Damaged&quot;, &quot;CriticallyInjured&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).CurrentHealth &amp;lt;= 25 &amp;amp;&amp;amp; ((GameCharacterContext)ctx).CurrentHealth &amp;gt; 0)
                .Transition(&quot;CriticallyInjured&quot;, &quot;Damaged&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).CurrentHealth &amp;gt; 25 &amp;amp;&amp;amp; ((GameCharacterContext)ctx).CurrentHealth &amp;lt;= 75)
                .Transition(&quot;CriticallyInjured&quot;, &quot;Dead&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).CurrentHealth &amp;lt;= 0)
                .Transition(&quot;Dead&quot;, &quot;Healthy&quot;, ctx =&amp;gt; 
                    ((GameCharacterContext)ctx).IsReviveCommandPending &amp;amp;&amp;amp; ((GameCharacterContext)ctx).CurrentHealth &amp;gt; 0)
                .BuildDefinition();
        }

        // Create a live FSM instance, associating it with our playerCharacter context.
        characterHealthFSM = FSM_API.CreateInstance(&quot;CharacterHealthFSM&quot;, playerCharacter);
        Console.WriteLine($&quot;FSM for {playerCharacter.Name} initialized to state: {characterHealthFSM.CurrentState}&quot;);
    }

    // Call this method from your main application loop to update the FSMs
    public void UpdateGameLogic() =&amp;gt; FSM_API.Update(&quot;GameLogic&quot;);

    // Helper methods for accessing character and FSM state
    public GameCharacterContext GetPlayerCharacter() =&amp;gt; playerCharacter;
    public string GetCharacterFSMState() =&amp;gt; characterHealthFSM.CurrentState;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-step-3-manual-update-loop&quot;&gt;✅ Step 3: Manual Update Loop&lt;/h3&gt;
&lt;p&gt;Since you don’t have an engine's &lt;code&gt;Update()&lt;/code&gt; or &lt;code&gt;FixedUpdate()&lt;/code&gt; loop, you'll explicitly &quot;tick&quot; the FSMs yourself from your main application loop or a dedicated manager. You'll call &lt;code&gt;FSM_API.Update()&lt;/code&gt; for the processing group you defined.&lt;/p&gt;
&lt;h4 id=&quot;example-program-cs-main-application-entry-point-&quot;&gt;Example: &lt;code&gt;Program.cs&lt;/code&gt; (Main Application Entry Point)&lt;/h4&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;Visuals/Simulation_Timeline.png&quot; target=&quot;_blank&quot;&gt;&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;img src=&quot;Visuals/Simulation_Timeline.png&quot; alt=&quot;A timeline of the 20-tick simulation showing key events and state changes.&quot; height=&quot;200&quot; style=&quot;display: block;&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br&gt;
&lt;em&gt;A timeline of the 20-tick simulation showing key events and state changes.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;Example c#:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;using System;
using System.Threading; // For Thread.Sleep

public class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine(&quot;--- Starting Pure C# FSM Demo ---&quot;);

        var game = new PureCSharpGameLoop();
        game.SetupGame();
        var player = game.GetPlayerCharacter();

        for (int i = 0; i &amp;lt; 20; i++) // Simulate 20 game ticks
        {
            Console.WriteLine($&quot;\n--- Tick {i + 1} ---&quot;);

            // Simulate events that affect the character's health
            if (i == 2) player.TakeDamage(30);   // Health: 100 -&amp;gt; 70 (Healthy -&amp;gt; Damaged)
            if (i == 5) player.TakeDamage(20);   // Health: 70 -&amp;gt; 50 (Still Damaged)
            if (i == 8) player.TakeDamage(30);   // Health: 50 -&amp;gt; 20 (Damaged -&amp;gt; Critically Injured)
            if (i == 10) player.TakeDamage(20);  // Health: 20 -&amp;gt; 0 (Critically Injured -&amp;gt; Dead)
            if (i == 12) player.IssueReviveCommand(); // Issue revive command
            if (i == 13) player.RestoreHealth(100);    // Restore health, FSM should transition Dead -&amp;gt; Healthy

            // Advance the FSMs in the &quot;GameLogic&quot; processing group
            game.UpdateGameLogic();

            Console.WriteLine($&quot;Current FSM State: {game.GetCharacterFSMState()}&quot;);
            Thread.Sleep(500); // Optional: pause for half a second to observe output
        }

        Console.WriteLine(&quot;\n--- FSM Demo Finished ---&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;running-the-example&quot;&gt;Running the Example&lt;/h3&gt;
&lt;p&gt;To run this pure C# FSM example:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create a Console App Project&lt;/strong&gt; in your preferred IDE (e.g., Visual Studio, VS Code with C# extension).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add FSM_API Reference:&lt;/strong&gt;&lt;ul&gt;
&lt;li&gt;If FSM_API is available on NuGet, add it via the NuGet Package Manager.&lt;/li&gt;
&lt;li&gt;Otherwise, manually add a reference to the &lt;code&gt;TheSingularityWorkshop.FSM_API.dll&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add Code Files:&lt;/strong&gt;&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;GameCharacterContext.cs&lt;/code&gt; and paste the code from Step 1.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;PureCSharpGameLoop.cs&lt;/code&gt; and paste the code from Step 2.&lt;/li&gt;
&lt;li&gt;Replace the content of &lt;code&gt;Program.cs&lt;/code&gt; with the code from Step 3.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Run the App&lt;/strong&gt; and observe the FSM transitions and console output, which will show your character moving through different health states.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;-summary&quot;&gt;✅ Summary&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;FSM_API works seamlessly outside of Unity and other game engines, providing a powerful FSM solution for any pure C# application.&lt;/li&gt;
&lt;li&gt;You define your application's data models or entities as classes that implement the &lt;strong&gt;&lt;code&gt;IStateContext&lt;/code&gt;&lt;/strong&gt; interface.&lt;/li&gt;
&lt;li&gt;FSM definition and instantiation logic remain consistent with Unity usage, using &lt;code&gt;FSM_API.CreateFiniteStateMachine()&lt;/code&gt; and &lt;code&gt;FSM_API.CreateInstance()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You gain explicit control over when FSMs process their logic by calling &lt;code&gt;FSM_API.Update(&quot;YourGroupName&quot;)&lt;/code&gt; from your application's main loop or scheduler.&lt;/li&gt;
&lt;li&gt;This makes FSM_API an ideal choice for server-side logic, complex simulations, AI systems, backend services, or custom game engines where you need robust and decoupled state management.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;hr&gt;
&lt;h4 id=&quot;support-us&quot;&gt;Support Us&lt;/h4&gt;
&lt;p&gt;If you find this project useful, you can support its development through PayPal.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;&lt;strong&gt;Donate via PayPal&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;useful-links&quot;&gt;Useful Links&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;NuGet Package:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;TrentBest/FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;License:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://opensource.org/licenses/MIT&quot;&gt;MIT License&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/tools/behavior-ai/the-singularity-workshop-fsm-api-advanced-332450&quot;&gt;Advanced Integration On Unity Asset Store!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Basic Integration is pending updates on Marketing content.&lt;hr&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;brought-to-you-by&quot;&gt;Brought to you by&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Singularity Workshop&lt;/strong&gt; – Tools for the curious, the bold, and the systemically inclined.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl6tdvgg73ixyj0m0kuf.png&quot; alt=&quot;The image depicts a futuristic, sci-fi landscape dominated by glowing circuitry. A large, stylized Patreon logo hovers in the dark, starry sky above a radiant, eye-like sphere. This sphere pulses with vibrant, multicolored light, casting a brilliant glow onto the digital terrain below. The ground is a vast circuit board, with rivers of glowing orange and blue energy flowing along intricate pathways. Small, button-like structures on the surface emit soft light. The overall scene feels alive and dynamic, suggesting a powerful, almost magical, connection between technology and consciousness, with the Patreon logo at the center of it all.&quot;&gt;&lt;br&gt;
Because state shouldn’t be a mess.&lt;/p&gt;
&lt;hr&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/7375/03-getting-started-with-fsmapi-in-pure-c-from-our-documentation</guid>
<pubDate>Fri, 14 Nov 2025 22:19:58 +0000</pubDate>
</item>
<item>
<title>06_FSM_Modifier Deep Dive: Modifying Your FSMs at Runtime (From our Documentation)</title>
<link>https://coderlegion.com/7359/06fsmmodifier-deep-dive-modifying-your-fsms-at-runtime-from-our-documentation</link>
<description>&lt;h3 id=&quot;the-fsm-api-advantage-runtime-modification-technology&quot;&gt;The FSM_API Advantage: Runtime Modification Technology&lt;/h3&gt;
&lt;p&gt;What sets the FSM_API apart is our &lt;strong&gt;FSMModifier technology&lt;/strong&gt;, which allows for the &lt;strong&gt;dynamic reconstitution or definition of your Finite State Machines (FSMs) during runtime&lt;/strong&gt;. No other FSM implementation offers this level of dynamic control over an FSM's blueprint after creation.&lt;/p&gt;
&lt;p&gt;We believe in providing the deepest, most robust tools while allowing you to engage only as far as you need. We've done the deep theoretical work so you don't have to.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;06-fsmmodifier-deep-dive-modifying-your-fsms-at-runtime&quot;&gt;06. FSMModifier Deep Dive: Modifying Your FSMs at Runtime&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;FSMModifier&lt;/strong&gt; provides advanced capabilities to &lt;strong&gt;dynamically alter the blueprint (definition) of your Finite State Machines at runtime&lt;/strong&gt;. This allows for highly &lt;strong&gt;adaptive behaviors&lt;/strong&gt;, hot-swappable logic, or configuration changes without rebuilding your application.&lt;/p&gt;
&lt;p&gt;While the &lt;strong&gt;FSMBuilder&lt;/strong&gt; is used to initially design and build an FSM's definition, the &lt;strong&gt;FSMModifier&lt;/strong&gt; allows you to &lt;strong&gt;change that definition after it has been created and registered&lt;/strong&gt; with &lt;code&gt;FSM_API&lt;/code&gt;. This is a powerful feature for scenarios requiring:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Adaptive AI:&lt;/strong&gt; Changing an enemy's behavior patterns on the fly (e.g., learning new attacks, adapting to player strategies).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic UI:&lt;/strong&gt; Adding or removing navigation paths or UI states based on user unlocks or content downloads.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hot Reloading:&lt;/strong&gt; Modifying FSM logic in a live environment (e.g., development tools for rapid iteration).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A/B Testing:&lt;/strong&gt; Dynamically switching between different FSM behaviors for experimentation.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;table-of-contents-disabled-for-this-article-&quot;&gt;Table of Contents (&lt;em&gt;Disabled for this article&lt;/em&gt;)&lt;/h3&gt;
&lt;p&gt;0.  Introduction to FSM_API&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Core Concepts: Your Guide to FSM_API&lt;/li&gt;
&lt;li&gt;Getting Started with C# (Non-Unity)&lt;/li&gt;
&lt;li&gt;FSMBuilder Deep Dive: Building Your FSMs&lt;/li&gt;
&lt;li&gt;Understanding and Implementing Your Context (IStateContext)&lt;/li&gt;
&lt;li&gt;Robust Error Handling: Cascading Degradation System&lt;/li&gt;
&lt;li&gt;FSMModifier Deep Dive&lt;/li&gt;
&lt;li&gt;Performance Tips &amp;amp; Best Practices&lt;/li&gt;
&lt;li&gt;Common Use Cases &amp;amp; Examples&lt;/li&gt;
&lt;li&gt;FSM_API for Non-Coders: A Big Picture Overview&lt;/li&gt;
&lt;li&gt;Frequently Asked Questions (FAQ)&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;accessing-and-using-the-fsmmodifier&quot;&gt;Accessing and Using the FSMModifier&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;FSMModifier&lt;/code&gt; is an internal class, so you can't create it directly. Instead, you access its functionality through a set of public, static helper methods on &lt;code&gt;FSM_API.Interaction&lt;/code&gt;. These methods are designed to simplify common modification tasks like adding or removing states and transitions.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;FSMModifier&lt;/code&gt; uses a &lt;strong&gt;fluent API pattern&lt;/strong&gt; where you first &lt;strong&gt;stage the changes&lt;/strong&gt; you want to make and then apply them with a single &lt;code&gt;ModifyDefinition()&lt;/code&gt; call. All changes are &lt;strong&gt;batched and applied sequentially&lt;/strong&gt; when &lt;code&gt;ModifyDefinition()&lt;/code&gt; is called, making the process safe and predictable.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;fsmmodifier-methods-altering-the-blueprint&quot;&gt;FSMModifier Methods: Altering the Blueprint&lt;/h3&gt;
&lt;p&gt;All the methods below are called on an instance of the &lt;strong&gt;FSMModifier&lt;/strong&gt; class. You get this instance by calling a public method on &lt;code&gt;FSM_API.Interaction&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&quot;staging-changes-with-with-and-without-&quot;&gt;Staging Changes with With... and Without...&lt;/h4&gt;
&lt;h5 id=&quot;withstate-adding-a-new-state&quot;&gt;&lt;code&gt;WithState()&lt;/code&gt;: Adding a New State&lt;/h5&gt;
&lt;p&gt;This method adds a new state to an existing FSM definition. If a state with the given name already exists, the operation is &lt;strong&gt;ignored&lt;/strong&gt;. Use &lt;code&gt;WithModifiedState()&lt;/code&gt; to change an existing state.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FSM_API.Interaction.AddStateToFSM(
    &quot;PlayerFSM&quot;,
    &quot;SpecialAttack&quot;,
    onEnter: ctx =&amp;gt; Console.WriteLine(&quot;Prepare special attack!&quot;),
    onUpdate: ctx =&amp;gt; Console.WriteLine(&quot;Execute special attack.&quot;),
    onExit: ctx =&amp;gt; Console.WriteLine(&quot;Cleanup after special attack.&quot;)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;withmodifiedstate-updating-an-existing-state&quot;&gt;&lt;code&gt;WithModifiedState()&lt;/code&gt;: Updating an Existing State&lt;/h5&gt;
&lt;p&gt;This method modifies the actions (&lt;code&gt;onEnter&lt;/code&gt;, &lt;code&gt;onUpdate&lt;/code&gt;, and &lt;code&gt;onExit&lt;/code&gt;) of a state that is already part of the FSM blueprint. If the state doesn't exist, the operation is &lt;strong&gt;ignored&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Change the &quot;Idle&quot; state's behavior
FSM_API.Interaction.ModifyState(
    &quot;PlayerFSM&quot;,
    &quot;Idle&quot;,
    onEnter: ctx =&amp;gt; Console.WriteLine(&quot;Entered a NEW and improved Idle state.&quot;),
    onUpdate: null, // You can pass null to remove an action
    onExit: ctx =&amp;gt; Console.WriteLine(&quot;Exiting new Idle state.&quot;)
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;withoutstate-removing-a-state&quot;&gt;&lt;code&gt;WithoutState()&lt;/code&gt;: Removing a State&lt;/h5&gt;
&lt;p&gt;This method stages a state for removal from the FSM definition.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Remove a state and transition all instances to &quot;InitialState&quot;
FSM_API.Interaction.RemoveStateFromFSM(&quot;PlayerFSM&quot;, &quot;Dead&quot;, null);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; When a state is removed, any active &lt;strong&gt;FSMHandle&lt;/strong&gt; instances currently in that state will be &lt;strong&gt;immediately transitioned&lt;/strong&gt; to a specified &lt;code&gt;fallbackStateName&lt;/code&gt;. If you pass &lt;strong&gt;null&lt;/strong&gt; or an empty string for the fallback, instances will automatically transition to the FSM's &lt;strong&gt;InitialState&lt;/strong&gt;. The &lt;code&gt;OnExit&lt;/code&gt; action of the removed state will be executed for these instances.&lt;/p&gt;
&lt;h5 id=&quot;withtransition-creating-a-new-path&quot;&gt;&lt;code&gt;WithTransition()&lt;/code&gt;: Creating a New Path&lt;/h5&gt;
&lt;p&gt;This method adds a new transition rule between two states. If the transition already exists, the operation is &lt;strong&gt;ignored&lt;/strong&gt;. Use &lt;code&gt;WithModifiedTransition()&lt;/code&gt; to change an existing one.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Add a new transition from &quot;Idle&quot; to &quot;Sleeping&quot;
FSM_API.Interaction.AddTransition(
    &quot;PlayerFSM&quot;,
    &quot;Idle&quot;,
    &quot;Sleeping&quot;,
    ctx =&amp;gt; ((PlayerContext)ctx).IsTired() &amp;amp;&amp;amp; DateTime.Now.Hour &amp;gt; 21
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;withmodifiedtransition-updating-a-transition&quot;&gt;&lt;code&gt;WithModifiedTransition()&lt;/code&gt;: Updating a Transition&lt;/h5&gt;
&lt;p&gt;This method updates the condition of an existing transition between two states. If the transition doesn't exist, the operation is &lt;strong&gt;ignored&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Change the condition for the &quot;Damaged&quot; -&amp;gt; &quot;CriticallyInjured&quot; transition
FSM_API.Interaction.ModifyTransition(
    &quot;PlayerFSM&quot;,
    &quot;Damaged&quot;,
    &quot;CriticallyInjured&quot;,
    ctx =&amp;gt; ((CharacterContext)ctx).Health &amp;lt;= 10 // Change from 25 to 10
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;withouttransition-blocking-a-path&quot;&gt;&lt;code&gt;WithoutTransition()&lt;/code&gt;: Blocking a Path&lt;/h5&gt;
&lt;p&gt;This method removes a specific transition rule. It requires the &lt;code&gt;fromState&lt;/code&gt; and &lt;code&gt;toState&lt;/code&gt; names to uniquely identify the transition.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;C# Example:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Remove the transition from &quot;Running&quot; to &quot;Jumping&quot;
FSM_API.Interaction.RemoveTransition(&quot;PlayerFSM&quot;, &quot;Running&quot;, &quot;Jumping&quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;manipulating-live-fsm-instances-fsmhandle-&quot;&gt;Manipulating Live FSM Instances (FSMHandle)&lt;/h3&gt;
&lt;p&gt;While &lt;strong&gt;FSMModifier&lt;/strong&gt; changes the FSM &lt;strong&gt;blueprint&lt;/strong&gt;, the &lt;strong&gt;FSMHandle&lt;/strong&gt; provides methods to directly influence individual, &lt;strong&gt;live FSMHandle instances&lt;/strong&gt; at runtime. These operations &lt;strong&gt;do not alter&lt;/strong&gt; the underlying FSM definition.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TransitionTo()&lt;/code&gt;: Forces an &lt;strong&gt;FSMHandle&lt;/strong&gt; instance to immediately transition to a specified state, bypassing any conditions. This is useful for debug commands or for recovering from an error state.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ResetFSMInstance()&lt;/code&gt;: Resets the FSM instance to its &lt;strong&gt;initial state&lt;/strong&gt;, as defined in its blueprint.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;EvaluateConditions()&lt;/code&gt;: Manually checks all transition rules from the current state. This is especially useful for FSMs with a &lt;code&gt;ProcessRate&lt;/code&gt; of 0, which do not update automatically.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DestroyHandle()&lt;/code&gt;: &lt;strong&gt;Shuts down this FSM instance&lt;/strong&gt;, removes it from the API's internal system, and calls the &lt;code&gt;OnExit&lt;/code&gt; action of its current state. This is a crucial cleanup step for any live instance that is no longer needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;important-considerations-and-best-practices&quot;&gt;Important Considerations and Best Practices&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Affects All Instances:&lt;/strong&gt; Remember that changes made with &lt;strong&gt;FSMModifier&lt;/strong&gt; affect the &lt;strong&gt;shared blueprint&lt;/strong&gt;. All active &lt;strong&gt;FSMHandle&lt;/strong&gt; instances created from that blueprint will immediately use the new states, transitions, and properties on their next update cycle.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Atomicity:&lt;/strong&gt; The &lt;strong&gt;FSMModifier stages changes&lt;/strong&gt; and applies them all at once when &lt;code&gt;ModifyDefinition()&lt;/code&gt; is called. This is a robust design that prevents partial or inconsistent changes from corrupting the FSM blueprint.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State Removal is Handled Gracefully:&lt;/strong&gt; The API will automatically handle instances in a removed state by transitioning them to a fallback state, ensuring your application doesn't crash or get stuck in an invalid state.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h4 id=&quot;support-us-1&quot;&gt;Support Us&lt;/h4&gt;
&lt;p&gt;If you find this project useful, you can support its development through PayPal.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;&lt;strong&gt;Donate via PayPal&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;useful-links-1&quot;&gt;Useful Links&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;NuGet Package:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;TrentBest/FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;License:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://opensource.org/licenses/MIT&quot;&gt;MIT License&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/tools/behavior-ai/the-singularity-workshop-fsm-api-advanced-332450&quot;&gt;Advanced Integration On Unity Asset Store!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Basic Integration is pending updates on Marketing content.&lt;hr&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;brought-to-you-by-1&quot;&gt;Brought to you by&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Singularity Workshop&lt;/strong&gt; – Tools for the curious, the bold, and the systemically inclined.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl6tdvgg73ixyj0m0kuf.png&quot; alt=&quot;The image depicts a futuristic, sci-fi landscape dominated by glowing circuitry. A large, stylized Patreon logo hovers in the dark, starry sky above a radiant, eye-like sphere. This sphere pulses with vibrant, multicolored light, casting a brilliant glow onto the digital terrain below. The ground is a vast circuit board, with rivers of glowing orange and blue energy flowing along intricate pathways. Small, button-like structures on the surface emit soft light. The overall scene feels alive and dynamic, suggesting a powerful, almost magical, connection between technology and consciousness, with the Patreon logo at the center of it all.&quot;&gt;&lt;br&gt;
Because state shouldn’t be a mess.&lt;/p&gt;
&lt;hr&gt;
</description>
<category>C#</category>
<guid isPermaLink="true">https://coderlegion.com/7359/06fsmmodifier-deep-dive-modifying-your-fsms-at-runtime-from-our-documentation</guid>
<pubDate>Fri, 14 Nov 2025 17:46:04 +0000</pubDate>
</item>
<item>
<title>Finite State Machines - the Universal Unit of Work</title>
<link>https://coderlegion.com/7034/finite-state-machines-the-universal-unit-of-work</link>
<description>&lt;h2 id=&quot;escaping-boolean-hell-why-your-state-machine-needs-to-be-data-driven&quot;&gt;Escaping Boolean Hell: Why Your State Machine Needs to be Data-Driven&lt;/h2&gt;
&lt;p&gt;We've all been there: a simple boolean flag here, a nested &lt;code&gt;if&lt;/code&gt; statement there. It seems harmless at first, but soon your codebase is a tangled mess of conditional logic.&lt;/p&gt;
&lt;p&gt;Let's take the humble &lt;strong&gt;Door&lt;/strong&gt; class. It can be opened and closed. Easy, right?&lt;/p&gt;
&lt;h4 id=&quot;the-simple-intuitive-code&quot;&gt;The Simple, Intuitive Code&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Door
{
    public bool IsOpen { get; set; } = false;

    public void Open()
    {
        IsOpen = true;
        Console.WriteLine(&quot;The door is now open.&quot;);
    }

    public void Close()
    {
        IsOpen = false;
        Console.WriteLine(&quot;The door is now closed.&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;the-inevitable-complexity-creep&quot;&gt;The Inevitable Complexity Creep&lt;/h4&gt;
&lt;p&gt;In the wild, the simple, intuitive code you first wrote quickly starts to &lt;strong&gt;smell&lt;/strong&gt;. The moment we try to add a new feature, such as a &lt;strong&gt;lock&lt;/strong&gt;, our elegant two-state object becomes a mess of conditional logic.&lt;/p&gt;
&lt;p&gt;To accommodate the &quot;locked&quot; state, we add a new boolean flag, &lt;code&gt;IsLocked&lt;/code&gt;, and then we must modify all existing methods to account for it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Door
{
    public bool IsOpen { get; set; } = false;
    public bool IsLocked = false; // We added this!

    public void Open()
    {
        if (!IsLocked) // We modified this!
        {
            IsOpen = true;
            Console.WriteLine(&quot;The door is now open.&quot;);
        }
        else
        {
            Console.WriteLine(&quot;The door is locked and cannot be opened.&quot;);
        }
    }

    public void Close()
    {
        IsOpen = false;
        Console.WriteLine(&quot;The door is now closed.&quot;);
    }

    public void Lock() // We added this!
    {
        IsLocked = true;
        Console.WriteLine(&quot;The door is now locked.&quot;);
    }

    public void Unlock() // We added this!
    {
        IsLocked = false;
        Console.WriteLine(&quot;The door is now unlocked.&quot;);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What about a &lt;strong&gt;Broken&lt;/strong&gt; state? Or a &lt;strong&gt;Sliding&lt;/strong&gt; door? Or a &lt;strong&gt;RollUp&lt;/strong&gt; door? We can approximate these with more booleans, but each new addition requires us to go back and add more and more &lt;code&gt;if/else&lt;/code&gt; statements to &lt;em&gt;every&lt;/em&gt; method. It’s not &lt;strong&gt;scalable&lt;/strong&gt;, it’s &lt;strong&gt;brittle&lt;/strong&gt;, and it’s full of &lt;strong&gt;boilerplate&lt;/strong&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Pros &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Cons&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Simple and quick to implement for basic cases. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Tight Coupling&lt;/strong&gt;: Logic is tied directly to a single object.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;No external dependencies or abstractions. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Boilerplate&lt;/strong&gt;: &lt;code&gt;if/else&lt;/code&gt; checks for every state change.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Difficult to Scale&lt;/strong&gt;: Adding new features breaks existing logic.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Difficult to Maintain&lt;/strong&gt;: Code quickly becomes a tangled mess.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-typical-fsm-solution-and-its-pitfalls&quot;&gt;The Typical FSM Solution and Its Pitfalls&lt;/h3&gt;
&lt;p&gt;A traditional Finite State Machine (FSM) approach uses the &lt;strong&gt;State Pattern&lt;/strong&gt;, where you create distinct classes for each state that implement a common interface. The main &lt;code&gt;Door&lt;/code&gt; class holds a reference to its current state object.&lt;/p&gt;
&lt;h4 id=&quot;traditional-state-pattern-implementation&quot;&gt;Traditional State Pattern Implementation&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public interface IState&amp;lt;T&amp;gt;
{
    void Enter(T context);
    void Update(T context);
    void Exit(T context);
}
    
public class DoorContext
{
    public bool IsOpen { get; set; } = false;
}
    
public class DoorClosedState : IState&amp;lt;DoorContext&amp;gt;
{
    public void Enter(DoorContext context)
    {
        context.IsOpen = false;
        Console.WriteLine(&quot;The door is now closed.&quot;);
    }
    
    public void Update(DoorContext context) { }
    public void Exit(DoorContext context) { }
}
    
public class DoorOpenState : IState&amp;lt;DoorContext&amp;gt;
{
    public void Enter(DoorContext context)
    {
        context.IsOpen = true;
        Console.WriteLine(&quot;The door is now open.&quot;);
    }
    
    public void Update(DoorContext context) { }
    public void Exit(DoorContext context) { }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, what does it take to add a &quot;locked&quot; state to this? It's not as simple as adding a boolean. We need to create a new state class, &lt;code&gt;DoorLockedState&lt;/code&gt;, and then modify our existing states and the context to allow for transitions to this new state. This still requires a fair amount of &lt;strong&gt;boilerplate and modification of existing code.&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;fsm-solution-trade-offs&quot;&gt;FSM Solution Trade-offs&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Pros &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Cons&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Clean State Separation&lt;/strong&gt;: Logic for each state is in a distinct class. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Boilerplate&lt;/strong&gt;: Requires a lot of code to set up states, transitions, and the state machine itself.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Enforced Transitions&lt;/strong&gt;: The model naturally enforces valid transitions. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Rigid Design&lt;/strong&gt;: FSM definition is static and difficult to modify at runtime.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Well-Established Pattern&lt;/strong&gt;: A common and well-understood design pattern. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;State Explosion&lt;/strong&gt;: Can lead to a large number of classes for each state, making it difficult to manage.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;a-better-way-fsm-api-and-centralized-state&quot;&gt;A Better Way: FSM_API and Centralized State&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;FSM_API&lt;/strong&gt; embraces a declarative, data-driven approach that is designed to be &lt;strong&gt;blazing-fast, software-agnostic, and fully decoupled&lt;/strong&gt; from your application's logic.&lt;/p&gt;
&lt;p&gt;The core concept is that the FSM_API operates on &lt;strong&gt;Plain Old C# Objects (POCOs)&lt;/strong&gt; that simply implement the &lt;code&gt;IStateContext&lt;/code&gt; interface. This ensures a clean separation between your FSM logic and your application's data.&lt;/p&gt;
&lt;h4 id=&quot;1-define-the-context&quot;&gt;1. Define the Context&lt;/h4&gt;
&lt;p&gt;Our &lt;code&gt;Door&lt;/code&gt; class is now a simple POCO. All its transition and state-entry logic is handled externally by the FSMs we are about to create.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class Door : IStateContext
{
    public bool IsOpen { get; set; } = false;
    public bool IsLocked = false;
    public string Name { get; set; } = &quot;FrontDoor&quot;;
    public bool IsValid =&amp;gt; true; // FSM API will not operate on this if false.
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;2-multiple-fsms-on-a-single-context&quot;&gt;2. Multiple FSMs on a Single Context&lt;/h4&gt;
&lt;p&gt;The true power of FSM_API is its ability to manage &lt;strong&gt;multiple, independent behaviors on a single context object&lt;/strong&gt;. This allows us to separate our &quot;open/close&quot; logic from our &quot;lock/unlock&quot; logic.&lt;/p&gt;
&lt;p&gt;Here is the declarative definition for the &lt;code&gt;DoorFSM&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;FSM_API.Create.CreateFiniteStateMachine(&quot;DoorFSM&quot;)
    .State(&quot;Closed&quot;, onEnter: (ctx) =&amp;gt; { ((Door)ctx).IsOpen = false; })
    .State(&quot;Open&quot;, onEnter: (ctx) =&amp;gt; { ((Door)ctx).IsOpen = true; })
    .State(&quot;Locked&quot;)
    .WithInitialState(&quot;Closed&quot;)
    // Transition to Open only if not locked
    .Transition(&quot;Closed&quot;, &quot;Open&quot;, (ctx) =&amp;gt; !((Door)ctx).IsLocked) 
    .Transition(&quot;Open&quot;, &quot;Closed&quot;)
    // Transition to Locked from Closed
    .Transition(&quot;Closed&quot;, &quot;Locked&quot;) 
    // Transition from Locked back to Closed only if unlocked
    .Transition(&quot;Locked&quot;, &quot;Closed&quot;, (ctx) =&amp;gt; !((Door)ctx).IsLocked) 
    .BuildDefinition();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the FSM_API allows for &lt;strong&gt;runtime redefinition&lt;/strong&gt; of FSMs, we can dynamically add states and transitions to our door object without recompiling. This capability makes it a powerful choice for highly configurable or live-updating systems.&lt;/p&gt;
&lt;h4 id=&quot;fsm-api-trade-offs&quot;&gt;FSM_API Trade-offs&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Pros &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Cons&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Centralized State&lt;/strong&gt;: FSM logic is fully separated from data. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Learning Curve&lt;/strong&gt;: New concepts might take time to grasp if you are used to traditional FSM implementations.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Runtime Redefinition&lt;/strong&gt;: FSMs can be modified on the fly without recompilation. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Minimalism&lt;/strong&gt;: The API is minimal by design; you will need to rely on the provided documentation to get started.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Lightweight &amp;amp; Performant&lt;/strong&gt;: Minimal memory allocations and optimized performance. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Framework Agnostic&lt;/strong&gt;: No external dependencies or frameworks required (works with .NET Framework 4.7 through .NET 8.0). &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Thread-Safe&lt;/strong&gt;: Designed for safe, deferred mutation handling. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This is just a glimpse of what's possible with the FSM_API. Its features make it a robust choice for any C# application requiring sophisticated state management.&lt;/p&gt;
&lt;p&gt;If you'd like to get started, you can find our NuGet package and all the documentation on our GitHub repository:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;NuGet Package:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;TrentBest/FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Patreon Page:&lt;/strong&gt;  &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unity Integration (Advanced):&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unity Integration (Basic):&lt;/strong&gt; Currently pending Marketing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you feel this tool is valuable to you, please consider supporting the project. &lt;strong&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;Donate via PayPal&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15220230761208519211&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/7034/finite-state-machines-the-universal-unit-of-work</guid>
<pubDate>Tue, 04 Nov 2025 22:53:50 +0000</pubDate>
</item>
<item>
<title>Engineering &quot;The&quot; Loop</title>
<link>https://coderlegion.com/7033/engineering-the-loop</link>
<description>&lt;h3 id=&quot;the-problem-with-the-classic-game-loop&quot;&gt;The Problem with the Classic Game Loop&lt;/h3&gt;
&lt;p&gt;Almost every interactive application, from video games to user interfaces, relies on a continuous &lt;strong&gt;execution loop&lt;/strong&gt;. This loop is the heart of the application, responsible for everything from updating the game state to rendering graphics. While it's a fundamental concept, the traditional approach can often feel like a point of contention among developers. Why? Because the classic game loop, often a simple &lt;code&gt;while(true)&lt;/code&gt; or &lt;code&gt;while(IsRunning)&lt;/code&gt; block, can quickly become an unmanageable monolith.&lt;/p&gt;
&lt;p&gt;Consider a typical game loop:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;void MainGameLoop()
{
    Initialize();
    
    while (IsRunning)
    {
        ProcessInput();
        UpdateGameState();
        RenderGraphics();
        PlayAudio();
        // ...and a dozen other things
    }
    
    Shutdown();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works for simple projects, but as an application grows, this single loop becomes a catch-all for complex logic. It tightly couples disparate systems (like input, rendering, and AI), making the code difficult to maintain, test, and debug. You end up with a single, massive function that handles everything, and any small change can have unintended consequences.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;a-better-way-a-state-machine-driven-loop-&quot;&gt;A Better Way: A State Machine-Driven Loop ✨&lt;/h3&gt;
&lt;p&gt;What if we could break free from this monolithic approach? What if our application's &quot;loop&quot; wasn't a static &lt;code&gt;while&lt;/code&gt; statement, but a dynamic, self-managing system? That's the power of a &lt;strong&gt;Finite State Machine (FSM)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In our project, we've integrated this idea into the &lt;strong&gt;MainWindowViewModel&lt;/strong&gt; for a WPF application. Instead of a single, endlessly running loop, our application's flow is managed by an FSM. Each &quot;tick&quot; of the application isn't a fixed set of actions, but a transition to a new state based on events.&lt;/p&gt;
&lt;p&gt;Our &lt;code&gt;MainWindowViewModel&lt;/code&gt; (from the provided code) implements the &lt;code&gt;IStateContext&lt;/code&gt; interface:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;public class MainWindowViewModel : INotifyPropertyChanged, IStateContext
{
    // ... properties and methods
    public bool IsValid { get; set; }
    public string Name { get; set; }

    public void InitializeState()
    {
        // This method will be called by the FSM
        // It will be the entry point for our initial actions
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This approach allows the FSM to dictate what happens at any given moment. For example, when the application starts, the FSM can trigger the &lt;code&gt;InitializeState()&lt;/code&gt; method. If a user clicks a button, the FSM can transition the application into a new state that handles that specific action, like fetching GitHub repository data. The loop isn't a single, continuous block—it's a series of transitions and actions managed by a state machine.&lt;/p&gt;
&lt;p&gt;This makes the &lt;code&gt;MainWindowViewModel&lt;/code&gt; highly modular and responsive. We can have states like &lt;code&gt;LoadingRepositories&lt;/code&gt;, &lt;code&gt;ShowingGitHubStatus&lt;/code&gt;, or &lt;code&gt;Idle&lt;/code&gt;, and the FSM ensures that the correct actions are executed for each state.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-api-evolution-from-simple-to-dynamic&quot;&gt;The API Evolution: From Simple to Dynamic&lt;/h3&gt;
&lt;p&gt;The two provided Unity C# scripts, &lt;code&gt;FSM_UnityIntegration.cs&lt;/code&gt; and &lt;code&gt;FSM_UnityIntegrationAdvanced.cs&lt;/code&gt;, showcase different approaches to creating a game loop driven by a Finite State Machine (FSM) API. The basic &lt;code&gt;FSM_UnityIntegration&lt;/code&gt; script uses a rigid one-to-one mapping between Unity's lifecycle methods and a single FSM processing group. In contrast, &lt;code&gt;FSM_UnityIntegrationAdvanced&lt;/code&gt; allows for a dynamic, runtime-modifiable list of processing groups for each Unity message, providing greater flexibility. Both scripts implement the singleton pattern to ensure only one instance of the integration exists in a scene.&lt;/p&gt;
&lt;h4 id=&quot;the-basic-approach-direct-mapping&quot;&gt;The Basic Approach: Direct Mapping&lt;/h4&gt;
&lt;p&gt;In our initial API, we used a direct one-to-one mapping. Each Unity message (like &lt;code&gt;Start&lt;/code&gt;, &lt;code&gt;Update&lt;/code&gt;, &lt;code&gt;OnDestroy&lt;/code&gt;) directly called a single, corresponding process group. This was a step up from the monolithic loop, but it was still quite rigid. You had a predefined set of actions for each phase of the application lifecycle.&lt;/p&gt;
&lt;p&gt;For instance, the &lt;code&gt;Update()&lt;/code&gt; method in the basic integration always calls the single &lt;code&gt;_updateProcessingGroup&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;void Update()
{
    FSM_API.Interaction.Update(_updateProcessingGroup);
    FSM_API.Interaction.Update(_unityHandles);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Simplicity:&lt;/strong&gt; It's a simple, predictable model that's easy for new developers to grasp.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance:&lt;/strong&gt; The direct call to a single processing group is efficient and has minimal overhead.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reliability:&lt;/strong&gt; The flow is fixed and well-defined, reducing the chance of unexpected behavior.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Rigidity:&lt;/strong&gt; The biggest drawback is its lack of flexibility. You can't dynamically add or remove processing groups at runtime. To change what happens during an &lt;code&gt;Update&lt;/code&gt;, you'd need to modify the code itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limited Customization:&lt;/strong&gt; It's not suitable for scenarios where the game loop needs to change its behavior based on the application's state, such as enabling or disabling different systems (e.g., a combat system) only when a specific state is active.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-advanced-approach-runtime-modifiable-loops&quot;&gt;The Advanced Approach: Runtime Modifiable Loops&lt;/h4&gt;
&lt;p&gt;Our more advanced API takes this a step further. We don't just have a single method for &lt;code&gt;Update&lt;/code&gt;; instead, we provide a &lt;strong&gt;list of strings&lt;/strong&gt; that represent the process groups to be executed. This is a simple but incredibly powerful change.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;Update()&lt;/code&gt; method in the advanced integration iterates through a list of groups, calling &lt;code&gt;FSM_API.Interaction.Update()&lt;/code&gt; for each one:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;void Update()
{
    foreach (var group in _updateProcessingGroup)
    {
        FSM_API.Interaction.Update(group);
    }
    FSM_API.Interaction.Update(_unityHandles);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This allows us to add, remove, or reorder process groups on the fly. For example, when the FSM enters a &lt;code&gt;FetchRepositories&lt;/code&gt; state, it can dynamically add the &lt;code&gt;GitHubRepositoryService&lt;/code&gt; process group to the update list using the &lt;code&gt;AddProcessingGroup()&lt;/code&gt; method. When the fetch is complete, the FSM transitions to another state and can remove that process group. The application's loop isn't just a fixed sequence of events—it's a fluid, context-aware process.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Flexibility and Modularity:&lt;/strong&gt; You can compose the game loop on the fly, adding and removing systems as needed without changing the core integration code.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State-Driven Behavior:&lt;/strong&gt; This approach fully leverages the power of the FSM. Different states can dictate which systems are active, making the application's behavior highly contextual and adaptive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; It's easier to add new systems without a cascading effect. You simply create a new processing group and add it to the relevant list when it's needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Complexity:&lt;/strong&gt; This model is more complex to set up and manage. Developers must be mindful of which groups are active at any given time to avoid unexpected behavior.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Potential Performance Overhead:&lt;/strong&gt; Iterating through a list of groups every frame adds a small amount of overhead compared to a direct function call, though this is negligible in most cases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debugging:&lt;/strong&gt; It can be more challenging to debug, as the flow of execution isn't fixed; it depends on the current state and the contents of the processing group lists.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;comparison-and-conclusion-&quot;&gt;Comparison and Conclusion ⚖️&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Feature &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Basic Integration &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Advanced Integration&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Execution Model&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Fixed&lt;/strong&gt;: One-to-one mapping between Unity messages and FSM groups. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Dynamic&lt;/strong&gt;: Iterates through a runtime-modifiable list of groups.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Flexibility&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Low: Changes require code modification. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;High: Groups can be added/removed at runtime.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Use Case&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Ideal for simple applications with a consistent, unchanging game loop. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Best for complex, state-driven applications where systems need to be enabled/disabled dynamically.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Maintainability&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Easy to maintain and understand for small projects. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;More maintainable in the long run for large projects, as logic is isolated by state.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Scalability&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Limited: Adding new features can lead to a monolithic &lt;code&gt;Update()&lt;/code&gt; method. &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;High: New systems can be added without modifying core code.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The choice between the two integrations depends on the needs of the project. The &lt;strong&gt;basic &lt;code&gt;FSM_UnityIntegration&lt;/code&gt;&lt;/strong&gt; is a great starting point for developers who want a simple, reliable FSM-driven loop without the need for complex, dynamic behavior. The &lt;strong&gt;advanced &lt;code&gt;FSM_UnityIntegrationAdvanced&lt;/code&gt;&lt;/strong&gt; is a more powerful and scalable solution for larger, more complex applications that require a fluid and responsive game loop that can adapt to different application states. By leveraging the FSM to control which groups are active, the advanced model creates a truly &lt;strong&gt;context-aware&lt;/strong&gt; application loop.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;conclusion-the-future-is-state-driven&quot;&gt;Conclusion: The Future is State-Driven&lt;/h3&gt;
&lt;p&gt;By moving from a monolithic &lt;code&gt;while&lt;/code&gt; loop to a &lt;strong&gt;dynamic, FSM-driven execution model&lt;/strong&gt;, we've created an application that is more:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Modular&lt;/strong&gt;: Each process group and state handles a single responsibility.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainable&lt;/strong&gt;: Logic is isolated, making it easier to debug and modify.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalable&lt;/strong&gt;: We can easily add new features without a cascading effect.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runtime Modifiable&lt;/strong&gt;: The application can adapt its behavior on the fly based on its current state.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This isn't just about elegant code; it's about building robust, flexible, and powerful applications that can grow and evolve without becoming a tangled mess. So next time you're about to write a classic &lt;code&gt;while(true)&lt;/code&gt; loop, ask yourself: could a state machine do this better?&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;support-us-2&quot;&gt;Support Us&lt;/h4&gt;
&lt;p&gt;If you find this project useful, you can support its development through PayPal.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;&lt;strong&gt;Donate via PayPal&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;useful-links-2&quot;&gt;Useful Links&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;NuGet Package:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;TrentBest/FSM_API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;License:&lt;/strong&gt; &lt;a rel=&quot;nofollow&quot; href=&quot;https://opensource.org/licenses/MIT&quot;&gt;MIT License&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/tools/behavior-ai/the-singularity-workshop-fsm-api-advanced-332450&quot;&gt;Advanced Integration On Unity Asset Store!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Basic Integration is pending updates on Marketing content.&lt;hr&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;brought-to-you-by-2&quot;&gt;Brought to you by&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;The Singularity Workshop&lt;/strong&gt; – Tools for the curious, the bold, and the systemically inclined.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl6tdvgg73ixyj0m0kuf.png&quot; alt=&quot;The image depicts a futuristic, sci-fi landscape dominated by glowing circuitry. A large, stylized Patreon logo hovers in the dark, starry sky above a radiant, eye-like sphere. This sphere pulses with vibrant, multicolored light, casting a brilliant glow onto the digital terrain below. The ground is a vast circuit board, with rivers of glowing orange and blue energy flowing along intricate pathways. Small, button-like structures on the surface emit soft light. The overall scene feels alive and dynamic, suggesting a powerful, almost magical, connection between technology and consciousness, with the Patreon logo at the center of it all.&quot;&gt;&lt;br&gt;
Because state shouldn’t be a mess.&lt;/p&gt;
&lt;hr&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/7033/engineering-the-loop</guid>
<pubDate>Tue, 04 Nov 2025 21:24:46 +0000</pubDate>
</item>
<item>
<title>raWWar: The Galactic RTS So Ambitious It Forced Us to Invent a New Technology</title>
<link>https://coderlegion.com/6957/rawwar-the-galactic-rts-so-ambitious-it-forced-us-to-invent-a-new-technology</link>
<description>&lt;p&gt;At &lt;strong&gt;The Singularity Workshop&lt;/strong&gt; we are building software for the &lt;strong&gt;singularity&lt;/strong&gt;. Our latest &lt;strong&gt;Milestone&lt;/strong&gt; has been reached: the resubmission of our &lt;em&gt;Unity Integration package&lt;/em&gt; for sale on the &lt;strong&gt;Unity Asset Store&lt;/strong&gt;. Before the release of our &lt;em&gt;45kb of raw digital power&lt;/em&gt;, and before our integration with Unity, there was the &lt;em&gt;driving vision&lt;/em&gt; which forced us to forge our &lt;strong&gt;core technology&lt;/strong&gt;, and then integrate it back into Unity.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;i-the-vision-of-unprecedented-scale&quot;&gt;I. The Vision of Unprecedented Scale&lt;/h3&gt;
&lt;p&gt;We are focused on the &lt;strong&gt;4X aspect&lt;/strong&gt; of our game: letting our players wage war on a scale beyond anything ever seen on Earth. The player's role is that of a &lt;em&gt;grand strategist&lt;/em&gt;, watching the battle happen safely from their bunker on a &lt;em&gt;holographic table&lt;/em&gt;, surrounded by their support staff, commanders, and advisors.&lt;/p&gt;
&lt;h4 id=&quot;a-the-necessity-of-low-poly&quot;&gt;A. The Necessity of Low-Poly&lt;/h4&gt;
&lt;p&gt;To achieve the scale necessary for this vision—allowing for &lt;em&gt;massive conflict simulation&lt;/em&gt;—we deliberately chose a &lt;strong&gt;low-poly aesthetic&lt;/strong&gt;. This decision is not about &lt;em&gt;style&lt;/em&gt;; it’s about &lt;strong&gt;performance&lt;/strong&gt;, enabling our engine to simulate the &lt;em&gt;massive 4X-scale conflict&lt;/em&gt; we promise.&lt;/p&gt;
&lt;p&gt;We started with these assets:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/106304&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/153234&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set 2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/167444&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set 3&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;ii-the-solution-fsm-api-technology&quot;&gt;II. The Solution: FSM_API Technology&lt;/h3&gt;
&lt;p&gt;Our commitment to scale is unlocked by the &lt;strong&gt;FSM_API&lt;/strong&gt;, a &lt;em&gt;proprietary Finite State Machine system&lt;/em&gt;. This technology is designed to handle &lt;em&gt;incredibly complex unit behaviors&lt;/em&gt; without becoming &lt;em&gt;overly complex for developers&lt;/em&gt;. Because we are leveraging the &lt;strong&gt;FSM_API&lt;/strong&gt;, we can create these behaviors efficiently. This is the &lt;strong&gt;core technology&lt;/strong&gt; enabling &lt;em&gt;true digital singularity&lt;/em&gt;.&lt;/p&gt;
&lt;h4 id=&quot;a-the-digital-lifeblood-our-soldier&quot;&gt;A. The Digital Lifeblood: Our Soldier&lt;/h4&gt;
&lt;p&gt;We decided that the &lt;strong&gt;soldier&lt;/strong&gt; will be the &lt;strong&gt;heart of our game&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=1717211770441930995&quot; alt=&quot;Our Low Poly Soldiers are the heroes of our Game!&quot;&gt;&lt;/p&gt;
&lt;p&gt;Our soldiers are trained from a highly advanced &lt;strong&gt;barracks&lt;/strong&gt; which has &lt;em&gt;VR training modules&lt;/em&gt; for a single squad. Once trained the squad leaves the barracks and, if not immediately assigned to another training program, will begin marching around the player's base. &lt;strong&gt;Barracks&lt;/strong&gt; using the same technology allow squads to be trained how to operate vehicles, use weapons, pilot aircraft, etc. &lt;strong&gt;Barracks&lt;/strong&gt; can also be tooled to provide additional training, increasing the squad's operational ability. A &lt;strong&gt;soldier&lt;/strong&gt; must undergo a complete training program before they and their squad can hop into a tank and operate it.&lt;/p&gt;
&lt;p&gt;Now here our soldiers are standing ready for review!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17017093589000102274&quot; alt=&quot;Our soldiers standing in formation awaiting the player's review!&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;iii-proof-of-concept-the-mvp-demo&quot;&gt;III. Proof of Concept: The MVP Demo&lt;/h3&gt;
&lt;p&gt;We determined that our &lt;strong&gt;critical path to release&lt;/strong&gt; is to establish an &lt;strong&gt;MVP demo&lt;/strong&gt; that allows for a &lt;em&gt;quick immersion&lt;/em&gt;, giving players an immediate idea of what to expect. We targeted the arrival of the player with their forces arrayed before them for review as a great start.&lt;/p&gt;
&lt;p&gt;Here is what the player would see upon starting our demo:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11380642652710897480&quot; alt=&quot;What the player would see, their soldiers standing at attention to either side of the roadway, tanks and aircraft farther in the distance, all awaiting the player's review!&quot;&gt;&lt;/p&gt;
&lt;p&gt;Here is a bird's eye view:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=4068697208731823583&quot; alt=&quot;Bird's eye view of the base, showing the soldiers standing at attention, tanks, aircraft stored around the base.&quot;&gt;&lt;/p&gt;
&lt;p&gt;This &lt;strong&gt;demo&lt;/strong&gt; provides enough environment to give the idea of what we are striving for, while keeping it &lt;em&gt;simple enough for rapid development&lt;/em&gt;. The player simply walks forward to the &lt;strong&gt;HQ building&lt;/strong&gt; where their &lt;em&gt;advisor&lt;/em&gt; will greet them and inform them that the rest of the game is currently under development.&lt;/p&gt;
&lt;h4 id=&quot;a-the-next-challenge-oppressive-darkness&quot;&gt;A. The Next Challenge: Oppressive Darkness&lt;/h4&gt;
&lt;p&gt;Our work now shifts to bringing down the visibility to make the environment &lt;strong&gt;oppressively dark&lt;/strong&gt;. We want to show the environment through the &lt;em&gt;high-contrast lenses&lt;/em&gt; of the light beams from our various light sources (light posts, headlights, etc.). This &lt;strong&gt;design choice&lt;/strong&gt; provides a &lt;em&gt;stripping down of visual context&lt;/em&gt;, creating a &lt;em&gt;naturally dark and oppressive feeling environment&lt;/em&gt;, which is the goal... to immerse the player and make them feel &lt;em&gt;innate dread&lt;/em&gt;, the &lt;em&gt;inner fear of darkness&lt;/em&gt; we all acquired from our ancestors... The &lt;em&gt;lack of visual context&lt;/em&gt; only makes our small &lt;strong&gt;demo&lt;/strong&gt; &lt;em&gt;feel much more massive&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=15460531802361004353&quot; alt=&quot;It's not perfect by any means, but it's a very dark view which is where we will start on our journey to bring this scene to life.&quot;&gt;&lt;/p&gt;
&lt;p&gt;Stay tuned as we bring this static scene to life using the power of our &lt;strong&gt;API&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;attributions-and-credits&quot;&gt;Attributions and Credits&lt;/h3&gt;
&lt;p&gt;A shout out to the talent who created the assets we are bringing to life:&lt;/p&gt;
&lt;p&gt;Asset Creator: &lt;strong&gt;Planesfar studio&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/106304&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/153234&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set 2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/package/167444&quot;&gt;Canopus-III Low Poly Sci-fi Desert Units Set 3&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;resources-amp-code--3&quot;&gt;Resources &amp;amp; Code:&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;FSM Package&lt;/strong&gt; (&lt;strong&gt;Unity Asset Store&lt;/strong&gt;):  &lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NuGet Package&lt;/strong&gt; (Non-Unity Core): &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;GitHub Repository&lt;/strong&gt;:  &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;support-our-work-&quot;&gt;Support Our Work:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Patreon Page&lt;/strong&gt;:  &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;strong&gt;Support Us&lt;/strong&gt; (&lt;strong&gt;PayPal Donation&lt;/strong&gt;):  &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please &lt;strong&gt;Like&lt;/strong&gt; this post, &lt;strong&gt;Love&lt;/strong&gt; the code, and &lt;strong&gt;Share&lt;/strong&gt; your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11922141097661488981&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/6957/rawwar-the-galactic-rts-so-ambitious-it-forced-us-to-invent-a-new-technology</guid>
<pubDate>Tue, 28 Oct 2025 23:10:46 +0000</pubDate>
</item>
<item>
<title>FSM API (Advanced) for Unity</title>
<link>https://coderlegion.com/6922/fsm-api-advanced-for-unity</link>
<description>&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=17047300794443488665&quot; alt=&quot;The Advanced Integration's Unity Package Cover Image with confetti and streamers bursting in celebration!&quot;&gt;&lt;/p&gt;
&lt;p&gt;The Singularity Workshop is proud to announce a pivotal achievement: After months of rigorous architectural design and engineering, we have successfully released &lt;strong&gt;'The Singularity Workshop - FSM API (Advanced)'&lt;/strong&gt; on the Unity Asset Store! This is a successful milestone, and we are just getting started.&lt;/p&gt;
&lt;p&gt;As dedicated readers of our work know, our focus is on robust software architecture, grounded in the deep theoretical understanding and powerful application of &lt;strong&gt;Finite State Machines (FSMs)&lt;/strong&gt;. This Unity Asset is the direct culmination of those efforts.&lt;/p&gt;
&lt;h4 id=&quot;the-paradigm-shift-is-here&quot;&gt;The Paradigm Shift is Here&lt;/h4&gt;
&lt;p&gt;Get ready to escape the chaos of &lt;strong&gt;&lt;code&gt;Update()&lt;/code&gt; spaghetti&lt;/strong&gt; and embrace a true &lt;strong&gt;architectural paradigm shift&lt;/strong&gt;. Our API is engineered for &lt;strong&gt;decoupling&lt;/strong&gt; and &lt;strong&gt;high reusability&lt;/strong&gt;, allowing you to build complex behavior through the &lt;em&gt;composition&lt;/em&gt; of simple, independent FSM blueprints.&lt;/p&gt;
&lt;p&gt;As demonstrated in our work on &lt;strong&gt;Multi-Context FSMs&lt;/strong&gt;, you can now apply multiple, independent FSMs to a single object's &lt;code&gt;Transform&lt;/code&gt; simultaneously without interference, resulting in game systems that are &lt;strong&gt;scalable, maintainable, and profoundly robust.&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;documentation-as-a-core-feature&quot;&gt;Documentation as a Core Feature&lt;/h4&gt;
&lt;p&gt;We engineered this API to be universally accessible, spending as much time on &lt;strong&gt;learning materials&lt;/strong&gt; as we did on the code itself. Our goal is to bring &lt;strong&gt;non-coders&lt;/strong&gt; and &lt;strong&gt;non-C# programmers&lt;/strong&gt; into this new paradigm.&lt;/p&gt;
&lt;p&gt;Beyond the comprehensive user guide, you can check out our &lt;strong&gt;NuGet package&lt;/strong&gt; which contains the core API and an extensive &lt;strong&gt;Theory Guide&lt;/strong&gt; that dives deep into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The fundamental &lt;strong&gt;mathematical models&lt;/strong&gt; behind FSMs.&lt;/li&gt;
&lt;li&gt;FSM types, classifications, and operational theory.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you understand the &quot;What,&quot; our API documentation walks you through the &quot;How,&quot; making the process of creating complex behavior accessible to anyone willing to learn the abstraction.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Explore the future of Unity behavior architecture today ($30 package on sale for $21 for two weeks on the Unity Asset Store!):&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;The Singularity Workshop - FSM API (Advanced)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Reference the Core Engine &amp;amp; Theory Guides:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;TheSingularityWorkshop.FSM_API NuGet Package&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The paradigm shift is here. We look forward to publishing deep dives into the API's advanced architecture and applications very soon!&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=12370772205691327121&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/6922/fsm-api-advanced-for-unity</guid>
<pubDate>Mon, 27 Oct 2025 20:56:19 +0000</pubDate>
</item>
<item>
<title> When Unity Glitches, You Build Your Own Loop: The Four-Line App Core </title>
<link>https://coderlegion.com/6610/when-unity-glitches-you-build-your-own-loop-the-four-line-app-core</link>
<description>&lt;p&gt;Every developer has a story about an IDE or engine glitch that made them momentarily question their career choices. For me, that moment arrived late one evening, tracing a bug in our FSM-driven agents. &lt;strong&gt;Unity's Inspector&lt;/strong&gt; decided to go on strike, showing empty fields without labels—the digital ghosts of components past.&lt;/p&gt;
&lt;p&gt;The simple fix? Close Unity. Reopen. Wait 10 minutes.&lt;/p&gt;
&lt;p&gt;It was late. I was done waiting.&lt;/p&gt;
&lt;p&gt;Instead, in an exhausted fit of annoyance and clarity, I opened a fresh C# console, installed &lt;strong&gt;The Singularity Workshop's FSM API&lt;/strong&gt;, and let my fingers dance. The next morning, groggy and foggy, I realized I had accidentally conceived an entire, engine-agnostic application core.&lt;/p&gt;
&lt;p&gt;Laugh at the simplicity, then realize this genuinely works! This is the entire executable heart of a Windows Desktop application:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class Program
{
    public static void Main(string[] args)
    {
        // 1. Instantiate the Context: Our Platform-Specific &quot;Drone as I like to think of it&quot;
        var appContext = new AppWindowsDesktopContextFSM(args); 
        
        // 2. Create the live Execution FSM bound to that Context
        FSM_API.Create.CreateInstance(&quot;ExecutionFSM&quot;, appContext, &quot;Update&quot;);

        // 3. The Self-Terminating Loop
        do
        {
            // Tick the FSM: Advance one logical step
            FSM_API.Interaction.Update(&quot;Update&quot;);
        } while (appContext.IsValid); // Control flow determined by the Context's vital sign
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's it. This four-line &lt;code&gt;do-while&lt;/code&gt; block is less boilerplate than setting up a complex, multi-threaded worker class, yet it provides unparalleled decoupling.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-conceptual-leap-context-driven-execution&quot;&gt;The Conceptual Leap: Context-Driven Execution&lt;/h3&gt;
&lt;p&gt;The conceptual breakthrough is that the traditional &lt;code&gt;while (IsRunning)&lt;/code&gt; loop, where control is external to the core logic, is entirely replaced by a check against the &lt;strong&gt;&lt;code&gt;IStateContext&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;the-context-as-the-application-s-heartbeat&quot;&gt;The Context as the Application's Heartbeat&lt;/h4&gt;
&lt;p&gt;The loop's survival depends entirely on &lt;code&gt;appContext.IsValid&lt;/code&gt;. This property is required by the &lt;strong&gt;&lt;code&gt;IStateContext&lt;/code&gt;&lt;/strong&gt; interface.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If &lt;strong&gt;&lt;code&gt;IsValid&lt;/code&gt;&lt;/strong&gt; is &lt;strong&gt;true&lt;/strong&gt;, the loop runs, calling &lt;code&gt;FSM_API.Interaction.Update()&lt;/code&gt; to execute the current state and check for transitions.&lt;/li&gt;
&lt;li&gt;If &lt;strong&gt;&lt;code&gt;IsValid&lt;/code&gt;&lt;/strong&gt; returns &lt;strong&gt;false&lt;/strong&gt;, the loop breaks, and the application cleanly exits. The FSM API even automatically cleans up the associated &lt;code&gt;FSMHandle&lt;/code&gt; instance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The application's &lt;strong&gt;&quot;ExecutionFSM&quot;&lt;/strong&gt; is defined to contain states like &lt;code&gt;Initializing&lt;/code&gt;, &lt;code&gt;Running&lt;/code&gt;, and &lt;code&gt;ShuttingDown&lt;/code&gt;. When a transition leads to the &lt;code&gt;ShuttingDown&lt;/code&gt; state, the &lt;code&gt;OnEnter&lt;/code&gt; action simply calls a method on the &lt;strong&gt;AppContext&lt;/strong&gt; (our &quot;Drone&quot;) that sets an internal flag, making &lt;code&gt;IsValid&lt;/code&gt; flip to false.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The FSM dictates &lt;em&gt;when&lt;/em&gt; to die; the Context executes &lt;em&gt;how&lt;/em&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;unparalleled-platform-decoupling&quot;&gt;Unparalleled Platform Decoupling&lt;/h3&gt;
&lt;p&gt;This pattern achieves the holy grail of platform-agnostic logic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The FSM Definition (&lt;code&gt;&quot;ExecutionFSM&quot;&lt;/code&gt;) is Pure Logic:&lt;/strong&gt; It knows nothing about Windows, Unity, or Android. It only knows about states (e.g., &lt;code&gt;ProcessingInput&lt;/code&gt;, &lt;code&gt;SavingData&lt;/code&gt;) and transitions (e.g., &lt;code&gt;OnInputProcessed&lt;/code&gt; → &lt;code&gt;ToState&lt;/code&gt;). This definition can be used anywhere.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Context (&lt;code&gt;AppWindowsDesktopContextFSM&lt;/code&gt;) is Pure Platform Abstraction:&lt;/strong&gt; This class is where all the OS-specific heavy lifting lives. A state's &lt;code&gt;OnEnter&lt;/code&gt; action might call &lt;code&gt;((AppWindowsDesktopContextFSM)ctx).InitializeWindow()&lt;/code&gt; or &lt;code&gt;((AppConsoleContext)ctx).ParseArgs()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The FSM definition remains constant, knowing only that the action is &lt;code&gt;ctx.DoThing()&lt;/code&gt;. The &lt;strong&gt;behavior&lt;/strong&gt; behind &lt;code&gt;DoThing()&lt;/code&gt; is entirely specific to the &lt;code&gt;AppWindowsDesktopContextFSM&lt;/code&gt; running on the client machine. This means the same &quot;ExecutionFSM&quot; definition can be shared across our Console, Windows Desktop, and (ironically) future Unity integrations, providing the necessary FSM behaviors without ever compromising the core logic to platform constraints.&lt;/p&gt;
&lt;p&gt;In the end, closing Unity would have taken 10 minutes. Building this foundational piece of software architecture took most of the night. But now, we have an application core that is robust, modular, and immune to inspector glitches. &lt;strong&gt;WTF indeed!&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14669829065118869161&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6610/when-unity-glitches-you-build-your-own-loop-the-four-line-app-core</guid>
<pubDate>Sat, 18 Oct 2025 01:02:55 +0000</pubDate>
</item>
<item>
<title>The FSM Agent Architecture: Scaling NavMesh Agents with Decoupled Logic </title>
<link>https://coderlegion.com/6495/the-fsm-agent-architecture-scaling-navmesh-agents-with-decoupled-logic</link>
<description>&lt;h3 id=&quot;the-fsm-agent-architecture-scaling-navmesh-agents-with-decoupled-logic&quot;&gt;The FSM Agent Architecture: Scaling NavMesh Agents with Decoupled Logic&lt;/h3&gt;
&lt;p&gt;We've mastered simple oscillating motion with the &lt;strong&gt;FSM Context Pattern&lt;/strong&gt;; now, we apply this powerful architectural approach to a far greater challenge: &lt;strong&gt;Massive NavMesh Agent AI&lt;/strong&gt;. Instead of relying on a monolithic &lt;code&gt;Update()&lt;/code&gt; loop, we delegate the complex logic of pathfinding, target acquisition, and state management into reusable Finite State Machine blueprints.&lt;/p&gt;
&lt;p&gt;Our goal for this series is twofold: achieve &lt;strong&gt;stable, high-performance&lt;/strong&gt; AI for hundreds of agents, and develop a system resilient to complex &lt;strong&gt;emergent behaviors&lt;/strong&gt; that inevitably arise at scale.&lt;/p&gt;
&lt;p&gt;This article introduces the two core components that make up our scalable agent system.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=7529296879811900778&quot; alt=&quot;Screen Capture with 1k agents&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-two-pillars-of-the-fsm-agent-system&quot;&gt;The Two Pillars of the FSM Agent System&lt;/h3&gt;
&lt;p&gt;Our architecture separates the agents from the environment, ensuring each component is only responsible for its own domain, which is the key to reusability and stability.&lt;/p&gt;
&lt;h4 id=&quot;1-the-environment-navmeshagentsdemo-cs-the-orchestrator-&quot;&gt;1. The Environment: &lt;code&gt;NavMeshAgentsDemo.cs&lt;/code&gt; (The Orchestrator)&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;NavMeshAgentsDemo&lt;/code&gt; class serves as the &lt;strong&gt;central context&lt;/strong&gt; for the entire simulation. Its primary responsibility is orchestration and resource distribution.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Target Management:&lt;/strong&gt; It holds the list of &lt;strong&gt;targets&lt;/strong&gt; (&lt;code&gt;targets&lt;/code&gt; list) that agents will navigate to. It includes a helper function, &lt;code&gt;GetRandomTarget&lt;/code&gt;, which ensures agents don't immediately re-select the target they just left, promoting better distribution.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Initialization:&lt;/strong&gt; In the main FSM's &lt;code&gt;OnEnterExecuting&lt;/code&gt; state, the demo dynamically creates our agents. It instantiates the &lt;code&gt;agentPrefab&lt;/code&gt;, assigns the environment reference (&lt;code&gt;agentFSM.Environment = demo.Status&lt;/code&gt;), and gives each agent a unique color for easy visual tracking.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scale Setup:&lt;/strong&gt; For our first test, the &lt;code&gt;NumberAgents&lt;/code&gt; property is set to a manageable value (e.g., a few dozen). At this scale, the system works perfectly, with agents moving smoothly between targets, proving the foundational architecture is sound.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;2-the-agent-navmeshagentfsm-cs-the-decoupled-ai-&quot;&gt;2. The Agent: &lt;code&gt;NavMeshAgentFSM.cs&lt;/code&gt; (The Decoupled AI)&lt;/h4&gt;
&lt;p&gt;This is where the magic happens. The &lt;code&gt;NavMeshAgentFSM&lt;/code&gt; class is both a &lt;strong&gt;MonoBehaviour&lt;/strong&gt; (to interface with the &lt;code&gt;NavMeshAgent&lt;/code&gt; component and physics events) and an &lt;strong&gt;IStateContext&lt;/strong&gt; that drives its own FSM instance.&lt;/p&gt;
&lt;p&gt;The agent's logic is boiled down to a simple, three-state cycle defined in the FSM blueprint, which is created only once:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;State &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Role &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Key Logic&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Idle&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Target Acquisition&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The agent is stopped and contacts the &lt;code&gt;Environment&lt;/code&gt; to get a new target. This is where the heavy work (target look-up) is performed.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Moving&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Path Execution&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The agent's &lt;code&gt;NavMeshAgent&lt;/code&gt; component handles movement to the destination set during &lt;strong&gt;Idle&lt;/strong&gt;. The FSM transitions out when collision with the target is detected.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Contacted&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Arrival Confirmation&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The agent confirms arrival (&lt;code&gt;Arrived = true&lt;/code&gt;), and the physics collider is temporarily disabled to prevent it from immediately getting stuck on the target.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The power here is &lt;strong&gt;delegation&lt;/strong&gt;: the FSM defines &lt;em&gt;when&lt;/em&gt; the agent decides (Idle) and &lt;em&gt;when&lt;/em&gt; it confirms arrival (Contacted), while the &lt;code&gt;NavMeshAgent&lt;/code&gt; component (outside the FSM's &lt;code&gt;Update&lt;/code&gt; loop) handles the complex movement &lt;em&gt;how&lt;/em&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-early-success-small-batch-&quot;&gt;The Early Success (Small Batch)&lt;/h3&gt;
&lt;p&gt;When we run the simulation with a small number of agents (e.g., 20–50), the system is seamless.&lt;/p&gt;
&lt;p&gt;The FSM Context Pattern successfully replaces the traditional &lt;code&gt;Update()&lt;/code&gt; based AI:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Instead of constantly checking if &lt;code&gt;if (target != null &amp;amp;&amp;amp; distance &amp;lt; threshold)&lt;/code&gt;, the system &lt;strong&gt;waits&lt;/strong&gt; in the &lt;strong&gt;Moving&lt;/strong&gt; state and is triggered only by the &lt;code&gt;OnCollisionEnter&lt;/code&gt; physics event, which flips the &lt;code&gt;Arrived&lt;/code&gt; flag.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Idle&lt;/code&gt; state automatically handles the transition out to &lt;strong&gt;Moving&lt;/strong&gt; once a target is assigned, using the &lt;code&gt;AssignedTarget&lt;/code&gt; predicate check (&lt;code&gt;return agent.Target != null&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The foundation is solid, proving that the FSM Context Pattern is highly effective for managing AI state.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Next, we push to a high agent count, but this is where the new architectural challenge arises...&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the next article, we will reveal the performance optimization that allows us to run &lt;strong&gt;over 1,000 agents&lt;/strong&gt; and introduce the subtle, yet critical, emergent behavior known as &lt;strong&gt;Agent Gridlock&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8116088306793481487&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6495/the-fsm-agent-architecture-scaling-navmesh-agents-with-decoupled-logic</guid>
<pubDate>Wed, 15 Oct 2025 20:27:35 +0000</pubDate>
</item>
<item>
<title>The Grand Finale: Orchestrating Complex Motion with Multi-Context FSMs</title>
<link>https://coderlegion.com/6494/the-grand-finale-orchestrating-complex-motion-with-multi-context-fsms</link>
<description>&lt;p&gt;We've successfully established a reusable architectural pattern by isolating the data (Context) from the logic flow (Finite State Machine) for the three primitive motions: &lt;strong&gt;Rotation&lt;/strong&gt;, &lt;strong&gt;Scaling&lt;/strong&gt;, and &lt;strong&gt;Translation&lt;/strong&gt;. We created three distinct, independent blueprints—&quot;RotationFSM,&quot; &quot;ScalarFSM,&quot; and &quot;TranslationFSM&quot;—each driving separate objects on various axes.&lt;/p&gt;
&lt;p&gt;Now, for the grand finale: we will demonstrate the true power of this decoupled architecture by applying &lt;strong&gt;all three FSM blueprints&lt;/strong&gt; simultaneously to the &lt;strong&gt;same three objects&lt;/strong&gt;, achieving a perfectly synchronized, multi-dimensional motion effect.&lt;/p&gt;
&lt;p&gt;This isn't about creating a new FSM; it's about proving the &lt;em&gt;flexibility and reusability&lt;/em&gt; of the existing ones. We will show that one object can be driven by multiple, independently managed FSM contexts, eliminating the need for a monolithic, complex state machine.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-power-of-decoupled-contexts&quot;&gt;The Power of Decoupled Contexts&lt;/h3&gt;
&lt;p&gt;The core principle remains the same: the FSM definition is the &lt;strong&gt;reusable logic&lt;/strong&gt; (the &lt;em&gt;how&lt;/em&gt;), and the Context is the &lt;strong&gt;unique data&lt;/strong&gt; (the &lt;em&gt;what&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;In our previous demos, we created one Context per object. In the Combined Motion Demo, we create &lt;strong&gt;three Contexts per object&lt;/strong&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Object &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Rotation Demo &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Scalar Demo &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Translation Demo &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Combined Demo&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;X-axis Cube&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;ScaleContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;TranslationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationFSM, ScalarFSM, TranslationFSM&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Y-axis Cube&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;ScaleContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;TranslationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationFSM, ScalarFSM, TranslationFSM&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Z-axis Cube&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;ScaleContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;TranslationContext &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;RotationFSM, ScalarFSM, TranslationFSM&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The FSM framework handles each Context instance completely independently. When the Unity &lt;code&gt;Update()&lt;/code&gt; loop runs, it executes the update for all nine individual FSM instances (three contexts * three objects), resulting in the compound motion.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-entry-point-simplerotationscalartranslationdemo-cs&quot;&gt;The Entry Point: SimpleRotationScalarTranslationDemo.cs&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleRotationScalarTranslationDemo.cs&lt;/code&gt; file is the orchestrator, instantiating the nine required Contexts in its main FSM's &lt;code&gt;OnEnterExecuting&lt;/code&gt; method.&lt;/p&gt;
&lt;h4 id=&quot;instantiation-logic-three-in-one&quot;&gt;Instantiation Logic: Three-in-One&lt;/h4&gt;
&lt;p&gt;The code combines the instantiation logic from all three previous demos. For the &lt;strong&gt;XaxisCube&lt;/strong&gt;, we instantiate a &lt;code&gt;ScaleContext&lt;/code&gt;, a &lt;code&gt;TranslationContext&lt;/code&gt;, and a &lt;code&gt;RotationContext&lt;/code&gt;, all referencing the same &lt;code&gt;demo.XaxisCube&lt;/code&gt; Transform.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private void OnEnterExecuting(IStateContext context)
{
    if (context is SimpleRotationScalarTranslationDemo demo)
    {
        // === X-AXIS CUBE ===
        // 1. Scale FSM (Uses ScaleContext/ScalarFSM)
        ScaleContext scX = new ScaleContext(demo.XaxisCube, new Vector3(1, 0, 0), 0.5f, 3f, 0.5f);
        // 2. Translation FSM (Uses TranslationContext/TranslationFSM)
        TranslationContext tcX = new TranslationContext(demo.XaxisCube, new Vector3(1, 0, 0), 1f, 2f, -2f);
        // 3. Rotation FSM (Uses RotationContext/RotationFSM)
        RotationContext rcX = new RotationContext(demo.XaxisCube, new Vector3(1, 0, 0), 90f, 45f, -45f);
       
        // === Y-AXIS CUBE ===
        // ... (Similar instantiation for Y-axis cube, using (0, 1, 0) for the axis)
        ScaleContext scY = new ScaleContext(demo.YaxisCube, new Vector3(0, 1, 0), 0.5f, 3f, 0.5f);
        TranslationContext tcY = new TranslationContext(demo.YaxisCube, new Vector3(0, 1, 0), 1f, 2f, -2f);
        RotationContext rcY = new RotationContext(demo.YaxisCube, new Vector3(0, 1, 0), 90f, 45f, -45f);
       
        // === Z-AXIS CUBE (Note: Scale is multi-axis for visual flair) ===
        // ... (Similar instantiation for Z-axis cube, using various axes)
        ScaleContext scZ = new ScaleContext(demo.ZaxisCube, new Vector3(1, 1, 0), 0.5f, 3f, 0.5f);
        TranslationContext tcZ = new TranslationContext(demo.ZaxisCube, new Vector3(0, 0, 1), 1f, 2f, -2f);
        RotationContext rcZ = new RotationContext(demo.ZaxisCube, new Vector3(0, 0, 1), 90f, 45f, -45f);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;the-decoupled-fsms-in-action&quot;&gt;The Decoupled FSMs in Action&lt;/h4&gt;
&lt;p&gt;Because each Context is an independent data container, the FSM framework executes them separately, resulting in simultaneous, non-interfering motion:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;RotationContext&lt;/code&gt;&lt;/strong&gt; drives the &lt;code&gt;TransformHandle.localRotation&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;ScaleContext&lt;/code&gt;&lt;/strong&gt; drives the &lt;code&gt;TransformHandle.localScale&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;&lt;code&gt;TranslationContext&lt;/code&gt;&lt;/strong&gt; drives the &lt;code&gt;TransformHandle.localPosition&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each FSM instance has its own independent state and transitions, yet they all operate on the same object's &lt;code&gt;Transform&lt;/code&gt;. The result is a fascinating display: the &lt;strong&gt;Z-axis Cube&lt;/strong&gt;, for instance, &lt;strong&gt;oscillates&lt;/strong&gt; along the Z-axis (Translation), &lt;strong&gt;pulses&lt;/strong&gt; in size along the X and Y axes (Scaling), and &lt;strong&gt;swings&lt;/strong&gt; around the Z-axis (Rotation).&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;conclusion-true-architectural-victory&quot;&gt;Conclusion: True Architectural Victory&lt;/h3&gt;
&lt;p&gt;This Combined Motion Demo is the ultimate proof of the &lt;strong&gt;FSM Context Pattern's power&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Separation of Concerns:&lt;/strong&gt; We fully separated the primitive operations. Modifying the boundary check for rotation, for instance, has zero impact on the translation or scaling logic.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High Reusability:&lt;/strong&gt; We did not write a single new state machine definition for this complex demo. We simply reused the &quot;RotationFSM,&quot; &quot;ScalarFSM,&quot; and &quot;TranslationFSM&quot; blueprints.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalable Complexity:&lt;/strong&gt; An object's behavior is now a &lt;strong&gt;composition&lt;/strong&gt; of independent FSM-driven movements. If we need to add a &quot;Color Modulation FSM,&quot; we simply instantiate a fourth context for each object.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This decoupled architecture provides the foundation for robust, maintainable, and highly extensible game systems. You've escaped &lt;strong&gt;Update() spaghetti&lt;/strong&gt; and unlocked the ability to &lt;strong&gt;compose complex behaviors from simple, reusable, and independent parts&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;See it in action on YouTube (Don't forget to like and subscribe!): &lt;/p&gt;
&lt;h3 id=&quot;https-youtu-be-1lkbinkttym&quot;&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/1lKBINkTtYM&quot;&gt;https://youtu.be/1lKBINkTtYM&lt;/a&gt;&lt;/h3&gt;
&lt;h3 id=&quot;support-the-vision-and-see-the-code-&quot;&gt;Support the Vision and See the Code!&lt;/h3&gt;
&lt;p&gt;If this pattern has helped clean up your &lt;code&gt;Update()&lt;/code&gt; loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Support Our Work&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=200526947688755563&quot; alt=&quot;The Singularity Workshop Logo, a digital Eye of energy within a circuit digital universe&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6494/the-grand-finale-orchestrating-complex-motion-with-multi-context-fsms</guid>
<pubDate>Wed, 15 Oct 2025 19:35:04 +0000</pubDate>
</item>
<item>
<title>️ Help Shape Our Next FSM_API Deep Dive! Take our Developer Poll on strawpoll</title>
<link>https://coderlegion.com/6465/help-shape-our-next-fsmapi-deep-dive-take-our-developer-poll-on-strawpoll</link>
<description>&lt;p&gt;We're constantly striving to deliver the most valuable, actionable content for the Coder Legion community. Our FSM_API and the Unity Integration package cover a broad range of technical scenarios—from core C# logic to real-time game state—and we want your vote to decide where we dedicate our next major technical article and tutorial.&lt;/p&gt;
&lt;p&gt;Whether you're building high-performance cloud backends or complex in-game AI, your vote directly prioritizes our content pipeline.&lt;/p&gt;
&lt;p&gt;Please take a moment to cast your vote below!&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://strawpoll.com/PKgle20e9Zp&quot;&gt;FSM_API Developer Interest Poll&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/TheSingularityWorkshop&quot;&gt;&lt;strong&gt;Patreon Page&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt; Support Us&lt;/a&gt;&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=10143091773746285338&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6465/help-shape-our-next-fsmapi-deep-dive-take-our-developer-poll-on-strawpoll</guid>
<pubDate>Wed, 15 Oct 2025 05:54:16 +0000</pubDate>
</item>
<item>
<title>Completing the Motion Trilogy: The Reusable TranslationFSM</title>
<link>https://coderlegion.com/6450/completing-the-motion-trilogy-the-reusable-translationfsm</link>
<description>&lt;h2 id=&quot;completing-the-motion-trilogy-the-reusable-translationfsm&quot;&gt;Completing the Motion Trilogy: The Reusable &lt;strong&gt;TranslationFSM&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;We've conquered Rotation and streamlined Scaling using our FSM Context Pattern. In this article, we tackle the final primitive motion—Translation (linear movement)—to complete our core motion trilogy.&lt;/p&gt;
&lt;p&gt;The biggest takeaway here is the demonstration of true &lt;strong&gt;architectural reuse&lt;/strong&gt;. We define a new Context class and a new FSM, but the logic flow remains 100% identical to the Rotation and Scaling demos.&lt;/p&gt;
&lt;h3 id=&quot;1-the-context-swapping-scale-for-position-parameters&quot;&gt;1. The Context: Swapping Scale for Position Parameters&lt;/h3&gt;
&lt;p&gt;We isolate the specific data required for linear position change into the &lt;code&gt;TranslationContext&lt;/code&gt; class.&lt;/p&gt;
&lt;p&gt;The primary conceptual difference from the Scale/Rotation demos lies in how boundaries are established: Translation must calculate its absolute boundaries relative to the object's &lt;strong&gt;starting local position&lt;/strong&gt; (&lt;code&gt;OriginalPosition&lt;/code&gt;). This ensures the oscillation is centered around the object's initial placement.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Previous Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Translation Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Purpose&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;ScaleSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MoveSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Linear speed of position change.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;ScaleAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MoveAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The axis (or axes) to apply the movement along.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;MaxScale / MinScale &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MaxPosition / MinPosition &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The absolute position bounds, calculated from &lt;code&gt;OriginalPosition&lt;/code&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;translationcontext-cs-absolute-boundary-calculation&quot;&gt;TranslationContext.cs: Absolute Boundary Calculation&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;TranslationContext&lt;/code&gt; calculates the precise &lt;code&gt;MaxPosition&lt;/code&gt; and &lt;code&gt;MinPosition&lt;/code&gt; by using the dot product to find the object's starting coordinate along the movement axis, and then adding/subtracting the desired displacement.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class TranslationContext : IStateContext
{
    // The new parameters that define linear movement
    public float MoveSpeed = 1.0f;
    public float MaxPosition = 5.0f;
    public float MinPosition = -5.0f;
    
    public Vector3 MoveAxis;
    public Vector3 OriginalPosition = Vector3.zero;

    // ... Constructor logic
    // 2. Calculate the absolute Max/Min boundaries:
    this.MaxPosition = initialCoord + maxPos;
    this.MinPosition = initialCoord + minPos;
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;2-the-fsm-definition-the-same-engine-new-states&quot;&gt;2. The FSM Definition: The Same Engine, New States&lt;/h3&gt;
&lt;p&gt;The Finite State Machine flow is identical to the Rotation and Scalar demos (Move $\rightarrow$ Max $\rightarrow$ Move Back $\rightarrow$ Min). The blueprint name is now &lt;code&gt;&quot;TranslationFSM&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Scalar FSM &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Translation FSM (Change)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingUp &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: MovingForward&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingDown &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: MovingBackward&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Apex &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MaxReached&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Root &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MinReached&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;the-core-logic-simple-vector-math-&quot;&gt;The Core Logic (Simple Vector Math)&lt;/h4&gt;
&lt;p&gt;The state updates are handled by direct vector math applied to &lt;code&gt;localPosition&lt;/code&gt; using &lt;code&gt;Time.deltaTime&lt;/code&gt; for smooth, framerate-independent movement.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// The OnUpdateMovingForward function within TranslationContext.cs
private void OnUpdateMovingForward(IStateContext context)
{
    if (context is TranslationContext tc)
    {
        // Add the movement vector based on speed and time
        tc.TransformHandle.localPosition += tc.MoveAxis * (tc.MoveSpeed * Time.deltaTime);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The transition predicates, &lt;code&gt;MaxReached&lt;/code&gt; and &lt;code&gt;MinReached&lt;/code&gt;, use the &lt;strong&gt;Dot Product&lt;/strong&gt; to extract the object's current coordinate along the axis, comparing it to the absolute &lt;code&gt;MaxPosition&lt;/code&gt;/&lt;code&gt;MinPosition&lt;/code&gt; boundary values calculated earlier.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;3-the-entry-point-final-proof-of-reusability&quot;&gt;3. The Entry Point: Final Proof of Reusability&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleTranslationDemo.cs&lt;/code&gt; handles the instantiation. We simply provide three different &lt;code&gt;MoveAxis&lt;/code&gt; vectors to three unique &lt;code&gt;TranslationContext&lt;/code&gt; instances, all utilizing the same &lt;code&gt;&quot;TranslationFSM&quot;&lt;/code&gt; definition.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private void OnEnterExecuting(IStateContext context)
{
    if (context is SimpleTranslationDemo std)
    {
        float moveSpeed = 1.0f;
        float maxDisplacement = 2.0f;
        float minDisplacement = -2.0f;
        
        // 1. X-axis: MoveAxis (1, 0, 0)
        TranslationContext xAxisContext = new TranslationContext(std.Xaxis, new Vector3(1, 0, 0), moveSpeed, maxDisplacement, minDisplacement);
        std.XaxisHandle = xAxisContext.Status; 

        // 2. Y-axis: MoveAxis (0, 1, 0)
        TranslationContext yAxisContext = new TranslationContext(std.Yaxis, new Vector3(0, 1, 0), moveSpeed, maxDisplacement, minDisplacement);
        std.YaxisHandle = yAxisContext.Status; 

        // 3. Z-axis: MoveAxis (0, 0, 1)
        TranslationContext zAxisContext = new TranslationContext(std.Zaxis, new Vector3(0, 0, 1), moveSpeed, maxDisplacement, minDisplacement);
        std.ZaxisHandle = zAxisContext.Status;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;p&gt;Conclusion: Architectural Reusability Confirmed&lt;/p&gt;
&lt;p&gt;With the implementation of the TranslationFSM, we have successfully completed our core motion trilogy, elegantly managing Rotation, Scaling, and Translation using a single, unified architectural approach.&lt;/p&gt;
&lt;p&gt;The key takeaway is the profound level of architectural reuse we achieved. By isolating the unique data (the what) into the Context class and retaining the generic logic flow (the how) within the FSM blueprint, we were able to build three distinct motion systems with virtually identical FSM definitions. This pattern has proven its ability to handle different primitive operations—be it altering localRotation, localScale, or localPosition—simply by swapping out the specialized context. This kind of separation of concerns leads to robust, maintainable, and highly reusable code.&lt;/p&gt;
&lt;p&gt;The final proof of concept in SimpleTranslationDemo.cs, simultaneously orchestrating three separate translation contexts with one FSM blueprint, underscores the pattern's efficiency and flexibility.&lt;/p&gt;
&lt;p&gt;Up Next: The Grand Finale&lt;/p&gt;
&lt;p&gt;We've mastered the primitives. In the final article of this series, we'll connect the three systems—RotationFSM, ScalingFSM, and TranslationFSM—to a single object. Get ready for the Combined Motion Demo, where we'll show an object spinning, pulsing, and oscillating all at once, driven by multiple, independently managed FSM contexts. This is where the true power of this decoupled architecture shines! Keep an eye out for the final installment.&lt;/p&gt;
&lt;p&gt;See the demo in action:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/SWzuJKpXIRU&quot;&gt;YouTube Channel Video&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=6430030048270798462&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6450/completing-the-motion-trilogy-the-reusable-translationfsm</guid>
<pubDate>Tue, 14 Oct 2025 22:23:29 +0000</pubDate>
</item>
<item>
<title>Applying the FSM Context Pattern to Scaling: The Reusable ScalarFSM</title>
<link>https://coderlegion.com/6448/applying-the-fsm-context-pattern-to-scaling-the-reusable-scalarfsm</link>
<description>&lt;h2 id=&quot;applying-the-fsm-context-pattern-to-scaling-the-reusable-scalarfsm&quot;&gt;Applying the FSM Context Pattern to Scaling: The Reusable &lt;strong&gt;ScalarFSM&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;In our previous article, we demonstrated how to eliminate &lt;code&gt;Update()&lt;/code&gt; spaghetti by applying the &lt;strong&gt;FSM Context Pattern&lt;/strong&gt; to complex &lt;strong&gt;Rotation&lt;/strong&gt; logic. The result was a single, reusable blueprint (&lt;code&gt;&quot;RotationFSM&quot;&lt;/code&gt;) that drove three objects on different axes.&lt;/p&gt;
&lt;p&gt;Here, we prove the true versatility of this pattern by applying it to &lt;strong&gt;Scale&lt;/strong&gt; motion. The vast majority of the logic remains the same—only the Context data and the specific Unity functions change.&lt;/p&gt;
&lt;h3 id=&quot;1-the-context-swapping-angular-for-linear-parameters&quot;&gt;1. The Context: Swapping Angular for Linear Parameters&lt;/h3&gt;
&lt;p&gt;The core philosophy remains: isolate the specific data required for the motion. We move from the &lt;code&gt;RotationContext&lt;/code&gt; to the &lt;code&gt;ScaleContext&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Rotation Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Scale Context Parameters &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Purpose&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;RotationSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;ScaleSpeed (float) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Linear speed of scale change.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;RotationAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;ScaleAxis (Vector3) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The axis (or axes) to apply the scale along.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;MaxAngle / MinAngle &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;MaxScale / MinScale &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;The absolute min and max bounds for the object's local scale.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;scalecontext-cs-data-encapsulation&quot;&gt;ScaleContext.cs: Data Encapsulation&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;ScaleContext&lt;/code&gt; holds the new parameters and is what ultimately manipulates the &lt;code&gt;TransformHandle.localScale&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class ScaleContext : IStateContext
{
    // The new parameters that define scaling motion
    public float ScaleSpeed = 0.5f;
    public float MaxScale = 3.0f;
    public float MinScale = 0.5f;

    public Vector3 ScaleAxis;
    public Vector3 OriginalScale = Vector3.one;

    public Transform TransformHandle;
    // ...
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;2-the-fsm-definition-same-flow-new-names&quot;&gt;2. The FSM Definition: Same Flow, New Names&lt;/h3&gt;
&lt;p&gt;The Finite State Machine flow is identical to the rotation demo (Move $\rightarrow$ Max $\rightarrow$ Move Back $\rightarrow$ Min) but uses domain-appropriate terminology.&lt;/p&gt;
&lt;p&gt;The blueprint name changes from &lt;code&gt;&quot;RotationFSM&quot;&lt;/code&gt; to &lt;code&gt;&quot;ScalarFSM&quot;&lt;/code&gt;.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Rotation FSM &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Scalar FSM (Change)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: RotatingForward &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingUp&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;States: RotatingBackward &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;States: ScalingDown&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MaxReached &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Apex&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;Predicate: MinReached &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Predicate: Root&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;the-core-logic-the-only-update-&quot;&gt;The Core Logic (The Only Update)&lt;/h4&gt;
&lt;p&gt;Instead of applying a Quaternion update using &lt;code&gt;Quaternion.AngleAxis&lt;/code&gt;, the state update logic now directly modifies the &lt;code&gt;localScale&lt;/code&gt; vector using the &lt;code&gt;ScaleAxis&lt;/code&gt; vector stored in the Context.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// The OnUpdateScalingUp function within ScaleContext.cs
private void OnUpdateScalingUp(IStateContext context)
{
    if (context is ScaleContext sc)
    {
        // Linearly increase the scale along the specified axis(es)
        Vector3 scaleDelta = sc.ScaleAxis * (sc.ScaleSpeed * Time.deltaTime);
        sc.TransformHandle.localScale += scaleDelta; // The only movement line!
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The elegance here is that the state engine (the FSM) required &lt;strong&gt;zero changes&lt;/strong&gt;. We only updated the specific motion logic inside the state functions of the new &lt;code&gt;ScaleContext&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;3-the-entry-point-demonstrating-multi-axis-motion&quot;&gt;3. The Entry Point: Demonstrating Multi-Axis Motion&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleScalarDemoFSM.cs&lt;/code&gt; acts as the entry point. This demo highlights a capability easily solved with scaling that was slightly more complex with rotation: &lt;strong&gt;multi-axis movement&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Notice how the third instance utilizes a &lt;code&gt;ScaleAxis&lt;/code&gt; vector with multiple components set to &lt;code&gt;1&lt;/code&gt; to drive a single FSM instance to scale along &lt;strong&gt;both the X and Y axes&lt;/strong&gt; simultaneously.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private void OnEnterExecuting(IStateContext context)
{
    if (context is SimpleScalarDemoFSM ssd)
    {
        float speed = 0.5f;
        float maxScale = 3f;
        float minScale = 0.5f;
        
        // 1. X-axis Scale
        ScaleContext xAxisContext = new ScaleContext(ssd.Xaxis, new Vector3(1, 0, 0), speed, maxScale, minScale);
        
        // 2. Y-axis Scale
        ScaleContext yAxisContext = new ScaleContext(ssd.Yaxis, new Vector3(0, 1, 0), speed, maxScale, minScale);
        
        // 3. XY-axis Scale: Scales on X and Y using the *same* FSM definition
        ScaleContext xyAxisContext = new ScaleContext(ssd.XYaxis, new Vector3(1, 1, 0), speed, maxScale, minScale);
        
        // ... Instantiate all handles and transition to start state
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This demo proves that the FSM Context Pattern is an engine-agnostic architectural solution. Once you define the pattern, reusing it for any kind of movement—Rotation, Scale, or Translation (coming next!)—is as simple as defining a new Context class.&lt;/p&gt;
&lt;p&gt;See the demo in action:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/gmFFuIdg82U&quot;&gt;YouTube Channel Video&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support the Vision and See the Code!&lt;/p&gt;
&lt;p&gt;If this pattern has helped clean up your Update() loop, please consider supporting our development! Your support ensures we can continue to provide advanced, architectural solutions for cleaner game development.&lt;/p&gt;
&lt;p&gt;Resources &amp;amp; Code:&lt;/p&gt;
&lt;p&gt;The FSM Package (Unity Asset Store):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://assetstore.unity.com/packages/slug/332450&quot;&gt;https://assetstore.unity.com/packages/slug/332450&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;NuGet Package (Non-Unity Core):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&quot;&gt;https://www.nuget.org/packages/TheSingularityWorkshop.FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;GitHub Repository:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/FSM_API&quot;&gt;https://github.com/TrentBest/FSM_API&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Support Our Work:&lt;/p&gt;
&lt;p&gt;Patreon Page:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/c/TheSingularityWorkshop&quot;&gt;https://www.patreon.com/c/TheSingularityWorkshop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; Support Us (PayPal Donation):&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&quot;&gt;https://www.paypal.com/donate/?hosted_button_id=3Z7263LCQMV9J&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We'd love to hear your thoughts! Please Like this post, Love the code, and Share your feedback in the comments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=11780617275403541958&quot; alt=&quot;A Hyper-Detailed, Architecturally Impossible Synthesis of Consciousness and Digital Matter. The image is a frenetic, deeply complex digital vista where a central Luminous Eye dominates a vast, glowing circuit landscape. This eye, suspended mid-air, is a sphere of intense, fractal energy—a pulsating vortex of pink, violet, and electric blue light—that powerfully suggests an emergence of digital consciousness or a Technological Singularity itself. The core is a bottomless black aperture, ringed by a white-hot plasma disc. Below this ocular energy source, the light dissipates into an intricate, copper-gold and neon-blue Circuit Board Megastructure that stretches to the horizon, impossibly dense with exaggerated microchips, glowing resistor arrays, and power conduits that form deep, glowing canyons. The background is a dark, holographic projection field displaying complex schematics, mathematical models, and flowing data streams, reinforcing the theme of Absolute Digital Engineering. The entire scene is bathed in a dramatic, opposing light source—a warm, orange-gold glow from the left and an ice-cold, electric-blue glow from the right—creating a maximalist, high-contrast visual experience that definitively rejects the minimalist simplicity of conventional design and announces: Technology is intricate, overwhelming, and infinitely complex.&quot;&gt;&lt;/p&gt;
</description>
<category>Open Source Tools</category>
<guid isPermaLink="true">https://coderlegion.com/6448/applying-the-fsm-context-pattern-to-scaling-the-reusable-scalarfsm</guid>
<pubDate>Tue, 14 Oct 2025 21:23:15 +0000</pubDate>
</item>
<item>
<title>Building a Reusable State Machine for Oscillating Rotation in Unity</title>
<link>https://coderlegion.com/6446/building-a-reusable-state-machine-for-oscillating-rotation-in-unity</link>
<description>&lt;h2 id=&quot;escaping-update-spaghetti-reusable-oscillation-with-fsm-amp-context-in-unity&quot;&gt;Escaping Update() Spaghetti: Reusable Oscillation with FSM &amp;amp; Context in Unity&lt;/h2&gt;
&lt;p&gt;If you’ve ever built a Unity object that needs to move or rotate between two points—like a swinging pendulum, a turret oscillating for patrol, or a security camera scanning an area—you’ve likely ended up with a tangle of booleans and &lt;code&gt;if/else&lt;/code&gt; statements in your &lt;code&gt;Update()&lt;/code&gt; loop.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// The typical mess you want to avoid
void Update()
{
    if (isMovingForward)
    {
        // Move Forward Logic
        if (transform.rotation.z &amp;gt; MaxAngle)
        {
            isMovingForward = false;
        }
    }
    else // isMovingBackward
    {
        // Move Backward Logic
        if (transform.rotation.z &amp;lt; MinAngle)
        {
            isMovingForward = true;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By leveraging the &lt;strong&gt;Finite State Machine (FSM)&lt;/strong&gt; pattern with a distinct &lt;strong&gt;Context&lt;/strong&gt; object (using the &lt;code&gt;FSM_UnityIntegrationAdvanced&lt;/code&gt; package), we can create a single, clean definition for &lt;em&gt;oscillating rotation&lt;/em&gt; that can be instantly reused across any number of objects and axes.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-heart-of-the-demo-the-fsm-context&quot;&gt;The Heart of the Demo: The FSM Context&lt;/h3&gt;
&lt;p&gt;The core idea is to separate the object's &lt;strong&gt;data&lt;/strong&gt; (where it is, how fast it moves) from the &lt;strong&gt;logic&lt;/strong&gt; (how it behaves). This is done via the &lt;code&gt;RotationContext&lt;/code&gt; class, which acts as the data structure for each rotating object.&lt;/p&gt;
&lt;h4 id=&quot;rotationcontext-cs-data-encapsulation&quot;&gt;RotationContext.cs: Data Encapsulation&lt;/h4&gt;
&lt;p&gt;By implementing &lt;code&gt;IStateContext&lt;/code&gt;, this class holds everything the FSM needs to operate on the specific object:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public class RotationContext : IStateContext
{
    // Object and parameters for THIS instance
    public Transform TransformHandle;
    public Vector3 RotationAxis;
    public float RotationSpeed;
    public float MaxAngle;
    public float MinAngle;
    // ... other data
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;the-universal-fsm-definition&quot;&gt;The Universal FSM Definition&lt;/h4&gt;
&lt;p&gt;The beauty of this approach is that the Finite State Machine itself (&lt;code&gt;&quot;RotationFSM&quot;&lt;/code&gt;) is defined &lt;strong&gt;only once&lt;/strong&gt; inside the &lt;code&gt;RotationContext&lt;/code&gt; constructor, making it a reusable blueprint.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;State Name &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Logic (Update)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;RotatingForward&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Apply positive rotation to &lt;code&gt;TransformHandle&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;RotatingBackward&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Apply negative rotation to &lt;code&gt;TransformHandle&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;Transition (What decides the change) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Condition (Predicate)&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;RotatingForward&lt;/code&gt; → &lt;code&gt;RotatingBackward&lt;/code&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;MaxReached()&lt;/code&gt;: Checks if the current angle ≥ &lt;code&gt;MaxAngle&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;RotatingBackward&lt;/code&gt; → &lt;code&gt;RotatingForward&lt;/code&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;MinReached()&lt;/code&gt;: Checks if the current angle ≤ &lt;code&gt;MinAngle&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The logic in &lt;code&gt;OnUpdateRotatingForward&lt;/code&gt; and &lt;code&gt;OnUpdateRotatingBackward&lt;/code&gt; simply drives the object, relying entirely on the &lt;code&gt;MaxReached&lt;/code&gt; and &lt;code&gt;MinReached&lt;/code&gt; predicates to decide when the object's behavior must change.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-entry-point-instantiating-reusable-logic&quot;&gt;The Entry Point: Instantiating Reusable Logic&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleRotationDemo.cs&lt;/code&gt; is a standard Unity &lt;code&gt;MonoBehaviour&lt;/code&gt; whose sole job is to kick off the system in its &lt;code&gt;Awake()&lt;/code&gt; or &lt;code&gt;OnEnterExecuting&lt;/code&gt; method.&lt;/p&gt;
&lt;p&gt;Instead of writing three separate components (one for X, one for Y, one for Z), we instantiate three unique &lt;strong&gt;Context&lt;/strong&gt; objects, each feeding the same shared FSM definition (&lt;code&gt;&quot;RotationFSM&quot;&lt;/code&gt;) with different parameters.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private void OnEnterExecuting(IStateContext context)
{
    if (context is SimpleRotationDemo srd)
    {
        float speed = 90.0f;
        float maxAngle = 45.0f;
        float minAngle = -45.0f;

        // 1. X-axis Rotation: Unique context, shared FSM logic
        RotationContext xAxisContext = new RotationContext(srd.Xaxis, new Vector3(1, 0, 0), speed, maxAngle, minAngle);
        srd.XaxisHandle = xAxisContext.Status;

        // 2. Y-axis Rotation: Same FSM logic, different object/axis
        RotationContext yAxisContext = new RotationContext(srd.Yaxis, new Vector3(0, 1, 0), speed, maxAngle, minAngle);
        srd.YaxisHandle = yAxisContext.Status;

        // 3. Z-axis Rotation: Same FSM logic, different object/axis
        RotationContext zAxisContext = new RotationContext(srd.Zaxis, new Vector3(0, 0, 1), speed, maxAngle, minAngle);
        srd.ZaxisHandle = zAxisContext.Status;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;the-result-scalable-advanced-integration&quot;&gt;The Result: Scalable Advanced Integration&lt;/h4&gt;
&lt;p&gt;With minimal setup, we achieve perfectly synchronized, bounded rotation across three distinct objects, all driven by a single, well-defined state machine. This pattern easily extends to more advanced scenarios:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Reusability:&lt;/strong&gt; The same &lt;code&gt;RotationFSM&lt;/code&gt; can be used to drive dozens of turrets, doors, or fans.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Maintainability:&lt;/strong&gt; If you need to change the rotation logic (e.g., adding easing), you change one piece of code (&lt;code&gt;OnUpdateRotatingForward&lt;/code&gt;), not three.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extensibility:&lt;/strong&gt; This blueprint instantly adapts to your &lt;code&gt;Translation&lt;/code&gt;, &lt;code&gt;Scale&lt;/code&gt;, or &lt;code&gt;NavMeshAgentsDemo&lt;/code&gt; logic—simply define a new FSM and Context for those specific concerns.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This demo proves that advanced FSM integration doesn't mean complex setup, but rather intelligent architectural separation to keep your Unity code clean and highly reusable.&lt;/p&gt;
</description>
<category>Java</category>
<guid isPermaLink="true">https://coderlegion.com/6446/building-a-reusable-state-machine-for-oscillating-rotation-in-unity</guid>
<pubDate>Tue, 14 Oct 2025 20:05:21 +0000</pubDate>
</item>
</channel>
</rss>