Skip to content

Commit

Permalink
Added StateMachine for AS3 Standard and MultiCore
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Hall committed Oct 19, 2009
1 parent 044a5e0 commit e59645d
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/assets/node/Node20543.xml
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Node id="20543" name="StateMachine" thumb="box">
<NodeMap>
<Project
name="StateMachine Utility for AS3"
status="Production"
repo="Utility_AS3_StateMachine"
tag="StateMachine_1_2"
version="1.2"
archive="AS3/Utility_AS3_StateMachine.zip"
docs="AS3/Utility_AS3_StateMachine/asdoc-multicore/"
live=""
forum="topic=859.0"
owner="Neil Manuell"
owner_node="320"
pic="PureMVC-Framework-AS3-Std-MC.png"
shot="">

<Description><![CDATA[
This utility provides a simple yet effective Finite State Machine implementation, which allows the definition of discrete states, and the valid transitions to other states available from any given state, and the actions which trigger the transitions. A mechanism is provided for defining the entire state machine in XML and having a fully populated StateMachine injected into the PureMVC app. Standard and MultiCore versions are included.
]]></Description>

<ReleaseNotes><![CDATA[<B>Changes in Version 1.2</B>
* Refactored source into src folder.
<B>Changes in Version 1.1</B>
* Enhanced to cater for fault outcome, with probability of fault.
* Provide a token tracking feature.
<B>Features in Version 1.0</B>
<I>Finite State Machine Implementation</I>
* A StateMachine class, which extends Mediator and maintains the FSM representation as a set of discrete, named States. This Mediator is interested in StateMachine.ACTION and StateMachine.CANCEL notifications. It exposes methods for regsistering and removing States.
<I>State Representation</I>
* The States held and navigated by the StateMachine are instances of a State class, which carries several critical pieces of information about that State. Each State has optional associated Notifications to be sent on entry into the State and exit from the State.
* The exiting notification carries a reference in the body to the State that we are transitioning to. This helps actors respond properly by anticipating the destination state.
* The entering notification for a State carries a reference in the body to the state we are entering as well, in case you've sub-classed State to pass data.
* It is up to the programmer to define and register commands or mediators with interest in these entering and exiting notifications, the state machine simply sends them at the appropriate times.
* The State class also exposes methods for defining and removing transitions. A transition simply maps an action name to a target State name.
<I>State Transitions</I>
* The transition from one state to the next is triggered by any actor sending a StateMachine.ACTION Notification. Include the name of the action in the Notification's type parameter.
* Actions are what trigger the StateMachine to initiate the transition from the one State to the next. There is no formal Action class at this time, it is merely a name that will trigger a State transition.
* It is up to the application to ensure any special conditions for making the transition are met before sending the StateMachine.ACTION Notification, which will initiate the transition immediately if one is defined for the input action given the current State.
* Any actor responding to the Notification sent when exiting a state may send a StateMachine.CANCEL notification, which will cause the StateMachine not to enter the next State. The programmer must insure that no other responses to the current State's exit notification need to be rolled back. This is best done by checking any items that could lead to a StateMachine.CANCEL being sent before initiating any exit activity such as visual transitions or form clearing/population, thus avoiding the need to rollback to restore the application to the state being exited.
* Finally, when a transition is complete, the StateMachine sends a StateMachine.CHANGED Notification, with a reference to the new State. This is sent once any exiting notification for the previous state, as well as any entering notification for the new state have both been executed, and the current state of the StateMachine has been updated to the new state.
<I>FSM Injector</I>
* Also included in this release is useful class that allows you to define your FSM in an XML format, and pass it to the FSMInjector where it will be parsed, and a fully populated StateMachine instance will be created and registered via your Facade.
* The FSMInjector extends Notifier to give it a reference to the Facade for injecting the completed StateMachine.
* The XML format for the FSM Injector is simple. For instance here is the FSM for a door:
<font face="courier" size="10">
&lt;fsm initial="CLOSED"&gt;
&lt;state name="OPENED" entering="openingNote" exiting="aboutToCloseNote"&gt;
&lt;transition action="CLOSE" target="CLOSED"/&gt;
&lt;/state&gt;
&lt;state name="CLOSED" entering="closingNote"&gt;
&lt;transition action="OPEN" target="OPENED"/&gt;
&lt;transition action="LOCK" target="UNLOCKED"/&gt;
&lt;/state&gt;
&lt;state name="LOCKED" entering="lockingNote"&gt;
&lt;transition action="UNLOCK" target="CLOSED"/&gt;
&lt;/state&gt;
&lt;/fsm&gt;
</font>
* The above FSM defines three discrete states OPENED, CLOSED and LOCKED.
* The actions OPEN, CLOSE and LOCK are used to trigger state transitions.
* It is only possible to LOCK the door when it is CLOSED, because only the CLOSED state defines a transition targeting the LOCKED state.
* It is not possible to OPEN the door from the LOCKED state because no transition is defined targeting the OPEN state.
* And when you UNLOCK the door, it returns to the CLOSED state, where it is once again possible to OPEN or LOCK.
* An exiting notification is defined only for exiting the OPEN state to illustrate that entering and exiting notifications are optional.
]]></ReleaseNotes>

