Beispiel #1
0
 // Adds a machine (located in path) to this GAIA_Manager
 // Returns:
 // 1 if OK
 //-1 if an GAIA_Parser is required to use this method
 //-2 if cannot be added (wrong parameters or repeated FA)
 //-3 if there are errors parsing file located in path
 public int addFSM(string path)
 {
     if (this.parser == null)
     {
         return(-1);
     }
     else
     {
         //Invoke parser with path
         FA_Classic parsedfsm = parser.ParsePath(path);
         if (parsedfsm != null)
         {
             try
             {
                 FSM_dic.Add(new Tuple(parsedfsm.getTag(), parsedfsm.getFAid()), parsedfsm);
                 return(1);
             }
             catch (Exception e)
             {
                 return(-2);
             }
         }
         else
         {
             return(-3);
         }
     }
 }
Beispiel #2
0
 // Removes a machine that had been added to this GAIA_Manager
 // Returns:
 // 1 if OK
 //-1 if cannot remove that machine (corrupted fsm object or it does not exist)
 public int deleteFSM(FA_Classic fsm)
 {
     try
     {
         FSM_dic.Remove(new Tuple(fsm.getTag(), fsm.getFAid()));
         return(1);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
Beispiel #3
0
 // Add a machine (passed as FA parameter) to this GAIA_Manager
 // Returns:
 // 1 if OK
 //-1 if cannot be added
 public int addFSM(FA_Classic fsm)
 {
     try
     {
         //Add the FA to the attribute FSM_dic
         FSM_dic.Add(new Tuple(fsm.getTag(), fsm.getFAid()), fsm);
         return(1);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
Beispiel #4
0
        // <summary>
        // Initializes a new instance of the <see cref="T:FSM.FSM_Machine">FSM_Machine</see> class.
        // </summary>
        // <param name="fsm">FA object</param>
        // <param name="character">Character that demands this FSM based on fsm param</param>
        // <remarks>FSM_Manager uses this method to initialize a machine</remarks>
        public FSM_Machine(FA_Classic fsm, System.Object character)
        {
            this.Character = character;
            FSM            = fsm;

            CurrentState = FSM.getInitialState();
            MaxEnabled   = 1;

            DoActions     = new List <int>();
            FSM_Stack     = new List <Stack <FA_Classic> >();
            ControlStack  = new List <Stack <State> >();
            SuperiorStack = new List <Stack <State> >();
            EnabledStates = new List <State>();

            //Concurrent
            if (FSM.getTag() == Tags.CONCURRENT_STATES)
            {
                MaxEnabled = (FSM as FA_Concurrent_States).getMaxConcurrent();
                for (int i = 0; i < (FSM as FA_Concurrent_States).getMaxConcurrent(); i++)
                {
                    SuperiorStack.Add(new Stack <State>());
                    FSM_Stack.Add(new Stack <FA_Classic>());
                    this.FSM_Stack[i].Push(FSM);
                    ControlStack.Add(new Stack <State>());
                    ControlStack[i].Push(CurrentState);
                }
                EnabledStates = (FSM as FA_Concurrent_States).getInitials().ToList();
                StatesCredits = (FSM as FA_Concurrent_States).getCreditsDic();
            }
            else      //The others
            {
                MaxEnabled = 1;
                SuperiorStack.Add(new Stack <State>());
                FSM_Stack.Add(new Stack <FA_Classic>());
                this.FSM_Stack[0].Push(FSM);
                ControlStack.Add(new Stack <State>());
                ControlStack[0].Push(CurrentState);

                EnabledStates.Add(FSM.getInitialState());
            }

            rnd           = new System.Random();
            UpdateEnabled = false;
            inertialTimer = new Stopwatch();
        }