Giter Site home page Giter Site logo

fastsm's Introduction

FastSM

FastSM aims to be a more lightweight alternative to the fantastic SnowState library by Sahaun. FastSM employs different design paradigms which make it more flexible in certain cases, while making it more restrictive in others. Hard limits FastSM has are :

  • There can never be more than 64 State Tags per FSM
  • There can never be more than 64 States per FSM if you are using the allow/forbid feature of state transitions.

I will be documenting FastSM properly soon but for now you can find example code here :

enum Tag {
    A,
    B,
    C
}
enum State {
    None, //required, any name allowed
    Foo,
    Bar,
    Baz,
    MAX //QoL
}
enum Trigger {
    A,
    MAX
}
fsm = new FastSM(State.MAX, Trigger.MAX);
fsm.event_add_default("update");

fsm.add( State.Baz, {
    name : "I should never show up in this example!",
    enter : function(this) {
       show_debug_message(this.name)
    }
});

fsm.add( State.Bar, {
    name : "I should show up in this example!",
    tags : Tag.C,
    enter : function(this) {
       show_debug_message(this.name)
    }, 
    update : function() {
         show_debug_message("update should be called!")
    }
});

fsm.add( State.Foo, {
    name : "I am the entry state!",
    tags : [Tag.A, Tag.B],
    enter : function(this) {
        show_debug_message(this.name)
    }
});

fsm.transition_add( Trigger.A, {
    name : "Trigger A",
    include: all,
    forbid: State.Bar,
    transition : function(_source) {
        switch _source {
            case State.Foo:
                return State.Bar;
            break;
            case State.Bar:
                return State.Baz;
            break;
            default:
                return State.None;
        }
    }
});

fsm.build().start( State.Foo );
fsm.trigger( Trigger.A );
fsm.trigger( Trigger.A );
fsm.trigger( Trigger.A );
fsm.update();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.