<Installation><![CDATA[<B>Installing the Project Source Code</B>
<U>From the archive</U>
* Download the latest source code archive.
* Unzip the source code zip to any folder on your disk.
For instance: c:\development\
* You will see a AsyncStub_X_Y (where X_Y is version) source folder.
For instance: c:\development\AsyncStub_X_Y
<U>From the Repository</U>
* Use your favorite SVN client to retrieve the latest source code release from the repository.
<B>Using the Utility in Your Project</B>
<I>Add the Utility Library to your Project Using Flex Builder 3</I>
* Open or create a Flex or AIR Project in Flex Builder 3
* From the Flex Builder menu, do: Project -> Properties -> Flex Build Path -> Library Path -> Add SWC
* Browse and select the SWC (for instance: c:\development\AsyncStub\Utility_AS3_AsyncStub_X_Y.swc)
* Click Finish.
<I>Add the Utility Library to your Flash/CS3/CS4 Project</I>
* The distributed SWC file will not work.
* You must place the source code in your classpath.
* Consult the CS3/CS4 documentation for the various ways to accomplish this.
]]></Installation>

</Project>
</NodeMap>
</Node>
101 changes: 101 additions & 0 deletions src/assets/node/Node20593.xml
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Node id="20593" name="StateMachine" thumb="box">
<NodeMap>
<Project
name="StateMachine Utility for AS3"
status="Production"
repo="Utility_AS3_StateMachine"
tag="StateMachine_1_2"
version="1.2"
archive="AS3/Utility_AS3_StateMachine.zip"
docs="AS3/Utility_AS3_StateMachine/asdoc-standard/"
live=""
forum="topic=859.0"
owner="Neil Manuell"
owner_node="320"
pic="PureMVC-Framework-AS3-Std-MC.png"
shot="">

<Description><![CDATA[
This utility provides a simple yet effective Finite State Machine implementation, which allows the definition of discrete states, and the valid transitions to other states available from any given state, and the actions which trigger the transitions. A mechanism is provided for defining the entire state machine in XML and having a fully populated StateMachine injected into the PureMVC app. Standard and MultiCore versions are included.
]]></Description>

