public override BehaviorExecution InstanciateOpaqueBehavior(Mascaret.Behavior behavior, string typeName, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
    {
        //Type type = Types. GetType( typeName,"Assembly-CSharp");
        Type type            = Type.GetType(typeName);
        BehaviorExecution be = null;

        if (type != null)
        {
            be = (BehaviorExecution)(Activator.CreateInstance(type));
        }
        // Use the Unity Monobehaviour method
        else
        {
            be = this.GetUnityBehaviourExecution(typeName, host, p);
        }

        if (be != null)
        {
            be.init(behavior, host, p, false);
        }
        else
        {
            PrintSingleton.Instance.log("ERREUR : " + typeName + " not found");
        }

        return(be);
    }
Exemplo n.º 2
0
    public static void onBehaviorStop(BehaviorExecution be)
    {
        ProceduralBehavior proceduralBehavior = (ProceduralBehavior)(((Agent)be.Host).getBehaviorExecutingByName("ProceduralBehavior"));

        proceduralBehavior.BehaviorToNode[be].CurrentExecution.Finish = BehaviorScheduler.Instance.getCurrentVirtualTime();
        for (int iP = 0; iP < proceduralBehavior.RunningProcedures.Count; iP++)
        {
            ProcedureExecution procInfo = proceduralBehavior.runningProcedures[iP];
            procInfo.informActionDone(((Agent)(proceduralBehavior.Host)).Aid, proceduralBehavior.BehaviorToNode[be]);
            proceduralBehavior.sendActionDoneMessage(proceduralBehavior.BehaviorToNode[be], procInfo);
        }

        //restart();
        proceduralBehavior.ispause = false;
    }
        public CallOperationBehaviorExecution(CallOperationAction paction, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
            : base(paction, host, p, false)
        {
            this.action = paction;
            MascaretApplication.Instance.VRComponentFactory.Log("CallOperationAction : " + action.Operation.Method);

            foreach (ValuePin pin in action.ValuePins)
            {
                p.Add(pin.name, pin.ValueSpec);
            }
            MascaretApplication.Instance.VRComponentFactory.Log("READY TO Start");

            behaviorExecution = action.Operation.Method.createBehaviorExecution(this.Host, p, false);
            if (behaviorExecution == null) MascaretApplication.Instance.VRComponentFactory.Log("Chérie ca va trancher");
        }
Exemplo n.º 4
0
    public static void executeIsolateOperation(string operation, Agent agt, Dictionary <string, ValueSpecification> spec)
    {
        Operation op = MascaretUtils.getOperation(operation, agt);

        if (op != null)
        {
            CallOperationAction act = new CallOperationAction();
            act.Operation = op;
            BehaviorExecution be = act.createBehaviorExecution(agt, spec, false);
            PrintSingleton.Instance.log("Manually executing " + operation + " for " + agt.name);
            be.execute(0.0);
        }
        else
        {
            PrintSingleton.Instance.log("Operation " + operation + " not found for " + agt.name);
        }
    }
    public override BehaviorExecution InstanciateOpaqueBehavior(Mascaret.Behavior behavior, string typeName, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
    {
        Type type            = Types.GetType(typeName, "Assembly-CSharp");
        BehaviorExecution be = null;

        if (type != null)
        {
            be = (BehaviorExecution)(Activator.CreateInstance(type));
        }
        else
        {
            Debug.Log("ERREUR : " + typeName + " not found");
        }

        if (be != null)
        {
            be.init(behavior, host, p, false);
        }
        return(be);
    }
    private BehaviorExecution GetUnityBehaviourExecution(string typeName, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
    {
        BehaviorExecution be = null;

        // Get the Class and Method names
        string[] split = typeName.Split('_');
        if (split.Length != 2)
        {
            return(be);
        }

        string className  = split[0];
        string methodName = split[1];

        GameObject unityObject = this.GetUnityObject(host);

        if (unityObject == null)
        {
            return(be);
        }
        Component comp = unityObject.GetComponent(className);

        if (comp == null)
        {
            return(be);
        }

        Type       t = Type.GetType(className);
        MethodInfo m = t.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);

        be = new UnityBehaviorExecution(comp, m);

        MethodInfo init = t.GetMethod("AddBehaviorExecution", BindingFlags.Public | BindingFlags.Instance);

        object[] initparams = new object[] { methodName, be };
        init.Invoke(comp, initparams);

        return(be);
    }
Exemplo n.º 7
0
 protected void onBehaviorStopped(BehaviorExecution be)
 {
     if (operationsExecution.Contains(be))
         operationsExecution.Remove(be);
 }
Exemplo n.º 8
0
        public void reActivate(BehaviorExecution be)
        {
            if (be != null)
                return;

            deleteExecutionBehavior(be);
            allBehaviors.Add(be);
        }
        protected void onBehaviorStop(BehaviorExecution be)
        {
            currentState.running = false;
            currentActionDone = true;

              //  StreamWriter file = MascaretApplication.Instance.logfile; file.Flush();
              //  file.WriteLine("Behavior stopped");

            foreach (Transition currentTransition in currentState.Outgoing)
            {
                if (currentTransition.Trigger.Count == 0)
                {
                    if (currentTransition.Guard == null) //|| trans[iT]->getGuard()->eval(context))
                    {
                        Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();

                        Action effect = currentTransition.Effect;
                        if (effect != null)
                        {
                            BehaviorScheduler.Instance.executeBehavior(effect, this.Host, param, false);
                        }

                        activateState(currentTransition.Target, param);
                    }
                }
            }
        }
        protected bool activateState(Vertex state, Dictionary<string, ValueSpecification> p)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;

              //  file.WriteLine("Activating State : " + state.name); file.Flush();
            currentState = state;

               if (state as FinalState == null)
                toStop = true;

            be = currentState.activate(Host, p);

            if (be != null)
            {

                currentState.running = true;
                //callBack function
                be.addCallbackOnBehaviorStop(onBehaviorStop);
                currentActionDone = false;
            }

            foreach (Transition currentTransition in currentState.Outgoing)
            {
                foreach (Trigger currentTrigger in currentTransition.Trigger)
                {
                    if (currentTrigger.MEvent.Type == "ChangeEvent")
                    {
                        ChangeEvent ce = currentTrigger.MEvent as ChangeEvent;
                        Expression exp = (Expression)ce.ChangeExpression.clone();
                        //callBack function
                        //evalutateExpression function
                    }
                }
            }

            return true;
        }
Exemplo n.º 11
0
        public void onBehaviorStop(BehaviorExecution be)
        {
            for (int iP = 0; iP < runningProcedures.Count; iP++)
            {
                ProcedureExecution procInfo = runningProcedures[iP];
                procInfo.informActionDone(((Agent)(this.Host)).Aid, behaviorToNode[be]);
                sendActionDoneMessage(behaviorToNode[be], procInfo);
            }

            //restart();
            ispause = false;
        }
Exemplo n.º 12
0
 public SchedInfo(BehaviorExecution b, TimeExpression time)
 {
     be = b;
     nextTime = time;
 }
Exemplo n.º 13
0
 protected void _onBehaviorRestarted(BehaviorExecution be)
 {
     if (be == null)
         return;
     foreach (BehaviorExecution currentBe in _suspendedBehaviors)
     {
         _insert(currentBe, 0);
         //currentBe = _suspendedBehaviors.Last;
         //COMMENT ON TRADUIT CE QUI SUIT?
         //_suspendedBehaviors[i]=_suspendedBehaviors.back();
         //_suspendedBehaviors.pop_back();
     }
 }
Exemplo n.º 14
0
        public void _insert(BehaviorExecution be, double dt)
        {
            if (be == null) return;

            _updateCurrentVirtualTime();

            TimeExpression nextTime = new TimeExpression(2000, 1, 1, 0, 0, 0);
            nextTime.TimeExp = currentVirtualTime.TimeExp + (long)(dt * 1000);
            foreach (SchedInfo info in behaviors)
            {

                if (nextTime.TimeExp < info.nextTime.TimeExp)
                {
                    //behaviors.AddBefore(new LinkedListNode<SchedInfo>(info), new SchedInfo(be,nextTime));
                    behaviors.AddBefore(behaviors.Find(info), new SchedInfo(be, nextTime));
                    return;
                }
            }

            behaviors.AddLast(new SchedInfo(be, nextTime));
        }
Exemplo n.º 15
0
 public void suspendExecutionBehavior(BehaviorExecution be)
 {
     if (be != null)
         return;
     _suspendedBehaviors.Add(be);
     //addCallbackOnBehaviorRestarted
     foreach (SchedInfo info in behaviors)
     {
         if (info.be == be)
         {
             behaviors.Remove(info);
             return;
         }
     }
 }
        public override double execute(double dt)
        {
            //  StreamWriter file = MascaretApplication.Instance.logfile; file.Flush();
             //   file.WriteLine("StateMachine"); file.Flush();
            if (first)
            {
                // TODO: Attention a gerer plus tard : possibilite de fixe l'etat en cours a l'initialisation de l'instance
                // Recherche de l'etat Initial
                List<PseudoState> ps = getStateMachine().ConnectionPoint;
                StateMachine machine = getStateMachine();
                List<Region> res = machine.Region;

                bool foundInitialState = false;
               // file.WriteLine("Pseudo state : " + ps.Count); file.Flush();
                foreach (PseudoState pseudo in ps)
                {
                    if (pseudo.kind == PseudoStateKind.INITIAL)
                    {
                        Dictionary<string, ValueSpecification> p = new Dictionary<string, ValueSpecification>();
                        List<Transition> trans = pseudo.Outgoing;
                        foreach (Transition transition in trans)
                        {
                            //if (_currentState) _currentState->desactivate();
                            activateState(transition.Target, p);
                        }
                        //file.WriteLine("Found Initial"); file.Flush();
                        foundInitialState = true;
                        break;
                    }
                }
                if (!foundInitialState) toStop = true;
                //toStop = foundInitialState ? false : true;
                first = false;
            }
            else
            {
                while (eventQueue.Count != 0)
                {
                    Vertex currentState = this.currentState;
                    if (currentState == null)//|| (currentState.Noninterpt && currentState.running))
                    { break; }

                   // if (this.Host.name == "tiroirProduits")
                       // file.WriteLine(" --->  " + this.Host.name + " stateMachine Behavior " + this.Specification.getFullName()+ " in " + currentState.getFullName()); file.Flush();

                    Trigger trigger = eventQueue[0];
                    eventQueue.RemoveAt(0);
                    List<Transition> trans = currentState.Outgoing;
                    MascaretApplication.Instance.VRComponentFactory.Log(" Trigger : " + trigger.name);
                   // file.WriteLine("Nb Trans : " + trans.Count); file.Flush();
                    for (int iT = 0; iT < trans.Count; iT++)
                    {

                        List<Trigger> transTriggers = trans[iT].Trigger;
                      //  file.WriteLine("Nb Triger : " + transTriggers.Count); file.Flush();
                        for (int i = 0; i < transTriggers.Count; i++)
                        {
                            Trigger transTrigger = transTriggers[i];
                           // if (this.Host.name == "tiroirProduits")
                               // file.WriteLine(" --->  " + this.Host.name + " " +  transTrigger.getFullName()); file.Flush();

                            if (transTrigger.equals(trigger))
                            {
                                Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();
                                //OclParser::Context context;
                                MascaretApplication.Instance.VRComponentFactory.Log(" Trigger OK");

                                MascaretEvent evt = trigger.MEvent;
                                if (evt != null && evt.Type == "SignalEvent")
                                {
                                    SignalEvent sevt = (SignalEvent)evt;
                                    InstanceSpecification signal = sevt.Signal;
                                    if (signal != null)
                                    {
                                        /*  // Gestion des parametres
                                        map<string, shared_ptr<Slot> > props = signal->getSlots();
                                        map<string, shared_ptr<Slot> >::iterator it;
                                        for (it = props.begin(); it != props.end(); it++)
                                        {
                                            vector<AnyValue> values;
                                            values.push_back((AnyValue)it->second->getValue()->getStringFromValue());
                                            context[it->first] = CollectionAnyValue(values);
                                            param[it->first] = it->second->getValue();
                                            cerr << it->first << " == " << it->second->getValue()->getStringFromValue() << endl;
                                        }
                                        */
                                    }
                                }
                                //context["self"]=getHost();

                                if (trans[iT].Guard == null) //|| trans[iT]->getGuard()->eval(context))
                                {
                                    if (currentState != null)
                                    {
                                        if (be != null)
                                        {
                                            be.stop();
                                            BehaviorScheduler.Instance.deleteExecutionBehavior(be);
                                            be = null;
                                        }
                                        currentState.desactivate();
                                    }

                                    Action effect = trans[iT].Effect;
                                    if (effect != null)
                                    {
                                        MascaretApplication.Instance.VRComponentFactory.Log("Has effect");

                                        BehaviorScheduler.Instance.executeBehavior(effect, this.Host, param, false);
                                    }

                                    MascaretApplication.Instance.VRComponentFactory.Log("Activate new state : " + trans[iT].Target.name);
                                    activateState(trans[iT].Target, param);
                                }
                            }
                        }
                    }
                }

                //	if(eventQueue.Count == 0)
                //		pause();
                //toStop = true;

            }

            return 0.01;
            //if (toStop) return 0;
            //else return 0.001;
        }
Exemplo n.º 17
0
        //default parameters sync = false
        public void start(InstanceSpecification host, Dictionary<string, InstanceSpecification> affectations, bool sync)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;
            if (action == null)
            {
               // file.WriteLine("Le noeud " + name + " n'a pas d'action associée!!!"); file.Flush();
                return;
            }

            Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();
            if (action.Kind == "SendSignal")
            {

                if (((SendSignalAction)action).Target == null)
                {
                    foreach (ActivityEdge currentEdge in Outgoing)
                    {
                        if (currentEdge.Target.Kind == "object")
                        {
                            if (affectations.ContainsKey(currentEdge.Target.name))
                            {
                                System.Console.WriteLine("Sending signal to : " + currentEdge.Target.name);
                                SendSignalAction ssAct = (SendSignalAction)action;
                                ssAct.Target = new SendSignalTarget();
                                ssAct.Target.target = affectations[currentEdge.Target.name];
                            }

                            else
                            {
                                System.Console.WriteLine("affectation of " + currentEdge.Target.name + " not found");
                            }

                        }
                    }
                }
            }
            if (action.Kind == "CallOperation")
            {
               // file.WriteLine("Executing Call operation" + action.name + " " + ((CallOperationAction)action).Operation.getFullName()); file.Flush();

                if (((CallOperationAction)action).isDynamic())
                {
                    param = ((CallOperationAction)action).getParameters();

                }
                else
                {
                    foreach (InputPin currentPin in action.InputPins)
                    {

                        string paramName = currentPin.getIncomingObjectNode()[0].name;
                      //  file.WriteLine(" Looking for : " + paramName); file.Flush();
                        if (!affectations.ContainsKey(currentPin.getIncomingObjectNode()[0].name))
                        {
                    //        file.WriteLine(((CallOperationAction)action).Operation.getFullName() + " from " + action.Owner.name + " MISS " + currentPin.getIncomingObjectNode()[0].name); file.Flush();
                        }
                        InstanceValue val = new InstanceValue(affectations[currentPin.getIncomingObjectNode()[0].name]);
                    //    file.WriteLine("..... Trouve " + val.ToString()); file.Flush();
                        param.Add(currentPin.name, val);
                    }
                }

                if (Activity != null)
                {
                    //	action.Context(Activity.Context);
                }

            }
            currentExecution = BehaviorScheduler.Instance.executeBehavior(action, host, param, sync);
        }
Exemplo n.º 18
0
 public void deleteExecutionBehavior(BehaviorExecution be)
 {
     if (be == null)
         return;
     allBehaviors.Remove(be);
     foreach (SchedInfo info in behaviors)
     {
         if (info.be == be)
         {
             behaviors.Remove(info);
             return;
         }
     }
 }