Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JulianDicken/FastSM
https://github.com/JulianDicken/FastSM
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/JulianDicken/FastSM
- Owner: JulianDicken
- License: mit
- Created: 2022-06-02T19:19:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-16T07:08:05.000Z (11 months ago)
- Last Synced: 2024-08-02T07:12:14.188Z (5 months ago)
- Language: Game Maker Language
- Size: 18.6 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-gamemaker - FastSM - Lightweight alternative to SnowState. (State Machines / Recommendations)
README
# FastSM
FastSM aims to be a more lightweight alternative to the fantastic SnowState library by [Sahaun](https://github.com/sohomsahaun/SnowState/).
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 :
```js
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.trigger_add( Trigger.A, {
name : "Trigger A",
include: all,
forbid: State.Bar,
trigger : 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();
```