<ReleaseNotes><![CDATA[<B>Changes in Version 1.2</B>
* Refactored source into src folder.
<B>Changes in Version 1.1</B>
* Enhanced to cater for fault outcome, with probability of fault.
* Provide a token tracking feature.
<B>Features in Version 1.0</B>
<I>Finite State Machine Implementation</I>
* A StateMachine class, which extends Mediator and maintains the FSM representation as a set of discrete, named States. This Mediator is interested in StateMachine.ACTION and StateMachine.CANCEL notifications. It exposes methods for regsistering and removing States.
<I>State Representation</I>
* The States held and navigated by the StateMachine are instances of a State class, which carries several critical pieces of information about that State. Each State has optional associated Notifications to be sent on entry into the State and exit from the State.
* The exiting notification carries a reference in the body to the State that we are transitioning to. This helps actors respond properly by anticipating the destination state.
* The entering notification for a State carries a reference in the body to the state we are entering as well, in case you've sub-classed State to pass data.
* It is up to the programmer to define and register commands or mediators with interest in these entering and exiting notifications, the state machine simply sends them at the appropriate times.
* The State class also exposes methods for defining and removing transitions. A transition simply maps an action name to a target State name.
<I>State Transitions</I>
* The transition from one state to the next is triggered by any actor sending a StateMachine.ACTION Notification. Include the name of the action in the Notification's type parameter.
* Actions are what trigger the StateMachine to initiate the transition from the one State to the next. There is no formal Action class at this time, it is merely a name that will trigger a State transition.
* It is up to the application to ensure any special conditions for making the transition are met before sending the StateMachine.ACTION Notification, which will initiate the transition immediately if one is defined for the input action given the current State.
* Any actor responding to the Notification sent when exiting a state may send a StateMachine.CANCEL notification, which will cause the StateMachine not to enter the next State. The programmer must insure that no other responses to the current State's exit notification need to be rolled back. This is best done by checking any items that could lead to a StateMachine.CANCEL being sent before initiating any exit activity such as visual transitions or form clearing/population, thus avoiding the need to rollback to restore the application to the state being exited.
* Finally, when a transition is complete, the StateMachine sends a StateMachine.CHANGED Notification, with a reference to the new State. This is sent once any exiting notification for the previous state, as well as any entering notification for the new state have both been executed, and the current state of the StateMachine has been updated to the new state.
<I>FSM Injector</I>
* Also included in this release is useful class that allows you to define your FSM in an XML format, and pass it to the FSMInjector where it will be parsed, and a fully populated StateMachine instance will be created and registered via your Facade.
* The FSMInjector extends Notifier to give it a reference to the Facade for injecting the completed StateMachine.
* The XML format for the FSM Injector is simple. For instance here is the FSM for a door:
<font face="courier" size="10">
&lt;fsm initial="CLOSED"&gt;
&lt;state name="OPENED" entering="openingNote" exiting="aboutToCloseNote"&gt;
&lt;transition action="CLOSE" target="CLOSED"/&gt;
&lt;/state&gt;
&lt;state name="CLOSED" entering="closingNote"&gt;
&lt;transition action="OPEN" target="OPENED"/&gt;
&lt;transition action="LOCK" target="UNLOCKED"/&gt;
&lt;/state&gt;
&lt;state name="LOCKED" entering="lockingNote"&gt;
&lt;transition action="UNLOCK" target="CLOSED"/&gt;
&lt;/state&gt;
&lt;/fsm&gt;
</font>
* The above FSM defines three discrete states OPENED, CLOSED and LOCKED.
* The actions OPEN, CLOSE and LOCK are used to trigger state transitions.
* It is only possible to LOCK the door when it is CLOSED, because only the CLOSED state defines a transition targeting the LOCKED state.
* It is not possible to OPEN the door from the LOCKED state because no transition is defined targeting the OPEN state.
* And when you UNLOCK the door, it returns to the CLOSED state, where it is once again possible to OPEN or LOCK.
* An exiting notification is defined only for exiting the OPEN state to illustrate that entering and exiting notifications are optional.
]]></ReleaseNotes>

<Installation><![CDATA[<B>Installing the Project Source Code</B>
<U>From the archive</U>
* Download the latest source code archive.
* Unzip the source code zip to any folder on your disk.
For instance: c:\development\
* You will see a AsyncStub_X_Y (where X_Y is version) source folder.
For instance: c:\development\AsyncStub_X_Y
<U>From the Repository</U>
* Use your favorite SVN client to retrieve the latest source code release from the repository.
<B>Using the Utility in Your Project</B>
<I>Add the Utility Library to your Project Using Flex Builder 3</I>
* Open or create a Flex or AIR Project in Flex Builder 3
* From the Flex Builder menu, do: Project -> Properties -> Flex Build Path -> Library Path -> Add SWC
* Browse and select the SWC (for instance: c:\development\AsyncStub\Utility_AS3_AsyncStub_X_Y.swc)
* Click Finish.
<I>Add the Utility Library to your Flash/CS3/CS4 Project</I>
* The distributed SWC file will not work.
* You must place the source code in your classpath.
* Consult the CS3/CS4 documentation for the various ways to accomplish this.
]]></Installation>

</Project>
</NodeMap>
</Node>

0 comments on commit e59645d

Please sign in to comment.